Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业2insideTriangle函数最后一个参数 const Vector3f* v

Viewing 0 reply threads
  • Author
    Posts
    • #16410 Score: 0
      wawvvv
      Participant

      判断点是否在三角形内的函数,最后一个参数为:const Vector3f* v。这个v不应该是指向vector3f类型的指针吗? 为什么在函数体中可以直接用v[0]表示第0个顶点?

      static bool insideTriangle(float x, float y, const Vector3f* v)
      {
      // TODO : Implement this function to check if the point (x, y) is inside the triangle represented by _v[0], _v[1], _v[2]
      //Eigen::Vector3f point = { x, y, 1.0f };
      Eigen::Vector3f point = Eigen::Vector3f(x, y, 1.0f);
      Eigen::Vector3f a = v[0] – v[1];
      Eigen::Vector3f b = v[1] – v[2];
      Eigen::Vector3f c = v[2] – v[0];

      在void rst::rasterizer::rasterize_triangle(const Triangle& t) 函数中给上面判断是否在三角形内函数的传参如下:

      if (insideTriangle(i+0.5, j+0.5, t.v))
      
      这里的t.v在Triangle类中定义为:
      

      Vector3f v[3]; /*the original coordinates of the triangle, v0, v1, v2 in counter clockwise order*/

Viewing 0 reply threads
  • You must be logged in to reply to this topic.