V-ARTContributions
viewerglutogl.h
Go to the documentation of this file.
1 
5 #ifndef VART_VIEWERGLUTOGL_H
6 #define VART_VIEWERGLUTOGL_H
7 
8 #include "vart/scene.h"
10 #include <list>
11 
12 namespace VART {
13  const int KEY_F1 = GLUT_KEY_F1 + 255;
14  const int KEY_F2 = GLUT_KEY_F2 + 255;
15  const int KEY_F3 = GLUT_KEY_F3 + 255;
16  const int KEY_F4 = GLUT_KEY_F4 + 255;
17  const int KEY_F5 = GLUT_KEY_F5 + 255;
18  const int KEY_F6 = GLUT_KEY_F6 + 255;
19  const int KEY_F7 = GLUT_KEY_F7 + 255;
20  const int KEY_F8 = GLUT_KEY_F8 + 255;
21  const int KEY_F9 = GLUT_KEY_F9 + 255;
22  const int KEY_F10 = GLUT_KEY_F10 + 255;
23  const int KEY_F11 = GLUT_KEY_F11 + 255;
24  const int KEY_F12 = GLUT_KEY_F12 + 255;
25  const int KEY_LEFT = GLUT_KEY_LEFT + 255;
26  const int KEY_UP = GLUT_KEY_UP + 255;
27  const int KEY_RIGHT = GLUT_KEY_RIGHT + 255;
28  const int KEY_DOWN = GLUT_KEY_DOWN + 255;
29  const int KEY_PAGE_UP = GLUT_KEY_PAGE_UP + 255;
30  const int KEY_PAGE_DOWN = GLUT_KEY_PAGE_DOWN + 255;
31  const int KEY_HOME = GLUT_KEY_HOME + 255;
32  const int KEY_END = GLUT_KEY_END + 255;
33  const int KEY_INSERT = GLUT_KEY_INSERT + 255;
34 
41  class ViewerGlutOGL {
42  public:
43  // PUBLIC NESTED CLASSES
44  // These classes are nested because other types of viewers may have different
45  // needs for their handlers.
46 
48  class KbHandler
49  {
50  friend class ViewerGlutOGL;
51  public:
52  virtual ~KbHandler() {};
56  virtual void HandleKey(unsigned char key) { }
63  virtual void OnKeyDown(int key); // FixMe: make pure virtual
67  virtual void HandleSpecialKey(int key) { }
75  virtual void OnKeyUp(int key) { }
76  protected:
79  };
82  {
83  friend class ViewerGlutOGL;
84  public:
85  virtual ~IdleHandler() {};
87  virtual void OnIdle()=0;
88  protected:
91  };
99  {
100  friend class ViewerGlutOGL;
101  public:
102  virtual ~DrawHandler() {};
107  virtual void OnDraw()=0;
108  protected:
111  };
112  // PUBLIC METHODS
117  ViewerGlutOGL();
118 
123  ViewerGlutOGL(int newWidth, int newHeight);
124 
125  ~ViewerGlutOGL();
126 
132  void SetScene(Scene& scene);
133 
137  void SetPosition(int x, int y);
138 
140  void SetKbHandler(KbHandler* ptrKbH);
141 
143  void SetIdleHandler(IdleHandler* newIHPtr);
144 
146  void SetDrawHandler(DrawHandler* newDHPtr);
147 
149  void SetCamera(Camera* camPtr);
150 
156 
159 
162 
166  void Idle();
167 
169  void SetSize(int newWidth, int newHeight);
171  int GetWidth() { return width; }
173  int GetHeight() { return height; }
174 
176  const Camera* GetCurrentCamera() const { return cameraPtr; }
177 
179  void Hide();
180 
182  void Show();
183 
185  void TurnIntoCurrentWindow();
186 
188  void SetTitle(const std::string& newTitle);
189 
191  void Iconify();
192 
194  void PostRedisplay();
195 
197  void UseNextCamera() { ptScene->UseNextCamera(); }
198 
199  // PUBLIC STATIC METHODS
200 
205  static void MainLoop();
206 
211  static void Init(int* argcPtr, char* argv[]);
212 
214  static void RedisplayAll();
215 
216  // PUBLIC ATTRIBUTES
220 
226 
228  float walkStep;
229 
232 
236 
237  protected:
239  void ClearOGLBuffers();
240 
241  private:
242  // PRIVATE STATIC METHODS (GLUT CALLBACKS)
243  // Drawing callbacks
244  static void DrawCB0();
245  static void DrawCB1();
246  static void DrawCB2();
247  static void DrawCB3();
248  static void DrawCB4();
249  static void DrawCB5();
250  // Mouse click callbacks
251  static void MouseCB0(int, int, int, int);
252  static void MouseCB1(int, int, int, int);
253  static void MouseCB2(int, int, int, int);
254  static void MouseCB3(int, int, int, int);
255  static void MouseCB4(int, int, int, int);
256  static void MouseCB5(int, int, int, int);
257  // Mouse drag callbacks
258  static void DragMouseCB0(int x, int y);
259  static void DragMouseCB1(int x, int y);
260  static void DragMouseCB2(int x, int y);
261  static void DragMouseCB3(int x, int y);
262  static void DragMouseCB4(int x, int y);
263  static void DragMouseCB5(int x, int y);
264  // Special keys callbacks for key down
265  static void SpecialKeyCB0(int key, int x, int y);
266  static void SpecialKeyCB1(int key, int x, int y);
267  static void SpecialKeyCB2(int key, int x, int y);
268  static void SpecialKeyCB3(int key, int x, int y);
269  static void SpecialKeyCB4(int key, int x, int y);
270  static void SpecialKeyCB5(int key, int x, int y);
271  // Special keys callbacks for key up
272  static void SpecialKeyUpCB0(int key, int x, int y);
273  static void SpecialKeyUpCB1(int key, int x, int y);
274  static void SpecialKeyUpCB2(int key, int x, int y);
275  static void SpecialKeyUpCB3(int key, int x, int y);
276  static void SpecialKeyUpCB4(int key, int x, int y);
277  static void SpecialKeyUpCB5(int key, int x, int y);
278  // Keyboard callbacks
279  static void KeyboardCB0(unsigned char key, int x, int y);
280  static void KeyboardCB1(unsigned char key, int x, int y);
281  static void KeyboardCB2(unsigned char key, int x, int y);
282  static void KeyboardCB3(unsigned char key, int x, int y);
283  static void KeyboardCB4(unsigned char key, int x, int y);
284  static void KeyboardCB5(unsigned char key, int x, int y);
285  // Callbacks for key ups:
286  static void OnKeyUpCB0(unsigned char key, int x, int y);
287  static void OnKeyUpCB1(unsigned char key, int x, int y);
288  static void OnKeyUpCB2(unsigned char key, int x, int y);
289  static void OnKeyUpCB3(unsigned char key, int x, int y);
290  static void OnKeyUpCB4(unsigned char key, int x, int y);
291  static void OnKeyUpCB5(unsigned char key, int x, int y);
292  // Resize callbacks
293  static void ResizeCB0(int newWidth, int newHeight);
294  static void ResizeCB1(int newWidth, int newHeight);
295  static void ResizeCB2(int newWidth, int newHeight);
296  static void ResizeCB3(int newWidth, int newHeight);
297  static void ResizeCB4(int newWidth, int newHeight);
298  static void ResizeCB5(int newWidth, int newHeight);
299  // Idle callback
300  static void IdleMngr();
301  // PRIVATE STATIC ATRIBUTES
302  static int glutIDVec[6]; // GLUT window IDs
303  static ViewerGlutOGL* instancePtrVec[6]; // pointers to class instances
304  // PRIVATE METHODS
305  void RegisterCallbacks();
306  void CommonConstructor();
307  void HandleKey(unsigned char key);
308  // PRIVATE ATRIBUTES
309  Scene* ptScene; // objects, lights and cameras
310  int glutID; // GLUT window id
311  KbHandler* kbHandlerPtr;
312  DrawHandler* drawHandlerPtr; // pointer to draw handler
313  IdleHandler* idleHndPtr; // pointer to idle handler
314  MouseControl mouseController;
315  int height; // window height in pixels
316  int width; // window width in pixels
317  Camera* cameraPtr;
318  }; // end class declaration
319 } // end namespace
320 
321 #endif
virtual void HandleKey(unsigned char key)
Called when a key is pressed.
Definition: viewerglutogl.h:56
void ClearOGLBuffers()
Sets clear color and clears OpenGL buffers.
const int KEY_UP
Definition: viewerglutogl.h:26
const int KEY_F9
Definition: viewerglutogl.h:21
const int KEY_F12
Definition: viewerglutogl.h:24
void SetDragHandler(MouseControl::DragHandler *newDHPtr)
Sets the mouse drag handler.
const int KEY_PAGE_UP
Definition: viewerglutogl.h:29
virtual void OnDraw()=0
Called when the window is redrawn.
const int KEY_F5
Definition: viewerglutogl.h:17
ViewerGlutOGL * viewerPtr
Points to the viewer on which the handler was attached.
Definition: viewerglutogl.h:90
void SetCamera(Camera *camPtr)
Sets the camera used to view the scene.
ViewerGlutOGL * viewerPtr
Points to the viewer on which the handler was attached.
V-ART Viewer that uses GLUT/OpenGL.
Definition: viewerglutogl.h:41
const int KEY_F8
Definition: viewerglutogl.h:20
void Iconify()
Iconifies (minimizes) the viewer window.
const int KEY_DOWN
Definition: viewerglutogl.h:28
const int KEY_INSERT
Definition: viewerglutogl.h:33
void Show()
Shows the viewer.
const int KEY_LEFT
Definition: viewerglutogl.h:25
void SetSize(int newWidth, int newHeight)
Sets the window size of the viewer.
virtual void OnIdle()=0
Called when the application is idle.
void Idle()
Idle Management.
ViewerGlutOGL()
Creates an empty, unusable viewer positioned at (0,0).
virtual void HandleSpecialKey(int key)
Called when a special key is pressed.
Definition: viewerglutogl.h:67
static void Init(int *argcPtr, char *argv[])
Initializes GLUT Library.
const int KEY_F4
Definition: viewerglutogl.h:16
const Camera * GetCurrentCamera() const
Returns the current camera or NULL if no camera exists.
void SetPosition(int x, int y)
Changes the position of a viewer.
void SetClickHandler(MouseControl::ClickHandler *newCHPtr)
Sets the mouse click handler.
void TurnIntoCurrentWindow()
Make the viewer become the current window.
Keeps track of mouse events and state.
Definition: mousecontrol.h:17
static void MainLoop()
Enters main rendering loop.
void SetMotionHandler(MouseControl::MotionHandler *newMHPtr)
Sets the mouse motion handler.
bool redrawOnIdle
Sets whether the viewer should redraw at every Idle call.
void SetDrawHandler(DrawHandler *newDHPtr)
Sets the drawing handler.
void SetIdleHandler(IdleHandler *newIHPtr)
Sets the idle time handler.
const int KEY_F10
Definition: viewerglutogl.h:22
void SetTitle(const std::string &newTitle)
Changes window title.
const int KEY_F3
Definition: viewerglutogl.h:15
ViewerGlutOGL * viewerPtr
Points to the viewer on which the handler was attached.
Definition: viewerglutogl.h:78
float walkStep
How much to walk at each step (mouse movement).
const int KEY_F2
Definition: viewerglutogl.h:14
void PostRedisplay()
Marks the viewer window for redisplay.
const int KEY_F11
Definition: viewerglutogl.h:23
void SetKbHandler(KbHandler *ptrKbH)
Add a keyboard handler to the viewer.
void Hide()
Hides the viewer.
Header file for V-ART class "MouseControl".
virtual void OnKeyDown(int key)
Called when a key is pressed.
void UseNextCamera()
Tells the scene to use next camera in its list.
const int KEY_F6
Definition: viewerglutogl.h:18
void SetScene(Scene &scene)
Attaches a scene to the viewer.
const int KEY_PAGE_DOWN
Definition: viewerglutogl.h:30
virtual void OnKeyUp(int key)
Called when a key is released.
Definition: viewerglutogl.h:75
int GetWidth()
Returns current window width.
const int KEY_F7
Definition: viewerglutogl.h:19
const int KEY_HOME
Definition: viewerglutogl.h:31
bool autoNavigationEnabled
Sets whether the built-in navigation is enabled. This is set to "true" by default.
const int KEY_RIGHT
Definition: viewerglutogl.h:27
static void RedisplayAll()
Marks all viewers for redisplay.
const int KEY_F1
Definition: viewerglutogl.h:13
const int KEY_END
Definition: viewerglutogl.h:32
int GetHeight()
Returns current window height.