Subversion Repositories gelsvn

Rev

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

Rev 314 Rev 319
Line 239... Line 239...
239
    bbox.compute_bbox(isecttris);
239
    bbox.compute_bbox(isecttris);
240
    bbox.min_corner-=Vec3f(1.0);
240
    bbox.min_corner-=Vec3f(1.0);
241
    bbox.max_corner+=Vec3f(1.0);
241
    bbox.max_corner+=Vec3f(1.0);
242
  }
242
  }
243
 
243
 
244
  void BSPTree::init(vector<TriMesh*>& _trimesh, 
244
  void BSPTree::init(vector<const TriMesh*>& _trimesh, 
245
		     vector<Mat4x4f>& _transforms, 
245
		     vector<Mat4x4f>& _transforms, 
246
		     int _max_objects, int _max_level) 
246
		     int _max_objects, int _max_level) 
247
  {
247
  {
248
    trimesh = _trimesh;
248
    trimesh = _trimesh;
249
    transforms = _transforms;
249
    transforms = _transforms;
250
    for(unsigned int i=0;i<trimesh.size();i++) 
250
    for(unsigned int i=0;i<trimesh.size();i++) 
251
    {
251
    {
252
      TriMesh *mesh = trimesh[i];
252
      const TriMesh *mesh = trimesh[i];
253
      // Loop through all triangles and add them to intersection structure
253
      // Loop through all triangles and add them to intersection structure
254
      for(int j=0;j<mesh->geometry.no_faces();j++) 
254
      for(int j=0;j<mesh->geometry.no_faces();j++) 
255
      {
255
      {
256
	Vec3i face = mesh->geometry.face(j);
256
	Vec3i face = mesh->geometry.face(j);
257
	ISectTri new_tri;
257
	ISectTri new_tri;
Line 274... Line 274...
274
    max_objects = _max_objects;
274
    max_objects = _max_objects;
275
    max_level = _max_level;
275
    max_level = _max_level;
276
    init();
276
    init();
277
  }
277
  }
278
 
278
 
279
  void BSPTree::init(TriMesh* mesh, Mat4x4f transform, 
279
  void BSPTree::init(const TriMesh* mesh, Mat4x4f transform, 
280
		     vector<int> &trilist, 
280
		     vector<int> &trilist, 
281
		     int _max_objects, int _max_level) 
281
		     int _max_objects, int _max_level) 
282
  {
282
  {
283
    trimesh.push_back(mesh);
283
    trimesh.push_back(mesh);
284
    transforms.push_back(transform);
284
    transforms.push_back(transform);
Line 471... Line 471...
471
    if (!ray.has_hit)
471
    if (!ray.has_hit)
472
      return false;
472
      return false;
473
    else 
473
    else 
474
    {
474
    {
475
      // Calculate the normal at the intersection
475
      // Calculate the normal at the intersection
-
 
476
		ray.id = (int)ray.hit_object;
476
      ray.hit_object = trimesh[(int)ray.hit_object];
477
		ray.hit_object = trimesh[ray.id];
-
 
478
		
-
 
479
		Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
-
 
480
		Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
-
 
481
		Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
-
 
482
		Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
-
 
483
		ray.hit_normal = transforms[ray.id].mul_3D_vector(
-
 
484
			normalize(normal0*(1 - ray.u - ray.v)
-
 
485
			+normal1*ray.u
-
 
486
			+normal2*ray.v));
-
 
487
		
-
 
488
		ray.hit_pos = ray.origin + ray.direction*ray.dist;
477
/*
489
/*
478
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
490
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
479
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
491
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
480
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
492
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
481
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
493
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
482
      ray.hit_normal = normalize(normal0*(1 - ray.u - ray.v)
494
      ray.hit_normal = normalize(normal0*(1 - ray.u - ray.v)
483
				 +normal1*ray.u
495
				 +normal1*ray.u
484
				 +normal2*ray.v);
496
				 +normal2*ray.v);
485
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
497
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
486
*/
498
*/
-
 
499
 
487
      return true;
500
	  return true;
488
    }
501
    }
489
  }
502
  }
490
 
503
 
491
  const int MAX_DEPTH=25;
504
  const int MAX_DEPTH=25;
492
 
505