clray

diff src/clray.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 6c44e4b1726d
children 353d80127627
line diff
     1.1 --- a/src/clray.cc	Tue Aug 17 01:19:43 2010 +0100
     1.2 +++ b/src/clray.cc	Tue Aug 17 20:35:00 2010 +0100
     1.3 @@ -1,6 +1,7 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6  #include <string.h>
     1.7 +#include <ctype.h>
     1.8  #include <errno.h>
     1.9  #ifndef __APPLE__
    1.10  #include <GL/glut.h>
    1.11 @@ -25,7 +26,9 @@
    1.12  static float cam_theta, cam_phi = 25.0;
    1.13  static float cam_dist = 10.0;
    1.14  
    1.15 -static bool dbg_glrender = false;
    1.16 +static bool dbg_glrender = true;
    1.17 +static bool dbg_show_kdtree = false;
    1.18 +static bool dbg_show_obj = true;
    1.19  
    1.20  static Scene scn;
    1.21  
    1.22 @@ -36,11 +39,46 @@
    1.23  
    1.24  	int loaded = 0;
    1.25  	for(int i=1; i<argc; i++) {
    1.26 -		if(!scn.load(argv[i])) {
    1.27 -			fprintf(stderr, "failed to load scene: %s\n", argv[i]);
    1.28 -			return false;
    1.29 +		if(argv[i][0] == '-' && argv[i][2] == 0) {
    1.30 +			switch(argv[i][1]) {
    1.31 +			case 'i':
    1.32 +				if(!argv[++i] || !isdigit(argv[i][0])) {
    1.33 +					fprintf(stderr, "-i must be followed by the intersection cost\n");
    1.34 +					return 1;
    1.35 +				}
    1.36 +
    1.37 +				set_accel_param(ACCEL_PARAM_COST_INTERSECT, atoi(argv[i]));
    1.38 +				break;
    1.39 +
    1.40 +			case 't':
    1.41 +				if(!argv[++i] || !isdigit(argv[i][0])) {
    1.42 +					fprintf(stderr, "-t must be followed by the traversal cost\n");
    1.43 +					return 1;
    1.44 +				}
    1.45 +
    1.46 +				set_accel_param(ACCEL_PARAM_COST_TRAVERSE, atoi(argv[i]));
    1.47 +				break;
    1.48 +
    1.49 +			case 'c':
    1.50 +				if(!argv[++i] || !isdigit(argv[i][0])) {
    1.51 +					fprintf(stderr, "-c must be followed by the max number of items per leaf node\n");
    1.52 +					return 1;
    1.53 +				}
    1.54 +
    1.55 +				set_accel_param(ACCEL_PARAM_MAX_NODE_ITEMS, atoi(argv[i]));
    1.56 +				break;
    1.57 +
    1.58 +			default:
    1.59 +				fprintf(stderr, "unrecognized option: %s\n", argv[i]);
    1.60 +				return 1;
    1.61 +			}
    1.62 +		} else {
    1.63 +			if(!scn.load(argv[i])) {
    1.64 +				fprintf(stderr, "failed to load scene: %s\n", argv[i]);
    1.65 +				return false;
    1.66 +			}
    1.67 +			loaded++;
    1.68  		}
    1.69 -		loaded++;
    1.70  	}
    1.71  
    1.72  	if(!loaded) {
    1.73 @@ -69,6 +107,11 @@
    1.74  	}
    1.75  	atexit(cleanup);
    1.76  
    1.77 +	if(!scn.build_kdtree()) {
    1.78 +		return 1;
    1.79 +	}
    1.80 +
    1.81 +
    1.82  	/*glGenTextures(1, &tex);
    1.83  	glBindTexture(GL_TEXTURE_2D, tex);*/
    1.84  	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    1.85 @@ -125,7 +168,7 @@
    1.86  	if(dbg_glrender) {
    1.87  		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.88  		glLoadMatrixf(inv_mat.m);
    1.89 -		dbg_render_gl(&scn);
    1.90 +		dbg_render_gl(&scn, dbg_show_kdtree, dbg_show_obj);
    1.91  	} else {
    1.92  		glEnable(GL_TEXTURE_2D);
    1.93  		glDisable(GL_LIGHTING);
    1.94 @@ -175,6 +218,20 @@
    1.95  		glutPostRedisplay();
    1.96  		break;
    1.97  
    1.98 +	case 'k':
    1.99 +		dbg_show_kdtree = !dbg_show_kdtree;
   1.100 +		if(dbg_glrender) {
   1.101 +			glutPostRedisplay();
   1.102 +		}
   1.103 +		break;
   1.104 +
   1.105 +	case 'o':
   1.106 +		dbg_show_obj = !dbg_show_obj;
   1.107 +		if(dbg_glrender) {
   1.108 +			glutPostRedisplay();
   1.109 +		}
   1.110 +		break;
   1.111 +
   1.112  	default:
   1.113  		break;
   1.114  	}