Subversion Repositories gelsvn

Rev

Rev 451 | Rev 595 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 451 Rev 541
Line 464... Line 464...
464
    {
464
    {
465
      // Calculate the normal at the intersection
465
      // Calculate the normal at the intersection
466
      ray.id = reinterpret_cast<int>(ray.hit_object);
466
      ray.id = reinterpret_cast<int>(ray.hit_object);
467
      ray.hit_object = trimesh[ray.id];
467
      ray.hit_object = trimesh[ray.id];
468
      
468
      
469
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
469
      const Vec3i& face = ray.hit_object->normals.face(ray.hit_face_id);
470
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
470
      const Vec3f& normal0 = ray.hit_object->normals.vertex(face[0]);
471
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
471
      const Vec3f& normal1 = ray.hit_object->normals.vertex(face[1]);
472
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
472
      const Vec3f& normal2 = ray.hit_object->normals.vertex(face[2]);
473
      ray.hit_normal = transforms[ray.id].mul_3D_vector(
473
      ray.hit_normal = transforms[ray.id].mul_3D_vector(
474
          normalize(normal0*(1 - ray.u - ray.v)
474
        normalize(normal0*(1 - ray.u - ray.v) + normal1*ray.u + normal2*ray.v));
475
          +normal1*ray.u
-
 
476
          +normal2*ray.v));
-
 
477
      
-
 
478
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
475
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
479
/*
476
/*
480
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
477
      const Vec3i& face = ray.hit_object->normals.face(ray.hit_face_id);
481
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
478
      const Vec3f& normal0 = ray.hit_object->normals.vertex(face[0]);
482
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
479
      const Vec3f& normal1 = ray.hit_object->normals.vertex(face[1]);
483
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
480
      const Vec3f& normal2 = ray.hit_object->normals.vertex(face[2]);
484
      ray.hit_normal = normalize(normal0*(1 - ray.u - ray.v)
481
      ray.hit_normal = normalize(normal0*(1 - ray.u - ray.v) + normal1*ray.u + normal2*ray.v);
485
                 +normal1*ray.u
-
 
486
                 +normal2*ray.v);
-
 
487
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
482
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
488
*/
483
*/
489
      return true;
484
      return true;
490
    }
485
    }
491
  }
486
  }
Line 541... Line 536...
541
    double t_max;
536
    double t_max;
542
  };
537
  };
543
 
538
 
544
  inline void IntersectAlltrianglesInLeaf(const BSPLeaf* leaf, Ray &ray, double t_max) {
539
  inline void IntersectAlltrianglesInLeaf(const BSPLeaf* leaf, Ray &ray, double t_max) {
545
    TriAccel** tri_acc_ptr = reinterpret_cast<TriAccel**>(leaf->flagAndOffset & (0x7FFFFFFF));
540
    TriAccel** tri_acc_ptr = reinterpret_cast<TriAccel**>(leaf->flagAndOffset & (0x7FFFFFFF));
546
    vector<TriAccel*>::iterator acc = vector<TriAccel*>::iterator(tri_acc_ptr);
-
 
547
    for(unsigned int i=0;i<leaf->count;++i)
541
    for(unsigned int i = 0; i < leaf->count; ++i)
548
      intersect2(ray, *(*acc++), t_max);
542
      intersect2(ray, *(*tri_acc_ptr + i), t_max);
549
  }
543
  }
550
 
544
 
551
  void BSPTree::intersect_fast_node(Ray &ray, const FastBSPNode *node, double t_min, double t_max) const 
545
  void BSPTree::intersect_fast_node(Ray &ray, const FastBSPNode *node, double t_min, double t_max) const 
552
  {
546
  {
553
    Stack stack[MAX_DEPTH];
547
    Stack stack[MAX_DEPTH];