rayfract
diff src/rayfract.cc @ 1:03022062c464
lalal
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Tue, 26 Oct 2010 08:45:37 +0300 |
parents | 09bb67c000bc |
children | bf1d56975cc9 |
line diff
1.1 --- a/src/rayfract.cc Thu Oct 21 23:39:26 2010 +0300 1.2 +++ b/src/rayfract.cc Tue Oct 26 08:45:37 2010 +0300 1.3 @@ -5,12 +5,15 @@ 1.4 #include <GL/glut.h> 1.5 #include <vmath.h> 1.6 #include "sdr.h" 1.7 +#include "gui.h" 1.8 1.9 void disp(); 1.10 void reshape(int x, int y); 1.11 void keyb(unsigned char key, int x, int y); 1.12 +void keyb_up(unsigned char key, int x, int y); 1.13 void mouse(int bn, int state, int x, int y); 1.14 void motion(int x, int y); 1.15 +void passive_motion(int x, int y); 1.16 1.17 int load_shader(); 1.18 unsigned int create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale = 0); 1.19 @@ -26,6 +29,8 @@ 1.20 Vector4 seed; 1.21 float err_thres = 0.0075; 1.22 int iter = 10; 1.23 +float reflectivity = 0.2; 1.24 +Vector3 color(0.9, 0.95, 1.0); 1.25 1.26 int main(int argc, char **argv) 1.27 { 1.28 @@ -43,8 +48,10 @@ 1.29 glutDisplayFunc(disp); 1.30 glutReshapeFunc(reshape); 1.31 glutKeyboardFunc(keyb); 1.32 + glutKeyboardUpFunc(keyb_up); 1.33 glutMouseFunc(mouse); 1.34 glutMotionFunc(motion); 1.35 + glutPassiveMotionFunc(passive_motion); 1.36 1.37 glEnable(GL_DEPTH_TEST); 1.38 glEnable(GL_LIGHTING); 1.39 @@ -57,6 +64,10 @@ 1.40 return 1; 1.41 } 1.42 1.43 + if(gui_init(xsz, ysz) == -1) { 1.44 + return 1; 1.45 + } 1.46 + 1.47 glutMainLoop(); 1.48 return 0; 1.49 } 1.50 @@ -73,6 +84,9 @@ 1.51 set_uniform_float4(sdr, "seed", seed.x, seed.y, seed.z, seed.w); 1.52 set_uniform_float(sdr, "err_thres", err_thres); 1.53 set_uniform_int(sdr, "iter", iter); 1.54 + set_uniform_float(sdr, "reflectivity", reflectivity); 1.55 + set_uniform_float3(sdr, "diffuse_color", color.x, color.y, color.z); 1.56 + 1.57 return 0; 1.58 } 1.59 1.60 @@ -112,6 +126,8 @@ 1.61 glMatrixMode(GL_TEXTURE); 1.62 glPopMatrix(); 1.63 1.64 + gui_draw(); 1.65 + 1.66 glutSwapBuffers(); 1.67 assert(glGetError() == GL_NO_ERROR); 1.68 } 1.69 @@ -170,7 +186,35 @@ 1.70 load_shader(); 1.71 glutPostRedisplay(); 1.72 break; 1.73 + 1.74 + case 'r': 1.75 + reflectivity = reflectivity > 0.0 ? 0.0 : 0.6; 1.76 + set_uniform_float(sdr, "reflectivity", reflectivity); 1.77 + glutPostRedisplay(); 1.78 + break; 1.79 + 1.80 + case '`': 1.81 + { 1.82 + static bool vis = true; 1.83 + vis = !vis; 1.84 + gui_set_visible(vis); 1.85 + glutPostRedisplay(); 1.86 + } 1.87 + break; 1.88 } 1.89 + 1.90 + utk::KeyboardEvent ev(key); 1.91 + ev.pressed = true; 1.92 + utk::event(&ev); 1.93 + glutPostRedisplay(); 1.94 +} 1.95 + 1.96 +void keyb_up(unsigned char key, int x, int y) 1.97 +{ 1.98 + utk::KeyboardEvent ev(key); 1.99 + ev.pressed = false; 1.100 + utk::event(&ev); 1.101 + glutPostRedisplay(); 1.102 } 1.103 1.104 int bnstate[16]; 1.105 @@ -178,22 +222,31 @@ 1.106 int prev_x = -1, prev_y; 1.107 void mouse(int bn, int state, int x, int y) 1.108 { 1.109 - bnstate[bn] = state == GLUT_DOWN ? 1 : 0; 1.110 - if(state == GLUT_DOWN) { 1.111 - if(bn == 3) { 1.112 - cam_dist -= 0.1; 1.113 - glutPostRedisplay(); 1.114 - if(cam_dist < 0) cam_dist = 0; 1.115 - } else if(bn == 4) { 1.116 - cam_dist += 0.1; 1.117 - glutPostRedisplay(); 1.118 + utk::Container *utkroot = utk::get_root_widget(); 1.119 + 1.120 + if(utkroot->get_child_at(x, y) == utkroot) { 1.121 + bnstate[bn] = state == GLUT_DOWN ? 1 : 0; 1.122 + if(state == GLUT_DOWN) { 1.123 + if(bn == 3) { 1.124 + cam_dist -= 0.1; 1.125 + glutPostRedisplay(); 1.126 + if(cam_dist < 0) cam_dist = 0; 1.127 + } else if(bn == 4) { 1.128 + cam_dist += 0.1; 1.129 + glutPostRedisplay(); 1.130 + } else { 1.131 + prev_x = x; 1.132 + prev_y = y; 1.133 + } 1.134 } else { 1.135 - prev_x = x; 1.136 - prev_y = y; 1.137 + prev_x = -1; 1.138 } 1.139 - } else { 1.140 - prev_x = -1; 1.141 } 1.142 + 1.143 + utk::MButtonEvent ev(bn, x, y); 1.144 + ev.pressed = state == GLUT_DOWN; 1.145 + utk::event(&ev); 1.146 + glutPostRedisplay(); 1.147 } 1.148 1.149 void motion(int x, int y) 1.150 @@ -220,6 +273,17 @@ 1.151 1.152 prev_x = x; 1.153 prev_y = y; 1.154 + 1.155 + utk::MMotionEvent ev(x, y); 1.156 + utk::event(&ev); 1.157 + glutPostRedisplay(); 1.158 +} 1.159 + 1.160 +void passive_motion(int x, int y) 1.161 +{ 1.162 + utk::MMotionEvent ev(x, y); 1.163 + utk::event(&ev); 1.164 + //glutPostRedisplay(); 1.165 } 1.166 1.167 unsigned int create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale)