HOG2
Classes | Macros | Typedefs | Enumerations | Functions | Variables
Common.h File Reference
#include "GLUtil.h"
#include "Graphics.h"
#include <stdio.h>
#include <cstring>
#include <cinttypes>
Include dependency graph for Common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  recRotation
 
struct  recFrustum
 
struct  recCamera
 
struct  viewport
 
struct  recContext
 
class  commandLineCallbackData
 ‍** More...
 
class  keyboardCallbackData
 
class  joystickCallbackData
 
class  mouseCallbackData
 
class  mouseCallbackData2
 
class  windowCallbackData
 
class  frameCallbackData
 

Macros

#define main   hog_main
 

Typedefs

typedef struct recContext recContext
 
typedef struct recContextpRecContext
 
typedef 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 drawing and/or update the unit simulation time. More...
 
typedef void(* WindowCallback) (unsigned long windowID, tWindowEventType)
 a window callback handler called when a window is created or destroyed More...
 
typedef 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 More...
 
typedef 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 the click/movement was handled; false if ignored More...
 
typedef 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. More...
 
typedef void(* KeyboardCallback) (unsigned long windowID, tKeyboardModifier, char)
 a keyboard callback handler is passed the current unit simulation, the key that was hit, and any modifiers that were being held down. More...
 
typedef int(* CommandLineCallback) (char **, int)
 A command-line callback handler takes in a char** which points to the argument which matches the argument that this handler was installed for. More...
 

Enumerations

enum  viewportType { kScaleToSquare, kScaleToFill }
 
enum  tKeyboardModifier {
  kNoModifier, kAnyModifier, kShiftDown, kControlDown,
  kAltDown
}
 
enum  tButtonType { kLeftButton, kRightButton, kMiddleButton, kNoButton }
 
enum  tMouseEventType : int { kMouseDown = 0x1, kMouseUp = 0x2, kMouseDrag = 0x4, kMouseMove = 0x8 }
 
enum  tWindowEventType { kWindowCreated, kWindowDestroyed }
 

Functions

void updateProjection (pRecContext pContextInfo, int viewPort=-1)
 Update the projection matrix based on camera and view info. More...
 
void drawGL (pRecContext pContextInfo, bool swap)
 
bool DoKeyboardCommand (pRecContext pContextInfo, unsigned char keyHit, bool shift, bool cntrl, bool alt)
 
void initialConditions (pRecContext pContextInfo)
 
void resetCamera (recCamera *pCamera)
 
void ProcessCommandLineArgs (int argc, char *argv[])
 
void SetNumPorts (unsigned long windowID, int count)
 
int GetNumPorts (unsigned long windowID)
 
void SetActivePort (unsigned long windowID, int which)
 
int GetActivePort (unsigned long windowID)
 
void ReinitViewports (unsigned long windowID, const Graphics::rect &r, viewportType v)
 
int AddViewport (unsigned long windowID, const Graphics::rect &r, viewportType v)
 
int AddViewport (unsigned long windowID, const Graphics::rect &initial, const Graphics::rect &fin, viewportType v)
 
void MoveViewport (unsigned long windowID, int viewport, const Graphics::rect &newLocation)
 
Graphics::point ViewportToGlobalHOG (Graphics::point where, int viewport)
 
Graphics::rect ViewportToGlobalHOG (const Graphics::rect &loc, int viewport)
 
Graphics::point ViewportToGlobalHOG (pRecContext pContextInfo, const viewport &v, Graphics::point where)
 
float ViewportToGlobalHOGX (float x, int v)
 
Graphics::point GlobalHOGToViewport (pRecContext pContextInfo, const viewport &v, Graphics::point where)
 
Graphics::point GlobalHOGToViewport (Graphics::point where, int viewport)
 
Graphics::rect GlobalHOGToViewport (const Graphics::rect &loc, int viewport)
 
float GlobalHOGToViewportX (float x, int v)
 
void InstallFrameHandler (FrameCallback jC, unsigned long windowID, void *userdata)
 
