goat3d

diff goatview/src/goatview.cc @ 76:9785847d52d4

bounding boxes calculation (untested) and automatic camera placement in goatview
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 May 2014 13:43:45 +0300
parents 76dea247f75c
children 53ea5b25426e
line diff
     1.1 --- a/goatview/src/goatview.cc	Thu May 08 00:50:16 2014 +0300
     1.2 +++ b/goatview/src/goatview.cc	Thu May 08 13:43:45 2014 +0300
     1.3 @@ -1,4 +1,6 @@
     1.4 +#include <QtOpenGL/QtOpenGL>
     1.5  #include <GL/glu.h>
     1.6 +#include <vmath/vmath.h>
     1.7  #include "goatview.h"
     1.8  #include "goat3d.h"
     1.9  
    1.10 @@ -7,7 +9,25 @@
    1.11  
    1.12  static long anim_time;
    1.13  static float cam_theta, cam_phi, cam_dist = 8;
    1.14 +static float fov = 60.0;
    1.15  
    1.16 +bool load_scene(const char *fname)
    1.17 +{
    1.18 +	if(scene) {
    1.19 +		goat3d_free(scene);
    1.20 +	}
    1.21 +	if(!(scene = goat3d_create()) || goat3d_load(scene, fname) == -1) {
    1.22 +		return false;
    1.23 +	}
    1.24 +
    1.25 +	float bmin[3], bmax[3];
    1.26 +	goat3d_get_bounds(scene, bmin, bmax);
    1.27 +	float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length();
    1.28 +	cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0) + bsize;
    1.29 +
    1.30 +	printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist);
    1.31 +	return true;
    1.32 +}
    1.33  
    1.34  GoatView::GoatView()
    1.35  {
    1.36 @@ -101,12 +121,8 @@
    1.37  		return;
    1.38  	}
    1.39  
    1.40 -	if(scene) {
    1.41 -		goat3d_free(scene);
    1.42 -	}
    1.43 -
    1.44  	statusBar()->showMessage("opening scene file");
    1.45 -	if(!(scene = goat3d_create()) || goat3d_load(scene, fname.c_str()) == -1) {
    1.46 +	if(!load_scene(fname.c_str())) {
    1.47  		statusBar()->showMessage("failed to load scene file");
    1.48  	}
    1.49  }
    1.50 @@ -207,6 +223,4 @@
    1.51  	for(int i=0; i<num_child; i++) {
    1.52  		draw_node(goat3d_get_node_child(node, i));
    1.53  	}
    1.54 -}
    1.55 -
    1.56 -
    1.57 +}
    1.58 \ No newline at end of file