Subversion Repositories gelsvn

Rev

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

Rev 364 Rev 428
Line 82... Line 82...
82
      delete_node(node->right);
82
      delete_node(node->right);
83
    delete node;
83
    delete node;
84
  }
84
  }
85
 
85
 
86
  void BSPTree::subdivide_node(BSPNode &node, BBox &bbox, 
86
  void BSPTree::subdivide_node(BSPNode &node, BBox &bbox, 
87
                   unsigned int level, 
87
                               unsigned int level, 
88
                   vector<ISectTri*>& objects, 
88
                               vector<ISectTri*>& objects, 
89
                   vector<TriAccel*>& tri_objects) 
89
                               vector<TriAccel*>& tri_objects) 
90
  {
90
  {
91
    const int TESTS = 2;
91
    const int TESTS = 2;
92
    
92
    
93
    if (objects.size()<=max_objects || level==max_level) 
93
    if (objects.size()<=max_objects || level==max_level) 
94
    {
94
    {
Line 99... Line 99...
99
      node.id = all_objects.size();
99
      node.id = all_objects.size();
100
      node.count = objects.size();
100
      node.count = objects.size();
101
        
101
        
102
      for(unsigned int i = 0; i < objects.size(); ++i) 
102
      for(unsigned int i = 0; i < objects.size(); ++i) 
103
      {
103
      {
104
    all_objects.push_back(objects[i]);
104
        all_objects.push_back(objects[i]);
105
    all_triaccel.push_back(tri_objects[i]);
105
        all_triaccel.push_back(tri_objects[i]);
106
      }  
106
      }  
107
    } 
107
    } 
108
    else 
108
    else 
109
    {
109
    {
110
      bool right_zero=false;
110
      bool right_zero=false;
Line 124... Line 124...
124
      double min_cost=CGLA::BIG;
124
      double min_cost=CGLA::BIG;
125
      int new_pos = -1;      
125
      int new_pos = -1;      
126
 
126
 
127
      for(i=0;i<3;i++) 
127
      for(i=0;i<3;i++) 
128
      {
128
      {
129
    for(int k=1;k<TESTS;k++) 
129
        for(int k=1;k<TESTS;k++) 
130
    {
130
        {
131
      BBox left_bbox = bbox;
131
          BBox left_bbox = bbox;
132
      BBox right_bbox = bbox;
132
          BBox right_bbox = bbox;
133
                
133
                    
134
      double center = (bbox.max_corner[i]- bbox.min_corner[i])*(double)k/(double)TESTS + bbox.min_corner[i];
134
          double center = (bbox.max_corner[i]- bbox.min_corner[i])*(double)k/(double)TESTS + bbox.min_corner[i];
135
      node.plane = center;
135
          node.plane = center;
136
      
136
          
137
      left_bbox.max_corner[i] = center; 
137
          left_bbox.max_corner[i] = center; 
138
      right_bbox.min_corner[i] = center; 
138
          right_bbox.min_corner[i] = center; 
139
 
139
 
140
      // Try putting the triangles in the left and right boxes
140
          // Try putting the triangles in the left and right boxes
141
      int left_count = 0;
141
          int left_count = 0;
142
      int right_count = 0;
142
          int right_count = 0;
143
      for(unsigned int j=0;j<objects.size();j++) 
143
          for(unsigned int j=0;j<objects.size();j++) 
144
      {
144
          {
145
        ISectTri* tri = objects[j];
145
            ISectTri* tri = objects[j];
146
        left_count += left_bbox.intersect_triangle(*tri);
146
            left_count += left_bbox.intersect_triangle(*tri);
147
        right_count += right_bbox.intersect_triangle(*tri);
147
            right_count += right_bbox.intersect_triangle(*tri);
148
      }
148
          }
149
 
149
 
150
      //double len = bbox.max_corner[i] - bbox.min_corner[i];
150
          //double len = bbox.max_corner[i] - bbox.min_corner[i];
151
      double cost = left_count*left_bbox.area() + right_count*right_bbox.area(); // - len*len;
151
          double cost = left_count*left_bbox.area() + right_count*right_bbox.area(); // - len*len;
152
      if(cost < min_cost) 
152
          if(cost < min_cost) 
153
      {
153
          {
154
        min_cost = cost;
154
            min_cost = cost;
155
        new_axis = i;
155
            new_axis = i;
156
        new_pos = k;
156
            new_pos = k;
157
        right_zero = (right_count==0);
157
            right_zero = (right_count==0);
158
        left_zero = (left_count==0);
158
            left_zero = (left_count==0);
159
      }
159
          }
160
    }
160
        }
161
      }
161
      }
162
      node.axis_leaf = new_axis;
162
      node.axis_leaf = new_axis;
163
      left_node->axis_leaf = static_cast<unsigned char>(-1); 
163
      left_node->axis_leaf = static_cast<unsigned char>(-1); 
164
      right_node->axis_leaf = static_cast<unsigned char>(-1); 
164
      right_node->axis_leaf = static_cast<unsigned char>(-1); 
165
 
165
 
Line 171... Line 171...
171
      double center = size*(double)new_pos/(double)TESTS + bbox.min_corner[node.axis_leaf];
171
      double center = size*(double)new_pos/(double)TESTS + bbox.min_corner[node.axis_leaf];
172
      double diff = f_eps < size/8.0 ? f_eps : size/8.0;
172
      double diff = f_eps < size/8.0 ? f_eps : size/8.0;
173
      
173
      
174
      if (left_zero) 
174
      if (left_zero) 
175
      {
175
      {
176
    // Find min position of all triangle vertices and place the center there
176
        // Find min position of all triangle vertices and place the center there
177
    center = bbox.max_corner[node.axis_leaf];
177
        center = bbox.max_corner[node.axis_leaf];
178
    for(unsigned int j=0;j<objects.size();j++) 
178
        for(unsigned int j=0;j<objects.size();j++) 
179
    {
179
        {
180
      ISectTri* tri = objects[j];
180
          ISectTri* tri = objects[j];
181
      if (tri->point0[node.axis_leaf]<center)
181
          if (tri->point0[node.axis_leaf]<center)
182
        center=tri->point0[node.axis_leaf];
182
            center=tri->point0[node.axis_leaf];
183
      if (tri->point1[node.axis_leaf]<center)
183
          if (tri->point1[node.axis_leaf]<center)
184
        center=tri->point1[node.axis_leaf];
184
            center=tri->point1[node.axis_leaf];
185
      if (tri->point2[node.axis_leaf]<center)
185
          if (tri->point2[node.axis_leaf]<center)
186
        center=tri->point2[node.axis_leaf];
186
            center=tri->point2[node.axis_leaf];
187
    }
187
        }
188
    center -= diff;
188
        center -= diff;
189
      }
189
      }
190
      if (right_zero) 
190
      if (right_zero) 
191
      {
191
      {
192
    // Find max position of all triangle vertices and place the center there
192
        // Find max position of all triangle vertices and place the center there
193
    center = bbox.min_corner[node.axis_leaf];
193
        center = bbox.min_corner[node.axis_leaf];
194
    for(unsigned int j=0;j<objects.size();j++) 
194
        for(unsigned int j=0;j<objects.size();j++) 
195
    {
195
        {
196
      ISectTri* tri = objects[j];
196
          ISectTri* tri = objects[j];
197
      if (tri->point0[node.axis_leaf]>center)
197
          if (tri->point0[node.axis_leaf]>center)
198
        center=tri->point0[node.axis_leaf];
198
            center=tri->point0[node.axis_leaf];
199
      if (tri->point1[node.axis_leaf]>center)
199
          if (tri->point1[node.axis_leaf]>center)
200
        center=tri->point1[node.axis_leaf];
200
            center=tri->point1[node.axis_leaf];
201
      if (tri->point2[node.axis_leaf]>center)
201
          if (tri->point2[node.axis_leaf]>center)
202
        center=tri->point2[node.axis_leaf];
202
            center=tri->point2[node.axis_leaf];
203
    }
203
        }
204
    center += diff;
204
        center += diff;
205
      }
205
      }
206
 
206
 
207
      node.plane = center;
207
      node.plane = center;
208
      left_bbox.max_corner[node.axis_leaf] = center; 
208
      left_bbox.max_corner[node.axis_leaf] = center; 
209
      right_bbox.min_corner[node.axis_leaf] = center;  
209
      right_bbox.min_corner[node.axis_leaf] = center;  
210
            
210
            
211
      // Now put the triangles in the right and left node
211
      // Now put the triangles in the right and left node
212
      for(i=0;i<objects.size();i++) 
212
      for(i=0;i<objects.size();i++) 
213
      {
213
      {
214
    ISectTri* tri = objects[i];
214
        ISectTri* tri = objects[i];
215
    TriAccel *tri_accel = tri_objects[i];
215
        TriAccel *tri_accel = tri_objects[i];
216
    if (left_bbox.intersect_triangle(*tri)) 
216
        if (left_bbox.intersect_triangle(*tri)) 
217
    {
217
        {
218
      left_objects.push_back(tri);
218
          left_objects.push_back(tri);
219
      tri_left_objects.push_back(tri_accel);
219
          tri_left_objects.push_back(tri_accel);
220
    }
220
        }
221
    if (right_bbox.intersect_triangle(*tri)) 
221
        if (right_bbox.intersect_triangle(*tri)) 
222
    {
222
        {
223
      right_objects.push_back(tri);
223
          right_objects.push_back(tri);
224
      tri_right_objects.push_back(tri_accel);
224
          tri_right_objects.push_back(tri_accel);
225
    }
225
        }
226
      }
226
      }
227
    //if (left_zero||right_zero)
227
    //if (left_zero||right_zero)
228
    //  cout << left_objects.size() << "," << right_objects.size() << "," << level << endl;
228
    //  cout << left_objects.size() << "," << right_objects.size() << "," << level << endl;
229
 
229
 
230
      objects.clear();
230
      objects.clear();
Line 240... Line 240...
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<const 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
      const 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;
258
    new_tri.point0 = transforms[i].mul_3D_point(mesh->geometry.vertex(face[0]));
258
        new_tri.point0 = transforms[i].mul_3D_point(mesh->geometry.vertex(face[0]));
259
    new_tri.point1 = transforms[i].mul_3D_point(mesh->geometry.vertex(face[1]));
259
        new_tri.point1 = transforms[i].mul_3D_point(mesh->geometry.vertex(face[1]));
260
    new_tri.point2 = transforms[i].mul_3D_point(mesh->geometry.vertex(face[2]));
260
        new_tri.point2 = transforms[i].mul_3D_point(mesh->geometry.vertex(face[2]));
261
    new_tri.edge0 = new_tri.point1 - new_tri.point0;
261
        new_tri.edge0 = new_tri.point1 - new_tri.point0;
262
    new_tri.edge1 = new_tri.point2 - new_tri.point0;
262
        new_tri.edge1 = new_tri.point2 - new_tri.point0;
263
    new_tri.mesh_id = i;
263
        new_tri.mesh_id = i;
264
    new_tri.tri_id = j;
264
        new_tri.tri_id = j;
265
    isecttris.push_back(new_tri);
265
        isecttris.push_back(new_tri);
266
    TriAccel ta;
266
        TriAccel ta;
267
    create_tri_accel(new_tri.point0, new_tri.point1, new_tri.point2, ta);
267
        create_tri_accel(new_tri.point0, new_tri.point1, new_tri.point2, ta);
268
    ta.mesh_id = i;
268
        ta.mesh_id = i;
269
    ta.tri_id = j;
269
        ta.tri_id = j;
270
    triaccel.push_back(ta);
270
        triaccel.push_back(ta);
271
      }
271
      }
272
    }
272
    }