void RemoveFrameHandler (FrameCallback jC, unsigned long windowID, void *userdata)
 
void HandleFrame (pRecContext pContextInfo, int viewport)
 
void InstallJoystickHandler (JoystickCallback jC, void *userdata)
 
void RemoveJoystickHandler (JoystickCallback jC, void *userdata)
 
void HandleJoystickMovement (pRecContext pContextInfo, double panX, double panY)
 
void InstallMouseClickHandler (MouseCallback mC, tMouseEventType which=static_cast< tMouseEventType >(kMouseDown|kMouseUp|kMouseDrag))
 
void InstallMouseClickHandler (MouseCallback2 mC, tMouseEventType which=static_cast< tMouseEventType >(kMouseDown|kMouseUp|kMouseDrag))
 
void RemoveMouseClickHandler (MouseCallback mC)
 
void RemoveMouseClickHandler (MouseCallback2 mC)
 
bool HandleMouse (pRecContext pContextInfo, point3d where, tButtonType button, tMouseEventType mouse)
 
bool HandleMouse (pRecContext pContextInfo, int xWindow, int yWindow, point3d where, tButtonType button, tMouseEventType mouse)
 
bool HandleMouseClick (pRecContext pContextInfo, int x, int y, point3d where, tButtonType, tMouseEventType)
 
bool HandleMouseClick (pRecContext pContextInfo, int viewport, int x, int y, point3d where, tButtonType, tMouseEventType)
 
void InstallWindowHandler (WindowCallback wC)
 
void RemoveWindowHandler (WindowCallback wC)
 
void HandleWindowEvent (pRecContext pContextInfo, tWindowEventType)
 
void InstallKeyboardHandler (KeyboardCallback kf, const char *title, const char *description, tKeyboardModifier mod, unsigned char firstKey, unsigned char lastKey=0)
 
void GetKeyAssignments (std::vector< char > &keys)
 
void GetKeyAssignmentDescriptions (std::vector< std::string > &keys)
 
void PrintKeyboardAssignments ()
 
void InstallCommandLineHandler (CommandLineCallback, const char *, const char *, const char *)
 
void PrintCommandLineArguments ()
 
void RunHOGGUI (int argc, char *argv[], int windowDimension=1000)
 
void RunHOGGUI (int argc, char *argv[], int xDimension, int yDimension)
 
void SaveScreenshot (unsigned long windowID, const char *filename)
 
void SetZoom (int windowID, float amount)
 
void submitTextToBuffer (const char *val)
 
void appendTextToBuffer (const char *)
 
const char * getTextBuffer ()
 
void setTextBufferVisibility (bool)
 
bool getTextBufferVisibility ()
 
pRecContext getCurrentContext ()
 
pRecContext GetContext (unsigned long windowID)
 
void updateModelView (pRecContext pContextInfo, int currPort)
 Updates the viewpoint of the model. More...
 
void cameraLookAt (GLfloat, GLfloat, GLfloat, float cameraSpeed=0.1, int port=-1)
 
recVec cameraLookingAt (int port=-1)
 
void cameraMoveTo (GLfloat x, GLfloat y, GLfloat z, float cameraSpeed=0.1, int port=-1)
 
void cameraOffset (GLfloat x, GLfloat y, GLfloat z, float cameraSpeed=0.1, int port=-1)
 
void resetCamera ()
 
recVec GetHeading (unsigned long windowID, int which)
 
void GetHeading (unsigned long windowID, int which, GLdouble &hx, GLdouble &hy, GLdouble &hz)
 
void setPortCamera (pRecContext pContextInfo, int currPort)
 
void setViewport (pRecContext pContextInfo, int currPort)
 

Variables

const int MAXPORTS = 6
 
GLfloat gTrackBallRotation [4]
 
pRecContext gTrackingContextInfo
 
char gDefaultMap [1024]
 
const char kLeftArrow = 0x11
 
const char kRightArrow = 0x12
 
