# HG changeset patch # User John Tsiombikas # Date 1308348265 -10800 # Node ID 8a9aa21b32cf4165f3fa108cc14725989ed98f28 # Parent 48e0e7d33d9e00b90a9ec92753c1ee080b02c93e added spaceball support through GLUT diff -r 48e0e7d33d9e -r 8a9aa21b32cf src/gui.cc --- a/src/gui.cc Sat May 28 22:31:07 2011 +0300 +++ b/src/gui.cc Sat Jun 18 01:04:25 2011 +0300 @@ -37,7 +37,9 @@ } imtk_begin(); - imtk_layout_start(10, 10, 10, IMTK_HORIZONTAL); + imtk_layout_start(10, 10); + imtk_layout_spacing(10); + imtk_layout_dir(IMTK_HORIZONTAL); imtk_label("seed x", IMTK_AUTO, IMTK_AUTO); seed.x = imtk_slider(IMUID, seed.x, -1.0, 1.0, IMTK_AUTO, IMTK_AUTO); @@ -56,6 +58,7 @@ imtk_layout_newline(); imtk_label("iterations", IMTK_AUTO, IMTK_AUTO); + fiter = (float)iter; fiter = imtk_slider(IMUID, fiter, 0, 32, IMTK_AUTO, IMTK_AUTO); iter = round(fiter); imtk_layout_newline(); @@ -63,7 +66,7 @@ imtk_label("max error", IMTK_AUTO, IMTK_AUTO); err_thres = imtk_slider(IMUID, err_thres, 0, 0.075, IMTK_AUTO, IMTK_AUTO); - imtk_layout_start(280, 10, 10, IMTK_HORIZONTAL); + imtk_layout_start(280, 10); imtk_label("reflectivity", IMTK_AUTO, IMTK_AUTO); reflectivity = imtk_slider(IMUID, reflectivity, 0, 1.0, IMTK_AUTO, IMTK_AUTO); imtk_layout_newline(); diff -r 48e0e7d33d9e -r 8a9aa21b32cf src/rayfract.cc --- a/src/rayfract.cc Sat May 28 22:31:07 2011 +0300 +++ b/src/rayfract.cc Sat Jun 18 01:04:25 2011 +0300 @@ -8,6 +8,8 @@ #include "gui.h" #include "vmath.h" +#define DEG_TO_RAD(x) (M_PI * (x) / 180.0) + void disp(); void reshape(int x, int y); void keyb(unsigned char key, int x, int y); @@ -15,6 +17,10 @@ void mouse(int bn, int state, int x, int y); void motion(int x, int y); void passive_motion(int x, int y); +void sball_motion(int x, int y, int z); +void sball_rot(int x, int y, int z); +void sball_button(int bn, int state); + int load_shader(); unsigned int create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale = 0); @@ -22,7 +28,7 @@ static int round_pow2(int x); float cam_theta = 0, cam_phi = 0, cam_dist = 4.0; -float cam_y = 0; +float cam_x, cam_y, cam_z; unsigned int sdr; unsigned int ray_tex; @@ -53,6 +59,9 @@ glutMouseFunc(mouse); glutMotionFunc(motion); glutPassiveMotionFunc(passive_motion); + glutSpaceballMotionFunc(sball_motion); + glutSpaceballRotateFunc(sball_rot); + glutSpaceballButtonFunc(sball_button); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); @@ -97,6 +106,7 @@ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + glTranslatef(cam_x, cam_y, -cam_z); glRotatef(cam_theta, 0, 1, 0); glRotatef(cam_phi, 1, 0, 0); glTranslatef(0, 0, -cam_dist); @@ -279,6 +289,7 @@ if(bnstate[2]) { cam_dist += (y - prev_y) * 0.1; + if(cam_dist < 0.0) cam_dist = 0.0; glutPostRedisplay(); } @@ -295,6 +306,42 @@ glutPostRedisplay(); } +void sball_motion(int x, int y, int z) +{ + float dx = (float)x * 0.0015f; + float dy = (float)y * 0.0015f; + float dz = -(float)z * 0.001f; + float angle = -DEG_TO_RAD(cam_theta); + + cam_x += cos(angle) * dx + sin(angle) * dz; + cam_z += -sin(angle) * dx + cos(angle) * dz; + cam_y += dy; + + glutPostRedisplay(); +} + +void sball_rot(int x, int y, int z) +{ + cam_theta += -y / 15.0; + cam_phi += -x / 15.0; + glutPostRedisplay(); +} + +void sball_button(int bn, int state) +{ + if(state == GLUT_DOWN) { + switch(bn) { + case 0: + /* TODO reset */ + break; + + default: + break; + } + } +} + + unsigned int create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale) { unsigned int tex;