273
 
273
 
274
    max_objects = _max_objects;
274
    max_objects = _max_objects;
275
    max_level = _max_level;
275
    max_level = _max_level;
Line 313... Line 313...
313
    {
313
    {
314
      vector<ISectTri*> objects;
314
      vector<ISectTri*> objects;
315
      vector<TriAccel*> tri_objects;
315
      vector<TriAccel*> tri_objects;
316
      for(unsigned int i=0;i<isecttris.size();i++) 
316
      for(unsigned int i=0;i<isecttris.size();i++) 
317
      {
317
      {
318
    ISectTri* tri = &isecttris[i];
318
        ISectTri* tri = &isecttris[i];
319
    TriAccel* tri_accel = &triaccel[i];
319
        TriAccel* tri_accel = &triaccel[i];
320
    objects.push_back(tri);
320
        objects.push_back(tri);
321
    tri_objects.push_back(tri_accel);
321
        tri_objects.push_back(tri_accel);
322
      }
322
      }
323
      subdivide_node(*root, bbox, 0, objects, tri_objects);
323
      subdivide_node(*root, bbox, 0, objects, tri_objects);
324
      b_is_build = true;
324
      b_is_build = true;
325
    }
325
    }
326
    isecttris.clear();
-
 
327
    all_objects.clear();
