$search
00001 //== INCLUDES ============================================================= 00002 #include <cmath> 00003 #include "rtc/rtcRenderManager.h" 00004 #include "rtc/rtcRenderer.h" 00005 00006 //== CONSTANTS ============================================================ 00007 #define DEFAULT_ZOOM_SENSITIVITY 0.2 00008 #define DEFAULT_ROTATE_SENSITIVITY 0.50 00009 #define DEFAULT_MOVE_SENSITIVITY 0.001 00010 #define DEFAULT_ZOOM_SENSITIVITY_2D 0.02 00011 #define DEFAULT_ROTATE_SENSITIVITY_2D 0.0050 00012 #define DEFAULT_MOVE_SENSITIVITY_2D 1.0 00013 00014 #define DEFAULT_MIN_ZOOM_RANGE 0.5 00015 #define DEFAULT_CAMERA_FOV 30.0 00016 #define DEFAULT_MIN_CLIP_RANGE 1.0 00017 #define DEFAULT_MAX_CLIP_RANGE 400.0 00018 00019 #define KEY_ROTATE_AMOUNT 5.0 00020 #define KEY_MOVE_AMOUNT 10.0 00021 #define KEY_ZOOM_AMOUNT 5.0 00022 00023 //Conversion factor for degrees to radians 00024 #define D2R 0.0174532925199432957692 00025 //Conversion factor for radians to degrees 00026 #define R2D 57.295779513082320876 00027 00028 //== NAMESPACES =============================================================== 00029 namespace rtc { 00030 00031 // Triangle vertices: 00032 const int num_arrow_triangle_faces = 8; 00033 const int num_arrow_triangle_vertices = num_arrow_triangle_faces*3; 00034 const GLfloat arrow_triangle_vertices[num_arrow_triangle_vertices*3] = { 00035 0.000000f,0.040000f,-0.800000f,0.028284f,0.028284f,-0.800000f, 00036 0.000000f,0.000000f,-1.000000f,0.028284f,0.028284f,-0.800000f, 00037 0.040000f,0.000000f,-0.800000f,0.000000f,0.000000f,-1.000000f, 00038 0.040000f,0.000000f,-0.800000f,0.028284f,-0.028284f,-0.800000f, 00039 0.000000f,0.000000f,-1.000000f,0.028284f,-0.028284f,-0.800000f, 00040 0.000000f,-0.040000f,-0.800000f,0.000000f,0.000000f,-1.000000f, 00041 0.000000f,-0.040000f,-0.800000f,-0.028284f,-0.028284f,-0.800000f, 00042 0.000000f,0.000000f,-1.000000f,-0.028284f,-0.028284f,-0.800000f, 00043 -0.040000f,0.000000f,-0.800000f,0.000000f,0.000000f,-1.000000f, 00044 -0.040000f,0.000000f,-0.800000f,-0.028284f,0.028284f,-0.800000f, 00045 0.000000f,0.000000f,-1.000000f,-0.028284f,0.028284f,-0.800000f, 00046 0.000000f,0.040000f,-0.800000f,0.000000f,0.000000f,-1.000000f 00047 }; 00048 const GLfloat arrow_triangle_normals[num_arrow_triangle_vertices*3] = { 00049 0.000000f,0.980581f,-0.196116f,0.693375f,0.693375f,-0.196116f, 00050 0.357407f,0.862856f,-0.357407f,0.693375f,0.693375f,-0.196116f, 00051 0.980581f,0.000000f,-0.196116f,0.862856f,0.357407f,-0.357407f, 00052 0.980581f,0.000000f,-0.196116f,0.693375f,-0.693375f,-0.196116f, 00053 0.862856f,-0.357407f,-0.357407f,0.693375f,-0.693375f,-0.196116f, 00054 0.000000f,-0.980581f,-0.196116f,0.357407f,-0.862856f,-0.357407f, 00055 0.000000f,-0.980581f,-0.196116f,-0.693375f,-0.693375f,-0.196116f, 00056 -0.357407f,-0.862856f,-0.357407f,-0.693375f,-0.693375f,-0.196116f, 00057 -0.980581f,0.000000f,-0.196116f,-0.862856f,-0.357407f,-0.357407f, 00058 -0.980581f,0.000000f,-0.196116f,-0.693375f,0.693375f,-0.196116f, 00059 -0.862856f,0.357407f,-0.357407f,-0.693375f,0.693375f,-0.196116f, 00060 0.000000f,0.980581f,-0.196116f,-0.357407f,0.862856f,-0.357407f 00061 }; 00062 00063 const int num_arrow_quad_faces = 16; 00064 const int num_arrow_quad_vertices = num_arrow_quad_faces*4; 00065 const GLfloat arrow_quad_vertices[num_arrow_quad_vertices*3] = { 00066 0.000000f,0.010000f,0.000000f,0.007000f,0.007000f,0.000000f, 00067 0.007000f,0.007000f,-0.800000f,0.000000f,0.010000f,-0.800000f, 00068 0.000000f,-0.010000f,0.000000f,-0.007000f,-0.007000f,0.000000f, 00069 -0.007000f,-0.007000f,-0.800000f,0.000000f,-0.010000f,-0.800000f, 00070 -0.007000f,-0.007000f,0.000000f,-0.010000f,0.000000f,0.000000f, 00071 -0.010000f,0.000000f,-0.800000f,-0.007000f,-0.007000f,-0.800000f, 00072 -0.010000f,0.000000f,0.000000f,-0.007000f,0.007000f,0.000000f, 00073 -0.007000f,0.007000f,-0.800000f,-0.010000f,0.000000f,-0.800000f, 00074 -0.007000f,0.007000f,0.000000f,0.000000f,0.010000f,0.000000f, 00075 0.000000f,0.010000f,-0.800000f,-0.007000f,0.007000f,-0.800000f, 00076 0.007000f,0.007000f,0.000000f,0.010000f,0.000000f,0.000000f, 00077 0.010000f,0.000000f,-0.800000f,0.007000f,0.007000f,-0.800000f, 00078 0.010000f,0.000000f,0.000000f,0.007000f,-0.007000f,0.000000f, 00079 0.007000f,-0.007000f,-0.800000f,0.010000f,0.000000f,-0.800000f, 00080 0.007000f,-0.007000f,0.000000f,0.000000f,-0.010000f,0.000000f, 00081 0.000000f,-0.010000f,-0.800000f,0.007000f,-0.007000f,-0.800000f, 00082 -0.007000f,0.007000f,-0.800000f,-0.028284f,0.028284f,-0.800000f, 00083 -0.040000f,0.000000f,-0.800000f,-0.010000f,0.000000f,-0.800000f, 00084 -0.010000f,0.000000f,-0.800000f,-0.040000f,0.000000f,-0.800000f, 00085 -0.028284f,-0.028284f,-0.800000f,-0.007000f,-0.007000f,-0.800000f, 00086 -0.007000f,-0.007000f,-0.800000f,-0.028284f,-0.028284f,-0.800000f, 00087 0.000000f,-0.040000f,-0.800000f,0.000000f,-0.010000f,-0.800000f, 00088 0.000000f,-0.010000f,-0.800000f,0.000000f,-0.040000f,-0.800000f, 00089 0.028284f,-0.028284f,-0.800000f,0.007000f,-0.007000f,-0.800000f, 00090 0.028284f,-0.028284f,-0.800000f,0.040000f,0.000000f,-0.800000f, 00091 0.010000f,0.000000f,-0.800000f,0.007000f,-0.007000f,-0.800000f, 00092 0.040000f,0.000000f,-0.800000f,0.028284f,0.028284f,-0.800000f, 00093 0.007000f,0.007000f,-0.800000f,0.010000f,0.000000f,-0.800000f, 00094 0.007000f,0.007000f,-0.800000f,0.028284f,0.028284f,-0.800000f, 00095 0.000000f,0.040000f,-0.800000f,0.000000f,0.010000f,-0.800000f, 00096 0.000000f,0.010000f,-0.800000f,0.000000f,0.040000f,-0.800000f, 00097 -0.028284f,0.028284f,-0.800000f,-0.007000f,0.007000f,-0.800000f 00098 }; 00099 const GLfloat arrow_quad_normals[num_arrow_quad_vertices*3] = { 00100 0.000000f,1.000000f,0.000000f,0.707107f,0.707107f,0.000000f, 00101 0.707107f,0.707107f,0.000000f,0.000000f,1.000000f,0.000000f, 00102 0.000000f,-1.000000f,0.000000f,-0.707107f,-0.707107f,0.000000f, 00103 -0.707107f,-0.707107f,0.000000f,0.000000f,-1.000000f,0.000000f, 00104 -0.707107f,-0.707107f,0.000000f,-1.000000f,0.000000f,0.000000f, 00105 -1.000000f,0.000000f,0.000000f,-0.707107f,-0.707107f,0.000000f, 00106 -1.000000f,0.000000f,0.000000f,-0.707107f,0.707107f,0.000000f, 00107 -0.707107f,0.707107f,0.000000f,-1.000000f,0.000000f,0.000000f, 00108 -0.707107f,0.707107f,0.000000f,0.000000f,1.000000f,0.000000f, 00109 0.000000f,1.000000f,0.000000f,-0.707107f,0.707107f,0.000000f, 00110 0.707107f,0.707107f,0.000000f,1.000000f,0.000000f,0.000000f, 00111 1.000000f,0.000000f,0.000000f,0.707107f,0.707107f,0.000000f, 00112 1.000000f,0.000000f,0.000000f,0.707107f,-0.707107f,0.000000f, 00113 0.707107f,-0.707107f,0.000000f,1.000000f,0.000000f,0.000000f, 00114 0.707107f,-0.707107f,0.000000f,0.000000f,-1.000000f,0.000000f, 00115 0.000000f,-1.000000f,0.000000f,0.707107f,-0.707107f,0.000000f, 00116 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00117 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00118 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00119 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00120 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00121 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00122 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00123 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00124 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00125 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00126 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00127 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00128 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00129 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00130 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f, 00131 0.000000f,0.000000f,1.000000f,0.000000f,0.000000f,1.000000f 00132 }; 00133 00134 00135 //== IMPLEMENTATION ======================================================= 00136 // constructor 00137 Renderer::Renderer(RenderManager* render_manager, int x, int y, int w, int h, const char *title) 00138 :received_input(false), screen_shot_number(0), arrow_initialized(false) 00139 { 00140 // initialize renderer 00141 initialize(render_manager,x,y,w,h,title); 00142 00143 is_initialized = true; 00144 00145 m_frame = 0; 00146 m_time = 0; 00147 m_timebase = 0; 00148 m_fps = 0; 00149 00150 ilGenImages(1,&image_id); 00151 ilBindImage(image_id); 00152 } 00153 00154 // constructor 00155 Renderer::Renderer() 00156 { 00157 is_initialized = false; 00158 } 00159 00160 // destructor 00161 Renderer::~Renderer() 00162 { 00163 } 00164 00165 void Renderer::initialize(RenderManager* render_manager, 00166 int x, int y, 00167 int w, int h, 00168 const char *title) 00169 { 00170 float light_ambient[] = { 0, 0, 0, 0 }; 00171 float light_diffuse[] = { 1, 1, 1, 1 }; 00172 float light_specular[] = { 1, 1, 1, 1 }; 00173 float light_position[] = { 0, 0, 100, 0 }; 00174 // float light_ambient[] = {0.01, 0.01, 0.01, 1.00}; 00175 // float light_diffuse[] = {0.65, 0.65, 0.65, 1.00}; 00176 // float light_specular[] = {0.30, 0.30, 0.30, 1.00}; 00177 // float light_position[] = { 0, 0, 100, 0 }; 00178 00179 camera_pose.state = IDLE; 00180 camera_pose.pan = 0; 00181 camera_pose.tilt = 0; 00182 camera_pose.distance = 10.0; 00183 camera_pose.x_offset = 0; 00184 camera_pose.y_offset = 0; 00185 camera_pose.z_offset = 0; 00186 00187 camera_pose.x_offset_2D = 0; 00188 camera_pose.y_offset_2D = 0; 00189 camera_pose.rotation_2D = 0; 00190 camera_pose.zoom = 1; 00191 camera_pose.warp_x = 1; 00192 camera_pose.warp_y = 1; 00193 00194 window_width = w; 00195 window_height = h; 00196 00197 fps = 30; 00198 00199 user_idle_func = NULL; 00200 user_timer_func = NULL; 00201 user_display_func = NULL; 00202 user_keyboard_func = NULL; 00203 user_mouse_func = NULL; 00204 user_motion_func = NULL; 00205 00206 zoom_sensitivity = DEFAULT_ZOOM_SENSITIVITY; 00207 rotate_sensitivity = DEFAULT_ROTATE_SENSITIVITY; 00208 move_sensitivity = DEFAULT_MOVE_SENSITIVITY; 00209 min_zoom_range = DEFAULT_MIN_ZOOM_RANGE; 00210 camera_fov = DEFAULT_CAMERA_FOV; 00211 min_clip_range = DEFAULT_MIN_CLIP_RANGE; 00212 max_clip_range = DEFAULT_MAX_CLIP_RANGE; 00213 00214 zoom_sensitivity_2D = DEFAULT_ZOOM_SENSITIVITY_2D; 00215 rotate_sensitivity_2D = DEFAULT_ROTATE_SENSITIVITY_2D; 00216 move_sensitivity_2D = DEFAULT_MOVE_SENSITIVITY_2D; 00217 00218 /* setup the window */ 00219 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); 00220 glutInitWindowSize(window_width, window_height); 00221 glutInitWindowPosition(x, y); 00222 00223 // create window 00224 window_id = render_manager->createWindow(title,this); 00225 00226 // clear color 00227 glClearColor(0, 0, 0, 0); 00228 00229 // depth test 00230 glEnable(GL_DEPTH_TEST); 00231 00232 // color 00233 glEnable(GL_COLOR_MATERIAL); 00234 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 00235 00236 // transparency 00237 glEnable(GL_BLEND); 00238 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00239 00240 // shader 00241 glShadeModel(GL_SMOOTH); 00242 00243 // light 00244 glEnable(GL_LIGHTING); 00245 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); 00246 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); 00247 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); 00248 glLightfv(GL_LIGHT0, GL_POSITION, light_position); 00249 glEnable(GL_LIGHT0); 00250 glEnable(GL_NORMALIZE); 00251 00252 // Fog 00253 // GLfloat fogColor[4] = { 0.3, 0.3, 0.4, 1.0 }; 00254 // glFogi(GL_FOG_MODE, GL_LINEAR); 00255 // glFogfv(GL_FOG_COLOR, fogColor); 00256 // glFogf(GL_FOG_DENSITY, 0.35); 00257 // glHint(GL_FOG_HINT, GL_DONT_CARE); 00258 // glFogf(GL_FOG_START, 5.0f); 00259 // glFogf(GL_FOG_END, 25.0f); 00260 // glEnable(GL_FOG); 00261 00262 mode = GUI_MODE_3D; 00263 } 00264 00265 00266 //void Renderer::initialize() 00267 //{ 00268 // // Create dummy variables 00269 // char * argv[1]; 00270 // argv[0] = "run"; 00271 // int argc = 1; 00272 // 00273 // // initialize gui3d 00274 // gui3D_initialize(argc, argv, 10, 10, 720, 480, 30.0); 00275 // gui3D_setInitialCameraPos(0.0, 0.0, 1.0, 0, 0, 1.5); 00276 // gui3D_setCameraParams(0.01, 0.3, 0.001, 0.009, 60, 0.4, 1000); 00277 // 00278 // 00279 //} 00280 00281 void Renderer::setIdleFunc(idle_func idle) 00282 { 00283 user_idle_func = idle; 00284 } 00285 00286 void Renderer::setTimerFunc(timer_func timer) 00287 { 00288 user_timer_func = timer; 00289 } 00290 00291 void Renderer::setDisplayFunc(display_func display) 00292 { 00293 user_display_func = display; 00294 } 00295 00296 void Renderer::setKeyboardFunc(keyboard_func keyboard) 00297 { 00298 user_keyboard_func = keyboard; 00299 } 00300 00301 void Renderer::setMouseFunc(mouse_func mouse) 00302 { 00303 user_mouse_func = mouse; 00304 } 00305 00306 void Renderer::setMotionFunc(motion_func motion) 00307 { 00308 user_motion_func = motion; 00309 } 00310 00311 void Renderer::setPassiveMotionFunc(passive_motion_func passive_motion) 00312 { 00313 user_passive_motion_func = passive_motion; 00314 } 00315 00316 void Renderer::clear() 00317 { 00318 00319 } 00320 00321 void Renderer::setRenderMode(eRenderMode render_mode) 00322 { 00323 render_mode = render_mode; 00324 } 00325 00326 eRenderMode Renderer::getRenderMode() 00327 { 00328 return render_mode; 00329 } 00330 00331 void Renderer::addRenderNode(RenderNode* node) 00332 { 00333 render_nodes.push_back(node); 00334 } 00335 00336 void Renderer::clearRenderNode() 00337 { 00338 render_nodes.clear(); 00339 } 00340 00341 void Renderer::setCameraParams(double _zoom_sensitivity, 00342 double _rotate_sensitivity, 00343 double _move_sensitivity, 00344 double _min_zoom_range, 00345 double _camera_fov, 00346 double _min_clip_range, 00347 double _max_clip_range) 00348 { 00349 zoom_sensitivity = _zoom_sensitivity; 00350 rotate_sensitivity = _rotate_sensitivity; 00351 move_sensitivity = _move_sensitivity; 00352 min_zoom_range = _min_zoom_range; 00353 camera_fov = _camera_fov; 00354 min_clip_range = _min_clip_range; 00355 max_clip_range = _max_clip_range; 00356 received_input = true; 00357 } 00358 00359 void Renderer::set2DCameraParams(double _zoom_sensitivity, 00360 double _rotate_sensitivity, 00361 double _move_sensitivity) 00362 { 00363 zoom_sensitivity_2D = _zoom_sensitivity; 00364 rotate_sensitivity_2D = _rotate_sensitivity; 00365 move_sensitivity_2D = _move_sensitivity; 00366 received_input = true; 00367 } 00368 00369 void Renderer::rotate_camera(double dx, double dy) 00370 { 00371 camera_pose.pan -= dx * rotate_sensitivity; 00372 camera_pose.tilt += dy * rotate_sensitivity; 00373 if(camera_pose.tilt < 0) 00374 camera_pose.tilt = 0; 00375 else if(camera_pose.tilt > 89.0) 00376 camera_pose.tilt = 89.0; 00377 //printf("pan %f tilt %f\n",camera_pose.pan,camera_pose.tilt); 00378 //if(camera_pose.tilt < 0) 00379 // camera_pose.tilt = 360.0-camera_pose.tilt; 00380 //else if(camera_pose.tilt > 360.0) 00381 // camera_pose.tilt = camera_pose.tilt-360.0; 00382 00383 } 00384 00385 void Renderer::zoom_camera(double dy) 00386 { 00387 if (dy>0) camera_pose.distance = camera_pose.distance / (1 + zoom_sensitivity_2D * dy); 00388 else camera_pose.distance = camera_pose.distance * ( 1 - dy * zoom_sensitivity_2D); 00389 00390 if(camera_pose.distance < min_zoom_range) 00391 camera_pose.distance = min_zoom_range; 00392 } 00393 00394 void Renderer::move_camera(double dx, double dy) 00395 { 00396 camera_pose.x_offset += -dy * cos(D2R*(camera_pose.pan)) * move_sensitivity * camera_pose.distance; 00397 camera_pose.y_offset += -dy * sin(D2R*(camera_pose.pan)) * move_sensitivity * camera_pose.distance; 00398 camera_pose.x_offset += dx * cos(D2R*(camera_pose.pan - 90.0)) * move_sensitivity * camera_pose.distance; 00399 camera_pose.y_offset += dx * sin(D2R*(camera_pose.pan - 90.0)) * move_sensitivity * camera_pose.distance; 00400 } 00401 00402 void Renderer::move_camera_2D(double dx, double dy) 00403 { 00404 double tempx, tempy; 00405 00406 tempx = dx / (float)camera_pose.zoom; 00407 tempy = -dy / (float)camera_pose.zoom; 00408 00409 camera_pose.x_offset_2D -= 00410 (tempx * cos(-camera_pose.rotation_2D) - 00411 tempy * sin(-camera_pose.rotation_2D)) / 00412 camera_pose.warp_x * move_sensitivity_2D; 00413 camera_pose.y_offset_2D -= 00414 (tempx * sin(-camera_pose.rotation_2D) + 00415 tempy * cos(-camera_pose.rotation_2D)) / 00416 camera_pose.warp_y * move_sensitivity_2D; 00417 } 00418 00419 void Renderer::rotate_camera_2D(double dx) 00420 { 00421 camera_pose.rotation_2D += dx * rotate_sensitivity_2D; 00422 } 00423 00424 void Renderer::zoom_camera_2D(double dx) 00425 { 00426 if (dx>0) camera_pose.zoom = camera_pose.zoom * (1 + zoom_sensitivity_2D * dx); 00427 else camera_pose.zoom = camera_pose.zoom / ( 1 - dx * zoom_sensitivity_2D); 00428 if(camera_pose.zoom > float(1e7)) 00429 camera_pose.zoom = float(1e7); 00430 if(camera_pose.zoom < float(1e-12)) 00431 camera_pose.zoom = float(1e-12); 00432 } 00433 00434 00435 void Renderer::setMode2D(void) 00436 { 00437 mode = GUI_MODE_2D; 00438 } 00439 00440 void Renderer::setMode3D(void) 00441 { 00442 mode = GUI_MODE_3D; 00443 } 00444 00445 int Renderer::getMode(void) 00446 { 00447 return mode; 00448 } 00449 00450 void Renderer::setMode(int _mode) 00451 { 00452 mode = _mode; 00453 } 00454 00455 void Renderer::switchTo2DMode(void) { 00456 setDisplayMode2D(window_width, window_height); 00457 /* do camera control */ 00458 glTranslatef(window_width / 2.0, window_height / 2.0, 0.0); 00459 glScalef(camera_pose.zoom, camera_pose.zoom, 1.0); 00460 glRotatef(R2D*(camera_pose.rotation_2D), 0, 0, 1); 00461 glScalef(camera_pose.warp_x, camera_pose.warp_y, 1); 00462 glTranslatef(-camera_pose.x_offset_2D, -camera_pose.y_offset_2D, 0.0); 00463 } 00464 00465 void Renderer::switchTo3DMode(void) 00466 { 00467 float cpan, ctilt, camera_x, camera_y, camera_z; 00468 00469 /* setup camera view */ 00470 cpan = camera_pose.pan * M_PI / 180.0; 00471 ctilt = camera_pose.tilt * M_PI / 180.0; 00472 camera_x = camera_pose.distance * cos(cpan) * cos(ctilt); 00473 camera_y = camera_pose.distance * sin(cpan) * cos(ctilt); 00474 camera_z = camera_pose.distance * sin(ctilt); 00475 setDisplayMode3D(window_width, window_height, camera_fov, min_clip_range, max_clip_range); 00476 glViewport(0, 0, (GLsizei)window_width, (GLsizei)window_height); 00477 gluLookAt(camera_x + camera_pose.x_offset, 00478 camera_y + camera_pose.y_offset, 00479 camera_z + camera_pose.z_offset, 00480 camera_pose.x_offset, 00481 camera_pose.y_offset, 00482 camera_pose.z_offset, 00483 0, 0, 1); 00484 } 00485 00486 00487 void Renderer::setInitialCameraPos(double pan, double tilt, double range, 00488 double x_offset, double y_offset, 00489 double z_offset) 00490 { 00491 camera_pose.pan = pan; 00492 camera_pose.tilt = tilt; 00493 camera_pose.distance = range; 00494 camera_pose.x_offset = x_offset; 00495 camera_pose.y_offset = y_offset; 00496 camera_pose.z_offset = z_offset; 00497 } 00498 00499 void Renderer::setInitial2DCameraPos(double x_offset, double y_offset, 00500 double rotation, double zoom) 00501 { 00502 camera_pose.x_offset_2D = x_offset; 00503 camera_pose.y_offset_2D = y_offset; 00504 camera_pose.rotation_2D = rotation; 00505 camera_pose.zoom = zoom; 00506 } 00507 00508 //void Renderer::add_timerFunc(unsigned int msecs, void (*func)(int value), 00509 // int value) 00510 //{ 00511 // glutTimerFunc(msecs, func, value); 00512 //} 00513 00514 void Renderer::forceRedraw(void) 00515 { 00516 received_input = true; 00517 } 00518 00519 void Renderer::set2DWarping(double warp_x, double warp_y) 00520 { 00521 camera_pose.warp_x = warp_x; 00522 camera_pose.warp_y = warp_y; 00523 } 00524 00525 void Renderer::recenter(void) 00526 { 00527 camera_pose.x_offset = 0; 00528 camera_pose.y_offset = 0; 00529 camera_pose.z_offset = 0; 00530 } 00531 00532 void Renderer::recenter2D(void) 00533 { 00534 camera_pose.x_offset_2D = 0; 00535 camera_pose.y_offset_2D = 0; 00536 } 00537 00538 void Renderer::pickPoint(int mouse_x, int mouse_y, double *scene_x, double *scene_y) 00539 { 00540 double cx = window_width / 2.0; 00541 double cy = window_height / 2.0; 00542 double pan = D2R*(-90.0 - camera_pose.pan); 00543 double tilt = D2R*(90.0 - camera_pose.tilt); 00544 double d = camera_pose.distance; 00545 double f = cy / tan(D2R*(camera_fov / 2.0)); 00546 00547 // from Matlab 00548 double px = (mouse_x - cx) * cos(tilt) * d / (cos(tilt) * f + sin(tilt) * mouse_y - sin(tilt) * cy); 00549 double py = -(mouse_y - cy) * d / (cos(tilt) * f + sin(tilt) * mouse_y - sin(tilt) * cy); 00550 00551 // rotate by pan, add offset 00552 *scene_x = px * cos(pan) + py * sin(pan) + camera_pose.x_offset; 00553 *scene_y = -px * sin(pan) + py * cos(pan) + camera_pose.y_offset; 00554 } 00555 00556 void Renderer::get2DPosition(int x, int y, double *xout, double *yout) 00557 { 00558 double dx, dy, ctheta, stheta; 00559 00560 dx = (x - window_width / 2.0 - GLUI_x_offset) / camera_pose.zoom; 00561 dy = (window_height / 2.0 - y + GLUI_y_offset) / camera_pose.zoom; 00562 ctheta = cos(-camera_pose.rotation_2D); 00563 stheta = sin(-camera_pose.rotation_2D); 00564 *xout = camera_pose.x_offset_2D + ctheta * dx - stheta * dy; 00565 *yout = camera_pose.y_offset_2D + stheta * dx + ctheta * dy; 00566 } 00567 00568 void Renderer::get3DPosition(double x, double y, double z, double *xout, double *yout, double *zout) 00569 { 00570 GLint viewport[4]; 00571 GLdouble modelview[16]; 00572 GLdouble projection[16]; 00573 glGetIntegerv(GL_VIEWPORT,viewport); 00574 glGetDoublev(GL_MODELVIEW_MATRIX,modelview); 00575 glGetDoublev(GL_PROJECTION_MATRIX,projection); 00576 gluUnProject(x,y,z,modelview,projection,viewport,xout,yout,zout); 00577 } 00578 00579 void Renderer::setDisplayMode2D(int w, int h) 00580 { 00581 glDisable(GL_DEPTH_TEST); 00582 glMatrixMode(GL_PROJECTION); 00583 glLoadIdentity(); 00584 gluOrtho2D(0.0, (GLfloat)w, 0.0, (GLfloat)h); 00585 glMatrixMode(GL_MODELVIEW); 00586 glLoadIdentity(); 00587 } 00588 00589 void Renderer::setDisplayMode3D(int w, int h, float fovy, float zNear, float zFar) 00590 { 00591 glEnable(GL_DEPTH_TEST); 00592 glMatrixMode(GL_PROJECTION); 00593 glLoadIdentity(); 00594 gluPerspective(fovy, w / (float)h, zNear, zFar); 00595 glMatrixMode(GL_MODELVIEW); 00596 glLoadIdentity(); 00597 } 00598 00599 // -------------------------------------------------- 00600 // Renderer callbacks 00601 // -------------------------------------------------- 00602 00603 void Renderer::special(int key, int x, int y) 00604 { 00605 int mod; 00606 double dx = 0, dy = 0; 00607 00608 mod = glutGetModifiers(); 00609 if(mode == GUI_MODE_3D) { 00610 if(mod & GLUT_ACTIVE_CTRL) { 00611 switch(key) { 00612 case GLUT_KEY_LEFT: 00613 dx = -KEY_ROTATE_AMOUNT; 00614 dy = 0; 00615 break; 00616 case GLUT_KEY_RIGHT: 00617 dx = KEY_ROTATE_AMOUNT; 00618 dy = 0; 00619 break; 00620 case GLUT_KEY_UP: 00621 dx = 0; 00622 dy = KEY_ROTATE_AMOUNT; 00623 break; 00624 case GLUT_KEY_DOWN: 00625 dx = 0; 00626 dy = -KEY_ROTATE_AMOUNT; 00627 break; 00628 } 00629 if(dx != 0 || dy != 0) 00630 rotate_camera(dx, dy); 00631 } 00632 else if(mod & GLUT_ACTIVE_ALT) { 00633 switch(key) { 00634 case GLUT_KEY_UP: 00635 dy = KEY_ZOOM_AMOUNT; 00636 break; 00637 case GLUT_KEY_DOWN: 00638 dy = -KEY_ZOOM_AMOUNT; 00639 break; 00640 } 00641 if(dy != 0) 00642 zoom_camera(dy); 00643 } 00644 else { 00645 switch(key) { 00646 case GLUT_KEY_LEFT: 00647 dx = KEY_MOVE_AMOUNT; 00648 dy = 0; 00649 break; 00650 case GLUT_KEY_RIGHT: 00651 dx = -KEY_MOVE_AMOUNT; 00652 dy = 0; 00653 break; 00654 case GLUT_KEY_UP: 00655 dx = 0; 00656 dy = KEY_MOVE_AMOUNT; 00657 break; 00658 case GLUT_KEY_DOWN: 00659 dx = 0; 00660 dy = -KEY_MOVE_AMOUNT; 00661 break; 00662 } 00663 if(dx != 0 || dy != 0) 00664 move_camera(dx, dy); 00665 } 00666 } 00667 else { 00668 if(mod & GLUT_ACTIVE_CTRL) { 00669 switch(key) { 00670 case GLUT_KEY_LEFT: 00671 dx = KEY_ROTATE_AMOUNT; 00672 dy = 0; 00673 break; 00674 case GLUT_KEY_RIGHT: 00675 dx = -KEY_ROTATE_AMOUNT; 00676 dy = 0; 00677 break; 00678 } 00679 if(dx != 0) 00680 rotate_camera_2D(dx); 00681 } 00682 else if(mod & GLUT_ACTIVE_ALT) { 00683 switch(key) { 00684 case GLUT_KEY_UP: 00685 dy = KEY_ZOOM_AMOUNT; 00686 break; 00687 case GLUT_KEY_DOWN: 00688 dy = -KEY_ZOOM_AMOUNT; 00689 break; 00690 } 00691 if(dy != 0) 00692 zoom_camera_2D(dy); 00693 } 00694 else { 00695 switch(key) { 00696 case GLUT_KEY_LEFT: 00697 dx = KEY_MOVE_AMOUNT; 00698 dy = 0; 00699 break; 00700 case GLUT_KEY_RIGHT: 00701 dx = -KEY_MOVE_AMOUNT; 00702 dy = 0; 00703 break; 00704 case GLUT_KEY_UP: 00705 dx = 0; 00706 dy = KEY_MOVE_AMOUNT; 00707 break; 00708 case GLUT_KEY_DOWN: 00709 dx = 0; 00710 dy = -KEY_MOVE_AMOUNT; 00711 break; 00712 } 00713 if(dx != 0 || dy != 0) 00714 move_camera_2D(dx, dy); 00715 } 00716 } 00717 received_input = true; 00718 } 00719 00720 void Renderer::keyboard(unsigned char key, int x, int y) 00721 { 00722 received_input = true; 00723 if(user_keyboard_func) 00724 user_keyboard_func(key, x, y); 00725 } 00726 00727 void Renderer::mouse(int button, int state, int x, int y) 00728 { 00729 if(state == GLUT_DOWN) { 00730 last_mouse_x = x; 00731 last_mouse_y = y; 00732 if(button == GLUT_LEFT_BUTTON) 00733 camera_pose.state = ROTATING; 00734 else if(button == GLUT_MIDDLE_BUTTON) 00735 camera_pose.state = MOVING; 00736 else if(button == GLUT_RIGHT_BUTTON) 00737 camera_pose.state = ZOOMING; 00738 } 00739 else if(state == GLUT_UP) 00740 camera_pose.state = IDLE; 00741 00742 received_input = true; 00743 if(user_mouse_func) 00744 user_mouse_func(button, state, x, y); 00745 } 00746 00747 void Renderer::motion(int x, int y) 00748 { 00749 int dx, dy; 00750 00751 dx = x - last_mouse_x; 00752 dy = y - last_mouse_y; 00753 00754 if(mode == GUI_MODE_3D) { 00755 if(camera_pose.state == ROTATING) 00756 rotate_camera(dx, dy); 00757 else if(camera_pose.state == MOVING) 00758 move_camera(dx, dy); 00759 else if(camera_pose.state == ZOOMING) 00760 zoom_camera(dy); 00761 } 00762 else if(mode == GUI_MODE_2D) { 00763 if(camera_pose.state == ROTATING) { 00764 // if(y < window_height / 2) 00765 // dx *= -1; 00766 00767 if(x > window_width / 2) 00768 dy *= -1; 00769 00770 rotate_camera_2D(dx); 00771 } 00772 else if(camera_pose.state == MOVING) 00773 move_camera_2D(dx, dy); 00774 else if(camera_pose.state == ZOOMING) 00775 zoom_camera_2D(dy); 00776 } 00777 00778 last_mouse_x = x; 00779 last_mouse_y = y; 00780 00781 received_input = true; 00782 00783 if(user_motion_func) 00784 user_motion_func(x, y); 00785 } 00786 00787 void Renderer::reshape(int w, int h) 00788 { 00789 int tx = 0, ty = 0, tw = w, th = h; 00790 00791 GLUI_Master.get_viewport_area(&tx, &ty, &tw, &th); 00792 GLUI_x_offset = tx; 00793 GLUI_y_offset = (h - th) - ty; 00794 glViewport(tx, ty, tw, th); 00795 00796 window_width = tw; 00797 window_height = th; 00798 00799 if(mode == GUI_MODE_3D) 00800 setDisplayMode3D(tw, th, camera_fov, min_clip_range, 00801 max_clip_range); 00802 else if(mode == GUI_MODE_2D) 00803 setDisplayMode2D(tw, th); 00804 } 00805 00806 void Renderer::display() 00807 { 00808 glutSetWindow(window_id); 00809 00810 // clear GL buffers 00811 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00812 if(mode == GUI_MODE_3D) { 00813 /* setup camera view */ 00814 switchTo3DMode(); 00815 } 00816 else if(mode == GUI_MODE_2D) { 00817 switchTo2DMode(); 00818 } 00819 00820 // render all nodes in the list 00821 glColor3f(1,1,1); 00822 int mode_save = mode; 00823 TRenderNodeList::iterator it, it_end; 00824 for(it=render_nodes.begin(), it_end=render_nodes.end();it!=it_end;++it) 00825 { 00826 (*it)->preRender(); 00827 (*it)->render(); 00828 (*it)->postRender(); 00829 } 00830 mode = mode_save; 00831 00832 // call user defined display function 00833 if(user_display_func) 00834 user_display_func(); 00835 00836 // calculate fps 00837 m_frame++; 00838 m_time=glutGet(GLUT_ELAPSED_TIME); 00839 if (m_time - m_timebase > 1000) 00840 { 00841 m_fps = m_frame*1000.0/(m_time-m_timebase); 00842 m_timebase = m_time; 00843 m_frame = 0; 00844 } 00845 00846 // draw the 2D graphics 00847 //char str[200]; 00848 //setDisplayMode2D(window_width, window_height); 00849 //glColor3f(1, 1, 0); 00850 //sprintf(str, "%6f fps", m_fps); 00851 //renderBitmapString(10, 10, GLUT_BITMAP_HELVETICA_18, str); 00852 00853 // flush gl and swap buffers 00854 glFlush(); 00855 glutSwapBuffers(); 00856 } 00857 00858 void Renderer::passive_motion(int x, int y) 00859 { 00860 00861 } 00862 00863 void Renderer::visibility(int visible) 00864 { 00865 00866 } 00867 00868 void Renderer::timer() 00869 { 00870 if(received_input) { 00871 glutSetWindow(window_id); 00872 glutPostRedisplay(); 00873 received_input = false; 00874 } 00875 if (user_timer_func) 00876 user_timer_func(); 00877 } 00878 00879 void Renderer::idle() 00880 { 00881 if (user_idle_func) 00882 user_idle_func(); 00883 } 00884 00885 camera_pose_p Renderer::getCameraPose() 00886 { 00887 return &camera_pose; 00888 } 00889 00890 void Renderer::setCameraPose(camera_pose_t camera_pose) 00891 { 00892 camera_pose = camera_pose; 00893 } 00894 00895 int Renderer::getWindowId() 00896 { 00897 return window_id; 00898 } 00899 00900 int Renderer::getWindowWidth() 00901 { 00902 return window_width; 00903 } 00904 00905 int Renderer::getWindowHeight() 00906 { 00907 return window_height; 00908 } 00909 00910 void Renderer::renderBitmapString(float x, float y, void *font, char *string) 00911 { 00912 char *c; 00913 00914 glPushMatrix(); 00915 glRasterPos2d(x, y); 00916 for(c = string; *c != '\0'; c++) 00917 glutBitmapCharacter(font, *c); 00918 glPopMatrix(); 00919 } 00920 00921 int Renderer::bitmapStringWidth(void *font, char *string) 00922 { 00923 int width = 0; 00924 char *c; 00925 00926 for(c = string; *c != '\0'; c++) 00927 width += glutBitmapWidth(font, *c); 00928 return width; 00929 } 00930 00931 void Renderer::renderBitmapString3D(float x, float y, float z, void *font, char *string) 00932 { 00933 char *c; 00934 00935 glPushMatrix(); 00936 glRasterPos3d(x, y, z); 00937 glBitmap(0, 0, 0, 0, -bitmapStringWidth(font, string) / 2.0, 0, NULL); 00938 00939 for(c = string; *c != '\0'; c++) 00940 glutBitmapCharacter(font, *c); 00941 glPopMatrix(); 00942 } 00943 00944 void Renderer::renderBitmapStringCentered(float x, float y, void *font, char *string) 00945 { 00946 char *c; 00947 int vert_offset = -5; 00948 00949 glPushMatrix(); 00950 glRasterPos2d(x, y); 00951 if(font == GLUT_BITMAP_HELVETICA_18) 00952 vert_offset = -7; 00953 else if(font == GLUT_BITMAP_HELVETICA_12) 00954 vert_offset = -4; 00955 else if(font == GLUT_BITMAP_HELVETICA_10) 00956 vert_offset = -3; 00957 glBitmap(0, 0, 0, 0, 00958 -bitmapStringWidth(font, string) / 2.0, vert_offset, NULL); 00959 for(c = string; *c != '\0'; c++) 00960 glutBitmapCharacter(font, *c); 00961 glPopMatrix(); 00962 } 00963 00964 // take a screenshot 00965 void Renderer::takeScreenShot(const char *filename) 00966 { 00967 ilutRenderer(ILUT_OPENGL); 00968 ilutGLScreen(); 00969 ilEnable(IL_FILE_OVERWRITE); 00970 ilSaveImage((const ILstring)filename); 00971 screen_shot_number++; 00972 } 00973 00974 void Renderer::takeScreenShot() 00975 { 00976 char buf[255]; 00977 sprintf(buf,"screenshot_%03d.png",screen_shot_number); 00978 takeScreenShot(buf); 00979 } 00980 00981 00982 void Renderer::initializeArrow() 00983 { 00984 if (!GLEW_ARB_vertex_buffer_object) 00985 { 00986 arrow_initialized = true; 00987 return; 00988 } 00989 00990 glGenBuffersARB(1, &arrow_triangle_vertices_vbo); 00991 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_vertices_vbo); 00992 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_triangle_vertices*3*sizeof(GLfloat), arrow_triangle_vertices, GL_STATIC_DRAW_ARB); 00993 00994 glGenBuffersARB(1, &arrow_triangle_normals_vbo); 00995 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_normals_vbo); 00996 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_triangle_vertices*3*sizeof(GLfloat), arrow_triangle_normals, GL_STATIC_DRAW_ARB); 00997 00998 glGenBuffersARB(1, &arrow_quad_vertices_vbo); 00999 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_vertices_vbo); 01000 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_quad_vertices*3*sizeof(GLfloat), arrow_quad_vertices, GL_STATIC_DRAW_ARB); 01001 01002 glGenBuffersARB(1, &arrow_quad_normals_vbo); 01003 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_normals_vbo); 01004 glBufferDataARB(GL_ARRAY_BUFFER_ARB, num_arrow_quad_vertices*3*sizeof(GLfloat), arrow_quad_normals, GL_STATIC_DRAW_ARB); 01005 01006 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 01007 arrow_initialized = true; 01008 }; 01009 01010 // Draw an X-Y-Z Frame. The red arrow corresponds to the X-Axis, 01011 // green to the Y-Axis, and blue to the Z-Axis. 01012 void Renderer::drawCoordinateFrame(double scale) 01013 { 01014 double a_axisThicknessScale = 3*scale; 01015 01016 // initialize vertex buffer objects 01017 if(!arrow_initialized) 01018 initializeArrow(); 01019 01020 // Set up nice color-tracking 01021 glEnable(GL_COLOR_MATERIAL); 01022 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 01023 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 01024 01025 int k; 01026 for(k=0; k<3; k++) { 01027 01028 glPushMatrix(); 01029 01030 // Rotate to the appropriate axis 01031 if (k==0) { 01032 glRotatef(-90.0,0,1,0); 01033 glColor3f(1.0f,0.0f,0.0f); 01034 } 01035 else if (k==1) { 01036 glRotatef(90.0,1,0,0); 01037 glColor3f(0.0f,1.0f,0.0f); 01038 } 01039 else { 01040 glRotatef(180.0,1,0,0); 01041 glColor3f(0.0f,0.0f,1.0f); 01042 } 01043 01044 glScaled(a_axisThicknessScale,a_axisThicknessScale,scale); 01045 01046 if (!GLEW_ARB_vertex_buffer_object) 01047 { 01048 glBegin(GL_TRIANGLES); 01049 for (int i=0;i<num_arrow_triangle_vertices;i++) 01050 { 01051 glVertex3d(arrow_triangle_vertices[i*3],arrow_triangle_vertices[i*3+1],arrow_triangle_vertices[i*3+2]); 01052 glNormal3d(arrow_triangle_normals[i*3],arrow_triangle_normals[i*3+1],arrow_triangle_normals[i*3+2]); 01053 } 01054 glEnd(); 01055 01056 glBegin(GL_QUADS); 01057 for (int i=0;i<num_arrow_quad_vertices;i++) 01058 { 01059 glVertex3d(arrow_quad_vertices[i*3],arrow_quad_vertices[i*3+1],arrow_quad_vertices[i*3+2]); 01060 glNormal3d(arrow_quad_normals[i*3],arrow_quad_normals[i*3+1],arrow_quad_normals[i*3+2]); 01061 } 01062 glEnd(); 01063 } 01064 else 01065 { 01066 glEnableClientState(GL_NORMAL_ARRAY); 01067 glEnableClientState(GL_VERTEX_ARRAY); 01068 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_vertices_vbo); 01069 glVertexPointer(3, GL_FLOAT, 0, 0); 01070 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_triangle_normals_vbo); 01071 glNormalPointer(GL_FLOAT, 0, 0); 01072 glDrawArrays(GL_TRIANGLES, 0, num_arrow_triangle_vertices); 01073 01074 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_vertices_vbo); 01075 glVertexPointer(3, GL_FLOAT, 0, 0); 01076 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrow_quad_normals_vbo); 01077 glNormalPointer(GL_FLOAT, 0, 0); 01078 glDrawArrays(GL_QUADS, 0, num_arrow_quad_vertices); 01079 01080 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); 01081 01082 glDisableClientState(GL_NORMAL_ARRAY); 01083 glDisableClientState(GL_VERTEX_ARRAY); 01084 } 01085 01086 glPopMatrix(); 01087 } 01088 } 01089 01090 void Renderer::drawGrid(double center_x, double center_y, int size, double resolution) const 01091 { 01092 double grid_x, grid_y; 01093 double size_2=(double)size/2.0; 01094 01095 glLineWidth(0.5); 01096 glEnable(GL_BLEND); 01097 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 01098 01099 glEnable(GL_LINE_SMOOTH); 01100 glBegin(GL_LINES); 01101 for(grid_x = -size_2; grid_x < size_2; grid_x+=resolution) { 01102 glVertex3f(grid_x - center_x, -size_2 - center_y, 0); 01103 glVertex3f(grid_x - center_x, size_2 - center_y, 0); 01104 } 01105 for(grid_y = -size_2; grid_y < size_2; grid_y+=resolution) { 01106 glVertex3f(-size_2 - center_x, grid_y - center_y, 0); 01107 glVertex3f( size_2 - center_x, grid_y - center_y, 0); 01108 } 01109 glEnd(); 01110 glDisable(GL_LINE_SMOOTH); 01111 glDisable(GL_BLEND); 01112 } 01113 01114 void Renderer::drawDashedLine3D(double x1, double y1, double z1, double x2, double y2, double z2, double stripe_len) const 01115 { 01116 double frac, dx, dy, dz, x, y, z; 01117 int i; 01118 01119 frac = stripe_len / sqrt(rtc_sqr(x2-x1)+rtc_sqr(y2-y1)+rtc_sqr(z2-z1)); 01120 dx = frac * (x2 - x1); 01121 dy = frac * (y2 - y1); 01122 dz = frac * (z2 - z1); 01123 x = x1; 01124 y = y1; 01125 z = z1; 01126 glBegin(GL_LINES); 01127 for(i = 0; i < (int)floor(1 / frac); i++) { 01128 if(i % 2 == 0) { 01129 glVertex3f(x, y, z); 01130 glVertex3f(x + dx, y + dy, z + dz); 01131 } 01132 x += dx; 01133 y += dy; 01134 z += dz; 01135 } 01136 glEnd(); 01137 } 01138 01139 Vec3d Renderer::unProject(double winx, double winy, double winz) 01140 { 01141 Vec3d pos; 01142 GLint viewport[4]; 01143 GLdouble modelview[16]; 01144 GLdouble projection[16]; 01145 glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); 01146 glGetDoublev( GL_PROJECTION_MATRIX, projection ); 01147 glGetIntegerv( GL_VIEWPORT, viewport ); 01148 gluUnProject( winx, winy, winz, modelview, projection, viewport, &pos[0], &pos[1], &pos[2]); 01149 return pos; 01150 } 01151 01152 void Renderer::setRasterPos(double winx, double winy, double winz) 01153 { 01154 Vec3d pos=unProject(winx,winy,winz); 01155 glRasterPos3dv(pos.x); 01156 } 01157 01158 //============================================================================== 01159 } // namespace rtc 01160 //============================================================================== 01161