rayfract

changeset 6:8a9aa21b32cf

added spaceball support through GLUT
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 18 Jun 2011 01:04:25 +0300
parents 48e0e7d33d9e
children c27b24c9fdd2
files src/gui.cc src/rayfract.cc
diffstat 2 files changed, 53 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/src/gui.cc	Sat May 28 22:31:07 2011 +0300
     1.2 +++ b/src/gui.cc	Sat Jun 18 01:04:25 2011 +0300
     1.3 @@ -37,7 +37,9 @@
     1.4  	}
     1.5  
     1.6  	imtk_begin();
     1.7 -	imtk_layout_start(10, 10, 10, IMTK_HORIZONTAL);
     1.8 +	imtk_layout_start(10, 10);
     1.9 +	imtk_layout_spacing(10);
    1.10 +	imtk_layout_dir(IMTK_HORIZONTAL);
    1.11  
    1.12  	imtk_label("seed x", IMTK_AUTO, IMTK_AUTO);
    1.13  	seed.x = imtk_slider(IMUID, seed.x, -1.0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.14 @@ -56,6 +58,7 @@
    1.15  	imtk_layout_newline();
    1.16  
    1.17  	imtk_label("iterations", IMTK_AUTO, IMTK_AUTO);
    1.18 +	fiter = (float)iter;
    1.19  	fiter = imtk_slider(IMUID, fiter, 0, 32, IMTK_AUTO, IMTK_AUTO);
    1.20  	iter = round(fiter);
    1.21  	imtk_layout_newline();
    1.22 @@ -63,7 +66,7 @@
    1.23  	imtk_label("max error", IMTK_AUTO, IMTK_AUTO);
    1.24  	err_thres = imtk_slider(IMUID, err_thres, 0, 0.075, IMTK_AUTO, IMTK_AUTO);
    1.25  
    1.26 -	imtk_layout_start(280, 10, 10, IMTK_HORIZONTAL);
    1.27 +	imtk_layout_start(280, 10);
    1.28  	imtk_label("reflectivity", IMTK_AUTO, IMTK_AUTO);
    1.29  	reflectivity = imtk_slider(IMUID, reflectivity, 0, 1.0, IMTK_AUTO, IMTK_AUTO);
    1.30  	imtk_layout_newline();
     2.1 --- a/src/rayfract.cc	Sat May 28 22:31:07 2011 +0300
     2.2 +++ b/src/rayfract.cc	Sat Jun 18 01:04:25 2011 +0300
     2.3 @@ -8,6 +8,8 @@
     2.4  #include "gui.h"
     2.5  #include "vmath.h"
     2.6  
     2.7 +#define DEG_TO_RAD(x)	(M_PI * (x) / 180.0)
     2.8 +
     2.9  void disp();
    2.10  void reshape(int x, int y);
    2.11  void keyb(unsigned char key, int x, int y);
    2.12 @@ -15,6 +17,10 @@
    2.13  void mouse(int bn, int state, int x, int y);
    2.14  void motion(int x, int y);
    2.15  void passive_motion(int x, int y);
    2.16 +void sball_motion(int x, int y, int z);
    2.17 +void sball_rot(int x, int y, int z);
    2.18 +void sball_button(int bn, int state);
    2.19 +
    2.20  
    2.21  int load_shader();
    2.22  unsigned int create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale = 0);
    2.23 @@ -22,7 +28,7 @@
    2.24  static int round_pow2(int x);
    2.25  
    2.26  float cam_theta = 0, cam_phi = 0, cam_dist = 4.0;
    2.27 -float cam_y = 0;
    2.28 +float cam_x, cam_y, cam_z;
    2.29  
    2.30  unsigned int sdr;
    2.31  unsigned int ray_tex;
    2.32 @@ -53,6 +59,9 @@
    2.33  	glutMouseFunc(mouse);
    2.34  	glutMotionFunc(motion);
    2.35  	glutPassiveMotionFunc(passive_motion);
    2.36 +	glutSpaceballMotionFunc(sball_motion);
    2.37 +	glutSpaceballRotateFunc(sball_rot);
    2.38 +	glutSpaceballButtonFunc(sball_button);
    2.39  
    2.40  	glEnable(GL_DEPTH_TEST);
    2.41  	glEnable(GL_LIGHTING);
    2.42 @@ -97,6 +106,7 @@
    2.43  
    2.44  	glMatrixMode(GL_MODELVIEW);
    2.45  	glLoadIdentity();
    2.46 +	glTranslatef(cam_x, cam_y, -cam_z);
    2.47  	glRotatef(cam_theta, 0, 1, 0);
    2.48  	glRotatef(cam_phi, 1, 0, 0);
    2.49  	glTranslatef(0, 0, -cam_dist);
    2.50 @@ -279,6 +289,7 @@
    2.51  
    2.52  	if(bnstate[2]) {
    2.53  		cam_dist += (y - prev_y) * 0.1;
    2.54 +		if(cam_dist < 0.0) cam_dist = 0.0;
    2.55  		glutPostRedisplay();
    2.56  	}
    2.57  
    2.58 @@ -295,6 +306,42 @@
    2.59  	glutPostRedisplay();
    2.60  }
    2.61  
    2.62 +void sball_motion(int x, int y, int z)
    2.63 +{
    2.64 +	float dx = (float)x * 0.0015f;
    2.65 +	float dy = (float)y * 0.0015f;
    2.66 +	float dz = -(float)z * 0.001f;
    2.67 +	float angle = -DEG_TO_RAD(cam_theta);
    2.68 +
    2.69 +	cam_x += cos(angle) * dx + sin(angle) * dz;
    2.70 +	cam_z += -sin(angle) * dx + cos(angle) * dz;
    2.71 +	cam_y += dy;
    2.72 +
    2.73 +	glutPostRedisplay();
    2.74 +}
    2.75 +
    2.76 +void sball_rot(int x, int y, int z)
    2.77 +{
    2.78 +	cam_theta += -y / 15.0;
    2.79 +	cam_phi += -x / 15.0;
    2.80 +	glutPostRedisplay();
    2.81 +}
    2.82 +
    2.83 +void sball_button(int bn, int state)
    2.84 +{
    2.85 +	if(state == GLUT_DOWN) {
    2.86 +		switch(bn) {
    2.87 +		case 0:
    2.88 +			/* TODO reset */
    2.89 +			break;
    2.90 +
    2.91 +		default:
    2.92 +			break;
    2.93 +		}
    2.94 +	}
    2.95 +}
    2.96 +
    2.97 +
    2.98  unsigned int create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale)
    2.99  {
   2.100  	unsigned int tex;