clray

diff src/rt.cc @ 27:8b2f2ad14ae7

semi-fixed the kdtree construction
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 17 Aug 2010 20:35:00 +0100
parents 13091c00d7ca
children 97cfd9675310
line diff
     1.1 --- a/src/rt.cc	Tue Aug 17 01:19:43 2010 +0100
     1.2 +++ b/src/rt.cc	Tue Aug 17 20:35:00 2010 +0100
     1.3 @@ -135,6 +135,7 @@
     1.4  	return true;
     1.5  }
     1.6  
     1.7 +#define MIN(a, b)	((a) < (b) ? (a) : (b))
     1.8  static void dbg_set_gl_material(Material *mat)
     1.9  {
    1.10  	static Material def_mat = {{0.7, 0.7, 0.7, 1}, {0, 0, 0, 0}, 0, 0, 0};
    1.11 @@ -143,10 +144,10 @@
    1.12  
    1.13  	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat->kd);
    1.14  	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat->ks);
    1.15 -	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, mat->spow);
    1.16 +	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, MIN(mat->spow, 128.0f));
    1.17  }
    1.18  
    1.19 -void dbg_render_gl(Scene *scn)
    1.20 +void dbg_render_gl(Scene *scn, bool show_tree, bool show_obj)
    1.21  {
    1.22  	glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT);
    1.23  
    1.24 @@ -170,27 +171,33 @@
    1.25  	glLoadIdentity();
    1.26  	gluPerspective(45.0, (float)rinf.xsz / (float)rinf.ysz, 0.5, 1000.0);
    1.27  
    1.28 -	Material *materials = scn->get_materials();
    1.29 +	if(show_obj) {
    1.30 +		Material *materials = scn->get_materials();
    1.31  
    1.32 -	int num_faces = scn->get_num_faces();
    1.33 -	int cur_mat = -1;
    1.34 +		int num_faces = scn->get_num_faces();
    1.35 +		int cur_mat = -1;
    1.36  
    1.37 -	for(int i=0; i<num_faces; i++) {
    1.38 -		if(faces[i].matid != cur_mat) {
    1.39 -			if(cur_mat != -1) {
    1.40 -				glEnd();
    1.41 +		for(int i=0; i<num_faces; i++) {
    1.42 +			if(faces[i].matid != cur_mat) {
    1.43 +				if(cur_mat != -1) {
    1.44 +					glEnd();
    1.45 +				}
    1.46 +				dbg_set_gl_material(materials ? materials + faces[i].matid : 0);
    1.47 +				cur_mat = faces[i].matid;
    1.48 +				glBegin(GL_TRIANGLES);
    1.49  			}
    1.50 -			dbg_set_gl_material(materials ? materials + faces[i].matid : 0);
    1.51 -			cur_mat = faces[i].matid;
    1.52 -			glBegin(GL_TRIANGLES);
    1.53 +
    1.54 +			for(int j=0; j<3; j++) {
    1.55 +				glNormal3fv(faces[i].v[j].normal);
    1.56 +				glVertex3fv(faces[i].v[j].pos);
    1.57 +			}
    1.58  		}
    1.59 +		glEnd();
    1.60 +	}
    1.61  
    1.62 -		for(int j=0; j<3; j++) {
    1.63 -			glNormal3fv(faces[i].v[j].normal);
    1.64 -			glVertex3fv(faces[i].v[j].pos);
    1.65 -		}
    1.66 +	if(show_tree) {
    1.67 +		scn->draw_kdtree();
    1.68  	}
    1.69 -	glEnd();
    1.70  
    1.71  	glPopMatrix();
    1.72  	glPopAttrib();