V-ARTContributions
viewerglutogl.cpp
Go to the documentation of this file.
1 
6 #include <cassert>
7 #include <GL/glut.h>
8 
9 #include <iostream> // FixMe: Remove me if possible.
10 #include <cstdlib>
11 
12 using namespace std;
13 
14 const unsigned int MAX_VIEWERS = 6;
15 
16 // INITIALIZATION OF STATIC ATRIBUTES
17 int VART::ViewerGlutOGL::glutIDVec[6] = { 0, 0, 0, 0, 0, 0 };
18 VART::ViewerGlutOGL* VART::ViewerGlutOGL::instancePtrVec[6] = { NULL, NULL, NULL, NULL, NULL, NULL };
19 
20 // Keyboard handler methods:
21 // virtual, deprecated
23  // This should have been implemented, warn client.
24  cerr << "Warning: ViewerGlutOGL::HandleKey is deprecated, use OnKeyDown.\n";
25  HandleKey(static_cast<unsigned char>(key));
26 }
27 
28 
29 // FixMe: Add other constructors to avoid SetPosition.
30 
32 {
33  glutInitWindowSize(300,300);
34  width = 300;
35  height = 300;
36  CommonConstructor();
37 }
38 
39 VART::ViewerGlutOGL::ViewerGlutOGL(int newWidth, int newHeight)
40 {
41  glutInitWindowSize(newWidth, newHeight);
42  width = newWidth;
43  height = newHeight;
44  CommonConstructor();
45 }
46 
47 void VART::ViewerGlutOGL::CommonConstructor()
48 {
49  glutInitWindowPosition(0,0);
50  glutID = glutCreateWindow("V-ART Glut OpenGL Viewer");
51  ptScene = NULL;
52  idleHndPtr = NULL;
53  kbHandlerPtr = NULL;
54  drawHandlerPtr = NULL;
55  mouseController.SetOwner(this);
56  walkStep = 0.0001;
57  redrawOnIdle = false;
58  autoChangeCameraAspect = true;
59  autoNavigationEnabled = true;
60  autoRespondKeys = true;
61  glShadeModel(GL_SMOOTH);
62  glEnable(GL_DEPTH_TEST);
63  glEnable(GL_CULL_FACE);
64  // Enable vertex arrays to allow drawing of optimized mesh objects
65  glEnableClientState(GL_VERTEX_ARRAY);
66  glEnableClientState(GL_NORMAL_ARRAY);
67  RegisterCallbacks();
68  cameraPtr = NULL;
69 }
70 
72 {
73  int i = 0;
74  while (glutIDVec[i] != glutID)
75  ++i;
76  glutIDVec[i] = 0;
77  instancePtrVec[i] = NULL;
78 }
79 
81 {
82  idleHndPtr = newIHPtr;
83  if (newIHPtr)
84  newIHPtr->viewerPtr = this;
85 }
86 
88 {
89  int currentWindow = glutGetWindow();
90  glutSetWindow(glutID);
91  glutPositionWindow(x,y);
92  glutSetWindow(currentWindow);
93 }
94 
95 void VART::ViewerGlutOGL::SetSize(int newWidth, int newHeight)
96 {
97  int currentWindow = glutGetWindow(); // save current window
98  if (autoChangeCameraAspect && ptScene)
99  {
100  ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
101  float horScale = static_cast<float>(newWidth)/width;
102  float verScale = static_cast<float>(newHeight)/height;
103  ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
104  }
105  width = newWidth;
106  height = newHeight;
107  glutSetWindow(glutID);
108  glutReshapeWindow(newWidth, newHeight);
109  glutSetWindow(currentWindow); // restore current window
110  //~ glViewport(0,0,newWidth,newHeight);
111 }
112 
114 {
115  glutSetWindow(glutID);
116 }
117 
119 {
120  drawHandlerPtr = newDHPtr;
121  if (newDHPtr)
122  newDHPtr->viewerPtr = this;
123 }
124 
125 void VART::ViewerGlutOGL::SetScene(VART::Scene& scene)
126 {
127  ptScene = &scene;
128  if (cameraPtr == NULL)
129  cameraPtr = scene.GetCurrentCamera();
130  if (scene.GetNumLights() > 0)
131  {
132  int currentWindow = glutGetWindow();
133  glutSetWindow(glutID);
134  glEnable(GL_LIGHTING);
135  glutSetWindow(currentWindow);
136  }
137 }
138 
140 {
141  static float bgColor[4];
142  ptScene->GetBackgroundColor().GetScaled(1.0f, bgColor); // convert color components to float
143  glClearColor(bgColor[0], bgColor[1], bgColor[2], bgColor[3]);
144  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
145 }
146 
147 
149 // static method
150 {
151  glutIdleFunc(IdleMngr);
152  glutMainLoop();
153 }
154 
155 void VART::ViewerGlutOGL::Init(int* argcPtr, char* argv[])
156 // static method
157 {
158  glutInit(argcPtr, argv);
159  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
160 }
161 
163 // static method
164 {
165  for (unsigned int i = 0; i < MAX_VIEWERS; ++i)
166  if (instancePtrVec[i])
167  instancePtrVec[i]->PostRedisplay();
168 }
169 
170 void VART::ViewerGlutOGL::DrawCB0()
171 // This is the only DrawCB that can check the result of ptScene->DrawOGL() because
172 // the first viewer is allways instance 0 and it doesn't matter which instance calls
173 // DrawOGL (all will fail for wrong compilation parameters). However, if one creates
174 // two viewers then deletes the first, this checking will be bypassed...
175 {
176  ViewerGlutOGL* viewerPtr = instancePtrVec[0];
177 #ifdef NDEBUG
178  // Release version
179  viewerPtr->ClearOGLBuffers();
180  viewerPtr->ptScene->DrawOGL(viewerPtr->cameraPtr);
181 #else
182  // Debug version
183  if (viewerPtr->ptScene == NULL)
184  {
185  cerr << "Fatal error: VART::ViewerGlutOGL tried to draw a scene pointed by NULL!" << endl;
186  exit(1);
187  }
188  viewerPtr->ClearOGLBuffers();
189  if (!(viewerPtr->ptScene->DrawOGL()))
190  {
191  cerr << "Fatal error: VART::Scene::DrawOGL returned false!\n\a"
192  << "This means that V-ART has been compiled with no underlying rendering "
193  << "engine, please check your project options and re-compile V-ART." << endl;
194  exit(1);
195  }
196 #endif
197  if (viewerPtr->drawHandlerPtr) // if (drawHandlerPtr != NULL)
198  viewerPtr->drawHandlerPtr->OnDraw();
199  glutSwapBuffers();
200 }
201 
202 void VART::ViewerGlutOGL::DrawCB1()
203 {
204  ViewerGlutOGL* viewerPtr = instancePtrVec[1];
205  viewerPtr->ClearOGLBuffers();
206  viewerPtr->ptScene->DrawOGL(viewerPtr->cameraPtr);
207  if (viewerPtr->drawHandlerPtr) // if (drawHandlerPtr != NULL)
208  viewerPtr->drawHandlerPtr->OnDraw();
209  glutSwapBuffers();
210 }
211 
212 void VART::ViewerGlutOGL::DrawCB2()
213 {
214  ViewerGlutOGL* viewerPtr = instancePtrVec[2];
215  viewerPtr->ClearOGLBuffers();
216  viewerPtr->ptScene->DrawOGL(viewerPtr->cameraPtr);
217  if (viewerPtr->drawHandlerPtr) // if (drawHandlerPtr != NULL)
218  viewerPtr->drawHandlerPtr->OnDraw();
219  glutSwapBuffers();
220 }
221 
222 void VART::ViewerGlutOGL::DrawCB3()
223 {
224  ViewerGlutOGL* viewerPtr = instancePtrVec[3];
225  viewerPtr->ClearOGLBuffers();
226  viewerPtr->ptScene->DrawOGL(viewerPtr->cameraPtr);
227  if (viewerPtr->drawHandlerPtr) // if (drawHandlerPtr != NULL)
228  viewerPtr->drawHandlerPtr->OnDraw();
229  glutSwapBuffers();
230 }
231 
232 void VART::ViewerGlutOGL::DrawCB4()
233 {
234  ViewerGlutOGL* viewerPtr = instancePtrVec[4];
235  viewerPtr->ClearOGLBuffers();
236  viewerPtr->ptScene->DrawOGL(viewerPtr->cameraPtr);
237  if (viewerPtr->drawHandlerPtr) // if (drawHandlerPtr != NULL)
238  viewerPtr->drawHandlerPtr->OnDraw();
239  glutSwapBuffers();
240 }
241 
242 void VART::ViewerGlutOGL::DrawCB5()
243 {
244  ViewerGlutOGL* viewerPtr = instancePtrVec[5];
245  viewerPtr->ClearOGLBuffers();
246  viewerPtr->ptScene->DrawOGL(viewerPtr->cameraPtr);
247  if (viewerPtr->drawHandlerPtr) // if (drawHandlerPtr != NULL)
248  viewerPtr->drawHandlerPtr->OnDraw();
249  glutSwapBuffers();
250 }
251 
252 void VART::ViewerGlutOGL::MouseCB0(int button, int state, int x, int y)
253 {
254  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[0];
255  int keyModifier = glutGetModifiers();
257 
258  switch (button)
259  {
260  //FixMe: There may be a faster way...
261  case GLUT_LEFT_BUTTON:
262  vpButton = VART::MouseControl::LEFT;
263  break;
264  case GLUT_MIDDLE_BUTTON:
265  vpButton = VART::MouseControl::MIDDLE;
266  break;
267  case GLUT_RIGHT_BUTTON:
268  vpButton = VART::MouseControl::RIGHT;
269  break;
270  case 3: // FixMe: use the GLUT constant!
271  vpButton = VART::MouseControl::WHEEL_UP;
272  break;
273  default:
275  }
276  if (state == GLUT_DOWN)
277  {
278  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::DOWN);
279  viewerPtr->mouseController.SetClickPosition(x, y);
280  }
281  else
282  {
283  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::UP);
284  viewerPtr->mouseController.SetReleasedPosition(x, y);
285  }
286  if (keyModifier & GLUT_ACTIVE_SHIFT)
287  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, true);
288  else
289  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, false);
290  if (keyModifier & GLUT_ACTIVE_CTRL)
291  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, true);
292  else
293  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, false);
294  if (keyModifier & GLUT_ACTIVE_ALT)
295  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, true);
296  else
297  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, false);
298  viewerPtr->mouseController.SetCurrentPosititon(x,y);
299  viewerPtr->mouseController.OnClick();
300 }
301 
302 void VART::ViewerGlutOGL::MouseCB1(int button, int state, int x, int y)
303 {
304  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[1];
305  int keyModifier = glutGetModifiers();
307 
308  switch (button)
309  {
310  //FixMe: There may be a faster way...
311  case GLUT_LEFT_BUTTON:
312  vpButton = VART::MouseControl::LEFT;
313  break;
314  case GLUT_MIDDLE_BUTTON:
315  vpButton = VART::MouseControl::MIDDLE;
316  break;
317  case GLUT_RIGHT_BUTTON:
318  vpButton = VART::MouseControl::RIGHT;
319  break;
320  case 3: // FixMe: use the GLUT constant!
321  vpButton = VART::MouseControl::WHEEL_UP;
322  break;
323  default:
325  }
326  if (state == GLUT_DOWN)
327  {
328  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::DOWN);
329  viewerPtr->mouseController.SetClickPosition(x, y);
330  }
331  else
332  {
333  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::UP);
334  viewerPtr->mouseController.SetReleasedPosition(x, y);
335  }
336  if (keyModifier & GLUT_ACTIVE_SHIFT)
337  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, true);
338  else
339  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, false);
340  if (keyModifier & GLUT_ACTIVE_CTRL)
341  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, true);
342  else
343  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, false);
344  if (keyModifier & GLUT_ACTIVE_ALT)
345  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, true);
346  else
347  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, false);
348  viewerPtr->mouseController.SetCurrentPosititon(x,y);
349  viewerPtr->mouseController.OnClick();
350 }
351 
352 void VART::ViewerGlutOGL::MouseCB2(int button, int state, int x, int y)
353 {
354  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[2];
355  int keyModifier = glutGetModifiers();
357 
358  switch (button)
359  {
360  //FixMe: There may be a faster way...
361  case GLUT_LEFT_BUTTON:
362  vpButton = VART::MouseControl::LEFT;
363  break;
364  case GLUT_MIDDLE_BUTTON:
365  vpButton = VART::MouseControl::MIDDLE;
366  break;
367  case GLUT_RIGHT_BUTTON:
368  vpButton = VART::MouseControl::RIGHT;
369  break;
370  case 3: // FixMe: use the GLUT constant!
371  vpButton = VART::MouseControl::WHEEL_UP;
372  break;
373  default:
375  }
376  if (state == GLUT_DOWN)
377  {
378  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::DOWN);
379  viewerPtr->mouseController.SetClickPosition(x, y);
380  }
381  else
382  {
383  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::UP);
384  viewerPtr->mouseController.SetReleasedPosition(x, y);
385  }
386  if (keyModifier & GLUT_ACTIVE_SHIFT)
387  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, true);
388  else
389  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, false);
390  if (keyModifier & GLUT_ACTIVE_CTRL)
391  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, true);
392  else
393  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, false);
394  if (keyModifier & GLUT_ACTIVE_ALT)
395  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, true);
396  else
397  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, false);
398  viewerPtr->mouseController.SetCurrentPosititon(x,y);
399  viewerPtr->mouseController.OnClick();
400 }
401 
402 void VART::ViewerGlutOGL::MouseCB3(int button, int state, int x, int y)
403 {
404  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[3];
405  int keyModifier = glutGetModifiers();
407 
408  switch (button)
409  {
410  //FixMe: There may be a faster way...
411  case GLUT_LEFT_BUTTON:
412  vpButton = VART::MouseControl::LEFT;
413  break;
414  case GLUT_MIDDLE_BUTTON:
415  vpButton = VART::MouseControl::MIDDLE;
416  break;
417  case GLUT_RIGHT_BUTTON:
418  vpButton = VART::MouseControl::RIGHT;
419  break;
420  case 3: // FixMe: use the GLUT constant!
421  vpButton = VART::MouseControl::WHEEL_UP;
422  break;
423  default:
425  }
426  if (state == GLUT_DOWN)
427  {
428  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::DOWN);
429  viewerPtr->mouseController.SetClickPosition(x, y);
430  }
431  else
432  {
433  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::UP);
434  viewerPtr->mouseController.SetReleasedPosition(x, y);
435  }
436  if (keyModifier & GLUT_ACTIVE_SHIFT)
437  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, true);
438  else
439  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, false);
440  if (keyModifier & GLUT_ACTIVE_CTRL)
441  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, true);
442  else
443  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, false);
444  if (keyModifier & GLUT_ACTIVE_ALT)
445  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, true);
446  else
447  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, false);
448  viewerPtr->mouseController.SetCurrentPosititon(x,y);
449  viewerPtr->mouseController.OnClick();
450 }
451 
452 void VART::ViewerGlutOGL::MouseCB4(int button, int state, int x, int y)
453 {
454  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[4];
455  int keyModifier = glutGetModifiers();
457 
458  switch (button)
459  {
460  //FixMe: There may be a faster way...
461  case GLUT_LEFT_BUTTON:
462  vpButton = VART::MouseControl::LEFT;
463  break;
464  case GLUT_MIDDLE_BUTTON:
465  vpButton = VART::MouseControl::MIDDLE;
466  break;
467  case GLUT_RIGHT_BUTTON:
468  vpButton = VART::MouseControl::RIGHT;
469  break;
470  case 3: // FixMe: use the GLUT constant!
471  vpButton = VART::MouseControl::WHEEL_UP;
472  break;
473  default:
475  }
476  if (state == GLUT_DOWN)
477  {
478  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::DOWN);
479  viewerPtr->mouseController.SetClickPosition(x, y);
480  }
481  else
482  {
483  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::UP);
484  viewerPtr->mouseController.SetReleasedPosition(x, y);
485  }
486  if (keyModifier & GLUT_ACTIVE_SHIFT)
487  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, true);
488  else
489  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, false);
490  if (keyModifier & GLUT_ACTIVE_CTRL)
491  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, true);
492  else
493  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, false);
494  if (keyModifier & GLUT_ACTIVE_ALT)
495  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, true);
496  else
497  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, false);
498  viewerPtr->mouseController.SetCurrentPosititon(x,y);
499  viewerPtr->mouseController.OnClick();
500 }
501 
502 void VART::ViewerGlutOGL::MouseCB5(int button, int state, int x, int y)
503 {
504  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[5];
505  int keyModifier = glutGetModifiers();
507 
508  switch (button)
509  {
510  //FixMe: There may be a faster way...
511  case GLUT_LEFT_BUTTON:
512  vpButton = VART::MouseControl::LEFT;
513  break;
514  case GLUT_MIDDLE_BUTTON:
515  vpButton = VART::MouseControl::MIDDLE;
516  break;
517  case GLUT_RIGHT_BUTTON:
518  vpButton = VART::MouseControl::RIGHT;
519  break;
520  case 3: // FixMe: use the GLUT constant!
521  vpButton = VART::MouseControl::WHEEL_UP;
522  break;
523  default:
525  }
526  if (state == GLUT_DOWN)
527  {
528  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::DOWN);
529  viewerPtr->mouseController.SetClickPosition(x, y);
530  }
531  else
532  {
533  viewerPtr->mouseController.NewEvent(vpButton, VART::MouseControl::UP);
534  viewerPtr->mouseController.SetReleasedPosition(x, y);
535  }
536  if (keyModifier & GLUT_ACTIVE_SHIFT)
537  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, true);
538  else
539  viewerPtr->mouseController.SetModifierState(VART::MouseControl::SHIFT, false);
540  if (keyModifier & GLUT_ACTIVE_CTRL)
541  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, true);
542  else
543  viewerPtr->mouseController.SetModifierState(VART::MouseControl::CONTROL, false);
544  if (keyModifier & GLUT_ACTIVE_ALT)
545  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, true);
546  else
547  viewerPtr->mouseController.SetModifierState(VART::MouseControl::ALT, false);
548  viewerPtr->mouseController.SetCurrentPosititon(x,y);
549  viewerPtr->mouseController.OnClick();
550 }
551 
552 void VART::ViewerGlutOGL::DragMouseCB0(int x, int y)
553 {
554  instancePtrVec[0]->mouseController.SetCurrentPosititon(x,y);
555  instancePtrVec[0]->mouseController.OnDrag();
556 }
557 
558 void VART::ViewerGlutOGL::DragMouseCB1(int x, int y)
559 {
560  instancePtrVec[1]->mouseController.SetCurrentPosititon(x,y);
561  instancePtrVec[1]->mouseController.OnDrag();
562 }
563 
564 void VART::ViewerGlutOGL::DragMouseCB2(int x, int y)
565 {
566  instancePtrVec[2]->mouseController.SetCurrentPosititon(x,y);
567  instancePtrVec[2]->mouseController.OnDrag();
568 }
569 
570 void VART::ViewerGlutOGL::DragMouseCB3(int x, int y)
571 {
572  instancePtrVec[3]->mouseController.SetCurrentPosititon(x,y);
573  instancePtrVec[3]->mouseController.OnDrag();
574 }
575 
576 void VART::ViewerGlutOGL::DragMouseCB4(int x, int y)
577 {
578  instancePtrVec[4]->mouseController.SetCurrentPosititon(x,y);
579  instancePtrVec[4]->mouseController.OnDrag();
580 }
581 
582 void VART::ViewerGlutOGL::DragMouseCB5(int x, int y)
583 {
584  instancePtrVec[5]->mouseController.SetCurrentPosititon(x,y);
585  instancePtrVec[5]->mouseController.OnDrag();
586 }
587 
588 void VART::ViewerGlutOGL::HandleKey(unsigned char key)
589 {
590  VART::Camera* cameraPtr = ptScene->GetCurrentCamera();
591  switch (key)
592  {
593  case 'a':
594  cameraPtr->YawAroundTarget(0.01);
595  break;
596  case 'd':
597  cameraPtr->YawAroundTarget(-0.01);
598  break;
599  case 'w':
600  cameraPtr->PitchAroundTarget(0.01);
601  break;
602  case 's':
603  cameraPtr->PitchAroundTarget(-0.01);
604  break;
605  case 'q':
606  exit(0);
607  break;
608  default:
609  return;
610  }
611  glutPostRedisplay();
612 }
613 
614 // Special keys get translated to V-ART's mixed key handler by adding 255, so that no
615 // special gets a value below 256.
616 void VART::ViewerGlutOGL::SpecialKeyCB0(int key, int x, int y)
617 {
618  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[0]; // to ease copy/paste among keyboard CBs
619  // Call keyboard handler
620  if (viewerPtr->kbHandlerPtr) {
621  viewerPtr->kbHandlerPtr->HandleSpecialKey(key); // deprecated, remove this in the future
622  viewerPtr->kbHandlerPtr->OnKeyDown(key+255);
623  }
624 }
625 
626 void VART::ViewerGlutOGL::SpecialKeyCB1(int key, int x, int y)
627 {
628  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[1]; // to ease copy/paste among keyboard CBs
629  // Call keyboard handler
630  if (viewerPtr->kbHandlerPtr) {
631  viewerPtr->kbHandlerPtr->HandleSpecialKey(key); // deprecated, remove this in the future
632  viewerPtr->kbHandlerPtr->OnKeyDown(key+255);
633  }
634 }
635 
636 void VART::ViewerGlutOGL::SpecialKeyCB2(int key, int x, int y)
637 {
638  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[2]; // to ease copy/paste among keyboard CBs
639  // Call keyboard handler
640  if (viewerPtr->kbHandlerPtr) {
641  viewerPtr->kbHandlerPtr->HandleSpecialKey(key); // deprecated, remove this in the future
642  viewerPtr->kbHandlerPtr->OnKeyDown(key+255);
643  }
644 }
645 
646 void VART::ViewerGlutOGL::SpecialKeyCB3(int key, int x, int y)
647 {
648  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[3]; // to ease copy/paste among keyboard CBs
649  // Call keyboard handler
650  if (viewerPtr->kbHandlerPtr) {
651  viewerPtr->kbHandlerPtr->HandleSpecialKey(key); // deprecated, remove this in the future
652  viewerPtr->kbHandlerPtr->OnKeyDown(key+255);
653  }
654 }
655 
656 void VART::ViewerGlutOGL::SpecialKeyCB4(int key, int x, int y)
657 {
658  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[4]; // to ease copy/paste among keyboard CBs
659  // Call keyboard handler
660  if (viewerPtr->kbHandlerPtr) {
661  viewerPtr->kbHandlerPtr->HandleSpecialKey(key); // deprecated, remove this in the future
662  viewerPtr->kbHandlerPtr->OnKeyDown(key+255);
663  }
664 }
665 
666 void VART::ViewerGlutOGL::SpecialKeyCB5(int key, int x, int y)
667 {
668  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[5]; // to ease copy/paste among keyboard CBs
669  // Call keyboard handler
670  if (viewerPtr->kbHandlerPtr) {
671  viewerPtr->kbHandlerPtr->HandleSpecialKey(key); // deprecated, remove this in the future
672  viewerPtr->kbHandlerPtr->OnKeyDown(key+255);
673  }
674 }
675 
676 // Special keys get translated to V-ART's mixed key handler by adding 255, so that no
677 // special gets a value below 256.
678 void VART::ViewerGlutOGL::SpecialKeyUpCB0(int key, int x, int y)
679 {
680  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[0]; // to ease copy/paste among keyboard CBs
681  // Call keyboard handler
682  if (viewerPtr->kbHandlerPtr)
683  viewerPtr->kbHandlerPtr->OnKeyUp(key+255);
684 }
685 
686 void VART::ViewerGlutOGL::SpecialKeyUpCB1(int key, int x, int y)
687 {
688  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[1]; // to ease copy/paste among keyboard CBs
689  // Call keyboard handler
690  if (viewerPtr->kbHandlerPtr)
691  viewerPtr->kbHandlerPtr->OnKeyUp(key+255);
692 }
693 
694 void VART::ViewerGlutOGL::SpecialKeyUpCB2(int key, int x, int y)
695 {
696  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[2]; // to ease copy/paste among keyboard CBs
697  // Call keyboard handler
698  if (viewerPtr->kbHandlerPtr)
699  viewerPtr->kbHandlerPtr->OnKeyUp(key+255);
700 }
701 
702 void VART::ViewerGlutOGL::SpecialKeyUpCB3(int key, int x, int y)
703 {
704  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[3]; // to ease copy/paste among keyboard CBs
705  // Call keyboard handler
706  if (viewerPtr->kbHandlerPtr)
707  viewerPtr->kbHandlerPtr->OnKeyUp(key+255);
708 }
709 
710 void VART::ViewerGlutOGL::SpecialKeyUpCB4(int key, int x, int y)
711 {
712  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[4]; // to ease copy/paste among keyboard CBs
713  // Call keyboard handler
714  if (viewerPtr->kbHandlerPtr)
715  viewerPtr->kbHandlerPtr->OnKeyUp(key+255);
716 }
717 
718 void VART::ViewerGlutOGL::SpecialKeyUpCB5(int key, int x, int y)
719 {
720  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[5]; // to ease copy/paste among keyboard CBs
721  // Call keyboard handler
722  if (viewerPtr->kbHandlerPtr)
723  viewerPtr->kbHandlerPtr->OnKeyUp(key+255);
724 }
725 
726 // Callbacks for "normal" keys:
727 void VART::ViewerGlutOGL::KeyboardCB0(unsigned char key, int x, int y)
728 {
729  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[0]; // to ease copy/paste among keyboard CBs
730  // Call keyboard handler
731  if (viewerPtr->kbHandlerPtr)
732  viewerPtr->kbHandlerPtr->OnKeyDown(static_cast<int>(key));
733  // Viewer's built-in keyboard handling
734  if (viewerPtr->autoRespondKeys)
735  viewerPtr->HandleKey(key);
736 }
737 
738 void VART::ViewerGlutOGL::KeyboardCB1(unsigned char key, int x, int y)
739 {
740  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[1]; // to ease copy/paste among keyboard CBs
741  // Call keyboard handler
742  if (viewerPtr->kbHandlerPtr)
743  viewerPtr->kbHandlerPtr->OnKeyDown(static_cast<int>(key));
744  // Viewer's built-in keyboard handling
745  if (viewerPtr->autoRespondKeys)
746  viewerPtr->HandleKey(key);
747 }
748 
749 void VART::ViewerGlutOGL::KeyboardCB2(unsigned char key, int x, int y)
750 {
751  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[2]; // to ease copy/paste among keyboard CBs
752  // Call keyboard handler
753  if (viewerPtr->kbHandlerPtr)
754  viewerPtr->kbHandlerPtr->OnKeyDown(static_cast<int>(key));
755  // Viewer's built-in keyboard handling
756  if (viewerPtr->autoRespondKeys)
757  viewerPtr->HandleKey(key);
758 }
759 
760 void VART::ViewerGlutOGL::KeyboardCB3(unsigned char key, int x, int y)
761 {
762  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[3]; // to ease copy/paste among keyboard CBs
763  // Call keyboard handler
764  if (viewerPtr->kbHandlerPtr)
765  viewerPtr->kbHandlerPtr->OnKeyDown(static_cast<int>(key));
766  // Viewer's built-in keyboard handling
767  if (viewerPtr->autoRespondKeys)
768  viewerPtr->HandleKey(key);
769 }
770 
771 void VART::ViewerGlutOGL::KeyboardCB4(unsigned char key, int x, int y)
772 {
773  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[4]; // to ease copy/paste among keyboard CBs
774  // Call keyboard handler
775  if (viewerPtr->kbHandlerPtr)
776  viewerPtr->kbHandlerPtr->OnKeyDown(static_cast<int>(key));
777  // Viewer's built-in keyboard handling
778  if (viewerPtr->autoRespondKeys)
779  viewerPtr->HandleKey(key);
780 }
781 
782 void VART::ViewerGlutOGL::KeyboardCB5(unsigned char key, int x, int y)
783 {
784  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[5]; // to ease copy/paste among keyboard CBs
785  // Call keyboard handler
786  if (viewerPtr->kbHandlerPtr)
787  viewerPtr->kbHandlerPtr->OnKeyDown(static_cast<int>(key));
788  // Viewer's built-in keyboard handling
789  if (viewerPtr->autoRespondKeys)
790  viewerPtr->HandleKey(key);
791 }
792 
793 // Callbacks for key ups:
794 void VART::ViewerGlutOGL::OnKeyUpCB0(unsigned char key, int x, int y)
795 {
796  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[0]; // to ease copy/paste among keyboard CBs
797  // Call keyboard handler
798  if (viewerPtr->kbHandlerPtr)
799  viewerPtr->kbHandlerPtr->OnKeyUp(static_cast<int>(key));
800 }
801 
802 void VART::ViewerGlutOGL::OnKeyUpCB1(unsigned char key, int x, int y)
803 {
804  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[1]; // to ease copy/paste among keyboard CBs
805  // Call keyboard handler
806  if (viewerPtr->kbHandlerPtr)
807  viewerPtr->kbHandlerPtr->OnKeyUp(static_cast<int>(key));
808 }
809 
810 void VART::ViewerGlutOGL::OnKeyUpCB2(unsigned char key, int x, int y)
811 {
812  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[2]; // to ease copy/paste among keyboard CBs
813  // Call keyboard handler
814  if (viewerPtr->kbHandlerPtr)
815  viewerPtr->kbHandlerPtr->OnKeyUp(static_cast<int>(key));
816 }
817 
818 void VART::ViewerGlutOGL::OnKeyUpCB3(unsigned char key, int x, int y)
819 {
820  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[3]; // to ease copy/paste among keyboard CBs
821  // Call keyboard handler
822  if (viewerPtr->kbHandlerPtr)
823  viewerPtr->kbHandlerPtr->OnKeyUp(static_cast<int>(key));
824 }
825 
826 void VART::ViewerGlutOGL::OnKeyUpCB4(unsigned char key, int x, int y)
827 {
828  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[4]; // to ease copy/paste among keyboard CBs
829  // Call keyboard handler
830  if (viewerPtr->kbHandlerPtr)
831  viewerPtr->kbHandlerPtr->OnKeyUp(static_cast<int>(key));
832 }
833 
834 void VART::ViewerGlutOGL::OnKeyUpCB5(unsigned char key, int x, int y)
835 {
836  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[5]; // to ease copy/paste among keyboard CBs
837  // Call keyboard handler
838  if (viewerPtr->kbHandlerPtr)
839  viewerPtr->kbHandlerPtr->OnKeyUp(static_cast<int>(key));
840 }
841 
842 // Resize callbacks:
843 void VART::ViewerGlutOGL::ResizeCB0(int newWidth, int newHeight)
844 {
845  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[0]; // to ease copy/paste among resize CBs
846  if (viewerPtr->autoChangeCameraAspect) {
847  assert(viewerPtr->ptScene != NULL);
848  viewerPtr->ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
849  float horScale = static_cast<float>(newWidth)/viewerPtr->width;
850  float verScale = static_cast<float>(newHeight)/viewerPtr->height;
851  viewerPtr->ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
852  }
853  viewerPtr->width = newWidth;
854  viewerPtr->height = newHeight;
855  glViewport(0,0,newWidth,newHeight);
856 }
857 
858 void VART::ViewerGlutOGL::ResizeCB1(int newWidth, int newHeight)
859 {
860  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[1]; // to ease copy/paste among resize CBs
861  if (viewerPtr->autoChangeCameraAspect) {
862  assert(viewerPtr->ptScene != NULL);
863  viewerPtr->ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
864  float horScale = static_cast<float>(newWidth)/viewerPtr->width;
865  float verScale = static_cast<float>(newHeight)/viewerPtr->height;
866  viewerPtr->ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
867  }
868  viewerPtr->width = newWidth;
869  viewerPtr->height = newHeight;
870  glViewport(0,0,newWidth,newHeight);
871 }
872 
873 void VART::ViewerGlutOGL::ResizeCB2(int newWidth, int newHeight)
874 {
875  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[2]; // to ease copy/paste among resize CBs
876  if (viewerPtr->autoChangeCameraAspect) {
877  assert(viewerPtr->ptScene != NULL);
878  viewerPtr->ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
879  float horScale = static_cast<float>(newWidth)/viewerPtr->width;
880  float verScale = static_cast<float>(newHeight)/viewerPtr->height;
881  viewerPtr->ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
882  }
883  viewerPtr->width = newWidth;
884  viewerPtr->height = newHeight;
885  glViewport(0,0,newWidth,newHeight);
886 }
887 
888 void VART::ViewerGlutOGL::ResizeCB3(int newWidth, int newHeight)
889 {
890  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[3]; // to ease copy/paste among resize CBs
891  if (viewerPtr->autoChangeCameraAspect) {
892  assert(viewerPtr->ptScene != NULL);
893  viewerPtr->ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
894  float horScale = static_cast<float>(newWidth)/viewerPtr->width;
895  float verScale = static_cast<float>(newHeight)/viewerPtr->height;
896  viewerPtr->ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
897  }
898  viewerPtr->width = newWidth;
899  viewerPtr->height = newHeight;
900  glViewport(0,0,newWidth,newHeight);
901 }
902 
903 void VART::ViewerGlutOGL::ResizeCB4(int newWidth, int newHeight)
904 {
905  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[4]; // to ease copy/paste among resize CBs
906  if (viewerPtr->autoChangeCameraAspect) {
907  assert(viewerPtr->ptScene != NULL);
908  viewerPtr->ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
909  float horScale = static_cast<float>(newWidth)/viewerPtr->width;
910  float verScale = static_cast<float>(newHeight)/viewerPtr->height;
911  viewerPtr->ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
912  }
913  viewerPtr->width = newWidth;
914  viewerPtr->height = newHeight;
915  glViewport(0,0,newWidth,newHeight);
916 }
917 
918 void VART::ViewerGlutOGL::ResizeCB5(int newWidth, int newHeight)
919 {
920  VART::ViewerGlutOGL* viewerPtr = instancePtrVec[5]; // to ease copy/paste among resize CBs
921  if (viewerPtr->autoChangeCameraAspect) {
922  assert(viewerPtr->ptScene != NULL);
923  viewerPtr->ptScene->SetAllCamerasAspectRatio(static_cast<float>(newWidth)/newHeight);
924  float horScale = static_cast<float>(newWidth)/viewerPtr->width;
925  float verScale = static_cast<float>(newHeight)/viewerPtr->height;
926  viewerPtr->ptScene->ChangeAllCamerasViewVolume(horScale,verScale);
927  }
928  viewerPtr->width = newWidth;
929  viewerPtr->height = newHeight;
930  glViewport(0,0,newWidth,newHeight);
931 }
932 
934 // Handles basic camera movment:
935 // LEFT: pitch and yaw around target.
936 // RIGHT: walk and yaw.
937 // RIGHT + CTRL: slide.
938 {
939  int currentWindow = glutGetWindow();
940  glutSetWindow(glutID);
941  if (mouseController.AnyButtonIsDown() && autoNavigationEnabled)
942  {
943  VART::Camera* ptCam = ptScene->GetCurrentCamera();
944  if (mouseController.ButtonIsDown(VART::MouseControl::LEFT))
945  {
946  double pitchAngle = mouseController.GetYDrag() * 0.00001;
947  double yawAngle = mouseController.GetXDrag() * -0.00001;
948  ptCam->PitchAroundTarget(pitchAngle);
949  ptCam->YawAroundTarget(yawAngle);
950  }
951  else
952  { // Consider RIGHT button is down
953  if (mouseController.ModifierIsActive(VART::MouseControl::CONTROL))
954  {
955  double Xdiff = mouseController.GetXDrag() * walkStep;
956  double Ydiff = mouseController.GetYDrag() * (-walkStep);
957  ptCam->MoveSideways(Xdiff);
958  ptCam->MoveUp(Ydiff);
959  }
960  else
961  {
962  double Ydiff = mouseController.GetYDrag() * (-walkStep);
963  double yawAngle = mouseController.GetXDrag() * -0.00001;
964  ptCam->MoveForward(Ydiff);
965  ptCam->Yaw(yawAngle);
966  }
967  }
968  glutPostRedisplay();
969  }
970  if (idleHndPtr) { // if (idleHndPtr != NULL)
971  idleHndPtr->OnIdle();
972  }
973  if (redrawOnIdle) {
974  glutPostRedisplay();
975  }
976  glutSetWindow(currentWindow);
977 }
978 
979 void VART::ViewerGlutOGL::IdleMngr()
980 {
981  for (int i = 0; i < 6; ++i)
982  if (instancePtrVec[i]) // if instancePtrVec[i] != NULL ...
983  instancePtrVec[i]->Idle();
984 }
985 
986 void VART::ViewerGlutOGL::RegisterCallbacks()
987 {
988  int i = 0;
989  while ((i<6) && (glutIDVec[i] != 0))
990  ++i;
991  if (i < 6)
992  {
993  glutIDVec[i] = glutID;
994  instancePtrVec[i] = this;
995  switch (i)
996  {
997  case 0:
998  glutDisplayFunc(DrawCB0);
999  glutMouseFunc(MouseCB0);
1000  glutMotionFunc(DragMouseCB0);
1001  glutKeyboardFunc(KeyboardCB0);
1002  glutKeyboardUpFunc(OnKeyUpCB0);
1003  glutReshapeFunc(ResizeCB0);
1004  glutSpecialFunc(SpecialKeyCB0);
1005  glutSpecialUpFunc(SpecialKeyUpCB0);
1006  break;
1007  case 1:
1008  glutDisplayFunc(DrawCB1);
1009  glutMouseFunc(MouseCB1);
1010  glutMotionFunc(DragMouseCB1);
1011  glutKeyboardFunc(KeyboardCB1);
1012  glutKeyboardUpFunc(OnKeyUpCB1);
1013  glutReshapeFunc(ResizeCB1);
1014  glutSpecialFunc(SpecialKeyCB1);
1015  glutSpecialUpFunc(SpecialKeyUpCB1);
1016  break;
1017  case 2:
1018  glutDisplayFunc(DrawCB2);
1019  glutMouseFunc(MouseCB2);
1020  glutMotionFunc(DragMouseCB2);
1021  glutKeyboardFunc(KeyboardCB2);
1022  glutKeyboardUpFunc(OnKeyUpCB2);
1023  glutReshapeFunc(ResizeCB2);
1024  glutSpecialFunc(SpecialKeyCB2);
1025  glutSpecialUpFunc(SpecialKeyUpCB2);
1026  break;
1027  case 3:
1028  glutDisplayFunc(DrawCB3);
1029  glutMouseFunc(MouseCB3);
1030  glutMotionFunc(DragMouseCB3);
1031  glutKeyboardFunc(KeyboardCB3);
1032  glutKeyboardUpFunc(OnKeyUpCB3);
1033  glutReshapeFunc(ResizeCB3);
1034  glutSpecialFunc(SpecialKeyCB3);
1035  glutSpecialUpFunc(SpecialKeyUpCB3);
1036  break;
1037  case 4:
1038  glutDisplayFunc(DrawCB4);
1039  glutMouseFunc(MouseCB4);
1040  glutMotionFunc(DragMouseCB4);
1041  glutKeyboardFunc(KeyboardCB4);
1042  glutKeyboardUpFunc(OnKeyUpCB4);
1043  glutReshapeFunc(ResizeCB4);
1044  glutSpecialFunc(SpecialKeyCB4);
1045  glutSpecialUpFunc(SpecialKeyUpCB4);
1046  break;
1047  default:
1048  glutDisplayFunc(DrawCB5);
1049  glutMouseFunc(MouseCB5);
1050  glutMotionFunc(DragMouseCB5);
1051  glutKeyboardFunc(KeyboardCB5);
1052  glutKeyboardUpFunc(OnKeyUpCB5);
1053  glutReshapeFunc(ResizeCB5);
1054  glutSpecialFunc(SpecialKeyCB5);
1055  glutSpecialUpFunc(SpecialKeyUpCB5);
1056  break;
1057  }
1058  }
1059 }
1060 
1062 {
1063  int currentWindow = glutGetWindow();
1064  glutSetWindow(glutID);
1065  glutHideWindow();
1066  glutSetWindow(currentWindow);
1067 }
1068 
1070 {
1071  int currentWindow = glutGetWindow();
1072  glutSetWindow(glutID);
1073  glutShowWindow();
1074  glutSetWindow(currentWindow);
1075 }
1076 
1077 void VART::ViewerGlutOGL::SetTitle(const std::string& newTitle)
1078 {
1079  int currentWindow = glutGetWindow();
1080  glutSetWindow(glutID);
1081  glutSetWindowTitle(newTitle.c_str());
1082  glutSetIconTitle(newTitle.c_str());
1083  glutSetWindow(currentWindow);
1084 }
1085 
1087 {
1088  int currentWindow = glutGetWindow();
1089  glutSetWindow(glutID);
1090  glutIconifyWindow();
1091  glutSetWindow(currentWindow);
1092 }
1093 
1095 {
1096  int currentWindow = glutGetWindow();
1097  glutSetWindow(glutID);
1098  glutPostRedisplay();
1099  glutSetWindow(currentWindow);
1100 }
1101 
1103 {
1104  kbHandlerPtr = ptrKbH;
1105  ptrKbH->viewerPtr = this;
1106 }
1107 
1109 {
1110  cameraPtr = camPtr;
1111 }
1112 
1114 {
1115  mouseController.SetClickHandler(newCHPtr);
1116 }
1117 
1119 {
1120  mouseController.SetDragHandler(newDHPtr);
1121 }
1122 
1124 {
1125  mouseController.SetMotionHandler(newMHPtr);
1126 }
void ClearOGLBuffers()
Sets clear color and clears OpenGL buffers.
void SetDragHandler(MouseControl::DragHandler *newDHPtr)
Sets the mouse drag handler.
virtual void OnDraw()=0
Called when the window is redrawn.
void SetModifierState(ModifierID mdValue, bool state)
Sets the modifier state on last event.
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
void SetCurrentPosititon(int newX, int newY)
Set the current position.
Definition: mousecontrol.h:123
Header file for V-ART class "ViewerGlutOGL".
void Iconify()
Iconifies (minimizes) the viewer window.
void Show()
Shows the viewer.
void SetSize(int newWidth, int newHeight)
Sets the window size of the viewer.
void NewEvent(ButtonID btn, StateID newState)
Registers new button event.
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.
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.
void OnClick()
Activates click handler, if any.
static void MainLoop()
Enters main rendering loop.
void SetMotionHandler(MouseControl::MotionHandler *newMHPtr)
Sets the mouse motion handler.
const unsigned int MAX_VIEWERS
void SetDrawHandler(DrawHandler *newDHPtr)
Sets the drawing handler.
void SetIdleHandler(IdleHandler *newIHPtr)
Sets the idle time handler.
void SetTitle(const std::string &newTitle)
Changes window title.
ViewerGlutOGL * viewerPtr
Points to the viewer on which the handler was attached.
Definition: viewerglutogl.h:78
void PostRedisplay()
Marks the viewer window for redisplay.
void SetKbHandler(KbHandler *ptrKbH)
Add a keyboard handler to the viewer.
void Hide()
Hides the viewer.
virtual void OnKeyDown(int key)
Called when a key is pressed.
void SetReleasedPosition(int newX, int newY)
Sets the position of last button release.
Definition: mousecontrol.h:134
void SetScene(Scene &scene)
Attaches a scene to the viewer.
virtual void OnKeyUp(int key)
Called when a key is released.
Definition: viewerglutogl.h:75
static void RedisplayAll()
Marks all viewers for redisplay.
void SetClickPosition(int newX, int newY)
Sets the position of last click.
Definition: mousecontrol.h:112