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

  • This topic has 1 reply, 2 voices, and was last updated 1 year ago by Yant.
Viewing 1 reply thread
  • Author
    Posts
    • #16411 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*/

    • #16446 Score: 0
      Yant
      Participant

      Vector3f类型传入的是某个点的坐标(x,y,z)
      用Vector3f*实际上传入的是含有三个顶点的v数组,这个变量的定义在triangle.hpp中可以看到

Viewing 1 reply thread
  • You must be logged in to reply to this topic.