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