HOG2
Common.cpp
Go to the documentation of this file.
1 /*
2  * $Id: common.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 11/02/06.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include <iostream>
13 #include <vector>
14 #include <stdio.h>
15 #include <stdint.h>
16 #include <math.h>
17 #include <cassert>
18 
19 #include "GLUtil.h"
20 #include "Trackball.h"
21 #include "Common.h"
22 
23 
24 
25 // For printing debug info
26 //static bool const verbose = false;
27 
28 static unsigned long gNextWindowID = 0;
29 char gDefaultMap[1024] = "";
30 const recVec gOrigin(0.0, 0.0, 0.0);
31 
32 using namespace std;
33 
34 static std::vector<commandLineCallbackData *> commandLineCallbacks;
35 static std::vector<joystickCallbackData *> joystickCallbacks;
36 static std::vector<mouseCallbackData *> mouseCallbacks;
37 static std::vector<mouseCallbackData2 *> mouseCallbacks2;
38 static std::vector<windowCallbackData *> windowCallbacks;
39 static std::vector<frameCallbackData *> glDrawCallbacks;
40 //static std::vector<dataCallbackData> dataCallbacks;
41 
43 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
54  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
59 
61 {
62  switch (t)
63  {
64  case kNoModifier: return "";
65  case kAnyModifier: return "*-";
66  case kShiftDown: return "Sft-";
67  case kControlDown: return "Ctl-";
68  case kAltDown: return "Alt-";
69  default: return "?-";
70  }
71 }
72 
73 void InstallKeyboardHandler(KeyboardCallback kf, const char *title, const char *description,
74  tKeyboardModifier mod, unsigned char firstKey, unsigned char lastKey)
75 {
76  for (int x = firstKey; ; x++)
77  {
78  keyboardCallbacks[x] = new keyboardCallbackData(kf, title, description, mod, keyboardCallbacks[x]);
79  if (x >= lastKey)
80  break;
81  }
82 }
83 
84 void GetKeyAssignments(std::vector<char> &keys)
85 {
86  for (int x = 0; x < 256; x++)
87  {
88  for (keyboardCallbackData *kd = keyboardCallbacks[x]; kd; kd = kd->next)
89  {
90  char val = x;
91  keys.push_back(val);
92 // printf("%s%c\t%s\t%s\n", getModifierText(kd->mod), x, kd->title, kd->desc);
93  }
94  }
95 }
96 
97 void GetKeyAssignmentDescriptions(std::vector<std::string> &keys)
98 {
99  for (int x = 0; x < 256; x++)
100  {
101  for (keyboardCallbackData *kd = keyboardCallbacks[x]; kd; kd = kd->next)
102  {
103  //char val = x;
104  keys.push_back(kd->title);
105  // printf("%s%c\t%s\t%s\n", getModifierText(kd->mod), x, kd->title, kd->desc);
106  }
107  }
108 }
110 {
111  printf("Legal Keyboard Commands\n-----------------------\n");
112  for (int x = 0; x < 256; x++)
113  {
114  for (keyboardCallbackData *kd = keyboardCallbacks[x]; kd; kd = kd->next)
115  {
116  printf("%s%c\t%s\t%s\n", getModifierText(kd->mod), x, kd->title, kd->desc);
117  }
118  }
119 }
120 
121 
123 {
124  bool called = false;
125  for (keyboardCallbackData *kd = keyboardCallbacks[keyHit]; kd; kd = kd->next)
126  {
127  if ((mod == kd->mod) || (kd->mod == kAnyModifier))
128  {
129 // printf("(DEBUG) calling: %s%c\t%s\t%s\n", getModifierText(kd->mod), keyHit,
130 // kd->title, kd->desc);
131  kd->call(pContextInfo->windowID, mod, keyHit);
132  called = true;
133  }
134  }
135  if (!called)
136  {
137  printf("Unknown keyboard command %s%c/%d\n\n", getModifierText(mod), keyHit, keyHit);
139  }
140  return false;
141 }
142 
143 void InstallFrameHandler(FrameCallback glCall, unsigned long windowID, void *userdata)
144 {
145  glDrawCallbacks.push_back(new frameCallbackData(glCall, windowID, userdata));
146 }
147 
148 void RemoveFrameHandler(FrameCallback glCall, unsigned long windowID, void *userdata)
149 {
150  for (unsigned int x = 0; x < glDrawCallbacks.size(); x++)
151  {
152  if ((glDrawCallbacks[x]->glCall == glCall) &&
153  (glDrawCallbacks[x]->userData == userdata) &&
154  (glDrawCallbacks[x]->windowID == windowID))
155  {
156  delete glDrawCallbacks[x];
158  glDrawCallbacks.pop_back();
159  }
160  }
161 }
162 
164 {
165  glEnable(GL_BLEND); // for text fading
166  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // ditto
167  for (unsigned int x = 0; x < glDrawCallbacks.size(); x++)
168  {
169  if (glDrawCallbacks[x]->windowID == pContextInfo->windowID)
170  glDrawCallbacks[x]->glCall(pContextInfo->windowID, viewport, glDrawCallbacks[x]->userData);
171  }
172  pContextInfo->display.EndFrame(); // end last frame
173  for (int x = 0; x < pContextInfo->numPorts; x++)
174  {
176  }
177 }
178 
179 void InstallJoystickHandler(JoystickCallback jC, void *userdata)
180 {
181  joystickCallbacks.push_back(new joystickCallbackData(jC, userdata));
182 }
183 
184 void RemoveJoystickHandler(JoystickCallback jC, void *userdata)
185 {
186  for (unsigned int x = 0; x < joystickCallbacks.size(); x++)
187  {
188  if ((joystickCallbacks[x]->jC == jC) &&
189  (joystickCallbacks[x]->userData == userdata))
190  {
191  delete joystickCallbacks[x];
193  joystickCallbacks.pop_back();
194  }
195  }
196 }
197 
198 void HandleJoystickMovement(pRecContext pContextInfo, double panX, double panY)
199 {
200  for (unsigned int x = 0; x < joystickCallbacks.size(); x++)
201  {
202  //printf("Calling joystick callback %d\n", x);
203  joystickCallbacks[x]->jC(pContextInfo->windowID, panX, panY, joystickCallbacks[x]->userData);
204  }
205 }
206 
208  const char *arg, const char *param, const char *usage)
209 {
210  commandLineCallbacks.push_back(new commandLineCallbackData(CLC, arg, param, usage));
211 }
212 
214 {
215  printf("Valid command-line flags:\n\n");
216  for (unsigned int x = 0; x < commandLineCallbacks.size(); x++)
217  commandLineCallbacks[x]->Print();
218  printf("\n");
219 }
220 
221 // Process command line arguments
222 void ProcessCommandLineArgs(int argc, char *argv[])
223 {
224 // printf("Processing %d command line arguments\n", argc);
225 // for (int x = 0; x < argc; x++)
226 // {
227 // printf("%s ", argv[x]);
228 // }
229 // printf("\n");
230  //initializeCommandLineHandlers();
231  // printCommandLineArguments();
232 
233  int lastval = 1;
234  for (int y = 1; y < argc; )
235  {
236  lastval = y;
237  for (unsigned int x = 0; x < commandLineCallbacks.size(); x++)
238  {
239  if (strcmp(commandLineCallbacks[x]->argument, argv[y]) == 0)
240  {
241  y += commandLineCallbacks[x]->CLC(&argv[y], argc-y);
242  break;
243  }
244  }
245  if (lastval == y)
246  {
247  printf("Error: unhandled command-line parameter (%s)\n\n", argv[y]);
249  y++;
250  //exit(10);
251  }
252  }
253 }
254 
256 {
257  mouseCallbacks.push_back(new mouseCallbackData(mC, which));
258 }
259 
261 {
262  mouseCallbacks2.push_back(new mouseCallbackData2(mC, which));
263 }
264 
266 {
267  for (unsigned int x = 0; x < mouseCallbacks.size(); x++)
268  {
269  if (mouseCallbacks[x]->mC == mC)
270  {
271  delete mouseCallbacks[x];
273  mouseCallbacks.pop_back();
274  }
275  }
276 }
277 
279 {
280  for (unsigned int x = 0; x < mouseCallbacks2.size(); x++)
281  {
282  if (mouseCallbacks2[x]->mC == mC)
283  {
284  delete mouseCallbacks2[x];
286  mouseCallbacks2.pop_back();
287  }
288  }
289 }
290 
291 void ReinitViewports(unsigned long windowID, const Graphics::rect &r, viewportType v)
292 {
293  pRecContext pContextInfo = GetContext(windowID);
294  pContextInfo->numPorts = 1;
295  pContextInfo->viewports[0].bounds = r;
297  pContextInfo->viewports[0].type = v;
298  pContextInfo->viewports[0].active = true;
299  for (int x = 1; x < MAXPORTS; x++)
300  pContextInfo->viewports[x].active = false;
301 }
302 
303 /* Adds a new viewport to the existing viewports and
304  * returns the new viewport numbers
305  */
306 int AddViewport(unsigned long windowID, const Graphics::rect &r, viewportType v)
307 {
308  pRecContext pContextInfo = GetContext(windowID);
310  {
311  printf("Cannot add viewport - reached limit of %d [constant MAXPORTS]\n", MAXPORTS);
312  return -1;
313  }
319  return pContextInfo->numPorts-1;
320 }
321 
322 /* Adds a new viewport to the existing viewports and
323  * returns the new viewport numbers. Will animate from initial to final location
324  */
325 int AddViewport(unsigned long windowID, const Graphics::rect &initial, const Graphics::rect &fin, viewportType v)
326 {
327  pRecContext pContextInfo = GetContext(windowID);
329  {
330  printf("Cannot add viewport - reached limit of %d [constant MAXPORTS]\n", MAXPORTS);
331  return -1;
332  }
338  return pContextInfo->numPorts-1;
339 }
340 
341 void MoveViewport(unsigned long windowID, int port, const Graphics::rect &newLocation)
342 {
343  pRecContext pContextInfo = GetContext(windowID);
344  pContextInfo->viewports[port].finalBound = newLocation;
345 }
346 
347 float GlobalHOGToViewportX(float x, int v)
348 {
350  Graphics::point input(x, 0.f, 0.f);
351  Graphics::point input2(0, 0.f, 0.f);
354  return result.x-result2.x;
355  // return ((result.x+1.0)*pContextInfo->windowWidth)/2.0;
356 }
357 
358 float ViewportToGlobalHOGX(float x, int v)
359 {
361  Graphics::point input(x, 0.f, 0.f);
362  Graphics::point input2(0, 0.f, 0.f);
365  return result.x-result2.x;
366  // return ((result.x+1.0)*pContextInfo->windowWidth)/2.0;
367 }
368 
369 float GlobalHOGToViewportY(float y, int v)
370 {
372  Graphics::point input(0.f, y, 0.f);
374 // result.y -= pContextInfo->viewports[v].bounds.bottom;
375 // result.y = pContextInfo->viewports[v].bounds.top - result.y;
376  // if (v == 1)
377 // printf("Y:%f -> %f\n", y, ((result.y+1.0))/2.0);
378  return -((result.y-1.0)*pContextInfo->windowHeight)/2.0;
379 }
380 
382 {
385 }
386 
388 {
391 }
392 
394 {
396  return Graphics::rect(GlobalHOGToViewport(pContextInfo, pContextInfo->viewports[port], {loc.left, loc.top}),
397  GlobalHOGToViewport(pContextInfo, pContextInfo->viewports[port], {loc.right, loc.bottom}));
398 }
399 
401 {
403  return Graphics::rect(ViewportToGlobalHOG(pContextInfo, pContextInfo->viewports[port], {loc.left, loc.top}),
404  ViewportToGlobalHOG(pContextInfo, pContextInfo->viewports[port], {loc.right, loc.bottom}));
405 }
406 
408 {
409  if (v.type == kScaleToFill) // just scale regular -1/1 axes into the rectangle
410  {
411  // gets offset into rect
412  where.x -= v.bounds.left;
413  where.x /= (v.bounds.right-v.bounds.left);
414  where.x = where.x*2.0-1.0;
415  where.y -= v.bounds.bottom;
416  where.y /= (v.bounds.top-v.bounds.bottom);
417  where.y = -where.y*2.0+1.0;
418  return where;
419  }
420  else if (v.type == kScaleToSquare)
421  {
422  double localWidth = v.bounds.right-v.bounds.left;
423  double localHeight = v.bounds.bottom-v.bounds.top;
424  double actualWidth = pContextInfo->windowWidth*localWidth;
425  double actualHeight = pContextInfo->windowHeight*localHeight;
426  double xRatio = actualWidth/actualHeight;
427  double yRatio = actualHeight/actualWidth;
428  xRatio = std::max(xRatio, 1.);
429  yRatio = std::max(yRatio, 1.);
430 
431  where.x *= xRatio;
432  where.x -= v.bounds.left;
433  where.x /= (v.bounds.right-v.bounds.left);
434  where.x = where.x*2.0-1.0;
435 
436 
437  where.y *= yRatio;
438  where.y -= v.bounds.bottom;
439  where.y /= (v.bounds.top-v.bounds.bottom);
440  where.y = (-where.y)*2.0+1.0;
441 
442 
443  return where;
444 
445 // // gets offset into rect
446 // where.x -= v.bounds.left;
447 // where.x /= (v.bounds.right-v.bounds.left);
448 // where.x = where.x*2.0-1.0;
449 // where.y -= v.bounds.bottom;
450 // where.y /= (v.bounds.top-v.bounds.bottom);
451 // where.y = -where.y*2.0+1.0;
452 // return where;
453 //
454 // float localWidth = v.bounds.right-v.bounds.left;
455 // float localHeight = v.bounds.bottom-v.bounds.top;
456 // // find the smallest dimension; scale into that dimension and then shift into the middle
457 // // minSize is in window pixels!
458 // float minSize = (pContextInfo->windowWidth*localWidth<pContextInfo->windowHeight*localHeight)?localWidth:localHeight;
459 // float xScale;
460 // float yScale;
461 // point3d center((v.bounds.left+v.bounds.right)/2.f, (v.bounds.top+v.bounds.bottom)/2.f, 0);
462 // if (pContextInfo->windowWidth*localWidth < pContextInfo->windowHeight*localHeight)
463 // {
464 // minSize = localWidth;
465 // xScale = 1.0;
466 // yScale = (pContextInfo->windowHeight*localHeight)/(pContextInfo->windowWidth*localWidth);
467 // //printf("Scaling x:%1.2f, y:%1.2f\n", xScale, yScale);
468 // }
469 // else {
470 // minSize = localHeight;
471 // xScale = (pContextInfo->windowWidth*localWidth)/(pContextInfo->windowHeight*localHeight);
472 // yScale = 1.0;
473 // }
474 //
475 // where.x *= xScale;
476 // where.y *= yScale;
477 // where *= (minSize/2.0f);
478 // where += center;
479 //
480 //
481 // return where;
482  }
483  else {
484  printf("Unknown scale type\n");
485  exit(0);
486  }
487 }
488 
490 {
491  if (v.type == kScaleToFill)
492  {
493  where.x = (where.x+1.0)/2.0;
494  where.x *= (v.bounds.right-v.bounds.left);
495  where.x += v.bounds.left;
496 
497  where.y = -(where.y-1.0)/2.0;
498  where.y *= (v.bounds.top-v.bounds.bottom);
499  where.y += v.bounds.bottom;
500  return where;
501  }
502  else if (v.type == kScaleToSquare)
503  {
504  double localWidth = v.bounds.right-v.bounds.left;
505  double localHeight = v.bounds.bottom-v.bounds.top;
506  double actualWidth = pContextInfo->windowWidth*localWidth;
507  double actualHeight = pContextInfo->windowHeight*localHeight;
508  double xRatio = actualWidth/actualHeight;
509  double yRatio = actualHeight/actualWidth;
510  xRatio = std::max(xRatio, 1.);
511  yRatio = std::max(yRatio, 1.);
512 
513  where.x = (where.x+1.0)/2.0;
514  where.x *= (v.bounds.right-v.bounds.left);
515  where.x += v.bounds.left;
516  where.x /= xRatio;
517 
518  where.y = -(where.y-1.0)/2.0;
519  where.y *= (v.bounds.top-v.bounds.bottom);
520  where.y += v.bounds.bottom;
521  where.y /= yRatio;
522  return where;
523 
524 
525 // // printf("From (%f, %f) to ", where.x, where.y);
528 // // find the smallest dimension; scale into that dimension and then shift into the middle
529 // // minSize is in window pixels!
530 // float minSize;// = (pContextInfo->windowWidth*localWidth<pContextInfo->windowHeight*localHeight)?localWidth:localHeight;
531 // float xScale;
532 // float yScale;
534 // if (pContextInfo->windowWidth*localWidth < pContextInfo->windowHeight*localHeight)
535 // {
536 // minSize = localWidth;
537 // xScale = 1.0;
538 // yScale = (pContextInfo->windowHeight*localHeight)/(pContextInfo->windowWidth*localWidth);
539 // //printf("Scaling x:%1.2f, y:%1.2f\n", xScale, yScale);
540 // }
541 // else {
542 // minSize = localHeight;
543 // xScale = (pContextInfo->windowWidth*localWidth)/(pContextInfo->windowHeight*localHeight);
544 // yScale = 1.0;
545 // }
546 // point3d center((v.bounds.left+v.bounds.right)/2.f, (v.bounds.top+v.bounds.bottom)/2.f, 0);
547 //
548 // where -= center;
549 // where /= (minSize/2.0f);
550 // where.x /= xScale;
551 // where.y /= yScale;
553 //
554 // return where;
555  }
556  else {
557  printf("Unknown scale type\n");
558  exit(0);
559  }
560 }
561 
562 
563 /* New low-end mouse handler. Does the viewport computation - just requires incoming global HOG coordinates. */
564 bool HandleMouse(pRecContext pContextInfo, int xWindow, int yWindow, point3d where, tButtonType button, tMouseEventType mouse)
565 {
566  for (int x = MAXPORTS-1; x >= 0; x--)
567  {
568 // if (!pContextInfo->viewports[x].active)
569 // continue;
570  if (!PointInRect(where, pContextInfo->viewports[x].bounds))
571  continue;
572  // got hit in rect
574  // click handled
575  if (HandleMouseClick(pContextInfo, x, xWindow, yWindow, res, button, mouse))
576  return true;
577  }
578  return false;
579 }
580 
581 /* New low-end mouse handler. Does the viewport computation - just requires incoming global HOG coordinates. */
583 {
584  for (int x = MAXPORTS-1; x >= 0; x--)
585  {
586 // if (!pContextInfo->viewports[x].active)
587 // continue;
588  if (!PointInRect(where, pContextInfo->viewports[x].bounds))
589  continue;
590  // got hit in rect
592  // click handled
593  if (HandleMouseClick(pContextInfo, x, -1, -1, res, button, mouse))
594  return true;
595  }
596  return false;
597 }
598 
599 // this is called by the OS when it gets a click
601  tButtonType button, tMouseEventType mouse)
602 {
603  for (unsigned int j = 0; j < mouseCallbacks2.size(); j++)
604  {
605  if (mouseCallbacks2[j]->which&mouse) // need to ask for event to call handler
606  {
607 // if (x == -1 || y == -1)
608 // fprintf(stderr, "Warning: window coordinates not being pased into HandleMouseClick (%s line %d)\n",
609 // __FILE__, __LINE__);
610 
611  if (mouseCallbacks2[j]->mC(pContextInfo->windowID, viewport, x, y, where,
612  button, mouse))
613  return true;
614  }
615  }
616  return HandleMouseClick(pContextInfo, x, y, where, button, mouse);
617 }
618 
620  tButtonType button, tMouseEventType mouse)
621 {
622  for (unsigned int j = 0; j < mouseCallbacks.size(); j++)
623  {
624  if (mouseCallbacks[j]->which&mouse) // need to ask for event to call handler
625  {
626  if (mouseCallbacks[j]->mC(pContextInfo->windowID, x, y, where,
627  button, mouse))
628  return true;
629  }
630  }
631  return false;
632 }
633 
635 {
636  windowCallbacks.push_back(new windowCallbackData(wC));
637 }
638 
640 {
641  for (unsigned int x = 0; x < windowCallbacks.size(); x++)
642  {
643  if (windowCallbacks[x]->wC == wC)
644  {
645  delete windowCallbacks[x];
647  windowCallbacks.pop_back();
648  }
649  }
650 }
651 
653 {
654  for (unsigned int j = 0; j < windowCallbacks.size(); j++)
655  {
656  //printf("Calling window callback %d\n", x);
658  }
659 }
660 
661 //void InstallDataHandler(DataCallback dC)
662 //{
663 // dataCallbacks.push_back(dataCallbackData(dC));
664 //}
665 //
666 //void RemoveDataHandler(DataCallback dC)
667 //{
668 // for (unsigned int x = 0; x < dataCallbacks.size(); x++)
669 // {
670 // if (dataCallbacks[x].dC == dC)
671 // {
672 // dataCallbacks[x] = dataCallbacks[dataCallbacks.size()-1];
673 // dataCallbacks.pop_back();
674 // }
675 // }
676 //}
677 
678 
679 // intializes context conditions
681 {
683  pContextInfo->numPorts = 3;
684  pContextInfo->currPort = 0;
685  for (int x = 0; x < MAXPORTS; x++)
686  {
688  for (int y = 0; y < 4; y++)
689  {
692  }
693 // pContextInfo->camera[x].rotations.cameraRotation[0] = 180;
694 // pContextInfo->camera[x].rotations.cameraRotation[2] = 1;
695  pContextInfo->camera[x].thirdPerson = true;
696  }
698 
701 }
702 
703 bool DoKeyboardCommand(pRecContext pContextInfo, unsigned char keyHit, bool shift, bool cntrl, bool alt)
704 {
705  DoKeyboardCallbacks(pContextInfo, tolower(keyHit),
706  shift?kShiftDown:(cntrl?kControlDown:(alt?kAltDown:kNoModifier)));
707  return false;
708 }
709 
710 
711 //void rotateObject()
712 //{
713 // pRecContext pContextInfo = getCurrentContext();
714 // if (!pContextInfo)
715 // return;
716 // pContextInfo->rotations[pContextInfo->currPort].objectRotation[0] += 1;
717 // pContextInfo->rotations[pContextInfo->currPort].objectRotation[1] = 0;
718 // pContextInfo->rotations[pContextInfo->currPort].objectRotation[2] = 1;
719 // pContextInfo->rotations[pContextInfo->currPort].objectRotation[3] = 0;
720 //}
721 
723 {
725  if (!pContextInfo)
726  return;
727  pContextInfo->numPorts = 1;
728  for (int x = 0; x < MAXPORTS; x++)
729  {
731  for (int y = 0; y < 4; y++)
732  {
735  }
736 // pContextInfo->camera[x].rotations.cameraRotation[0] = 180;
737 // pContextInfo->camera[x].rotations.cameraRotation[2] = 1;
738  }
739 
742 
743  updateProjection(pContextInfo); // update projection matrix
744 // updateModelView(pContextInfo);
745 }
746 
747 // sets the camera data to initial conditions
748 void resetCamera(recCamera * pCamera)
749 {
750  pCamera->aperture = 10.0;
751 
752  pCamera->viewPos.x = 0.0;
753  pCamera->viewPos.y = 0.0;
754  pCamera->viewPos.z = -12.5;
755  pCamera->viewDir.x = -pCamera->viewPos.x;
756  pCamera->viewDir.y = -pCamera->viewPos.y;
757  pCamera->viewDir.z = -pCamera->viewPos.z;
758 
759  pCamera->viewUp.x = 0;
760  pCamera->viewUp.y = -1;//-.1;
761  pCamera->viewUp.z = 0;//-1;
762 
763  //pCamera->viewRot.worldRotation = {0,0,0,0};
764 }
765 
767 {
769  if (port == -1)
770  port = pContextInfo->currPort;
771  return /*pContextInfo->camera[port].viewPos-*/pContextInfo->camera[port].viewDir;
772 }
773 
774 
775 void cameraLookAt(GLfloat x, GLfloat y, GLfloat z, float cameraSpeed, int port)
776 {
778  if (!pContextInfo)
779  return;
780 // const float cameraSpeed = .1;
781  if (port == -1)
782  port = pContextInfo->currPort;
783 
784  pContextInfo->camera[port].viewDir.x = (1-cameraSpeed)*pContextInfo->camera[port].viewDir.x + cameraSpeed*(x - pContextInfo->camera[port].viewPos.x);
785  pContextInfo->camera[port].viewDir.y = (1-cameraSpeed)*pContextInfo->camera[port].viewDir.y + cameraSpeed*(y - pContextInfo->camera[port].viewPos.y);
786  pContextInfo->camera[port].viewDir.z = (1-cameraSpeed)*pContextInfo->camera[port].viewDir.z + cameraSpeed*(z - pContextInfo->camera[port].viewPos.z);
787 // pContextInfo->rotations[port].objectRotation[0] *= (1-cameraSpeed);
788 // pContextInfo->rotations[port].worldRotation[0] *= (1-cameraSpeed);
790 }
791 
792 void cameraMoveTo(GLfloat x, GLfloat y, GLfloat z, float cameraSpeed, int port)
793 {
795  if (!pContextInfo)
796  return;
797 // const float cameraSpeed = .1;
798  if (port == -1)
799  {
800  port = pContextInfo->currPort;
801  }
802  pContextInfo->camera[port].viewPos.x = (1-cameraSpeed)*pContextInfo->camera[port].viewPos.x + cameraSpeed*x;
803  pContextInfo->camera[port].viewPos.y = (1-cameraSpeed)*pContextInfo->camera[port].viewPos.y + cameraSpeed*y;
804  pContextInfo->camera[port].viewPos.z = (1-cameraSpeed)*pContextInfo->camera[port].viewPos.z + cameraSpeed*z;
806 }
807 
808 void cameraOffset(GLfloat x, GLfloat y, GLfloat z, float cameraSpeed, int port)
809 {
811  if (!pContextInfo)
812  return;
813  if (port == -1)
814  {
815  port = pContextInfo->currPort;
816  }
817  pContextInfo->camera[port].viewPos.x += cameraSpeed*x;
818  pContextInfo->camera[port].viewPos.y += cameraSpeed*y;
819  pContextInfo->camera[port].viewPos.z += cameraSpeed*z;
821 }
822 
824 {
825  const double ratios[4][4][4] =
826 {{{0, 1, 0, 1}},
827 {{0, 0.5, 0, 1}, {0.5, 0.5, 0, 1}},
828 {{0, 0.5, 0.5, 0.5}, {0.5, 0.5, 0.5, 0.5}, {0, 1, 0, 0.5}},
829 {{0, 0.5, 0.5, 0.5}, {0.5, 0.5, 0.5, 0.5}, {0, 0.5, 0, 0.5}, {0.5, 0.5, 0, 0.5}}};
830 
831  currPort = 0; // NOTE: everyone gets the "full" screen
832  //const double *val = ratios[pContextInfo->numPorts-1][currPort];
833  const double *val = ratios[0][currPort];
834 
837 
838  pContextInfo->camera[currPort].viewWidth = (GLint)(val[1]*pContextInfo->globalCamera.viewWidth);
839  pContextInfo->camera[currPort].viewHeight = (GLint)(val[3]*pContextInfo->globalCamera.viewHeight);
840  // printf("Window %d port %d width: %d, height %d\n",
841  // pContextInfo->windowID, currPort,
842  // pContextInfo->camera[currPort].viewWidth,
843  // pContextInfo->camera[currPort].viewHeight);
844 }
845 
847 {
848  pContextInfo->display.SetViewport(currPort);
849  currPort = 0;
850 
851  const double ratios[4][4][4] =
852  {{{0, 1, 0, 1}}, // x, width%, y, height%
853  {{0, 0.5, 0, 1}, {0.5, 0.5, 0, 1}},
854  {{0, 0.5, 0.5, 0.5}, {0.5, 0.5, 0.5, 0.5}, {0, 1, 0, 0.5}},
855  {{0, 0.5, 0.5, 0.5}, {0.5, 0.5, 0.5, 0.5}, {0, 0.5, 0, 0.5}, {0.5, 0.5, 0, 0.5}}};
856 
857  const double *val = ratios[0][currPort];
858  // const double *val = ratios[pContextInfo->numPorts-1][currPort];
859 
860  glViewport(val[0]*pContextInfo->globalCamera.viewWidth,
864 
865 }
866 
868 {
870  glMatrixMode(GL_PROJECTION);
871  glLoadIdentity();
875  // projection matrix already set
877 
878  if (pContextInfo->numPorts > 1)
880 
881  GLint viewport[4];
882  GLdouble modelview[16];
883  GLdouble projection[16];
884  GLfloat winX, winY, winZ;
885  GLdouble posX, posY, posZ;
886 
887  glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
888  glGetDoublev( GL_PROJECTION_MATRIX, projection );
889  glGetIntegerv( GL_VIEWPORT, viewport );
890  winX = (float)x;
891  winY = (float)viewport[3] - (float)y;
892  glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
893  // if (gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ) == GL_FALSE)
894  // printf("WARNING: gluUnProject failed\n");
895  //assert(!"gluUnProject missing");
896 
897 // printf("Clicked (%f, %f, %f) [far plane %f near %f]\n", posX, posY, posZ,
898 // pContextInfo->frust[pContextInfo->currPort].far+pContextInfo->camera[pContextInfo->currPort].viewPos.z,
899 // pContextInfo->frust[pContextInfo->currPort].near+pContextInfo->camera[pContextInfo->currPort].viewPos.z);
900  return point3d(posX, posY, posZ);
901 }
902 
903 void SetNumPorts(unsigned long windowID, int count)
904 {
905  pRecContext pContextInfo = GetContext(windowID);
906  if ((count <= MAXPORTS) && (count > 0))
907  {
910 
911  if (pContextInfo->numPorts > count)
912  pContextInfo->currPort = 0;
913 
914  pContextInfo->numPorts = count;
915  for (int x = 0; x < pContextInfo->numPorts; x++)
916  {
918  }
920  }
921 }
922 
923 int GetNumPorts(unsigned long windowID)
924 {
925  pRecContext pContextInfo = GetContext(windowID);
926  return pContextInfo->numPorts;
927 }
928 
929 int GetActivePort(unsigned long windowID)
930 {
931  pRecContext pContextInfo = GetContext(windowID);
932  return pContextInfo->currPort;
933 }
934 
935 void SetActivePort(unsigned long windowID, int which)
936 {
937  pRecContext pContextInfo = GetContext(windowID);
938  if ((which >= 0) && (which < pContextInfo->numPorts))
939  pContextInfo->currPort = which;
940 }
941 
942 
943 class bmp_header {
944 public:
946  ://bfType(19778),
947  zero(0), bfOffBits(sizeof(bmp_header)+2), biSize(40), biPlanes(1),
948  biBitCount(32), biCompression(0), biSizeImage(0), biXPelsPerMeter(2835), biYPelsPerMeter(2835),
949  biClrUsed(0), biClrImportant(0) {}
950 
951 // uint16_t bfType;// 19778
952  uint32_t bfSize; // ?? specifies the size of the file in bytes.
953  uint32_t zero; // 0
954  uint32_t bfOffBits;
955  // 11 4 bfOffBits 1078 specifies the offset from the beginning of the file to the bitmap data.
956 
957  uint32_t biSize; // 40
958  uint32_t biWidth;
959  uint32_t biHeight;
960  uint16_t biPlanes; // 0 (1??)
961  uint16_t biBitCount; // 24
962  uint32_t biCompression; // 0
963  uint32_t biSizeImage; // 0
964  uint32_t biXPelsPerMeter; // 0
965  uint32_t biYPelsPerMeter; // 0
966  uint32_t biClrUsed; // 0
967  uint32_t biClrImportant; // 0
968 };
969 
970 void SaveScreenshot(unsigned long windowID, const char *filename)
971 {
972  pRecContext pContextInfo = GetContext(windowID);
973 
974  char file[strlen(filename)+5];
975  sprintf(file, "%s.bmp", filename);
976  FILE *f = fopen(file, "w+");
977 
978  if (f == 0) return;
979 
980 // 3 4 bfSize ?? specifies the size of the file in bytes.
981 // 19 4 biWidth 100 specifies the width of the image, in pixels.
982 // 23 4 biHeight 100 specifies the height of the image, in pixels.
983 
984 
987  long rowBytes = width * 4;
988  long imageSize = rowBytes * height;
989  std::vector<char> image(imageSize);
990 // char image[imageSize];
991  char zero[4] = {0, 0, 0, 0};
992  glReadPixels(0, 0, GLsizei(width), GLsizei(height), GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &image[0]);//GL_BGRA
993 
994  bmp_header h;
995  h.biWidth = width;
996  h.biHeight = height;
997  int buffer = (4-width%4)%4;
998  h.bfSize = sizeof(bmp_header)+2+(width+buffer)*height*4;
999  h.biSizeImage = (width+buffer)*height*4;
1000  uint16_t bfType = 19778;
1001  fwrite(&bfType, sizeof(bfType), 1, f);
1002  fwrite(&h, sizeof(bmp_header), 1, f);
1003  for (int x = 0; x < height; x++)
1004  {
1005  fwrite(&image[x*width*4], sizeof(char), width*4, f);
1006  if (0 != width%4)
1007  fwrite(&zero, sizeof(char), buffer, f);
1008  }
1009  fclose(f);
1010 }
1011 
1012 void SetZoom(int windowID, float amount)
1013 {
1014  pRecContext pContextInfo = GetContext(windowID);
1015 
1017  {
1018  for (int x = 0; x < pContextInfo->numPorts; x++)
1019  {
1020  pContextInfo->camera[x].aperture = amount;
1021 // pContextInfo->camera[x].viewPos.z = -12.5+amount;
1022 // if (pContextInfo->camera[x].viewPos.z == 0.0) // do not let z = 0.0
1023 // pContextInfo->camera[x].viewPos.z = 0.0001;
1024  updateProjection(pContextInfo, x); // update projection matrix
1025  }
1026  }
1027  else {
1029 // pContextInfo->camera[pContextInfo->currPort].viewPos.z = -12.5+amount;
1030 // if (pContextInfo->camera[pContextInfo->currPort].viewPos.z == 0.0) // do not let z = 0.0
1031 // pContextInfo->camera[pContextInfo->currPort].viewPos.z = 0.0001;
1032  updateProjection(pContextInfo, pContextInfo->currPort); // update projection matrix
1033  }
1034 }
1035 
1036 recVec GetHeading(unsigned long windowID, int which)
1037 {
1038  recVec v;
1039  GetHeading(windowID, which, v.x, v.y, v.z);
1040  return v;
1041 }
1042 
1043 void GetHeading(unsigned long windowID, int which, GLdouble &hx, GLdouble &hy, GLdouble &hz)
1044 {
1045  pRecContext pContextInfo = GetContext(windowID);
1046 
1047  double fRot[4];
1048  for (int x = 0; x < 4; x++)
1049  fRot[x] = pContextInfo->camera[which].rotations.cameraRotation[x];
1050  // these formulas are derived from the opengl redbook 1.4 pg 700
1051  double xp, yp, zp, len, sa, ca;//hx, hy, hz,
1052  len = 1/sqrt(fRot[1]*fRot[1] +
1053  fRot[2]*fRot[2] +
1054  fRot[3]*fRot[3]);
1055  xp = fRot[1]*len;
1056  yp = fRot[2]*len;
1057  zp = fRot[3]*len;
1058  ca = cos(-fRot[0]*PI/180.0);
1059  sa = sin(-fRot[0]*PI/180.0);
1060  hx = (1-ca)*xp*zp+sa*yp;
1061  hy = (1-ca)*yp*zp-sa*xp;
1062  hz = ca+(1-ca)*zp*zp;
1063  len = 1/sqrt(hx*hx+hy*hy+hz*hz);
1064  hx *= len;
1065  hy *= len;
1066  hz *= len;
1067 // printf("Heading vector: (%1.3f, %1.3f, %1.3f)\n", hx, hy, hz);
1068 }
1069 
joystickCallbackData
Definition: Common.h:245
Graphics::point
Definition: Graphics.h:32
commandLineCallbacks
static std::vector< commandLineCallbackData * > commandLineCallbacks
Definition: Common.cpp:34
Graphics::point::y
float y
Definition: Graphics.h:36
PrintKeyboardAssignments
void PrintKeyboardAssignments()
Definition: Common.cpp:109
HandleFrame
void HandleFrame(pRecContext pContextInfo, int viewport)
Definition: Common.cpp:163
ViewportToGlobalHOG
Graphics::point ViewportToGlobalHOG(Graphics::point where, int viewport)
Definition: Common.cpp:387
recContext::globalCamera
recCamera globalCamera
Definition: Common.h:67
glDrawCallbacks
static std::vector< frameCallbackData * > glDrawCallbacks
Definition: Common.cpp:39
gTrackBallRotation
GLfloat gTrackBallRotation[4]
Definition: GLUThog.cpp:33
RemoveMouseClickHandler
void RemoveMouseClickHandler(MouseCallback mC)
Definition: Common.cpp:265
recVec
A generic vector (essentially the same as a point, but offers normalization)
Definition: GLUtil.h:78
InstallJoystickHandler
void InstallJoystickHandler(JoystickCallback jC, void *userdata)
Definition: Common.cpp:179
HandleMouse
bool HandleMouse(pRecContext pContextInfo, int xWindow, int yWindow, point3d where, tButtonType button, tMouseEventType mouse)
Definition: Common.cpp:564
recVec::z
GLdouble z
Definition: GLUtil.h:98
ProcessCommandLineArgs
void ProcessCommandLineArgs(int argc, char *argv[])
Definition: Common.cpp:222
Graphics::Display::SetNumViewports
void SetNumViewports(uint8_t v)
Definition: Graphics.cpp:63
cameraOffset
void cameraOffset(GLfloat x, GLfloat y, GLfloat z, float cameraSpeed, int port)
Definition: Common.cpp:808
keyboardCallbackData
Definition: Common.h:232
Graphics::Display::EndFrame
void EndFrame()
Definition: Graphics.cpp:37
recContext::windowWidth
int windowWidth
Definition: Common.h:74
bmp_header::bfSize
uint32_t bfSize
Definition: Common.cpp:952
HandleWindowEvent
void HandleWindowEvent(pRecContext pContextInfo, tWindowEventType e)
Definition: Common.cpp:652
tKeyboardModifier
tKeyboardModifier
Definition: Common.h:136
updateProjection
void updateProjection(pRecContext pContextInfo, int viewPort=-1)
Update the projection matrix based on camera and view info.
Definition: GLUThog.cpp:560
Common.h
ViewportToGlobalHOGX
float ViewportToGlobalHOGX(float x, int v)
Definition: Common.cpp:358
bmp_header
Definition: Common.cpp:943
RemoveJoystickHandler
void RemoveJoystickHandler(JoystickCallback jC, void *userdata)
Definition: Common.cpp:184
windowCallbacks
static std::vector< windowCallbackData * > windowCallbacks
Definition: Common.cpp:38
updateModelView
void updateModelView(pRecContext pContextInfo, int currPort)
Updates the viewpoint of the model.
Definition: GLUThog.cpp:598
recCamera::frust
recFrustum frust
Definition: Common.h:45
RemoveWindowHandler
void RemoveWindowHandler(WindowCallback wC)
Definition: Common.cpp:639
JoystickCallback
void(* JoystickCallback)(unsigned long windowID, double offsetX, double offsetY, void *)
a joystaick callback handler is passed the same data passed in when it was installed
Definition: Common.h:180
kNoModifier
@ kNoModifier
Definition: Common.h:137
recContext::viewports
viewport viewports[MAXPORTS]
Definition: Common.h:73
recContext::camera
recCamera camera[MAXPORTS]
Definition: Common.h:69
kShiftDown
@ kShiftDown
Definition: Common.h:139
Graphics::rect
Definition: Graphics.h:94
MouseCallback
bool(* MouseCallback)(unsigned long windowID, int x, int y, point3d loc, tButtonType, tMouseEventType)
a mouse callback handler passes the absolute and local mouse coordinates of the click returns true if...
Definition: Common.h:186
width
int width
Definition: SFML_HOG.cpp:54
InstallKeyboardHandler
void InstallKeyboardHandler(KeyboardCallback kf, const char *title, const char *description, tKeyboardModifier mod, unsigned char firstKey, unsigned char lastKey)
Definition: Common.cpp:73
kControlDown
@ kControlDown
Definition: Common.h:140
kScaleToFill
@ kScaleToFill
Definition: Common.h:53
Graphics::Display::SetViewport
void SetViewport(uint8_t v)
Definition: Graphics.cpp:68
recContext::windowID
unsigned long windowID
Definition: Common.h:80
DoKeyboardCommand
bool DoKeyboardCommand(pRecContext pContextInfo, unsigned char keyHit, bool shift, bool cntrl, bool alt)
Definition: Common.cpp:703
bmp_header::biYPelsPerMeter
uint32_t biYPelsPerMeter
Definition: Common.cpp:965
recCamera::viewOriginY
GLfloat viewOriginY
Definition: Common.h:48
InstallCommandLineHandler
void InstallCommandLineHandler(CommandLineCallback CLC, const char *arg, const char *param, const char *usage)
Definition: Common.cpp:207
HandleMouseClick
bool HandleMouseClick(pRecContext pContextInfo, int viewport, int x, int y, point3d where, tButtonType button, tMouseEventType mouse)
Definition: Common.cpp:600
frameCallbackData
Definition: Common.h:281
viewport::type
viewportType type
Definition: Common.h:59
keyboardCallbacks
static keyboardCallbackData * keyboardCallbacks[256]
Definition: Common.cpp:42
viewportType
viewportType
Definition: Common.h:51
recFrustum::far
GLdouble far
Definition: Common.h:31
bmp_header::biClrUsed
uint32_t biClrUsed
Definition: Common.cpp:966
recContext::display
Graphics::Display display
Definition: Common.h:79
viewport
Definition: Common.h:56
resetCamera
void resetCamera()
Definition: Common.cpp:722
gNextWindowID
static unsigned long gNextWindowID
Definition: Common.cpp:28
bmp_header::biCompression
uint32_t biCompression
Definition: Common.cpp:962
GetKeyAssignmentDescriptions
void GetKeyAssignmentDescriptions(std::vector< std::string > &keys)
Definition: Common.cpp:97
GetOGLPos
point3d GetOGLPos(pRecContext pContextInfo, int x, int y)
Definition: Common.cpp:867
getCurrentContext
pRecContext getCurrentContext()
Definition: GLUThog.cpp:49
Graphics::PointInRect
bool PointInRect(const point &p, const rect &r)
Definition: Graphics.cpp:17
mouseCallbacks2
static std::vector< mouseCallbackData2 * > mouseCallbacks2
Definition: Common.cpp:37
recCamera::viewDir
recVec viewDir
Definition: Common.h:40
commandLineCallbackData
‍**
Definition: Common.h:217
MouseCallback2
bool(* MouseCallback2)(unsigned long windowID, int viewport, int x, int y, point3d loc, tButtonType, tMouseEventType)
the new callback handler also passes the viewport frame in which the click occured.
Definition: Common.h:191
keyboardCallbackData::next
keyboardCallbackData * next
Definition: Common.h:242
Graphics::rect::top
float top
Definition: Graphics.h:100
FrameCallback
void(* FrameCallback)(unsigned long windowID, unsigned int viewport, void *)
install a FrameCallback to be called once per frame and viewport This is where you should do any draw...
Definition: Common.h:170
SetNumPorts
void SetNumPorts(unsigned long windowID, int count)
Definition: Common.cpp:903
loc
Definition: MapGenerators.cpp:296
InstallWindowHandler
void InstallWindowHandler(WindowCallback wC)
Definition: Common.cpp:634
cameraMoveTo
void cameraMoveTo(GLfloat x, GLfloat y, GLfloat z, float cameraSpeed, int port)
Definition: Common.cpp:792
gTrackingContextInfo
pRecContext gTrackingContextInfo
Definition: GLUThog.cpp:37
getModifierText
const char * getModifierText(tKeyboardModifier t)
Definition: Common.cpp:60
tWindowEventType
tWindowEventType
Definition: Common.h:158
RemoveFrameHandler
void RemoveFrameHandler(FrameCallback glCall, unsigned long windowID, void *userdata)
Definition: Common.cpp:148
PI
static const double PI
Definition: GLUtil.h:66
recRotation::worldRotation
GLfloat worldRotation[4]
Definition: Common.h:26
point3d
#define point3d
Definition: GLUtil.h:123
kAnyModifier
@ kAnyModifier
Definition: Common.h:138
SetActivePort
void SetActivePort(unsigned long windowID, int which)
Definition: Common.cpp:935
GlobalHOGToViewport
Graphics::point GlobalHOGToViewport(Graphics::point where, int viewport)
Definition: Common.cpp:381
recContext
Definition: Common.h:64
mouseCallbackData
Definition: Common.h:255
recContext::windowHeight
int windowHeight
Definition: Common.h:74
WindowCallback
void(* WindowCallback)(unsigned long windowID, tWindowEventType)
a window callback handler called when a window is created or destroyed
Definition: Common.h:175
bmp_header::biClrImportant
uint32_t biClrImportant
Definition: Common.cpp:967
recCamera::rotations
recRotation rotations
Definition: Common.h:42
Graphics::rect::right
float right
Definition: Graphics.h:100
recRotation::cameraRotation
GLfloat cameraRotation[4]
Definition: Common.h:27
GlobalHOGToViewportY
float GlobalHOGToViewportY(float y, int v)
Definition: Common.cpp:369
recContext::currPort
int currPort
Definition: Common.h:71
setPortCamera
void setPortCamera(pRecContext pContextInfo, int currPort)
Definition: Common.cpp:823
bmp_header::biPlanes
uint16_t biPlanes
Definition: Common.cpp:960
bmp_header::bmp_header
bmp_header()
Definition: Common.cpp:945
ReinitViewports
void ReinitViewports(unsigned long windowID, const Graphics::rect &r, viewportType v)
Definition: Common.cpp:291
mouseCallbackData2
Definition: Common.h:264
GetHeading
recVec GetHeading(unsigned long windowID, int which)
Definition: Common.cpp:1036
SaveScreenshot
void SaveScreenshot(unsigned long windowID, const char *filename)
Definition: Common.cpp:970
Trackball.h
bmp_header::zero
uint32_t zero
Definition: Common.cpp:953
kScaleToSquare
@ kScaleToSquare
Definition: Common.h:52
GlobalHOGToViewportX
float GlobalHOGToViewportX(float x, int v)
Definition: Common.cpp:347
recCamera::viewOriginX
GLfloat viewOriginX
Definition: Common.h:48
height
int height
Definition: SFML_HOG.cpp:54
MAXPORTS
const int MAXPORTS
Definition: Common.h:23
recCamera::thirdPerson
bool thirdPerson
Definition: Common.h:37
bmp_header::biWidth
uint32_t biWidth
Definition: Common.cpp:958
windowCallbackData
Definition: Common.h:273
recCamera::viewWidth
GLint viewWidth
Definition: Common.h:47
AddViewport
int AddViewport(unsigned long windowID, const Graphics::rect &r, viewportType v)
Definition: Common.cpp:306
max
#define max(a, b)
Definition: MinimalSectorAbstraction.cpp:40
GLUtil.h
bmp_header::biBitCount
uint16_t biBitCount
Definition: Common.cpp:961
InstallFrameHandler
void InstallFrameHandler(FrameCallback glCall, unsigned long windowID, void *userdata)
Definition: Common.cpp:143
cameraLookingAt
recVec cameraLookingAt(int port)
Definition: Common.cpp:766
recFrustum::left
GLdouble left
Definition: Common.h:31
cameraLookAt
void cameraLookAt(GLfloat x, GLfloat y, GLfloat z, float cameraSpeed, int port)
Definition: Common.cpp:775
recFrustum::near
GLdouble near
Definition: Common.h:31
gOrigin
const recVec gOrigin(0.0, 0.0, 0.0)
setViewport
void setViewport(pRecContext pContextInfo, int currPort)
Definition: Common.cpp:846
SetZoom
void SetZoom(int windowID, float amount)
Definition: Common.cpp:1012
tMouseEventType
tMouseEventType
Definition: Common.h:151
GetKeyAssignments
void GetKeyAssignments(std::vector< char > &keys)
Definition: Common.cpp:84
Graphics::point::x
float x
Definition: Graphics.h:36
GetNumPorts
int GetNumPorts(unsigned long windowID)
Definition: Common.cpp:923
viewport::bounds
Graphics::rect bounds
Definition: Common.h:57
std
Definition: CanonicalGraphEnvironment.h:26
recFrustum::bottom
GLdouble bottom
Definition: Common.h:31
KeyboardCallback
void(* KeyboardCallback)(unsigned long windowID, tKeyboardModifier, char)
a keyboard callback handler is passed the current unit simulation, the key that was hit,...
Definition: Common.h:198
kAltDown
@ kAltDown
Definition: Common.h:141
recContext::numPorts
int numPorts
Definition: Common.h:71
CommandLineCallback
int(* CommandLineCallback)(char **, int)
A command-line callback handler takes in a char** which points to the argument which matches the argu...
Definition: Common.h:206
bmp_header::biSizeImage
uint32_t biSizeImage
Definition: Common.cpp:963
Graphics::rect::left
float left
Definition: Graphics.h:100
recFrustum::top
GLdouble top
Definition: Common.h:31
joystickCallbacks
static std::vector< joystickCallbackData * > joystickCallbacks
Definition: Common.cpp:35
GetActivePort
int GetActivePort(unsigned long windowID)
Definition: Common.cpp:929
bmp_header::biHeight
uint32_t biHeight
Definition: Common.cpp:959
HandleJoystickMovement
void HandleJoystickMovement(pRecContext pContextInfo, double panX, double panY)
Definition: Common.cpp:198
bmp_header::biXPelsPerMeter
uint32_t biXPelsPerMeter
Definition: Common.cpp:964
recFrustum::right
GLdouble right
Definition: Common.h:31
recVec::y
GLdouble y
Definition: GLUtil.h:98
viewport::finalBound
Graphics::rect finalBound
Definition: Common.h:58
recCamera::aperture
GLdouble aperture
Definition: Common.h:46
Graphics::rect::lerp
void lerp(const rect &val, float percentage)
Definition: Graphics.h:121
tButtonType
tButtonType
Definition: Common.h:144
Graphics::rect::bottom
float bottom
Definition: Graphics.h:100
viewport::active
bool active
Definition: Common.h:60
InstallMouseClickHandler
void InstallMouseClickHandler(MouseCallback mC, tMouseEventType which)
Definition: Common.cpp:255
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
PrintCommandLineArguments
void PrintCommandLineArguments()
Definition: Common.cpp:213
recCamera::viewHeight
GLint viewHeight
Definition: Common.h:47
bmp_header::bfOffBits
uint32_t bfOffBits
Definition: Common.cpp:954
GetContext
pRecContext GetContext(unsigned long windowID)
Definition: GLUThog.cpp:44
recContext::moveAllPortsTogether
bool moveAllPortsTogether
Definition: Common.h:72
recCamera
Definition: Common.h:34
gDefaultMap
char gDefaultMap[1024]
Definition: Common.cpp:29
MoveViewport
void MoveViewport(unsigned long windowID, int port, const Graphics::rect &newLocation)
Definition: Common.cpp:341
recCamera::viewPos
recVec viewPos
Definition: Common.h:35
bmp_header::biSize
uint32_t biSize
Definition: Common.cpp:957
mouseCallbacks
static std::vector< mouseCallbackData * > mouseCallbacks
Definition: Common.cpp:36
DoKeyboardCallbacks
bool DoKeyboardCallbacks(pRecContext pContextInfo, unsigned char keyHit, tKeyboardModifier mod)
Definition: Common.cpp:122
pContextInfo
pRecContext pContextInfo
Definition: GLUThog.cpp:31