Subversion Repositories gelsvn

Rev

Rev 309 | Rev 312 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 309 Rev 310
Line 22... Line 22...
22
#include "Geometry/AABox.h"
22
#include "Geometry/AABox.h"
23
#include "Geometry/OBox.h"
23
#include "Geometry/OBox.h"
24
#include "Util/Timer.h"
24
#include "Util/Timer.h"
25
#include "Camera.h"
25
#include "Camera.h"
26
 
26
 
27
//#define USE_BDL
27
// #define USE_BSP
28
 
28
 
29
using namespace std;
29
using namespace std;
30
using namespace CGLA;
30
using namespace CGLA;
31
using namespace Geometry;
31
using namespace Geometry;
32
using namespace HMesh;
32
using namespace HMesh;
33
using namespace GLGraphics;
33
using namespace GLGraphics;
34
 
34
 
35
/*
35
/*
36
 * TODO: 
36
 * TODO: 
37
 * - BSP fix bug preventing bunny model from loading.
37
 * - BSP find out why BSP tree is suboptimal for the bunny mesh.
38
 * - BBOX remove HMesh dependency - that is crazy.
38
 * - BBOX remove HMesh dependency - that is crazy.
39
 * - BBox visit child nodes in order of how far away the intersection point on
39
 * - BBox visit child nodes in order of how far away the intersection point on
40
 *        the bbox is. Closest nodes visited first. Cull nodes farther than
40
 *        the bbox is. Closest nodes visited first. Cull nodes farther than
41
 *        an actual intersection point.
41
 *        an actual intersection point.
42
 * - BBox Smooth interpolation of triangle normals. Straightforward.
42
 * - BBox Smooth interpolation of triangle normals. Straightforward.
43
 */
43
 */
44
					
44
					
45
 
45
 
46
namespace
46
namespace
47
{
47
{
48
  const int MAX_OBJECTS = 2;   // Maximum number of triangles in a BSP tree node
48
  const int MAX_OBJECTS = 4;   // Maximum number of triangles in a BSP tree node
49
  const int MAX_LEVEL = 20;    // Maximum number of BSP tree subdivisions
49
  const int MAX_LEVEL = 20;    // Maximum number of BSP tree subdivisions
50
 
50
 
51
  const unsigned int TEX_SIZE = 512;
51
  const unsigned int TEX_SIZE = 512;
52
 
52
 
53
  bool raytrace = false;
53
  bool raytrace = false;
Line 85... Line 85...
85
  {
85
  {
86
    return rand()/static_cast<double>(RAND_MAX);
86
    return rand()/static_cast<double>(RAND_MAX);
87
  }
87
  }
88
		
88
		
89
		AABBTree bb_tree;
89
  AABBTree bb_tree;		
90
		
-
 
91
 
-
 
92
}
90
}
93
 
91
 
94
void spin(int x);
92
void spin(int x);
95
 
93
 
96
//////////////////////////////////////////////////////////////
94
//////////////////////////////////////////////////////////////
Line 345... Line 343...
345
#else
343
#else
346
										float t = FLT_MAX;
344
			float t = FLT_MAX;
347
										bb_tree.intersect(r);
345
			bb_tree.intersect(r);
348
										if(r.has_hit)
346
			if(r.has_hit)
349
												sum += Vec3d(shade_ray[0](r));
347
			  sum += Vec3d(shade_ray[0](r));
-
 
348
			else 
350
										else sum += background;
349
			  sum += background;
351
#endif		
350
#endif		
352
								}
351
		  }
353
 
352
 
354
						image[i][j] = Vec3f(sum/static_cast<double>(PIXEL_SUBDIVS*PIXEL_SUBDIVS));
353
		  image[i][j] = Vec3f(sum/static_cast<double>(PIXEL_SUBDIVS*PIXEL_SUBDIVS));
355
				}
354
	  }
Line 374... Line 373...
374
  else
373
  else
375
  {
374
  {
376
    glEnable(GL_DEPTH_TEST);
375
    glEnable(GL_DEPTH_TEST);
377
 
376
 
378
    cam->glSetPerspective(winx, winy);
377
    cam->glSetPerspective(winx, winy);
379
		vctrl->reset_projection();
-
 
380
 
378
 
381
    glClearColor(background[0], background[1], background[2], 1.0);
379
    glClearColor(background[0], background[1], background[2], 1.0);
382
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
380
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
383
    glLoadIdentity();
381
    glLoadIdentity();
384
 
382
 
Line 398... Line 396...
398
  winx = w; winy = h;
396
  winx = w; winy = h;
399
 
397
 
400
  vctrl->reshape(winx, winy);
398
  vctrl->reshape(winx, winy);
401
 
399
 
402
  glViewport(0, 0, winx, winy);
400
  glViewport(0, 0, winx, winy);
403
  set_ortho_proj();
-
 
404
}
401
}
405
 
402
 
406
void keyboard(unsigned char key, int x, int y)
403
void keyboard(unsigned char key, int x, int y)
407
{
404
{
408
  switch(key)
405
  switch(key)