Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 Triangle.hpp中两个重名函数的区别是什么?

Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #5296 Score: 0
      Keneyr
      Participant
      7 pts

      RT

      Intersection getIntersection(Ray ray)
          {
              //std::cout<<"1"<<std::endl;
              Intersection intersec;
      
              if (bvh) {
                  intersec = bvh->Intersect(ray);
              }
      
              return intersec;
          }
      inline Intersection Triangle::getIntersection(Ray ray)
      {
      <code></code>

      }`
      debug也看不出来,感觉两个都在调用···但是看不出来哪个是啥情况下调用的

    • #5297 Score: 0
      arc
      Participant
      5 pts

      这是两个不同类的方法吧, 一个是 Triangle 的, 另一个是 MeshTriangle 的.

      • #5298 Score: 0
        Keneyr
        Participant
        7 pts

        额,这我也知道。。。

        • #5299 Score: 1
          arc
          Participant
          5 pts

          首先调用链 Renderer:Render() –> Scene::castRay() –> Scene::Intersect() -> BVHAccel::Intersect() –> BVHAccel::getIntersection(), 此时求的是光线与 Scene 的 BVH 的交, 从 main.cpp 可以知道 BVH 里的物体只有类型为 MeshTriangle 的对象, 那么在 Scene 的叶结点处调用光线与 MeshTriangle 的求交, 即 BVHAccel::getIntersection() –> MeshTriangle::getIntersection().
          MeshTriangle 构造时从 .obj 读取三角形的信息, 将三角形坐标存放在成员 std::vector<Triangle> triangles 内, 并在构造函数的最后构造了它的 BVH. 那么对一个 MeshTriangle 求交时光线就和它的 BVH 求交, 遍历到叶结点时与 Triangle 求交, 即 MeshTriangle::getIntersection() –> BVHAccel::Intersect() –> BVHAccel::getIntersection() –> … –> Triangle::getIntersection().
          总的来说, 就是光线先与 Scene 的 BVH 求交, 再与 MeshTriangle 的 BVH 求交, 最后与 Triangle 求交.

          This post has received 1 vote up.
          • This reply was modified 4 years, 3 months ago by arc.
          • #5302 Score: 0
            Keneyr
            Participant
            7 pts

            !!谢谢巨巨~这就是我想看的!!

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