-
 
328
    make_fast_tree(root);
326
    make_fast_tree(root);
329
  }
327
  }
330
 
328
 
331
  bool BSPTree::is_build() 
329
  bool BSPTree::is_build() 
332
  {
330
  {
Line 405... Line 403...
405
    if (node.axis_leaf==4) 
403
    if (node.axis_leaf==4) 
406
    {
404
    {
407
      found = false; 
405
      found = false; 
408
      for(i=0;i<node.count;i++) 
406
      for(i=0;i<node.count;i++) 
409
      {
407
      {
410
//  const TriAccel* tri2 = all_triaccel[node.id+i];
408
//        const TriAccel* tri2 = all_triaccel[node.id+i];
411
    const ISectTri* tri = all_objects[node.id+i];
409
        const ISectTri* tri = all_objects[node.id+i];
412
//          if (intersect2(ray, *tri2, t_max))  
410
//        if (intersect2(ray, *tri2, t_max))  
413
//              found=true;
411
//          found=true;
414
    if (intersect(ray, *tri, t_max))  
412
        if (intersect(ray, *tri, t_max))  
415
      found=true;
413
          found=true;
416
      }
414
      }
417
      if (found)
415
      if (found)
418
    return true;
416
    return true;
419
      else 
417
      else 
420
    return false;
418
    return false;
Line 423... Line 421...
423
    {
421
    {
424
      BSPNode *near_node;
422
      BSPNode *near_node;
425
      BSPNode *far_node;
423
      BSPNode *far_node;
426
      if (ray.direction[node.axis_leaf]>=0) 
424
      if (ray.direction[node.axis_leaf]>=0) 
427
      {
425
      {
428
    near_node = node.left;
426
        near_node = node.left;
429
    far_node = node.right;
427
        far_node = node.right;
430
      } 
428
      } 
431
      else 
429
      else 
432
      {
430
      {
433
    near_node = node.right;
431
        near_node = node.right;
434
    far_node = node.left;
432
        far_node = node.left;
435
      }
433
      }
436
 
434
 
437
      // In order to avoid instability
435
      // In order to avoid instability
438
      double t;
436
      double t;
439
      if (fabs(ray.direction[node.axis_leaf])<d_eps)
437
      if (fabs(ray.direction[node.axis_leaf])<d_eps)
440
    t = (node.plane - ray.origin[node.axis_leaf])/d_eps;// intersect node plane;
438
        t = (node.plane - ray.origin[node.axis_leaf])/d_eps;// intersect node plane;
441
      else
439
      else
442
    t = (node.plane - ray.origin[node.axis_leaf])/ray.direction[node.axis_leaf];// intersect node plane;
440
        t = (node.plane - ray.origin[node.axis_leaf])/ray.direction[node.axis_leaf];// intersect node plane;
443
      
441
      
444
      if (t>t_max) 
442
      if (t>t_max) 
445
        return intersect_node(ray, *near_node, t_min, t_max);
443
        return intersect_node(ray, *near_node, t_min, t_max);      
446
      
-
 
447
      else if (t<t_min) 
444
      else if (t<t_min) 
448
    return intersect_node(ray, *far_node, t_min, t_max);
445
        return intersect_node(ray, *far_node, t_min, t_max);
449
      else 
446
      else 
450
      {
447
      {
451
    if (intersect_node(ray, *near_node, t_min, t))
448
        if (intersect_node(ray, *near_node, t_min, t))
452
      return true;
449
          return true;
453
    else 
450
        else 
454
      return intersect_node(ray, *far_node, t, t_max);
451
          return intersect_node(ray, *far_node, t, t_max);
455
      }
452
      }
456
    }
453
    }
457
  }
454
  }
458
 
455
 
459
  bool BSPTree::intersect(Ray &ray) const 
456
  bool BSPTree::intersect(Ray &ray) const 
Line 472... Line 469...
472
//    intersect_fast_node(ray, &fast_tree[0], t_min, t_max);
469
//    intersect_fast_node(ray, &fast_tree[0], t_min, t_max);
473
    //  if (!ray.has_hit)
470
    //  if (!ray.has_hit)
474
    //return false;
471
    //return false;
475
    else 
472
    else 
476
    {
473
    {
477
 
-
 
478
        //printf("HIT\n");
474
      //printf("HIT\n");
479
 
-
 
480
 
475
 
481
      // Calculate the normal at the intersection
476
      // Calculate the normal at the intersection
482
        ray.id = reinterpret_cast<int>(ray.hit_object);
477
      ray.id = reinterpret_cast<int>(ray.hit_object);
483
        ray.hit_object = trimesh[ray.id];
478
      ray.hit_object = trimesh[ray.id];
484
        
479
      
485
        Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
480
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
486
        Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
481
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
487
        Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
482
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
488
        Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
483
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
489
        ray.hit_normal = transforms[ray.id].mul_3D_vector(
484
      ray.hit_normal = transforms[ray.id].mul_3D_vector(
490
            normalize(normal0*(1 - ray.u - ray.v)
485
          normalize(normal0*(1 - ray.u - ray.v)
491
            +normal1*ray.u
486
          +normal1*ray.u
492
            +normal2*ray.v));
487
          +normal2*ray.v));
493
        
488
      
494
        ray.hit_pos = ray.origin + ray.direction*ray.dist;
489
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
495
/*
490
/*
496
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
491
      Vec3i face = ray.hit_object->normals.face(ray.hit_face_id);
497
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
492
      Vec3f normal0 = ray.hit_object->normals.vertex(face[0]);
498
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
493
      Vec3f normal1 = ray.hit_object->normals.vertex(face[1]);
499
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
494
      Vec3f normal2 = ray.hit_object->normals.vertex(face[2]);
500
      ray.hit_normal = normalize(normal0*(1 - ray.u - ray.v)
495
      ray.hit_normal = normalize(normal0*(1 - ray.u - ray.v)
501
                 +normal1*ray.u
496
                 +normal1*ray.u
502
                 +normal2*ray.v);
497
                 +normal2*ray.v);
503
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
498
      ray.hit_pos = ray.origin + ray.direction*ray.dist;
504
*/
499
*/
505
 
-
 
506
      return true;
500
      return true;
507
    }
501
    }
508
  }
502
  }
