view3d

changeset 8:5562a637e5aa

load multiple files and concatenate them
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Jan 2012 08:51:59 +0200
parents 75e4377f3cdc
children d2e283764fca d0896caa3e5b
files src/main.c src/scene.c src/scene.h
diffstat 3 files changed, 26 insertions(+), 24 deletions(-) [+]
line diff
     1.1 --- a/src/main.c	Sat Jan 21 18:20:14 2012 +0200
     1.2 +++ b/src/main.c	Mon Jan 23 08:51:59 2012 +0200
     1.3 @@ -26,7 +26,6 @@
     1.4  void sball_button(int bn, int state);
     1.5  int parse_args(int argc, char **argv);
     1.6  
     1.7 -char *scene_fname;
     1.8  int win_width, win_height;
     1.9  int stereo;
    1.10  int flip_winding;
    1.11 @@ -48,13 +47,9 @@
    1.12  	float ldir[] = {-1, 1, 1, 0};
    1.13  	float dx, dy, dz, diag;
    1.14  
    1.15 +
    1.16  	glutInitWindowSize(800, 600);
    1.17  	glutInit(&argc, argv);
    1.18 -
    1.19 -	if(parse_args(argc, argv) == -1) {
    1.20 -		return 1;
    1.21 -	}
    1.22 -
    1.23  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (stereo ? GLUT_STEREO : 0));
    1.24  	glutCreateWindow("OpenGL 3D viewer");
    1.25  
    1.26 @@ -82,10 +77,16 @@
    1.27  
    1.28  	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb);
    1.29  
    1.30 -	if((load_scene(&scn, scene_fname)) == -1) {
    1.31 -		fprintf(stderr, "failed to load: %s\n", scene_fname);
    1.32 +
    1.33 +	init_scene(&scn);
    1.34 +	if(parse_args(argc, argv) == -1) {
    1.35  		return 1;
    1.36  	}
    1.37 +	if(verbose) {
    1.38 +		printf("scene bounds: %.2f %.2f %.2f -> %.2f %.2f %.2f\n", scn.bbox.min[0], scn.bbox.min[1],
    1.39 +				scn.bbox.min[2], scn.bbox.max[0], scn.bbox.max[1], scn.bbox.max[2]);
    1.40 +	}
    1.41 +
    1.42  	dx = scn.bbox.max[0] - scn.bbox.min[0];
    1.43  	dy = scn.bbox.max[1] - scn.bbox.min[1];
    1.44  	dz = scn.bbox.max[2] - scn.bbox.min[2];
    1.45 @@ -352,7 +353,7 @@
    1.46  
    1.47  int parse_args(int argc, char **argv)
    1.48  {
    1.49 -	int i;
    1.50 +	int i, num_loaded = 0;
    1.51  
    1.52  	for(i=1; i<argc; i++) {
    1.53  		if(argv[i][0] == '-') {
    1.54 @@ -375,15 +376,15 @@
    1.55  				goto inval;
    1.56  			}
    1.57  		} else {
    1.58 -			if(scene_fname) {
    1.59 -				fprintf(stderr, "unexpected argument: %s\n", argv[i]);
    1.60 +			if((load_scene(&scn, argv[i])) == -1) {
    1.61 +				fprintf(stderr, "failed to load: %s\n", argv[1]);
    1.62  				return -1;
    1.63  			}
    1.64 -			scene_fname = argv[i];
    1.65 +			num_loaded++;
    1.66  		}
    1.67  	}
    1.68  
    1.69 -	if(!scene_fname) {
    1.70 +	if(num_loaded == 0) {
    1.71  		fprintf(stderr, "you must pass the filename of a scene to open\n");
    1.72  		return -1;
    1.73  	}
     2.1 --- a/src/scene.c	Sat Jan 21 18:20:14 2012 +0200
     2.2 +++ b/src/scene.c	Mon Jan 23 08:51:59 2012 +0200
     2.3 @@ -20,6 +20,16 @@
     2.4  
     2.5  extern int verbose;
     2.6  
     2.7 +int init_scene(struct scene *scn)
     2.8 +{
     2.9 +	scn->meshes = 0;
    2.10 +	scn->lights = 0;
    2.11 +
    2.12 +	scn->bbox.min[0] = scn->bbox.min[1] = scn->bbox.min[2] = FLT_MAX;
    2.13 +	scn->bbox.max[0] = scn->bbox.max[1] = scn->bbox.max[2] = -FLT_MAX;
    2.14 +	return 0;
    2.15 +}
    2.16 +
    2.17  int load_scene(struct scene *scn, const char *fname)
    2.18  {
    2.19  	int i, j;
    2.20 @@ -37,9 +47,6 @@
    2.21  		printf("scene: %s  (%d meshes, %d lights)\n", fname, aiscn->mNumMeshes, aiscn->mNumLights);
    2.22  	}
    2.23  
    2.24 -	scn->meshes = 0;
    2.25 -	scn->lights = 0;
    2.26 -
    2.27  	for(i=0; i<aiscn->mNumLights; i++) {
    2.28  		struct light *lt;
    2.29  		struct aiLight *ailt = aiscn->mLights[i];
    2.30 @@ -97,9 +104,7 @@
    2.31  		scn->lights = lt;
    2.32  	}
    2.33  
    2.34 -	scn->bbox.min[0] = scn->bbox.min[1] = scn->bbox.min[2] = FLT_MAX;
    2.35 -	scn->bbox.max[0] = scn->bbox.max[1] = scn->bbox.max[2] = -FLT_MAX;
    2.36 -
    2.37 +	/* load meshes and calculate bounding box */
    2.38  	for(i=0; i<aiscn->mNumMeshes; i++) {
    2.39  		struct mesh *m;
    2.40  
    2.41 @@ -120,11 +125,6 @@
    2.42  		scn->meshes = m;
    2.43  	}
    2.44  
    2.45 -	if(verbose) {
    2.46 -		printf("scene bounds: %.2f %.2f %.2f -> %.2f %.2f %.2f\n", scn->bbox.min[0], scn->bbox.min[1],
    2.47 -				scn->bbox.min[2], scn->bbox.max[0], scn->bbox.max[1], scn->bbox.max[2]);
    2.48 -	}
    2.49 -
    2.50  	aiReleaseImport(aiscn);
    2.51  	return 0;
    2.52  }
     3.1 --- a/src/scene.h	Sat Jan 21 18:20:14 2012 +0200
     3.2 +++ b/src/scene.h	Mon Jan 23 08:51:59 2012 +0200
     3.3 @@ -42,6 +42,7 @@
     3.4  };
     3.5  
     3.6  
     3.7 +int init_scene(struct scene *scn);
     3.8  int load_scene(struct scene *scn, const char *fname);
     3.9  
    3.10  void render_scene(struct scene *scn);