HOG2
SFML_HOG.cpp
Go to the documentation of this file.
1 /*
2  * $Id: main.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 11/02/06.
6  * Modified by Nathan Sturtevant on 06/22/21.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include <SFML/Window.hpp>
13 #include <SFML/OpenGL.hpp>
14 #define GL_SILENCE_DEPRECATION
15 
16 extern "C" {
17  void glutStrokeCharacter(void *font, int character){}
18  int glutStrokeWidth(void *font, int character) {return 0;}
19 }
20 
21 int hog_main(int argc, char **argv);
22 int main(int argc, char **argv)
23 {
24  return hog_main(argc, argv);
25 }
26 
27 
28 #include "SFML_HOG.h"
29 #include "Trackball.h"
30 #include "Common.h"
31 #include "TextBox.h"
32 #include <stdlib.h>
33 #include <time.h>
34 #include <math.h>
35 #include <string.h>
36 #include <cassert>
37 #include "MonoFont.h"
38 
39 using namespace std;
40 
42 GLint gDollyPanStartPoint[2] = {0, 0};
43 GLfloat gTrackBallRotation [4] = {0.0f, 0.0f, 0.0f, 0.0f};
44 GLboolean gDolly = GL_FALSE;
45 GLboolean gPan = GL_FALSE;
46 GLboolean gTrackball = GL_FALSE;
48 int gCurrButton = -1;
49 //bool pointpath = false;
50 //int ppMouseClicks = 0;
52 double fps = 30.0;
53 // window width and height
54 int width=100, height=100;
58 std::vector<Graphics::Display::lineInfo> textLines;
59 
60 void Line(Graphics::point p1, Graphics::point p2, float width, int viewport);
61 
62 pRecContext GetContext(unsigned long windowID)
63 {
64  return pContextInfo;
65 }
66 
68 {
69  return pContextInfo;
70 }
71 
73 {
75  p.x = 2.0*x/width-1.0;
76  p.y = 2.0*y/height-1.0;
77  p.z = 0;
78  return p;
79 }
80 
81 
82 void RunHOGGUI(int argc, char** argv, int windowDimension)
83 {
84  RunHOGGUI(argc, argv, windowDimension, windowDimension);
85 }
86 
87 void RunHOGGUI(int argc, char* argv[], int xDimension, int yDimension)
88 {
89  int mousePressCount = 0;
90  srandom(unsigned(time(0)));
91  ProcessCommandLineArgs(argc, argv);
93 
94  sf::Window window(sf::VideoMode(xDimension, yDimension), "My window");
95  window.setFramerateLimit(30); // call it once, after creating the window
96 /*
97  glutReshapeFunc(resizeWindow);
98  glutDisplayFunc(renderScene);
99  glutIdleFunc(renderScene);
100  glutMouseFunc(mousePressedButton);
101  glutMotionFunc(mouseMovedButton);
102  glutPassiveMotionFunc(mouseMovedNoButton);
103  glutKeyboardFunc(keyPressed);*/
105  buildGL(xDimension, yDimension);
106  pContextInfo->windowHeight = xDimension;
107  pContextInfo->windowWidth = yDimension;
108 
110  // createMenus();
111 
112  while (window.isOpen())
113  {
114  // check all the window's events that were triggered since the last iteration of the loop
115  sf::Event event;
116  while (window.pollEvent(event))
117  {
118  // "close requested" event: we close the window
119  switch (event.type)
120  {
121  case sf::Event::Closed:
122  window.close();
123  break;
124  case sf::Event::TextEntered:
125  if (event.text.unicode < 128)
126  DoKeyboardCommand(pContextInfo, event.text.unicode, false, false, false);
127  break;
128  case sf::Event::KeyPressed:
129  switch (event.key.code)
130  {
131  case sf::Keyboard::Left: DoKeyboardCommand(pContextInfo, kLeftArrow, event.key.shift, event.key.control, event.key.alt); break;
132  case sf::Keyboard::Right: DoKeyboardCommand(pContextInfo, kRightArrow, event.key.shift, event.key.control, event.key.alt); break;
133  case sf::Keyboard::Up: DoKeyboardCommand(pContextInfo, kUpArrow, event.key.shift, event.key.control, event.key.alt); break;
134  case sf::Keyboard::Down: DoKeyboardCommand(pContextInfo, kDownArrow, event.key.shift, event.key.control, event.key.alt); break;
135  default: break; // others handled by TextEntered
136  }
137  break;
138  case sf::Event::Resized:
139  resizeWindow(event.size.width, event.size.height);
140  //printf("Window now %dx%d\n", event.size.width, event.size.height);
141  xDimension = event.size.width;
142  yDimension = event.size.height;
143  pContextInfo->windowHeight = yDimension;
144  pContextInfo->windowWidth = xDimension;
145  resizeGL(pContextInfo, xDimension, yDimension); // forces projection matrix update
146  break;
147  case sf::Event::MouseButtonPressed:
148  {
149  Graphics::point p = WindowToHOG(Graphics::point(event.mouseButton.x, event.mouseButton.y));//convertToGlobalHogCoordinate(event.mouseButton.x, event.mouseButton.y);
150  //printf("Click (%d, %d) - {%f, %f, %f}\n", event.mouseButton.x, event.mouseButton.y, p.x, p.y, p.z);
151  mousePressCount+=1;
152  switch (event.mouseButton.button)
153  {
154  case sf::Mouse::Right:
155  //HandleMouseClick(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kRightButton, kMouseDown);
156  //printf("Right (%d, %d) - {%f, %f, %f}\n", event.mouseButton.x, event.mouseButton.y, p.x, p.y, p.z);
157  HandleMouse(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kRightButton, kMouseDown);
158  break;
159  case sf::Mouse::Left:
160  //printf("Left (%d, %d) - {%f, %f, %f}\n", event.mouseButton.x, event.mouseButton.y, p.x, p.y, p.z);
161  HandleMouse(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kLeftButton, kMouseDown);
162  break;
163  case sf::Mouse::Middle:
164  HandleMouse(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kMiddleButton, kMouseDown);
165  break;
166  default: break;
167  }
168  }
169  break;
170  case sf::Event::MouseButtonReleased:
171  {
172  Graphics::point p = WindowToHOG(Graphics::point(event.mouseButton.x, event.mouseButton.y));
173  mousePressCount-=1;
174  switch (event.mouseButton.button)
175  {
176  case sf::Mouse::Right:
177  HandleMouse(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kRightButton, kMouseUp);
178  break;
179  case sf::Mouse::Left:
180  HandleMouse(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kLeftButton, kMouseUp);
181  break;
182  case sf::Mouse::Middle:
183  HandleMouse(pContextInfo, event.mouseButton.x, event.mouseButton.y, p, kMiddleButton, kMouseUp);
184  break;
185  }
186  }
187  break;
188  case sf::Event::MouseMoved:
189  {
190  Graphics::point p = WindowToHOG(Graphics::point(event.mouseMove.x, event.mouseMove.y));
191  tButtonType bType = kNoButton;
192  if (mousePressCount == 0)
193  {
194  //printf("Move (%d, %d) - {%f, %f, %f}\n", event.mouseMove.x, event.mouseMove.y, p.x, p.y, p.z);
195  HandleMouse(pContextInfo, event.mouseMove.x, event.mouseMove.y, p, bType, kMouseMove);
196  }
197  else {
198  //printf("Drag (%d, %d) - {%f, %f, %f}\n", event.mouseMove.x, event.mouseMove.y, p.x, p.y, p.z);
199  HandleMouse(pContextInfo, event.mouseMove.x, event.mouseMove.y, p, bType, kMouseDrag);
200  }
201  }
202  //std::cout << "new mouse x: " << event.mouseMove.x << std::endl;
203  //std::cout << "new mouse y: " << event.mouseMove.y << std::endl;
204  break;
205  }
206  }
207  drawGL (pContextInfo, window);
208  }
209 
210 
211  //processStats(pContextInfo->unitLayer->getStats());
212  //delete pContextInfo->unitLayer;
213  delete pContextInfo;
214 }
215 
217 {
218 }
219 
220 void processMenuEvents(int option)
221 {
222 }
223 
224 
225 
229 void keyPressed(unsigned char key, int, int)
230 {
231  //x+=y;
232  bool shift = false;//(glutGetModifiers() == GLUT_ACTIVE_SHIFT);
233  bool alt = false;//(glutGetModifiers() == GLUT_ACTIVE_ALT);
234  bool cntrl = false;//(glutGetModifiers() == GLUT_ACTIVE_CTRL);
235  DoKeyboardCommand(pContextInfo, key, shift, cntrl, alt);
236 }
237 
238 
239 
240 void mouseMovedNoButton(int x, int y)
241 {
242  //Graphics::point p = GetOGLPos(pContextInfo, x, y);
243 // tButtonType bType = kNoButton;
244 // if (HandleMouseClick(pContextInfo, x, y, p, bType, kMouseMove))
245 // return;
246 
247 
248 // if (!pContextInfo->camera[pContextInfo->currPort].thirdPerson)
249 // {
250 // if (gPan == GL_FALSE)
251 // {
252 // gDollyPanStartPoint[0] = (GLint)x;
253 // gDollyPanStartPoint[1] = (GLint)y;
254 // gTrackingContextInfo = pContextInfo;
255 // gPan = GL_TRUE;
256 // //glutSetCursor(GLUT_CURSOR_NONE);
257 // }
258 
259 // float dx = gDollyPanStartPoint[0]-x;
260 // float dy = gDollyPanStartPoint[1]-y;
261 // gDollyPanStartPoint[0] = (GLint)x;
262 // gDollyPanStartPoint[1] = (GLint)y;
263 // float rotation[4] = {0.0f, 0.0f, 0.0f, 0.0f};
264 
265 // // rotation[0] = -dy/24;
266 // // rotation[1] = 1;
267 // // addToRotationTrackball(rotation, pContextInfo->camera[pContextInfo->currPort].rotations.cameraRotation);
268 // //pContextInfo->controlShip->addRotation(rotation);
269 // //addToRotationTrackball(rotation, pContextInfo->fRot);
270 // rotation[0] = -dx/24;
271 // rotation[1] = 0;
272 // rotation[2] = 1;
273 // // if ((pContextInfo->controlShip) && (rotation[0] != 0))
274 // // pContextInfo->controlShip->addRotation(rotation);
275 
276 // addToRotationTrackball(rotation, pContextInfo->camera[pContextInfo->currPort].rotations.cameraRotation);
277 
278 
279 // if (x > pContextInfo->globalCamera.viewWidth ||
280 // y > pContextInfo->globalCamera.viewHeight || x < 1 || y < 1)
281 // {
282 // //glutWarpPointer(pContextInfo->globalCamera.viewWidth/2, pContextInfo->globalCamera.viewHeight/2);
283 // gDollyPanStartPoint[0] = (GLint)pContextInfo->globalCamera.viewWidth/2;
284 // gDollyPanStartPoint[1] = (GLint)pContextInfo->globalCamera.viewHeight/2;
285 // }
286 // }
287 }
288 
292 void mouseMovedButton(int x, int y)
293 {
294  // Graphics::point p = GetOGLPos(pContextInfo, x, y);
295  // tButtonType bType = kLeftButton;
296  // switch (gCurrButton)
297  // {
298  // //case GLUT_RIGHT_BUTTON: bType = kRightButton; break;
299  // //case GLUT_LEFT_BUTTON: bType = kLeftButton; break;
300  // //case GLUT_MIDDLE_BUTTON: bType = kMiddleButton; break;
301  // }
302  // bType = kLeftButton; // TODO: fix with SFML
303  // if (HandleMouseClick(pContextInfo, x, y, p, bType, kMouseDrag))
304  // return;
305 }
306 
307 
311 void mousePressedButton(int button, int state, int x, int y)
312 {
313 // gCurrButton = button;
314 // int modifiers = 0;//glutGetModifiers();
315 
316 // //printf("Button = %d\n", button);
317 // if (state == GLUT_DOWN) {
318 // Graphics::point p = GetOGLPos(pContextInfo, x, y);
319 // tButtonType bType = kLeftButton;
320 // switch (gCurrButton)
321 // {
322 // case GLUT_RIGHT_BUTTON: bType = kRightButton; break;
323 // case GLUT_LEFT_BUTTON: bType = kLeftButton; break;
324 // case GLUT_MIDDLE_BUTTON: bType = kMiddleButton; break;
325 // }
326 // if (HandleMouseClick(pContextInfo, x, y, p, bType, kMouseDown))
327 // return;
328 
329 // if (!pContextInfo->camera[pContextInfo->currPort].thirdPerson)
330 // {
331 // gDollyPanStartPoint[0] = (GLint)x;
332 // gDollyPanStartPoint[1] = (GLint)y;
333 // gPan = GL_TRUE;
334 // gTrackingContextInfo = pContextInfo;
335 // }
336 // else if ((button == GLUT_RIGHT_BUTTON) || ((button == GLUT_LEFT_BUTTON) && (modifiers == GLUT_ACTIVE_CTRL)))
337 // { // pan
338 // if (gTrackball)
339 // { // if we are currently tracking, end trackball
340 // gTrackball = GL_FALSE;
341 // if (gTrackBallRotation[0] != 0.0)
342 // {
343 // // Mouse moves world object
344 // if (pContextInfo->camera[pContextInfo->currPort].thirdPerson == true)
345 // {
346 // if (pContextInfo->moveAllPortsTogether)
347 // {
348 // for (int x = 0; x < pContextInfo->numPorts; x++)
349 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[x].rotations.worldRotation);
350 // }
351 
352 // else {
353 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[pContextInfo->currPort].rotations.worldRotation);
354 // }
355 // }
356 // else {
357 // if (pContextInfo->moveAllPortsTogether)
358 // {
359 // for (int x = 0; x < pContextInfo->numPorts; x++)
360 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[x].rotations.cameraRotation);
361 // }
362 
363 // else {
364 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[pContextInfo->currPort].rotations.cameraRotation);
365 // }
366 // }
367 // }
368 // gTrackBallRotation [0] = gTrackBallRotation [1] = gTrackBallRotation [2] = gTrackBallRotation [3] = 0.0f;
369 // }
370 // else if (gDolly)
371 // { // if we are currently dollying, end dolly
372 // gDolly = GL_FALSE;
373 // }
374 // gDollyPanStartPoint[0] = (GLint)x;
375 // gDollyPanStartPoint[1] = (GLint)y;
376 // gPan = GL_TRUE;
377 // gTrackingContextInfo = pContextInfo;
378 // }
379 // else if ((button == GLUT_MIDDLE_BUTTON) || ((button == GLUT_LEFT_BUTTON) && (modifiers == GLUT_ACTIVE_SHIFT)))
380 // { // dolly
381 // if (gTrackball)
382 // { // if we are currently tracking, end trackball
383 // gTrackball = GL_FALSE;
384 // if (gTrackBallRotation[0] != 0.0)
385 // {
386 // // Mouse moves world object
387 // if (pContextInfo->camera[pContextInfo->currPort].thirdPerson == true)
388 // {
389 // if (pContextInfo->moveAllPortsTogether)
390 // {
391 // for (int x = 0; x < pContextInfo->numPorts; x++)
392 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[x].rotations.worldRotation);
393 // }
394 
395 // else {
396 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[pContextInfo->currPort].rotations.worldRotation);
397 // }
398 // }
399 // else {
400 // if (pContextInfo->moveAllPortsTogether)
401 // {
402 // for (int x = 0; x < pContextInfo->numPorts; x++)
403 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[x].rotations.cameraRotation);
404 // }
405 
406 // else {
407 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[pContextInfo->currPort].rotations.cameraRotation);
408 // }
409 // }
410 // }
411 // gTrackBallRotation [0] = gTrackBallRotation [1] = gTrackBallRotation [2] = gTrackBallRotation [3] = 0.0f;
412 // }
413 // else if (gPan)
414 // { // if we are currently panning, end pan
415 // gPan = GL_FALSE;
416 // }
417 // gDollyPanStartPoint[0] = (GLint)x;
418 // gDollyPanStartPoint[1] = (GLint)y;
419 // gDolly = GL_TRUE;
420 // gTrackingContextInfo = pContextInfo;
421 // }
422 // else if (button == GLUT_LEFT_BUTTON)
423 // { // trackball
424 // if (gDolly)
425 // { // if we are currently dollying, end dolly
426 // gDolly = GL_FALSE;
427 // gTrackingContextInfo = NULL;
428 // }
429 // else if (gPan)
430 // { // if we are currently panning, end pan
431 // gPan = GL_FALSE;
432 // gTrackingContextInfo = NULL;
433 // }
434 // startTrackball((long)x, (long)y,
435 // (long)pContextInfo->camera[pContextInfo->currPort].viewOriginX,
436 // (long)pContextInfo->camera[pContextInfo->currPort].viewOriginY,
437 // pContextInfo->globalCamera.viewWidth,
438 // pContextInfo->globalCamera.viewHeight);
439 // gTrackball = GL_TRUE;
440 // gTrackingContextInfo = pContextInfo;
441 // }
442 // }
443 
444 
445 
446 // if (state == GLUT_UP)
447 // {
448 // // stop trackball, pan, or dolly
449 // Graphics::point p = GetOGLPos(pContextInfo, x, y);
450 // tButtonType bType = kLeftButton;
451 // switch (gCurrButton)
452 // {
453 // case GLUT_RIGHT_BUTTON: bType = kRightButton; break;
454 // case GLUT_LEFT_BUTTON: bType = kLeftButton; break;
455 // case GLUT_MIDDLE_BUTTON: bType = kMiddleButton; break;
456 // }
457 // if (HandleMouseClick(pContextInfo, x, y, p, bType, kMouseUp))
458 // return;
459 
460 
461 // // if we want to handle final movement when mouse is released
462 // // if (!pContextInfo->camera[pContextInfo->currPort].thirdPerson)
463 // // {
464 // // }
465 
466 
467 // if (gDolly) { // end dolly
468 // gDolly = GL_FALSE;
469 // }
470 // else if (gPan) { // end pan
471 // gPan = GL_FALSE;
472 // }
473 // else if (gTrackball) { // end trackball
474 // gTrackball = GL_FALSE;
475 // if (gTrackBallRotation[0] != 0.0)
476 // {
477 // // Mouse moves world object
478 // if (pContextInfo->camera[pContextInfo->currPort].thirdPerson == true)
479 // {
480 // if (pContextInfo->moveAllPortsTogether)
481 // {
482 // for (int x = 0; x < pContextInfo->numPorts; x++)
483 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[x].rotations.worldRotation);
484 // }
485 
486 // else {
487 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[pContextInfo->currPort].rotations.worldRotation);
488 // }
489 // }
490 // else {
491 // if (pContextInfo->moveAllPortsTogether)
492 // {
493 // for (int x = 0; x < pContextInfo->numPorts; x++)
494 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[x].rotations.cameraRotation);
495 // }
496 
497 // else {
498 // addToRotationTrackball(gTrackBallRotation, pContextInfo->camera[pContextInfo->currPort].rotations.cameraRotation);
499 // }
500 // }
501 // }
502 // gTrackBallRotation [0] = gTrackBallRotation [1] = gTrackBallRotation [2] = gTrackBallRotation [3] = 0.0f;
503 // }
504 // gTrackingContextInfo = NULL;
505 // }
506 }
507 
508 
509 // move camera in x/y plane
510 static void mousePan (int x, int y, pRecContext pContextInfo)
511 {
512 }
513 
514 
515 // move camera in z axis
516 static void mouseDolly (int x, int y, pRecContext pContextInfo)
517 {
518 }
519 
524 void renderScene(void)
525 {
526 
527  // Update the tank model frame (basically the treads)
528  //tankModelFrameUpdate();
529 
530  static double lastTime = ((double)clock()/CLOCKS_PER_SEC);
531  double currTime = ((double)clock()/CLOCKS_PER_SEC);
532 
533  if ((currTime - lastTime) > (1/fps)) {
534  lastTime = currTime;
535  //drawGL(pContextInfo);
536 
537  assert(false);
538  }
539 
540 }
541 
542 
546 void resizeWindow(int x, int y)
547 {
548  /*
549  CGRect rect;
550  while (0 != x%4)
551  x++;
552  while (0 != y%4)
553  y++;
554  int scale = 2;//glutGet(GLUT_WINDOW_SCALE);
555  rect.size.width = scale*x;
556  rect.size.height = scale*y;
557  rect.origin.x = 0;
558  rect.origin.y = 0;
559  */
560  resizeGL(pContextInfo, x, y);
561 }
562 
563 
569 {
570  if (!pContextInfo)
571  return;
572 
573  pContextInfo->globalCamera.viewOriginX = 0;//viewRect.origin.x;
574  pContextInfo->globalCamera.viewOriginY = 0;//viewRect.origin.y;
575 
576  pContextInfo->globalCamera.viewWidth = width;//(GLint)viewRect.size.width;
577  pContextInfo->globalCamera.viewHeight = height;//(GLint)viewRect.size.height;
578  // printf("Window size: {%d, %d}\n", width, height);
579  for (int x = 0; x < pContextInfo->numPorts; x++)
580  {
582  }
583  // glViewport(0, 0, pContextInfo->camera.viewWidth, pContextInfo->camera.viewHeight);
584 
585  updateProjection(pContextInfo); // update projection matrix
586 }
587 
588 
589 
596 {
597  GLdouble ratio, radians, wd2;
598  int minVal, maxVal;
599  if (viewPort == -1)
600  {
601  minVal = 0;
602  maxVal = pContextInfo->numPorts-1;
603  }
604  else {
605  minVal = maxVal = viewPort;
606  }
607  for (int x = minVal; x <= maxVal; x++)
608  {
609  pContextInfo->camera[x].frust.near = 0.01;
610  pContextInfo->camera[x].frust.far = 20.0;
611 
612  radians = 0.0174532925 * pContextInfo->camera[x].aperture / 2; // half aperture degrees to radians
613  wd2 = pContextInfo->camera[x].frust.near * tan(radians);
614  //ratio = pContextInfo->camera[x].viewWidth / (float) pContextInfo->camera[x].viewHeight;
616  // printf("[%d/%d]\n", pContextInfo->camera[x].viewWidth, pContextInfo->camera[x].viewHeight);
617  if (ratio >= 1.0) // wider than tall
618  {
623  screenRect.left = -ratio;
624  screenRect.right = ratio;
625  screenRect.top = -1;
626  screenRect.bottom = 1;
627  // std::cout << "window coordinates: {" << screenRect << "}\n";
628  // pContextInfo->camera[x].frust.left = -ratio * wd2;
629  // pContextInfo->camera[x].frust.right = ratio * wd2;
630  // pContextInfo->camera[x].frust.top = wd2;
631  // pContextInfo->camera[x].frust.bottom = -wd2;
632 
633  // printf("=> l: %f r: %f t: %f b: %f\n",
634  // pContextInfo->camera[x].frust.left,
635  // pContextInfo->camera[x].frust.right,
636  // pContextInfo->camera[x].frust.top,
637  // pContextInfo->camera[x].frust.bottom);
638  Graphics::rect t1, t2, r(-1, -1, 1, 1);
639  t1 = ViewportToGlobalHOG(r, x);
640  // std::cout << "Port " << x << " {" << r << "} -> {" << t1 << "}\n";
641  } else {
642  ratio = 1/ratio;
647  screenRect.left = -1;
648  screenRect.right = 1;
649  screenRect.top = -ratio;
650  screenRect.bottom = ratio;
651 
652  // std::cout << "-->window coordinates: {" << screenRect << "}\n";
653  // pContextInfo->camera[x].frust.left = -ratio * wd2;
654  // pContextInfo->camera[x].frust.right = ratio * wd2;
655  // pContextInfo->camera[x].frust.top = wd2;
656  // pContextInfo->camera[x].frust.bottom = -wd2;
657 
658  // printf("--> l: %f r: %f t: %f b: %f\n",
659  // pContextInfo->camera[x].frust.left,
660  // pContextInfo->camera[x].frust.right,
661  // pContextInfo->camera[x].frust.top,
662  // pContextInfo->camera[x].frust.bottom);
663  Graphics::rect t1, t2, r(-1, -1, 1, 1);
664  t1 = ViewportToGlobalHOG(r, x);
665  // std::cout << "Port " << x << " {" << r << "} -> {" << t1 << "}\n";
666  }
667  }
668 }
669 
670 
671 // to perform cross product between 2 vectors in myGluLookAt
672 void CrossProd(float x1, float y1, float z1, float x2, float y2, float z2, float res[3])
673 {
674  res[0] = y1*z2 - y2*z1;
675  res[1] = x2*z1 - x1*z2;
676  res[2] = x1*y2 - x2*y1;
677 }
678 
679 // my own implementation
680 void MyGluLookAt(float eyeX, float eyeY, float eyeZ, float lookAtX, float lookAtY, float lookAtZ, float upX, float upY, float upZ)
681 {
682  // i am not using here proper implementation for vectors.
683  // if you want, you can replace the arrays with your own
684  // vector types
685  float f[3];
686 
687  // calculating the viewing vector
688  f[0] = lookAtX - eyeX;
689  f[1] = lookAtY - eyeY;
690  f[2] = lookAtZ - eyeZ;
691 
692  float fMag, upMag;
693  fMag = sqrt(f[0]*f[0] + f[1]*f[1] + f[2]*f[2]);
694  upMag = sqrt(upX*upX + upY*upY + upZ*upZ);
695 
696  // normalizing the viewing vector
697  if( fMag != 0)
698  {
699  f[0] = f[0]/fMag;
700  f[1] = f[1]/fMag;
701  f[2] = f[2]/fMag;
702  }
703 
704  // normalising the up vector. no need for this here if you have your
705  // up vector already normalised, which is mostly the case.
706  if( upMag != 0 )
707  {
708  upX = upX/upMag;
709  upY = upY/upMag;
710  upZ = upZ/upMag;
711  }
712 
713  float s[3], u[3];
714 
715  CrossProd(f[0], f[1], f[2], upX, upY, upZ, s);
716  CrossProd(s[0], s[1], s[2], f[0], f[1], f[2], u);
717 
718  float M[]=
719  {
720  s[0], u[0], -f[0], 0,
721  s[1], u[1], -f[1], 0,
722  s[2], u[2], -f[2], 0,
723  0, 0, 0, 1
724  };
725 
726  glMultMatrixf(M);
727  glTranslatef(-eyeX, -eyeY, -eyeZ);
728 }
729 
730 
735 {
736  // move view
737  glMatrixMode(GL_MODELVIEW);
738  glLoadIdentity();
739 
740  // mouse transforms object
741  if (pContextInfo->camera[currPort].thirdPerson)
742  {
744  pContextInfo->camera[currPort].viewPos.y,
745  pContextInfo->camera[currPort].viewPos.z,
746  pContextInfo->camera[currPort].viewPos.x + pContextInfo->camera[currPort].viewDir.x,
747  pContextInfo->camera[currPort].viewPos.y + pContextInfo->camera[currPort].viewDir.y,
748  pContextInfo->camera[currPort].viewPos.z + pContextInfo->camera[currPort].viewDir.z,
749  pContextInfo->camera[currPort].viewUp.x, pContextInfo->camera[currPort].viewUp.y ,pContextInfo->camera[currPort].viewUp.z);
750 
751  if ((gTrackingContextInfo == pContextInfo) && gTrackBallRotation[0] != 0.0f) // if we have trackball rotation to map (this IS the test I want as it can be explicitly 0.0f)
752  {
755  }
756  else {
757  }
758 
759  // accumlated world rotation via trackball
760  glRotatef (pContextInfo->camera[currPort].rotations.worldRotation[0],
764  }
765  // if mouse moves whole world:
766  else {
767  glTranslatef(pContextInfo->camera[currPort].viewPos.x,
768  pContextInfo->camera[currPort].viewPos.y,
769  pContextInfo->camera[currPort].viewPos.z);
770  }
771 
772 }
773 
774 
778 void drawCStringGL (char * cstrOut, GLuint fontList)
779 {
780  GLint i = 0;
781  if (!cstrOut)
782  return;
783  while (cstrOut [i])
784  glCallList (fontList + cstrOut[i++]);
785 }
786 
788 
789 bool bufferVisibility = true;
790 
791 void setTextBufferVisibility(bool visible)
792 {
793  bufferVisibility = visible;
794  if (bufferVisibility)
795  {
796  if (myTextBox == 0 && pContextInfo->message != 0)
797  {
798  Graphics::point a(-.95, .95, -.95), b(.95, -.95, .95);
799  rgbColor rc(1, 1, 1);
800  myTextBox = new TextBox(pContextInfo->message, 120, a, b, 1000, true);
801  myTextBox->setColor(rc);
802  }
803  }
804  else
805  {
806  delete myTextBox;
807  myTextBox = 0;
808  }
809 }
811 { return bufferVisibility; }
812 
813 void appendTextToBuffer(const char *tempStr)
814 {
815  int ind = int(strlen(pContextInfo->message));
816  pContextInfo->message[ind] = ' ';
817  snprintf(&pContextInfo->message[ind+1], 256-(ind+2), "%s", tempStr);
818 
819  delete myTextBox;
820  myTextBox = 0;
821  Graphics::point a(-.95, .95, -.95), b(.95, -.95, .95);
822  rgbColor rc(1, 1, 1);
823  if (bufferVisibility)
824  {
825  myTextBox = new TextBox(pContextInfo->message, 120, a, b, 1000, true);
826  myTextBox->setColor(rc);
827  }
828 }
829 
830 void submitTextToBuffer(const char *val)
831 {
832  strncpy(pContextInfo->message, val, 255);
833  delete myTextBox;
834  myTextBox = 0;
835  Graphics::point a(-.95, .95, -.95), b(.95, -.95, .95);
836  rgbColor rc(1, 1, 1);
837  if (bufferVisibility)
838  {
839  myTextBox = new TextBox(pContextInfo->message, 120, a, b, 1000, true);
840  myTextBox->setColor(rc);
841  }
842 }
843 
845 {
846  auto p = ViewportToGlobalHOG(where, viewport);
847  p.x *= screenRect.right;
848  p.y *= screenRect.bottom;
849  return p;
850 }
851 
853 {
854  auto r = ViewportToGlobalHOG(loc, viewport);
855  r.left *= screenRect.right;
856  r.right *= screenRect.right;
857  r.top *= screenRect.bottom;
858  r.bottom *= screenRect.bottom;
859  return r;
860 }
861 
862 float ViewportToScreenX(float x, int v)
863 {
864  float val = ViewportToGlobalHOGX(x, v);
865  return val*screenRect.right;
866 }
867 
869 {
870  // Convert from 0,0 -> width/height range to HOG range
871  // Just map to screenRect
872  float xperc = p.x/pContextInfo->windowWidth;
873  float yperc = p.y/pContextInfo->windowHeight;
874  // return Graphics::point(screenRect.left*(1-xperc)+screenRect.right*xperc,
875  // screenRect.top*(1-yperc)+screenRect.bottom*yperc);
876  return Graphics::point(-1*(1-xperc)+1*xperc,
877  -1*(1-yperc)+1*yperc);
878 }
879 
880 void DoDrawCommands(Graphics::Display &display, int port, sf::Window &window, std::vector<Graphics::Display::data> &commands)
881 {
882  for (auto &i: commands)
883  {
884  //auto &i = display.backgroundDrawCommands[x];
885  if (i.viewport != port)
886  continue;
887  switch (i.what)
888  {
890  {
891  glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
892  //Graphics::rect tmp = GlobalHOGToViewport(i.shape.r, i.viewport);
893  Graphics::rect tmp = ViewportToScreen(i.shape.r, i.viewport);
894  //Graphics::rect tmp = ViewportToGlobalHOG(i.shape.r, i.viewport);
895  //tmp *= {screenRect.right, screenRect.bottom}; // scale to screen
896  glBegin(GL_QUADS);
897  glVertex2f(tmp.left, tmp.bottom);
898  glVertex2f(tmp.left, tmp.top);
899  glVertex2f(tmp.right, tmp.top);
900  glVertex2f(tmp.right, tmp.bottom);
901  glEnd();
902  // epsilon -= de;
903  break;
904  }
906  {
907  glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
908  //Graphics::rect tmp = ViewportToGlobalHOG(i.shape.r, i.viewport);
909  auto r2 = ViewportToScreen(i.shape.r.inset(i.shape.width/2), i.viewport);
910  auto r1 = ViewportToScreen(i.shape.r.expand(i.shape.width/2), i.viewport);
911  //tmp *= {screenRect.right, screenRect.bottom}; // scale to screen
912 
913  glBegin(GL_TRIANGLE_STRIP);
914  //GLfloat rad = ViewportToGlobalHOGX(i.shape.width, i.viewport)/2.0;
915  //GLfloat rad = ViewportToScreenX(i.shape.width, i.viewport)/2.0;
916  glVertex2f(r1.left, r1.bottom);
917  glVertex2f(r2.left, r2.bottom);
918 
919  glVertex2f(r1.left, r1.top);
920  glVertex2f(r2.left, r2.top);
921 
922  glVertex2f(r1.right, r1.top);
923  glVertex2f(r2.right, r2.top);
924 
925  glVertex2f(r1.right, r1.bottom);
926  glVertex2f(r2.right, r2.bottom);
927 
928  glVertex2f(r1.left, r1.bottom);
929  glVertex2f(r2.left, r2.bottom);
930 
931 
932  glEnd();
933 
934 
935  break;
936  }
938  {
939  //Graphics::rect tmp = ViewportToGlobalHOG(i.shape.r, i.viewport);
940  Graphics::rect tmp = ViewportToScreen(i.shape.r, i.viewport);
941  glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
942  DrawCircle((tmp.right+tmp.left)/2, (tmp.top+tmp.bottom)/2, fabs(tmp.top-tmp.bottom)/2.0, 64);
943  break;
944  }
946  {
947  //Graphics::rect tmp = ViewportToGlobalHOG(i.shape.r, i.viewport);
948  Graphics::rect tmp = ViewportToScreen(i.shape.r, i.viewport);
949  glColor3f(i.shape.c.r, i.shape.c.g, i.shape.c.b);
950  FrameCircle((tmp.right+tmp.left)/2, (tmp.top+tmp.bottom)/2, fabs(tmp.top-tmp.bottom)/2.0, ViewportToScreenX(i.shape.width, i.viewport), 64);
951  break;
952  }
954  {
955  glColor3f(i.polygon.c.r, i.polygon.c.g, i.polygon.c.b);
956  Graphics::rect hog(i.polygon.center, i.polygon.radius);
957  auto tmp = ViewportToScreen(hog, i.viewport);
958  DrawCircle((tmp.right+tmp.left)/2, (tmp.top+tmp.bottom)/2, fabs(tmp.top-tmp.bottom)/2.0, i.polygon.segments, i.polygon.rotate);
959  break;
960  }
962  {
963  glColor3f(i.polygon.c.r, i.polygon.c.g, i.polygon.c.b);
964  Graphics::rect hog(i.polygon.center, i.polygon.radius);
965  auto tmp = ViewportToScreen(hog, i.viewport);
966  FrameCircle((tmp.right+tmp.left)/2, (tmp.top+tmp.bottom)/2, fabs(tmp.top-tmp.bottom)/2.0, ViewportToScreenX(i.polygon.width, i.viewport), i.polygon.segments, i.polygon.rotate);
967  break;
968  }
970  {
971  glColor3f(i.triangle.c.r, i.triangle.c.g, i.triangle.c.b);
972  Graphics::point tmp1 = ViewportToScreen(i.triangle.p1, i.viewport);
973  Graphics::point tmp2 = ViewportToScreen(i.triangle.p2, i.viewport);
974  Graphics::point tmp3 = ViewportToScreen(i.triangle.p3, i.viewport);
975 
976  glBegin(GL_TRIANGLES);
977  glVertex3f(tmp1.x, tmp1.y, tmp1.z);
978  glVertex3f(tmp2.x, tmp2.y, tmp2.z);
979  glVertex3f(tmp3.x, tmp3.y, tmp3.z);
980  glEnd();
981  break;
982  }
984  {
985  glColor3f(i.triangle.c.r, i.triangle.c.g, i.triangle.c.b);
986 
987  glBegin(GL_QUADS);
988  Line(i.triangle.p1, i.triangle.p2, i.triangle.width, i.viewport);
989  Line(i.triangle.p2, i.triangle.p3, i.triangle.width, i.viewport);
990  Line(i.triangle.p3, i.triangle.p1, i.triangle.width, i.viewport);
991  glEnd();
992  }
994  {
995  glColor3f(i.line.c.r, i.line.c.g, i.line.c.b);
996 
997  Line(i.line.start, i.line.end, i.line.width, i.viewport);
998  //std::cout << i.line.start << " <=> " << i.line.end << " " << i.line.width << "\n";
999  /*
1000  Graphics::point tmp1 = ViewportToScreen(i.line.start, i.viewport);
1001  Graphics::point tmp2 = ViewportToScreen(i.line.end, i.viewport);
1002  GLfloat xOff = tmp1.x-tmp2.x;
1003  GLfloat yOff = tmp2.y-tmp1.y;
1004  GLfloat ratio = ViewportToScreenX(0.5*i.line.width, i.viewport)/sqrt(xOff*xOff+yOff*yOff);
1005  glBegin(GL_QUADS);
1006  glVertex3f(tmp1.x-ratio*yOff, tmp1.y-ratio*xOff, tmp1.z);
1007  glVertex3f(tmp1.x+ratio*yOff, tmp1.y+ratio*xOff, tmp1.z);
1008  glVertex3f(tmp2.x+ratio*yOff, tmp2.y+ratio*xOff, tmp1.z);
1009  glVertex3f(tmp2.x-ratio*yOff, tmp2.y-ratio*xOff, tmp1.z);
1010  glEnd();
1011  */
1012  break;
1013  }
1014  }
1015  }
1016 
1017 }
1018 
1019 void DrawLines(std::vector<Graphics::Display::lineInfo> &textLines, int viewport)
1020 {
1021  for (auto i : textLines)
1022  {
1023  Graphics::point tmp1 = ViewportToScreen(i.start, viewport);
1024  Graphics::point tmp2 = ViewportToScreen(i.end, viewport);
1025  GLfloat xOff = tmp1.x-tmp2.x;
1026  GLfloat yOff = tmp2.y-tmp1.y;
1027  GLfloat wide = ViewportToScreenX(0.5f*i.width, viewport);
1028  GLfloat ratio = wide/sqrt(xOff*xOff+yOff*yOff);
1029 
1030  glBegin(GL_QUADS);
1031  glColor3f(i.c.r, i.c.g, i.c.b);
1032  glVertex3f(tmp1.x-ratio*yOff, tmp1.y-ratio*xOff, tmp1.z);
1033  glVertex3f(tmp1.x+ratio*yOff, tmp1.y+ratio*xOff, tmp1.z);
1034  glVertex3f(tmp2.x+ratio*yOff, tmp2.y+ratio*xOff, tmp1.z);
1035  glVertex3f(tmp2.x-ratio*yOff, tmp2.y-ratio*xOff, tmp1.z);
1036  glEnd();
1037  DrawCircle(tmp1.x, tmp1.y, wide, 16);
1038  DrawCircle(tmp2.x, tmp2.y, wide, 16);
1039  }
1040 }
1041 
1043 {
1046  GLfloat xOff = tmp1.x-tmp2.x;
1047  GLfloat yOff = tmp2.y-tmp1.y;
1048  GLfloat ratio = ViewportToScreenX(0.5*width, viewport)/sqrt(xOff*xOff+yOff*yOff);
1049  glBegin(GL_QUADS);
1050  glVertex3f(tmp1.x-ratio*yOff, tmp1.y-ratio*xOff, tmp1.z);
1051  glVertex3f(tmp1.x+ratio*yOff, tmp1.y+ratio*xOff, tmp1.z);
1052  glVertex3f(tmp2.x+ratio*yOff, tmp2.y+ratio*xOff, tmp1.z);
1053  glVertex3f(tmp2.x-ratio*yOff, tmp2.y-ratio*xOff, tmp1.z);
1054  glEnd();
1055 
1056  // Graphics::point tmp1 = ViewportToScreen(p1, viewport);
1057  // Graphics::point tmp2 = ViewportToScreen(p2, viewport);
1058  // GLfloat xOff = tmp1.x-tmp2.x;
1059  // GLfloat yOff = tmp1.y-tmp2.y;
1060  // GLfloat ratio = 0.5f*width/sqrt(xOff*xOff+yOff*yOff);
1061  // glVertex3f(tmp1.x-ratio*yOff, tmp1.y-ratio*xOff, tmp1.z);
1062  // glVertex3f(tmp1.x+ratio*yOff, tmp1.y+ratio*xOff, tmp1.z);
1063  // glVertex3f(tmp2.x+ratio*yOff, tmp2.y+ratio*xOff, tmp1.z);
1064  // glVertex3f(tmp2.x-ratio*yOff, tmp2.y-ratio*xOff, tmp1.z);
1065 }
1066 
1067 void DrawGraphics(Graphics::Display &display, int port, sf::Window &window)
1068 {
1069  for (auto &i : display.backgroundLineSegments)
1070  {
1071  if (i.viewport != port)
1072  continue;
1073  glColor3f(i.c.r, i.c.g, i.c.b);
1074 
1075  glBegin(GL_QUADS);
1076  for (int t = 0; t < i.points.size()-1; t++)
1077  {
1078  Graphics::point tmp1 = ViewportToScreen(i.points[t], i.viewport);
1079  Graphics::point tmp2 = ViewportToScreen(i.points[t+1], i.viewport);
1080  GLfloat xOff = tmp1.x-tmp2.x;
1081  GLfloat yOff = tmp2.y-tmp1.y;
1082  GLfloat ratio = 0.5f*i.size/sqrt(xOff*xOff+yOff*yOff);
1083  glVertex3f(tmp1.x-ratio*yOff, tmp1.y-ratio*xOff, tmp1.z);
1084  glVertex3f(tmp1.x+ratio*yOff, tmp1.y+ratio*xOff, tmp1.z);
1085  glVertex3f(tmp2.x+ratio*yOff, tmp2.y+ratio*xOff, tmp1.z);
1086  glVertex3f(tmp2.x-ratio*yOff, tmp2.y-ratio*xOff, tmp1.z);
1087  }
1088  glEnd();
1089  }
1090  DoDrawCommands(display, port, window, display.backgroundDrawCommands);
1091  for (auto &i : display.backgroundText)
1092  {
1093  if (i.viewport != port)
1094  continue;
1095 
1097  i.loc, i.s.c_str(), i.size,
1098  i.c,
1099  i.align, i.base);
1100  DrawLines(textLines, i.viewport);
1101  }
1102 
1103 
1104  for (auto &i : display.lineSegments)
1105  {
1106  if (i.viewport != port)
1107  continue;
1108  glColor3f(i.c.r, i.c.g, i.c.b);
1109 
1110  glBegin(GL_QUADS);
1111  for (int t = 0; t < i.points.size()-1; t++)
1112  {
1113  Line(i.points[t], i.points[t+1], i.size, i.viewport);
1114  }
1115  glEnd();
1116 
1117  }
1118  DoDrawCommands(display, port, window, display.drawCommands);
1119  for (auto &i : display.text)
1120  {
1121  if (i.viewport != port)
1122  continue;
1123 
1125  i.loc, i.s.c_str(), i.size,
1126  i.c,
1127  i.align, i.base);
1128  DrawLines(textLines, i.viewport);
1129  }
1130 
1131 }
1132 
1136 void drawGL (pRecContext pContextInfo, sf::Window &window)
1137 {
1138  if (!pContextInfo)
1139  return;
1141  //window.clear();
1142  // clear our drawable
1143  glClear(GL_COLOR_BUFFER_BIT);
1144  glClear(GL_DEPTH_BUFFER_BIT);
1145 
1146  for (int x = 0; x < pContextInfo->numPorts; x++)
1147  {
1150  //if (pContextInfo->drawing)
1151  {
1152  // set projection
1153  glMatrixMode(GL_PROJECTION);
1154  glLoadIdentity();
1155 
1159  // projection matrix already set
1162  DrawGraphics(pContextInfo->display, x, window);
1163  }
1164  }
1165  if (myTextBox)
1166  {
1167  myTextBox->stepTime(0.1);
1168  myTextBox->draw();
1169  }
1171  //glutSwapBuffers();
1172  window.display();
1173 }
1174 
1175 
1179 /*void trajectoryDrawGL (pRecContext pContextInfo)
1180 {
1181  if (!pContextInfo)
1182  return;
1183 
1184  // clear our drawable
1185  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1186 
1187  // projection matrix already set
1188  updateModelView (pContextInfo);
1189 
1190  glDisable(GL_LIGHTING);
1191  pContextInfo->unitLayer->GetMap()->OpenGLDraw(kPolygons);
1192  if (pContextInfo->unitLayer->getMapAbstractionDisplay())
1193  {
1194  pContextInfo->unitLayer->getMapAbstractionDisplay()->OpenGLDraw();
1195  }
1196  glEnable(GL_LIGHTING);
1197 
1198  static double lastTime = ((double)clock()/CLOCKS_PER_SEC);
1199  double currTime = ((double)clock()/CLOCKS_PER_SEC);
1200 
1201  pContextInfo->unitLayer->advanceTime(currTime-lastTime);
1202  lastTime = currTime;
1203  if (pContextInfo->drawing)
1204  {
1205  pContextInfo->unitLayer->OpenGLDraw();
1206  if (pContextInfo->info) {
1207  glDisable(GL_LIGHTING);
1208  drawInfo (pContextInfo);
1209  }
1210  }
1211  frameCallback(pContextInfo->unitLayer);
1212 
1213  //glFlush();
1214  glutSwapBuffers();
1215 
1216 }*/
1217 
1218 
1222 void buildGL(int xDim, int yDim)
1223 {
1224  if (NULL == pContextInfo)
1225  return;
1226 
1227  // build context
1228  //CGRect viewRect = {{0.0f, 0.0f}, {0.0f, 0.0f}};
1229 
1230 // switch (pContextInfo->modeFSAA) {
1231 // case kFSAAOff:
1232 //#ifndef WIN32
1233 // //glDisable (GL_MULTISAMPLE_ARB);
1234 //#endif
1235 // break;
1236 // case kFSAAFast:
1239 // break;
1240 // case kFSAANice:
1241 // #ifndef WIN32
1242 // //glEnable (GL_MULTISAMPLE_ARB);
1243 // //glHint (GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
1244 // #endif
1245 // break;
1246 // }
1247 
1248  // init GL stuff here
1249  //glEnable(GL_DEPTH_TEST);
1250  glDisable(GL_DEPTH_TEST);
1251 
1252  glShadeModel(GL_SMOOTH);
1253  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
1254  glFrontFace(GL_CCW);
1255  glPolygonOffset (1.0, 1.0);
1256 
1257  glClearColor(0.0,0.0,0.0,0.0);
1258 
1259  //int scale = 2;//glutGet(GLUT_WINDOW_SCALE);
1260  //viewRect.size.width = xDim;//scale*glutGet(GLUT_WINDOW_WIDTH);
1261  //viewRect.size.height = yDim;//scale*glutGet(GLUT_WINDOW_HEIGHT);
1262 
1263  // setup viewport and prespective
1264  resizeGL(pContextInfo, xDim, yDim); // forces projection matrix update
1265 
1266  SetLighting();
1267 }
1268 
Graphics::point
Definition: Graphics.h:32
Graphics::point::y
float y
Definition: Graphics.h:36
HandleFrame
void HandleFrame(pRecContext pContextInfo, int viewport)
Definition: Common.cpp:163
MonoFont.h
mousePan
static void mousePan(int x, int y, pRecContext pContextInfo)
Definition: SFML_HOG.cpp:510
ViewportToGlobalHOG
Graphics::point ViewportToGlobalHOG(Graphics::point where, int viewport)
Definition: Common.cpp:387
recContext::globalCamera
recCamera globalCamera
Definition: Common.h:67
submitTextToBuffer
void submitTextToBuffer(const char *val)
Definition: SFML_HOG.cpp:830
RunHOGGUI
void RunHOGGUI(int argc, char **argv, int windowDimension)
Definition: SFML_HOG.cpp:82
rgbColor
A color; r/g/b are between 0...1.
Definition: Colors.h:17
Graphics::Display::backgroundText
std::vector< textInfo > backgroundText
Definition: Graphics.h:273
DrawCircle
void DrawCircle(GLdouble _x, GLdouble _y, GLdouble tRadius, int segments, float rotation)
Definition: GLUtil.cpp:421
TextBox
Definition: TextBox.h:19
kWindowCreated
@ kWindowCreated
Definition: Common.h:159
createMenus
void createMenus()
Definition: SFML_HOG.cpp:216
HandleMouse
bool HandleMouse(pRecContext pContextInfo, int xWindow, int yWindow, point3d where, tButtonType button, tMouseEventType mouse)
Definition: Common.cpp:564
CrossProd
void CrossProd(float x1, float y1, float z1, float x2, float y2, float z2, float res[3])
Definition: SFML_HOG.cpp:672
recVec::z
GLdouble z
Definition: GLUtil.h:98
ProcessCommandLineArgs
void ProcessCommandLineArgs(int argc, char *argv[])
Definition: Common.cpp:222
hog_main
int hog_main(int argc, char **argv)
Graphics::Display::EndFrame
void EndFrame()
Definition: Graphics.cpp:37
gTrackingContextInfo
pRecContext gTrackingContextInfo
Definition: SFML_HOG.cpp:47
recContext::windowWidth
int windowWidth
Definition: Common.h:74
kDownArrow
const char kDownArrow
Definition: Common.h:134
HandleWindowEvent
void HandleWindowEvent(pRecContext pContextInfo, tWindowEventType e)
Definition: Common.cpp:652
screenRect
Graphics::rect screenRect
Definition: SFML_HOG.cpp:55
DoDrawCommands
void DoDrawCommands(Graphics::Display &display, int port, sf::Window &window, std::vector< Graphics::Display::data > &commands)
Definition: SFML_HOG.cpp:880
kUpArrow
const char kUpArrow
Definition: Common.h:133
if
if(state==GLUT_DOWN)
Definition: GLUThog.cpp:244
Common.h
ViewportToGlobalHOGX
float ViewportToGlobalHOGX(float x, int v)
Definition: Common.cpp:358
backup
pRecContext backup
Definition: SFML_HOG.cpp:51
Graphics::Display::kFrameRectangle
@ kFrameRectangle
Definition: Graphics.h:217
recCamera::frust
recFrustum frust
Definition: Common.h:45
Graphics::Display::backgroundDrawCommands
std::vector< data > backgroundDrawCommands
Definition: Graphics.h:272
gDollyPanStartPoint
GLint gDollyPanStartPoint[2]
Definition: SFML_HOG.cpp:42
TextBox::setColor
void setColor(rgbColor _myColor)
Definition: TextBox.h:27
recContext::camera
recCamera camera[MAXPORTS]
Definition: Common.h:69
Graphics::Display::kLine
@ kLine
Definition: Graphics.h:224
processMenuEvents
void processMenuEvents(int option)
Definition: SFML_HOG.cpp:220
Graphics::rect
Definition: Graphics.h:94
Graphics::Display::kFillRectangle
@ kFillRectangle
Definition: Graphics.h:216
gTrackball
GLboolean gTrackball
Definition: SFML_HOG.cpp:46
keyPressed
void keyPressed(unsigned char key, int, int)
Called when a key is pressed, and no other keys are held down.
Definition: SFML_HOG.cpp:229
TextBox.h
width
int width
Definition: SFML_HOG.cpp:54
myTextBox
TextBox * myTextBox
Definition: SFML_HOG.cpp:787
gCurrButton
int gCurrButton
Definition: SFML_HOG.cpp:48
DoKeyboardCommand
bool DoKeyboardCommand(pRecContext pContextInfo, unsigned char keyHit, bool shift, bool cntrl, bool alt)
Definition: Common.cpp:703
SFML_HOG.h
recCamera::viewOriginY
GLfloat viewOriginY
Definition: Common.h:48
glutStrokeCharacter
void glutStrokeCharacter(void *font, int character)
Definition: SFML_HOG.cpp:17
SetLighting
void SetLighting(GLfloat ambientf=0.2f, GLfloat diffusef=1.0f, GLfloat specularf=1.0f)
Definition: GLUtil.cpp:565
Graphics::Display::StartFrame
void StartFrame()
Definition: Graphics.cpp:29
gPan
GLboolean gPan
Definition: SFML_HOG.cpp:45
recContext::message
char message[256]
Definition: Common.h:76
Graphics::Display::kFillTriangle
@ kFillTriangle
Definition: Graphics.h:218
recContext
struct recContext recContext
Definition: Common.h:82
Graphics::Display::kFrameOval
@ kFrameOval
Definition: Graphics.h:221
updateModelView
void updateModelView(pRecContext pContextInfo, int currPort)
Updates the viewpoint of the model.
Definition: SFML_HOG.cpp:734
glutStrokeWidth
int glutStrokeWidth(void *font, int character)
Definition: SFML_HOG.cpp:18
recFrustum::far
GLdouble far
Definition: Common.h:31
recContext::display
Graphics::Display display
Definition: Common.h:79
viewport
Definition: Common.h:56
TextBox::draw
void draw()
Definition: TextBox.cpp:46
appendTextToBuffer
void appendTextToBuffer(const char *tempStr)
Definition: SFML_HOG.cpp:813
Graphics::Display::kFrameNGon
@ kFrameNGon
Definition: Graphics.h:223
recCamera::viewDir
recVec viewDir
Definition: Common.h:40
getCurrentContext
pRecContext getCurrentContext()
Definition: SFML_HOG.cpp:67
pContextInfo
pRecContext pContextInfo
Definition: SFML_HOG.cpp:41
gTrackBallRotation
GLfloat gTrackBallRotation[4]
Definition: SFML_HOG.cpp:43
Graphics::rect::top
float top
Definition: Graphics.h:100
kLeftArrow
const char kLeftArrow
Definition: Common.h:131
buildGL
void buildGL(int xDim, int yDim)
End OpenGL drawing function - for visualizing trajectory merging.
Definition: SFML_HOG.cpp:1222
main
int main(int argc, char **argv)
Definition: SFML_HOG.cpp:22
loc
Definition: MapGenerators.cpp:296
Graphics::Display::drawCommands
std::vector< data > drawCommands
Definition: Graphics.h:268
fps
double fps
Definition: SFML_HOG.cpp:52
kMiddleButton
@ kMiddleButton
Definition: Common.h:147
mouseMovedNoButton
void mouseMovedNoButton(int x, int y)
Definition: SFML_HOG.cpp:240
kMouseDrag
@ kMouseDrag
Definition: Common.h:154
textLines
std::vector< Graphics::Display::lineInfo > textLines
Definition: SFML_HOG.cpp:58
Graphics::Display::kFillOval
@ kFillOval
Definition: Graphics.h:220
recRotation::worldRotation
GLfloat worldRotation[4]
Definition: Common.h:26
MonoFont
Definition: MonoFont.h:21
renderScene
void renderScene(void)
Renders the scene.
Definition: SFML_HOG.cpp:524
Graphics::Display
Definition: Graphics.h:146
kRightArrow
const char kRightArrow
Definition: Common.h:132
recContext
Definition: Common.h:64
DrawLines
void DrawLines(std::vector< Graphics::Display::lineInfo > &textLines, int viewport)
Definition: SFML_HOG.cpp:1019
kMouseDown
@ kMouseDown
Definition: Common.h:152
recContext::windowHeight
int windowHeight
Definition: Common.h:74
GetContext
pRecContext GetContext(unsigned long windowID)
Definition: SFML_HOG.cpp:62
font
MonoFont font
Definition: SFML_HOG.cpp:57
recCamera::rotations
recRotation rotations
Definition: Common.h:42
Graphics::rect::right
float right
Definition: Graphics.h:100
recContext::currPort
int currPort
Definition: Common.h:71
setPortCamera
void setPortCamera(pRecContext pContextInfo, int currPort)
Definition: Common.cpp:823
ViewportToScreen
Graphics::point ViewportToScreen(Graphics::point where, int viewport)
Definition: SFML_HOG.cpp:844
Graphics::Display::kFillNGon
@ kFillNGon
Definition: Graphics.h:222
kRightButton
@ kRightButton
Definition: Common.h:146
kLeftButton
@ kLeftButton
Definition: Common.h:145
Trackball.h
ViewportToScreenX
float ViewportToScreenX(float x, int v)
Definition: SFML_HOG.cpp:862
recCamera::viewOriginX
GLfloat viewOriginX
Definition: Common.h:48
height
int height
Definition: SFML_HOG.cpp:54
DrawGraphics
void DrawGraphics(Graphics::Display &display, int port, sf::Window &window)
Definition: SFML_HOG.cpp:1067
recCamera::thirdPerson
bool thirdPerson
Definition: Common.h:37
recCamera::viewWidth
GLint viewWidth
Definition: Common.h:47
kNoButton
@ kNoButton
Definition: Common.h:148
FrameCircle
void FrameCircle(GLdouble _x, GLdouble _y, GLdouble tRadius, GLdouble lineWidth, int segments, float rotation)
Definition: GLUtil.cpp:407
TextBox::stepTime
void stepTime(double amount)
Definition: TextBox.cpp:41
Graphics::Display::text
std::vector< textInfo > text
Definition: Graphics.h:269
getTextBufferVisibility
bool getTextBufferVisibility()
Definition: SFML_HOG.cpp:810
recFrustum::left
GLdouble left
Definition: Common.h:31
recFrustum::near
GLdouble near
Definition: Common.h:31
setViewport
void setViewport(pRecContext pContextInfo, int currPort)
Definition: Common.cpp:846
mousePressedButton
void mousePressedButton(int button, int state, int x, int y)
Called when a mouse button is pressed.
Definition: SFML_HOG.cpp:311
Graphics::point::x
float x
Definition: Graphics.h:36
std
Definition: CanonicalGraphEnvironment.h:26
recFrustum::bottom
GLdouble bottom
Definition: Common.h:31
Graphics::point::z
float z
Definition: Graphics.h:36
kMouseMove
@ kMouseMove
Definition: Common.h:155
recContext::numPorts
int numPorts
Definition: Common.h:71
resizeGL
void resizeGL(pRecContext pContextInfo, int width, int height)
Handles resizing of GL need context update and if the window dimensions change, a window dimension up...
Definition: SFML_HOG.cpp:568
WindowToHOG
Graphics::point WindowToHOG(const Graphics::point &p)
Definition: SFML_HOG.cpp:868
Graphics::Display::lineSegments
std::vector< segments > lineSegments
Definition: Graphics.h:270
Graphics::rect::left
float left
Definition: Graphics.h:100
recFrustum::top
GLdouble top
Definition: Common.h:31
resizeWindow
void resizeWindow(int x, int y)
Called when the window is resized.
Definition: SFML_HOG.cpp:546
mouseMovedButton
void mouseMovedButton(int x, int y)
Called when the mouse is moved with a button pressed down.
Definition: SFML_HOG.cpp:292
Graphics::Display::kFrameTriangle
@ kFrameTriangle
Definition: Graphics.h:219
setTextBufferVisibility
void setTextBufferVisibility(bool visible)
Definition: SFML_HOG.cpp:791
MyGluLookAt
void MyGluLookAt(float eyeX, float eyeY, float eyeZ, float lookAtX, float lookAtY, float lookAtZ, float upX, float upY, float upZ)
Definition: SFML_HOG.cpp:680
MonoFont::GetTextLines
void GetTextLines(std::vector< Graphics::Display::lineInfo > &lines, Graphics::point location, const char *text, float height, const rgbColor &color=Colors::black, Graphics::textAlign align=Graphics::textAlignLeft, Graphics::textBaseline base=Graphics::textBaselineBottom)
Definition: MonoFont.cpp:20
drawCStringGL
void drawCStringGL(char *cstrOut, GLuint fontList)
Draws a CString in OpenGL.
Definition: SFML_HOG.cpp:778
kMouseUp
@ kMouseUp
Definition: Common.h:153
gDolly
GLboolean gDolly
Definition: SFML_HOG.cpp:44
Line
void Line(Graphics::point p1, Graphics::point p2, float width, int viewport)
Definition: SFML_HOG.cpp:1042
recFrustum::right
GLdouble right
Definition: Common.h:31
recVec::y
GLdouble y
Definition: GLUtil.h:98
recCamera::aperture
GLdouble aperture
Definition: Common.h:46
mouseDolly
static void mouseDolly(int x, int y, pRecContext pContextInfo)
Definition: SFML_HOG.cpp:516
tButtonType
tButtonType
Definition: Common.h:144
drawGL
void drawGL(pRecContext pContextInfo, sf::Window &window)
Main OpenGL drawing function.
Definition: SFML_HOG.cpp:1136
updateProjection
void updateProjection(pRecContext pContextInfo, int viewPort)
Update the projection matrix based on camera and view info.
Definition: SFML_HOG.cpp:595
Graphics::rect::bottom
float bottom
Definition: Graphics.h:100
Graphics::Display::backgroundLineSegments
std::vector< segments > backgroundLineSegments
Definition: Graphics.h:274
recVec::x
GLdouble x
Definition: GLUtil.h:98
recCamera::viewUp
recVec viewUp
Definition: Common.h:41
initialConditions
void initialConditions(pRecContext pContextInfo)
Definition: Common.cpp:680
recCamera::viewHeight
GLint viewHeight
Definition: Common.h:47
recContext::moveAllPortsTogether
bool moveAllPortsTogether
Definition: Common.h:72
convertToGlobalHogCoordinate
Graphics::point convertToGlobalHogCoordinate(int x, int y)
Definition: SFML_HOG.cpp:72
recCamera::viewPos
recVec viewPos
Definition: Common.h:35
bufferVisibility
bool bufferVisibility
Definition: SFML_HOG.cpp:789