509
 
503
 
510
  const int MAX_DEPTH=25;
504
  const int MAX_DEPTH=25;
Line 519... Line 513...
519
 
513
 
520
  void BSPTree::push_fast_bsp_node(BSPNode *node, int id) 
514
  void BSPTree::push_fast_bsp_node(BSPNode *node, int id) 
521
  {
515
  {
522
    if (node->axis_leaf==4)  // It is a leaf
516
    if (node->axis_leaf==4)  // It is a leaf
523
    {
517
    {
524
        //assert(false);
518
      //assert(false);
525
        //TODO: cant compile on 64 bit gcc
519
      //TODO: cant compile on 64 bit gcc
526
 
520
 
527
        //fast_tree[id].leaf.flagAndOffset = (unsigned int)1<<31 | (unsigned int)(&all_triaccel[node->id]);
521
      //fast_tree[id].leaf.flagAndOffset = (unsigned int)1<<31 | (unsigned int)(&all_triaccel[node->id]);
528
      fast_tree[id].leaf.count = node->count;
522
      fast_tree[id].leaf.count = node->count;
529
    } 
523
    } 
530
    else // It is an inner node
524
    else // It is an inner node
531
    { 
525
    { 
532
      FastBSPNode fnode;
526
      FastBSPNode fnode;
Line 575... Line 569...
575
    // Precalculate one over dir
569
    // Precalculate one over dir
576
    double one_over_dir[3];
570
    double one_over_dir[3];
577
    for(int i=0;i<3;i++) 
571
    for(int i=0;i<3;i++) 
578
    {
572
    {
579
      if (ray.direction[i]!=0)
573
      if (ray.direction[i]!=0)
580
    one_over_dir[i]=1.0/ray.direction[i];
574
        one_over_dir[i]=1.0/ray.direction[i];
581
      else
575
      else
582
    one_over_dir[i]=1.0/d_eps;
576
        one_over_dir[i]=1.0/d_eps;
583
    }
577
    }
584
 
578
 
585
    int dimension;
579
    int dimension;
586
    while(1) 
580
    while(1) 
587
    {
581
    {
588
      while(!ABSP_ISLEAF(node)) 
582
      while(!ABSP_ISLEAF(node)) 
589
      {
583
      {
590
    dimension = ABSP_DIMENSION(node);
584
        dimension = ABSP_DIMENSION(node);
591
    t = (node->inner.splitCoordinate - ray.origin[dimension])*one_over_dir[dimension];
585
        t = (node->inner.splitCoordinate - ray.origin[dimension])*one_over_dir[dimension];
592
    if (t>=t_max) 
586
        if (t>=t_max) 
593
      node = ABSP_NEARNODE(node);
587
          node = ABSP_NEARNODE(node);
594
    else if (t<=t_min)
588
        else if (t<=t_min)
595
      node = ABSP_FARNODE(node);
589
          node = ABSP_FARNODE(node);
596
    else 
590
        else 
597
    {
591
        {
598
      // Stack push
592
          // Stack push
599
      stack[stack_id].node = ABSP_FARNODE(node);
593
          stack[stack_id].node = ABSP_FARNODE(node);
600
      stack[stack_id].t_min = t;
594
          stack[stack_id].t_min = t;
601
      stack[stack_id++].t_max = t_max;
595
          stack[stack_id++].t_max = t_max;
602
      // Set current node to near side
596
          // Set current node to near side
603
      node = ABSP_NEARNODE(node);
597
          node = ABSP_NEARNODE(node);
604
      t_max = t;
598
          t_max = t;
605
    }
599
        }
606
      }
600
      }
607
      
601
      
608
      IntersectAlltrianglesInLeaf(&node->leaf, ray, t_max);
602
      IntersectAlltrianglesInLeaf(&node->leaf, ray, t_max);
609
      if (ray.dist<t_max)
603
      if (ray.dist<t_max)
610
    return;
604
        return;
611
      if (stack_id==0)
605
      if (stack_id==0)
612
    return;
606
        return;
613
      // Stack pop
607
      // Stack pop
614
      
608
      
615
      node = stack[--stack_id].node;
609
      node = stack[--stack_id].node;
616
      t_min = stack[stack_id].t_min;
610
      t_min = stack[stack_id].t_min;
617
      t_max = stack[stack_id].t_max;
611
      t_max = stack[stack_id].t_max;
Line 646... Line 640...
646
//      const double eps = 0.001f;
640
//      const double eps = 0.001f;
647
/********* Complain!!!!!!!!!!!!!!!! *****************/      
641
/********* Complain!!!!!!!!!!!!!!!! *****************/      
648
    //p = cross(direction, edge1);
642
    //p = cross(direction, edge1);
649
    // Why the &%¤/ is this so much faster????? - Because of MS Compiler - the intel compiler does it right!!
643
    // Why the &%¤/ is this so much faster????? - Because of MS Compiler - the intel compiler does it right!!
650
    p.set(direction[1] * edge1[2] - direction[2] * edge1[1], 
644
    p.set(direction[1] * edge1[2] - direction[2] * edge1[1], 
651
      direction[2] * edge1[0] - direction[0] * edge1[2], 
645
          direction[2] * edge1[0] - direction[0] * edge1[2], 
652
      direction[0] * edge1[1] - direction[1] * edge1[0]);
646
          direction[0] * edge1[1] - direction[1] * edge1[0]);
653
/****************************************************/
647
/****************************************************/
654
    a = dot(edge0,p);
648
    a = dot(edge0,p);
655
    if (a>-d_eps && a<d_eps)
649
    if (a>-d_eps && a<d_eps)
656
      return false;
650
      return false;
657
  // Just delay these 
651
  // Just delay these