const char kUpArrow = 0x13
 
const char kDownArrow = 0x14
 

Macro Definition Documentation

◆ main

#define main   hog_main

Definition at line 21 of file Common.h.

Typedef Documentation

◆ CommandLineCallback

typedef int(* CommandLineCallback) (char **, int)

A command-line callback handler takes in a char** which points to the argument which matches the argument that this handler was installed for.

The second argument is the number of remaining arguments available. The handler can process and use as many of the remaining arguments, and returns the number of arguments it processed.

Definition at line 206 of file Common.h.

◆ FrameCallback

typedef 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 drawing and/or update the unit simulation time.

The viewports will be processed in order (0..#, max 4), so any global processing should only be done when the viewport is 0. The void* data is passed back to each call.

Definition at line 170 of file Common.h.

◆ JoystickCallback

typedef 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 at line 180 of file Common.h.

◆ KeyboardCallback

typedef void(* KeyboardCallback) (unsigned long windowID, tKeyboardModifier, char)

a keyboard callback handler is passed the current unit simulation, the key that was hit, and any modifiers that were being held down.

Note that the modifiers can change the character being passed.

Definition at line 198 of file Common.h.

◆ MouseCallback

typedef 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 the click/movement was handled; false if ignored

Definition at line 186 of file Common.h.

◆ MouseCallback2

typedef 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.

The loc is relative to the frame which was clicked

Definition at line 191 of file Common.h.

◆ pRecContext

typedef struct recContext* pRecContext

Definition at line 83 of file Common.h.

◆ recContext

typedef struct recContext recContext

Definition at line 82 of file Common.h.

◆ WindowCallback

typedef void(* WindowCallback) (unsigned long windowID, tWindowEventType)

a window callback handler called when a window is created or destroyed

Definition at line 175 of file Common.h.

Enumeration Type Documentation

◆ tButtonType

Enumerator
kLeftButton 
kRightButton 
kMiddleButton 
kNoButton 

Definition at line 144 of file Common.h.

◆ tKeyboardModifier

Enumerator
kNoModifier 
kAnyModifier 
kShiftDown 
kControlDown 
kAltDown 

Definition at line 136 of file Common.h.

◆ tMouseEventType

enum tMouseEventType : int
Enumerator
kMouseDown 
kMouseUp 
kMouseDrag 
kMouseMove 

Definition at line 151 of file Common.h.

◆ tWindowEventType

Enumerator
kWindowCreated 
kWindowDestroyed 

Definition at line 158 of file Common.h.

◆ viewportType

Enumerator
kScaleToSquare 
kScaleToFill 

Definition at line 51 of file Common.h.

Function Documentation

◆ AddViewport() [1/2]

int AddViewport ( unsigned long  windowID,
const Graphics::rect initial,
const Graphics::rect fin,
viewportType  v 
)

◆ AddViewport() [2/2]

int AddViewport ( unsigned long  windowID,
const Graphics::rect r,
viewportType  v 
)

◆ appendTextToBuffer()

void appendTextToBuffer ( const char *  )

◆ cameraLookAt()

void cameraLookAt ( GLfloat  ,
GLfloat  ,
GLfloat  ,
float  cameraSpeed = 0.1,
int  port = -1 
)

◆ cameraLookingAt()

recVec cameraLookingAt ( int  port = -1)

◆ cameraMoveTo()

void cameraMoveTo ( GLfloat  x,
GLfloat  y,
GLfloat  z,
float  cameraSpeed = 0.1,
int  port = -1 
)

◆ cameraOffset()

void cameraOffset ( GLfloat  x,
GLfloat  y,
GLfloat  z,
float  cameraSpeed = 0.1,
int  port = -1 
)

◆ DoKeyboardCommand()

bool DoKeyboardCommand ( pRecContext  pContextInfo,
unsigned char  keyHit,
bool  shift,
bool  cntrl,
bool  alt 
)

Definition at line 703 of file Common.cpp.

References DoKeyboardCallbacks(), kAltDown, kControlDown, kNoModifier, kShiftDown, and pContextInfo.

Referenced by keyPressed(), and RunHOGGUI().

◆ drawGL()

void drawGL ( pRecContext  pContextInfo,
bool  swap 
)

◆ GetActivePort()

int GetActivePort ( unsigned long  windowID)

Definition at line 929 of file Common.cpp.

References recContext::currPort, GetContext(), and pContextInfo.

Referenced by MyDisplayHandler().

◆ GetContext()

pRecContext GetContext ( unsigned long  windowID)

◆ getCurrentContext()

pRecContext getCurrentContext ( )

◆ GetHeading() [1/2]

recVec GetHeading ( unsigned long  windowID,
int  which 
)

Definition at line 1036 of file Common.cpp.

References GetHeading(), recVec::x, recVec::y, and recVec::z.

Referenced by GetHeading().

◆ GetHeading() [2/2]

void GetHeading ( unsigned long  windowID,
int  which,
GLdouble &  hx,
GLdouble &  hy,
GLdouble &  hz 
)

◆ GetKeyAssignmentDescriptions()

void GetKeyAssignmentDescriptions ( std::vector< std::string > &  keys)

Definition at line 97 of file Common.cpp.

References keyboardCallbacks, and keyboardCallbackData::next.

◆ GetKeyAssignments()

void GetKeyAssignments ( std::vector< char > &  keys)

Definition at line 84 of file Common.cpp.

References keyboardCallbacks, and keyboardCallbackData::next.

◆ GetNumPorts()

int GetNumPorts ( unsigned long  windowID)

Definition at line 923 of file Common.cpp.

References GetContext(), recContext::numPorts, and pContextInfo.

Referenced by MyDisplayHandler(), and MyFrameHandler().

◆ getTextBuffer()

const char* getTextBuffer ( )

◆ getTextBufferVisibility()

bool getTextBufferVisibility ( )

Definition at line 810 of file SFML_HOG.cpp.

References bufferVisibility.

◆ GlobalHOGToViewport() [1/3]

Graphics::rect GlobalHOGToViewport ( const Graphics::rect loc,
int  viewport 
)

◆ GlobalHOGToViewport() [2/3]

Graphics::point GlobalHOGToViewport ( Graphics::point  where,
int  viewport 
)

◆ GlobalHOGToViewport() [3/3]

Graphics::point GlobalHOGToViewport ( pRecContext  pContextInfo,
const viewport v,
Graphics::point  where 
)

◆ GlobalHOGToViewportX()

float GlobalHOGToViewportX ( float  x,
int  v 
)

◆ HandleFrame()

void HandleFrame ( pRecContext  pContextInfo,
int  viewport 
)

◆ HandleJoystickMovement()

void HandleJoystickMovement ( pRecContext  pContextInfo,
double  panX,
double  panY 
)

Definition at line 198 of file Common.cpp.

References joystickCallbacks, pContextInfo, and recContext::windowID.

◆ HandleMouse() [1/2]

bool HandleMouse ( pRecContext  pContextInfo,
int  xWindow,
int  yWindow,
point3d  where,
tButtonType  button,
tMouseEventType  mouse 
)

◆ HandleMouse() [2/2]

bool HandleMouse ( pRecContext  pContextInfo,
point3d  where,
tButtonType  button,
tMouseEventType  mouse 
)

◆ HandleMouseClick() [1/2]

bool HandleMouseClick ( pRecContext  pContextInfo,
int  viewport,
int  x,
int  y,
point3d  where,
tButtonType  ,
tMouseEventType   
)

◆ HandleMouseClick() [2/2]

bool HandleMouseClick ( pRecContext  pContextInfo,
int  x,
int  y,
point3d  where,
tButtonType  ,
tMouseEventType   
)

Definition at line 619 of file Common.cpp.

References mouseCallbacks, pContextInfo, and recContext::windowID.

◆ HandleWindowEvent()

void HandleWindowEvent ( pRecContext  pContextInfo,
tWindowEventType   
)

Definition at line 652 of file Common.cpp.

References pContextInfo, windowCallbacks, and recContext::windowID.

Referenced by RunHOGGUI().

◆ initialConditions()

void initialConditions ( pRecContext  pContextInfo)

◆ InstallCommandLineHandler()

void InstallCommandLineHandler ( CommandLineCallback  ,
const char *  ,
const char *  ,
const char *   
)

Definition at line 207 of file Common.cpp.

References commandLineCallbacks.

Referenced by InstallHandlers().

◆ InstallFrameHandler()

void InstallFrameHandler ( FrameCallback  jC,
unsigned long  windowID,
void *  userdata 
)

Definition at line 143 of file Common.cpp.

References glDrawCallbacks.

Referenced by MyWindowHandler().

◆ InstallJoystickHandler()

void InstallJoystickHandler ( JoystickCallback  jC,
void *  userdata 
)

Definition at line 179 of file Common.cpp.

References joystickCallbacks.

◆ InstallKeyboardHandler()

void InstallKeyboardHandler ( KeyboardCallback  kf,
const char *  title,
const char *  description,
tKeyboardModifier  mod,
unsigned char  firstKey,
unsigned char  lastKey = 0 
)

Definition at line 73 of file Common.cpp.

References keyboardCallbacks.

Referenced by InstallHandlers().

◆ InstallMouseClickHandler() [1/2]

void InstallMouseClickHandler ( MouseCallback  mC,
tMouseEventType  which = static_cast< tMouseEventType >(kMouseDown|kMouseUp|kMouseDrag) 
)

Definition at line 255 of file Common.cpp.

References mouseCallbacks.

Referenced by InstallHandlers().

◆ InstallMouseClickHandler() [2/2]

void InstallMouseClickHandler ( MouseCallback2  mC,
tMouseEventType  which = static_cast< tMouseEventType >(kMouseDown|kMouseUp|kMouseDrag) 
)

Definition at line 260 of file Common.cpp.

References mouseCallbacks2.

◆ InstallWindowHandler()

void InstallWindowHandler ( WindowCallback  wC)

Definition at line 634 of file Common.cpp.

References windowCallbacks.

Referenced by InstallHandlers().

◆ MoveViewport()

void MoveViewport ( unsigned long  windowID,
int  viewport,
const Graphics::rect newLocation 
)

Definition at line 341 of file Common.cpp.

References viewport::finalBound, GetContext(), pContextInfo, and recContext::viewports.

◆ PrintCommandLineArguments()

void PrintCommandLineArguments ( )

Definition at line 213 of file Common.cpp.

References commandLineCallbacks.

Referenced by ProcessCommandLineArgs().

◆ PrintKeyboardAssignments()

void PrintKeyboardAssignments ( )

Definition at line 109 of file Common.cpp.

References getModifierText(), keyboardCallbacks, and keyboardCallbackData::next.

Referenced by DoKeyboardCallbacks().

◆ ProcessCommandLineArgs()

void ProcessCommandLineArgs ( int  argc,
char *  argv[] 
)

Definition at line 222 of file Common.cpp.

References commandLineCallbacks, and PrintCommandLineArguments().

Referenced by RunHOGGUI().

◆ ReinitViewports()

void ReinitViewports ( unsigned long  windowID,
const Graphics::rect r,
viewportType  v 
)

◆ RemoveFrameHandler()

void RemoveFrameHandler ( FrameCallback  jC,
unsigned long  windowID,
void *  userdata 
)

Definition at line 148 of file Common.cpp.

References glDrawCallbacks.

Referenced by MyWindowHandler().

◆ RemoveJoystickHandler()

void RemoveJoystickHandler ( JoystickCallback  jC,
void *  userdata 
)

Definition at line 184 of file Common.cpp.

References joystickCallbacks.

◆ RemoveMouseClickHandler() [1/2]

void RemoveMouseClickHandler ( MouseCallback  mC)

Definition at line 265 of file Common.cpp.

References mouseCallbacks.

◆ RemoveMouseClickHandler() [2/2]

void RemoveMouseClickHandler ( MouseCallback2  mC)

Definition at line 278 of file Common.cpp.

References mouseCallbacks2.

◆ RemoveWindowHandler()

void RemoveWindowHandler ( WindowCallback  wC)

Definition at line 639 of file Common.cpp.

References windowCallbacks.

◆ resetCamera() [1/2]

void resetCamera ( )

◆ resetCamera() [2/2]

void resetCamera ( recCamera pCamera)

◆ RunHOGGUI() [1/2]

void RunHOGGUI ( int  argc,
char *  argv[],
int  windowDimension = 1000 
)

Referenced by main().

◆ RunHOGGUI() [2/2]

void RunHOGGUI ( int  argc,
char *  argv[],
int  xDimension,
int  yDimension 
)

◆ SaveScreenshot()

void SaveScreenshot ( unsigned long  windowID,
const char *  filename 
)

◆ SetActivePort()

void SetActivePort ( unsigned long  windowID,
int  which 
)

Definition at line 935 of file Common.cpp.

References recContext::currPort, GetContext(), and pContextInfo.

Referenced by MyDisplayHandler().

◆ SetNumPorts()

void SetNumPorts ( unsigned long  windowID,
int  count 
)

◆ setPortCamera()

void setPortCamera ( pRecContext  pContextInfo,
int  currPort 
)

◆ setTextBufferVisibility()

void setTextBufferVisibility ( bool  )

◆ setViewport()

void setViewport ( pRecContext  pContextInfo,
int  currPort 
)

◆ SetZoom()

void SetZoom ( int  windowID,
float  amount 
)

◆ submitTextToBuffer()

void submitTextToBuffer ( const char *  val)

◆ updateModelView()

void updateModelView ( pRecContext  pContextInfo,
int  currPort 
)

◆ updateProjection()

void updateProjection ( pRecContext  pContextInfo,
int  viewPort 
)

◆ ViewportToGlobalHOG() [1/3]

Graphics::rect ViewportToGlobalHOG ( const Graphics::rect loc,
int  viewport 
)

◆ ViewportToGlobalHOG() [2/3]

Graphics::point ViewportToGlobalHOG ( Graphics::point  where,
int  viewport 
)

◆ ViewportToGlobalHOG() [3/3]

Graphics::point ViewportToGlobalHOG ( pRecContext  pContextInfo,
const viewport v,
Graphics::point  where 
)

◆ ViewportToGlobalHOGX()

float ViewportToGlobalHOGX ( float  x,
int  v 
)

Variable Documentation

◆ gDefaultMap

char gDefaultMap[1024]

Definition at line 29 of file Common.cpp.

Referenced by CreateSimulation(), MyCLHandler(), and MyFrameHandler().

◆ gTrackBallRotation

GLfloat gTrackBallRotation[4]

Definition at line 33 of file GLUThog.cpp.

Referenced by if(), initialConditions(), mouseMovedButton(), resetCamera(), and updateModelView().

◆ gTrackingContextInfo

pRecContext gTrackingContextInfo

Definition at line 37 of file GLUThog.cpp.

Referenced by if(), mouseMovedNoButton(), resetCamera(), and updateModelView().

◆ kDownArrow

const char kDownArrow = 0x14

Definition at line 134 of file Common.h.

Referenced by RunHOGGUI().

◆ kLeftArrow

const char kLeftArrow = 0x11

Definition at line 131 of file Common.h.

Referenced by RunHOGGUI().

◆ kRightArrow

const char kRightArrow = 0x12

Definition at line 132 of file Common.h.

Referenced by RunHOGGUI().

◆ kUpArrow

const char kUpArrow = 0x13

Definition at line 133 of file Common.h.

Referenced by RunHOGGUI().

◆ MAXPORTS

const int MAXPORTS = 6