$search
00001 #ifndef RENDERER_H 00002 #define RENDERER_H 00003 00004 //== INCLUDES ================================================================== 00005 #include <list> 00006 #include <string> 00007 00008 #include <GL/glew.h> 00009 #include <GL/gl.h> 00010 #include <GL/glu.h> 00011 #define ILUT_USE_OPENGL 00012 #include <IL/il.h> 00013 #include <IL/ilu.h> 00014 #include <IL/ilut.h> 00015 00016 #include "rtc/rtcRenderNode.h" 00017 00018 //== NAMESPACES ================================================================ 00019 namespace rtc { 00020 00021 //== CONSTANTS ================================================================ 00022 00023 typedef enum { GUI_MODE_3D, GUI_MODE_2D } eGUIMode; 00024 typedef enum { IDLE, ROTATING, MOVING, ZOOMING } camera_state_t; 00025 00026 typedef void (*idle_func)(void); 00027 typedef void (*timer_func)(void); 00028 typedef void (*display_func)(void); 00029 typedef void (*keyboard_func)(unsigned char, int, int); 00030 typedef void (*mouse_func)(int, int, int, int); 00031 typedef void (*motion_func)(int, int); 00032 typedef void (*passive_motion_func)(int, int); 00033 00034 typedef struct { 00035 camera_state_t state; 00036 float pan, tilt, distance; 00037 float x_offset, y_offset, z_offset; 00038 float x_offset_2D, y_offset_2D, rotation_2D, zoom, warp_x, warp_y; 00039 } camera_pose_t, *camera_pose_p; 00040 00041 class RenderManager; 00042 00043 class Renderer { 00044 friend class RenderManager; 00045 public: 00046 // c'tor 00047 Renderer(RenderManager* render_manager, 00048 int window_x, int window_y, 00049 int window_width, int window_height, 00050 const char * title); 00051 // c'tor 00052 Renderer(); 00053 // d'tor 00054 virtual ~Renderer(); 00055 // initialize rendering 00056 virtual void initialize(RenderManager* render_manager, 00057 int window_x, int window_y, 00058 int window_width, int window_height, 00059 const char * title); 00060 //clear rendering 00061 virtual void clear(); 00062 // sets the render mode 00063 void setRenderMode(eRenderMode render_mode); 00064 // returns the render mode 00065 eRenderMode getRenderMode(); 00066 /***************************************************************************** 00067 * set user defined callback functions 00068 ****************************************************************************/ 00069 // sets a user defined idle function 00070 void setIdleFunc(idle_func idle); 00071 // sets a user defined timer function 00072 void setTimerFunc(timer_func timer); 00073 // sets a user defined display function 00074 void setDisplayFunc(display_func display); 00075 // sets a user defined keyboard function 00076 void setKeyboardFunc(keyboard_func keyboard); 00077 // sets a user defined mouse function 00078 void setMouseFunc(mouse_func mouse); 00079 // sets a user defined motion function 00080 void setMotionFunc(motion_func motion); 00081 // sets a user defined passive motion function 00082 void setPassiveMotionFunc(passive_motion_func motion); 00083 // adds a render node to the renderer 00084 void addRenderNode(RenderNode* node); 00085 void clearRenderNode(); 00086 // set 3D camera parameters 00087 void setCameraParams(double zoom_sensitivity, 00088 double rotate_sensitivity, 00089 double move_sensitivity, 00090 double min_zoom_range, 00091 double camera_fov, 00092 double min_clip_range, 00093 double max_clip_range); 00094 // set 2D camera parameters 00095 void set2DCameraParams(double zoom_sensitivity, 00096 double rotate_sensivitity, 00097 double move_sensitivity); 00098 // initialize the renderer 00099 void initialize(int argc, char **argv, 00100 int window_x, int window_y, 00101 int window_width, int window_height, 00102 double fps); 00103 // set initial camera position 00104 void setInitialCameraPos(double pan, 00105 double tilt, 00106 double range, 00107 double x_offset, 00108 double y_offset, 00109 double z_offset); 00110 // set initial 2D camera position 00111 void setInitial2DCameraPos(double x_offset, 00112 double y_offset, 00113 double rotation, 00114 double zoom); 00115 // switch to 2D mode 00116 void setMode2D(void); 00117 // switch to 3D mode 00118 void setMode3D(void); 00119 // set custom mode 00120 void setMode(int mode); 00121 // get current mode 00122 int getMode(void); 00123 // force a redraw 00124 void forceRedraw(void); 00125 // set the 2D warping 00126 void set2DWarping(double warp_x, double warp_y); 00127 // recenter viewer 00128 void recenter(void); 00129 // recenter viewer in 2D mode 00130 void recenter2D(void); 00131 // pick a point in viewing pane 00132 void pickPoint(int mouse_x, int mouse_y, double *scene_x, double *scene_y); 00133 // get 2D position for 2D point 00134 void get2DPosition(int x, int y, double *xout, double *yout); 00135 // get 3D position for 3D point 00136 void get3DPosition(double x, double y, double z, double *xout, double *yout, double *zout); 00137 // return glut window id 00138 int getWindowId(); 00139 // returns the camera pose 00140 camera_pose_p getCameraPose(); 00141 // sets the camera pose 00142 void setCameraPose(camera_pose_t camera_pose); 00143 // returns the window width 00144 int getWindowWidth(); 00145 // returns the window height 00146 int getWindowHeight(); 00147 // set display to 2d mode 00148 void setDisplayMode2D(int w, int h); 00149 // set display to 3d mode 00150 void setDisplayMode3D(int w, int h, float fov, float zNear, float zFar); 00151 // switch to 2D mode 00152 void switchTo2DMode(void); 00153 // switch to 3D mode 00154 void switchTo3DMode(void); 00155 // render bitmap string 00156 void renderBitmapString(float x, float y, void *font, char *string) ; 00157 // render 3D bitmap string 00158 void renderBitmapString3D(float x, float y, float z, void *font, char *string); 00159 // render bitmap string 00160 int bitmapStringWidth(void *font, char *string); 00161 // render centered bitmap string 00162 void renderBitmapStringCentered(float x, float y, void *font, char *string); 00163 // take a screenshot 00164 void takeScreenShot(const char *filename); 00165 void takeScreenShot(); 00166 00167 void drawCoordinateFrame(double scale = 1.0); 00168 void drawGrid(double center_x=0, double center_y=0, int size=100, double resolution=1.0) const; 00169 void drawDashedLine3D(double x1, double y1, double z1, double x2, double y2, double z2, double stripe_len) const; 00170 00171 Vec3d unProject(double winx, double winy, double winz=0.0); 00172 void setRasterPos(double winx, double winy, double winz=0.0); 00173 00174 private: 00175 bool arrow_initialized; 00176 GLuint arrow_triangle_vertices_vbo; 00177 GLuint arrow_triangle_normals_vbo; 00178 GLuint arrow_quad_vertices_vbo; 00179 GLuint arrow_quad_normals_vbo; 00180 void initializeArrow(); 00181 00182 protected: 00183 // internal rendering callbacks 00184 void display(void); 00185 void mouse(int button, int state, int x, int y); 00186 void keyboard(unsigned char key, int x, int y); 00187 void motion(int x, int y); 00188 void passive_motion(int x, int y); 00189 void special(int key, int x, int y); 00190 void visibility(int visible); 00191 void reshape(int w, int h); 00192 void timer(); 00193 void idle(); 00194 00195 // internal helper functions 00196 void rotate_camera(double dx, double dy); 00197 void zoom_camera(double dy); 00198 void move_camera(double dx, double dy); 00199 void rotate_camera_2D(double dx); 00200 void zoom_camera_2D(double dx); 00201 void move_camera_2D(double dx, double dy); 00202 00203 00204 public: 00205 // initialized flag 00206 bool is_initialized; 00207 // the rendering mode 00208 eRenderMode render_mode; 00209 // list of rendering nodes 00210 typedef std::vector<RenderNode*> TRenderNodeList; 00211 TRenderNodeList render_nodes; 00212 00213 int m_frame; 00214 int m_time; 00215 int m_timebase; 00216 float m_fps; 00217 00218 int window_id; 00219 int window_width, window_height; 00220 float GLUI_x_offset, GLUI_y_offset; 00221 double fps; 00222 camera_pose_t camera_pose; 00223 int last_mouse_x, last_mouse_y; 00224 bool received_input; 00225 00226 idle_func user_idle_func; 00227 timer_func user_timer_func; 00228 display_func user_display_func; 00229 keyboard_func user_keyboard_func; 00230 mouse_func user_mouse_func; 00231 motion_func user_motion_func; 00232 passive_motion_func user_passive_motion_func; 00233 00234 double zoom_sensitivity; 00235 double rotate_sensitivity; 00236 double move_sensitivity; 00237 double min_zoom_range; 00238 double camera_fov; 00239 double min_clip_range; 00240 double max_clip_range; 00241 00242 double zoom_sensitivity_2D; 00243 double rotate_sensitivity_2D; 00244 double move_sensitivity_2D; 00245 int mode; 00246 00247 ILuint image_id; 00248 int screen_shot_number; 00249 }; 00250 00251 //============================================================================== 00252 } // namespace rtc 00253 //============================================================================== 00254 #endif // RENDERER_H defined 00255 //============================================================================== 00256