#include <glvu.hpp>
Public Types | |
| typedef void(* | InertiaFunc )(int x, int y) |
| A function type used by the 'inertia' handling system. | |
| enum | WorldNavMode { NAV_MODE_TRACKBALL, NAV_MODE_HYPERBALL, NAV_MODE_DRIVE, NAV_MODE_TRANSLATE, NAV_MODE_LOOK } |
| The world navigation modes. See SetWorldNavMode(). More... | |
| enum | CameraID { CAMERA_1, CAMERA_2, CAMERA_3, CAMERA_4, CAMERA_NUM_CAMS } |
| Camera IDs. There are 4 predefined cameras in a GLVU that can be switched between. | |
Public Methods | |
| GLVU () | |
| The constructor. More... | |
| virtual | ~GLVU () |
| The destructor. More... | |
| int | Init (char *WindowTitle, unsigned int VisualMode, int WindowStartX, int WindowStartY, int WindowWidth, int WindowHeight) |
| Initialize a viewer. More... | |
| virtual int | InitWin (int aPreviouslyCreatedGlutWindow) |
| Initialize a viewer with an existing GLUT window. More... | |
| void | BeginFrame () |
| Prepare the current frame for drawing in display routine. More... | |
| void | EndFrame () |
| Finish up the current OpenGL display frame. More... | |
| int | GetPlaybackOn () const |
| Return whether or not playback mode is currently active. More... | |
| int | GetRecordingOn () const |
| Return whether or not playback mode is currently active. More... | |
| void | SetAllCams (const Vec3f &WorldMin, const Vec3f &WorldMax, const Vec3f &Eye, const Vec3f &LookAtCntr, const Vec3f &viewup, float Yfov, float Aspect, float NearFactor, float FarFactor) |
| Set all cameras to the same viewing parameters. More... | |
| void | AllCamsPerspectiveChange (float Yfov, float Aspect, float Ndist, float Fdist) |
| Change some parameters of all camearas. More... | |
| void | AllCamsPerspectiveAspectChange (float Aspect) |
| Change the aspect ratio of all cameras. More... | |
| void | AllCamsResetToOrig () |
| Change the aspect ratio of all cameras. More... | |
| float * | GetModelviewMatrix (float *M) |
| Return the next modelview matrix. More... | |
| float * | GetProjectionMatrix (float *M) |
| Return the OpenGL-style projection matrix from the current camera. More... | |
| void | GetPixelRay (int sx, int sy, int ww, int wh, Vec3f *Start, Vec3f *Dir) const |
| Return the world space ray corresponding to a particular screen pixel. More... | |
| void | SelectCam (int WhichCam) |
| Switch to the specified camera. More... | |
| Camera * | GetCurrentCam () |
| Return a pointer to the active camera. | |
| void | SetCurrentCam (Camera *NewCam) |
| Set the active camera. More... | |
| Camera * | GetCam (int WhichCam) |
| Return a pointer to the specified camera. More... | |
| int | GetInOutMode () const |
| void | SetInOutMode (int Bool) |
| void | ToggleInOutMode () |
| void | SetOrigCam (Camera *Cam) |
| const Vec3f & | GetViewUp () const |
| const Vec3f & | GetWorldCenter () const |
| void | SetWorldCenter (const Vec3f &newCenter) |
| float | GetWorldRadius () const |
| void | SetWorldRadius (float newRadius) |
| void | SetViewUp (Vec3f viewup) |
| void | SetMoveSpeed (float speed) |
| void | TranslateX (int OldX, int NewX, int WW) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | TranslateY (int OldY, int NewY, int WH) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | DriveY (int OldY, int NewY, int WH) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | LookX (int OldX, int NewX, int WW) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | LookY (int OldY, int NewY, int WH) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | TrackBallX (int OldX, int NewX, int WW) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | TrackBallY (int OldY, int NewY, int WH) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | HyperBall (int OldX, int OldY, int NewX, int NewY, int WW, int WH) |
| One of the core routines used to translate mouse motion into camera motion. | |
| void | StartRecording (const char *FileName="path0.dat") |
| void | EndRecording () |
| void | StartPlayback (const char *FileName="path0.dat") |
| void | EndPlayback () |
| void | StopRecordingPlayback () |
| void | StartFPSClock () |
| void | StopFPSClock () |
| void | DrawFPS (int xpos=5, int ypos=5) |
| float | GetFPS () const |
| void | UpdateFPS () |
| int | GetMainMenuID () const |
| int | GetWorldNavMode () const |
| void | SetWorldNavMode (int mode) |
| int | GetCamDisplayOn (int WhichCam) const |
| int | IsWorldNavMode () const |
| int | GetLeftButtonDown () const |
| int | GetInertiaOn () const |
| int | GetInertiaEnabled () const |
| Return whether inertia is enabled. More... | |
| void | SetInertiaOn (int Bool) |
| Turn inertia on or off. More... | |
| void | SetInertiaEnabled (int Bool) |
| Enable or disable the GLVU's inertia feature. More... | |
| int | GetInertiaDelay () const |
| Return the number of milliseconds between inertia callbacks. More... | |
| void | SetInertiaDelay (int msec) |
| Set the number of milliseconds to wait between inertia callbacks. More... | |
| void | SetInertiaFunc (InertiaFunc f) |
| Set the function to use as an inertia callback. More... | |
| InertiaFunc | GetInertiaFunc () const |
| Return the function being uses as the inertia callback. More... | |
| virtual void | Mouse (int button, int state, int x, int y) |
| Handler for mouse clicks (called when a button is pressed or released). More... | |
| virtual void | Motion (int x, int y) |
| Handler for 'active' mouse drag events, i.e. dragging with a button pressed. More... | |
| virtual void | Reshape (int WW, int WH) |
| Handler for changed window size. More... | |
| virtual void | Display () |
| Handler for redrawing application OpenGL content. More... | |
| virtual void | Keyboard (unsigned char Key, int x, int y) |
| Handler for keyboard events. More... | |
| virtual void | Inertia (int x, int y) |
| Handler for inertia events. More... | |
| int | GetWindowID () const |
| Return the GLUT window ID associated with this GLVU. More... | |
| void | MakeCurrent () |
Make this the currently active GL context. More... | |
Static Public Methods | |
| void | DefaultMouseFunc (int button, int state, int x, int y) |
| The default GLUT mouse button callback implementation. More... | |
| void | DefaultMotionFunc (int x, int y) |
| The default GLUT motion function implementation. More... | |
| void | DefaultReshapeFunc (int WW, int WH) |
| The default GLUT display function implementation. More... | |
| void | DefaultDisplayFunc () |
| The default GLUT display function implementation. More... | |
| void | DefaultKeyboardFunc (unsigned char Key, int x, int y) |
| The default GLUT keyboard function implementation. More... | |
| void | DefaultInertiaFunc (int x, int y) |
| The default intertia function implementation. More... | |
| GLVU * | GetCurrent () |
| Returns the currently active GLVU window. More... | |
| GLVU * | GetGLVU (int WindowID) |
| Returns a pointer to the GLVU that corresponds to the specified GLUT window ID. More... | |
| GLVU * | GetGLVU () |
| Returns the currently active GLVU window. More... | |
| void | PrintVisualInfo () |
| Dump info about the selected visuals to standard out. | |
Protected Methods | |
| int | DoInertia () |
| Call the inertia handler after some setup. More... | |
| virtual void | InitMenu () |
Static Protected Methods | |
| void | MainMenuHandler (int value) |
| void | vuOptionsMenuHandler (int value) |
| void | glOptionsMenuHandler (int value) |
| void | PathPlaybackMenuHandler (int value) |
| void | CamViewMenuHandler (int value) |
| void | CamViewDisplayMenuHandler (int value) |
| void | EscapeHandler (int value) |
| void | InertialTimerFunc (int value) |
| void | PathPlaybackTimerFunc (int value) |
Protected Attributes | |
| Camera * | Cams |
| Camera * | Cam |
| Camera | OrigCam |
| int | RecordingOn |
| int | PlaybackOn |
| FILE * | RecordPlaybackFP |
| Vec3f | WorldCenter |
| float | WorldRadius |
| Vec3f | ViewUp |
| int | InsideLookingOutMode |
| clock_t | PlaybackTime |
| int | NumCams |
| timeb | lastFPSClock |
| int | calcFPS |
| float | lastFPS |
| int | lastFPSCount |
| int | LeftButtonDown |
| int | OldX |
| int | OldY |
| int | NewX |
| int | NewY |
| float | moveSpeed |
| int | CtrlPressed |
| int | InertiaOn |
| int | InertiaEnabled |
| int | InertiaDelay |
| int | MainMenuID |
| int | WorldNavMode |
| int * | CamDisplayOn |
| InertiaFunc | UserInertiaFunc |
| int | WindowID |
Static Protected Attributes | |
| GLVU * | GLVUs [MAX_GLVUS] |
GLVU is part of a collection of C++ libraries for creating OpenGL applications based on the cross-platform GLUT library. There are many sub-libraries that comprise GLVU, but the actual GLVU class is the one that encapsulates all of the GLUT user interface functionality. Most of the other libraries do not depend on GLUT, or depend on it in trivial ways. Another class that is based on the Qt toolkit, QGLVU, can also be used for more advanced user interface capabilities. Note however that Qt comes with some significant licensing restrictions, whereas GLUT does not.
The viewer library was developed mainly for creating small research applications, and as such implements much of the functionality necessary in a small viewer for prototyping rendering algorithms. Among these features are a flexible camera class [Camera], several camera manipulation, or navigation, modes, frame rate calculation, and the ability to record and play back camera paths. All of these are features likely to be needed at one time or another by most anyone that wants to look at 3D geometric scene data with OpenGL, and each requires some effor to implement. In particular, developing the mouse-based camera manipulation routines can be quite time consuming, as how to construct a mapping from 2D to 3D (6D, really) that is intuitive for the user is far from obvious.
Another nice feature supported by GLVU is "inertia", or the ability to start a model spinning and have it keep spinning even after the user releases the mouse. GLVU can also support multiple windows easily, and the inertia works independently in each via GLUT timers. GLVU does not use the one global GLUT idle callback at all, leaving that instead for the user to do with as desired.
Since GLUT is really more of a windowing toolkit than a user interface toolkit, users of the GLVUT-based version of GLVU may find an external GLUT-based UI toolkit to be useful. For quick prototyping, GLUI is recommended (http://www.cs.unc.edu/~rademach/glui). For more sophisticated interfaces, use Qt and QGLVU rather than this class.
Part of the philosophy in the design of GLVU was to make it as easy as possible for current GLUT users to start using it right away. For this reason all of the GLUT callbacks are still accessible to the GLVU programmer. GLVU also supports a more object-oriented approach as well, by allowing you to subclass GLVU and override handler methods.
|
|
The world navigation modes. See SetWorldNavMode(). These are the different modes for manipulating the current camera with mouse input. |
|
|
The constructor. Create a new GLVU object with default settings.
|
|
|
The destructor. Virtual since GLVU has virtual methods and allocates some members on the heap. |
|
|
Change the aspect ratio of all cameras. Change the aspect ratio of the perspective transformation for every camera without changing any of the other parameters of the perspective matrix. This is called by the default implementation of Reshape().
|
|
||||||||||||||||||||
|
Change some parameters of all camearas. This is an easy way to change some key parameters that define the perspective transformation being used by every camera, without changing the location or orientation of the cameras.
|
|
|
Change the aspect ratio of all cameras. Change the aspect ratio of the perspective transformation for every camera without changing any of the other parameters of the perspective matrix. This is called by the default implementation of Reshape().
|
|
|
Prepare the current frame for drawing in display routine. Sets up the modelview and projection matrices based on the current camera, and updates the frame rate timer. Unless you need to do some fancy customized manipulation of the OpenGL matrix stack, just calling BeginFrame() is a convenient and effective way to set things up so you can just do your application-specific OpenGL drawing.
|
|
|
The default GLUT display function implementation. This just calls GetGLVU()->Display(), thus allowing Object-Oriented people to customize GLVU's behavior by overriding the Display() method instead of by dealing directly with GLUTs callbacks.
|
|
||||||||||||
|
The default intertia function implementation. This just calls GetGLVU()->Inertia(), thus allowing Object-Oriented people to customize GLVU's behavior by overriding the Inertia() method instead of by dealing with callbacks. Unlike the other methods of its ilk, this does not correspond to any GLUT callback, it is purely a GLVU invention.
|
|
||||||||||||||||
|
The default GLUT keyboard function implementation. This just calls GetGLVU()->Keyboard(), thus allowing Object-Oriented people to customize GLVU's behavior by overriding the Keyboard() method instead of by dealing directly with GLUT's callbacks.
|
|
||||||||||||
|
The default GLUT motion function implementation. This just calls GetGLVU()->Motion(), thus allowing Object-Oriented people to customize GLVU's behavior by overriding the Motion() method instead of by dealing directly with GLUTs callbacks.
|
|
||||||||||||||||||||
|
The default GLUT mouse button callback implementation. This just calls GetGLVU()->Mouse(), thus allowing Object-Oriented people to customize GLVU's behavior by overriding the Mouse() method instead of by dealing directly with GLUTs callbacks.
|
|
||||||||||||
|
The default GLUT display function implementation. This just calls GetGLVU()->Reshape(), thus allowing Object-Oriented people to customize GLVU's behavior by overriding the Reshape() method instead of by dealing directly with GLUTs callbacks.
|
|
|
Handler for redrawing application OpenGL content. This method can be overridden to perform the application's actual OpenGL drawing. Typically one begins by calling BeginFrame() as the first call, and ends with EndFrame() as the last call. Those two methods handle camera setup (path playback and recording), buffer swapping for double buffered windows, and frame rate timing calculations. The default implementation does nothing.
In the default configuration, this method is called indirectly via GLUTs
|
|
|
Call the inertia handler after some setup. The way inertia is handled is to trick GLVU into thinking it is getting the exact same mouse motion again and again, i.e, that the mouse was dragged from x1,y1 to x2,y2 repeatedly. This method munges the various internal data members as necessary to pull this trick off, then calls the inertia callback. Returns TRUE (1) if inertia is enabled, FALSE (0) otherwise.
|
|
||||||||||||
|
Draw the current frame rate in frames per second at position This uses the current OpenGL drawing color, whatever that is. Probably best to set it explicitly yourself before calling this method. Frame rate calculation requires calling StartFPSClock() once, and either BeginFrame()/EndFrame() ever frame or manual calls to UpdateFPS().
|
|
|
Finish up the current OpenGL display frame. This should be, or at least can be, called at the end of your Display() method. Unless you need to swap buffers in the middle of a frame for some reason, this is usually sufficient. This method is also responsible for drawing the lines in space to represent other cameras, so that you can see from one camera where the others are located in space. The default keys for switching cameras are 1, 2, 3, and 4. The default keys for toggling display of camera frusta are Shift-1, Shift-2, Shift-3, and Shift-4.
|
|
|
Ends camera path playback, and closes the file that was being read from.
|
|
|
Stops path recording and closes the file being recorded to.
|
|
|
Return a pointer to the specified camera.
|
|
|
Returns the display status of the specified Camera. Camera display refers to rendering of some lines that show the extents of a camera's frustum. GLVU has some functionality to do this automically.
|
|
|
Returns the currently active GLVU window. See MakeCurrent() for a discussion of what it means to be the active window, and why you should care.
|
|
|
Returns the last calculated Frames Per Second measurement.
|
|
|
Returns the currently active GLVU window.
|
|
|
Returns a pointer to the GLVU that corresponds to the specified GLUT window ID. There's a one-to-one mapping between GLVUs and GLUT windows. This does the reverse lookup to find the GLVU for a given GLUT window ID. GetWindowID() does the forward lookup.
|
|
|
Returns a boolean specifying whether the navigation mode is "inside looking out" (true) or "outside looking in" (false, the default).
|
|
|
Return the number of milliseconds between inertia callbacks. Inertia callbacks are only made by GLVU when inertia is active and enabled. But when triggered, inertia callbacks are made repeatedly at regular intervals to animate the camera.
|
|
|
Return whether inertia is enabled. Returns TRUE (1) if inertia is enabled, FALSE (0) otherwise.
|
|
|
Return the function being uses as the inertia callback.
|
|
|
Returns true (nonzero) if inertia is currently active. Note that this is different from whether or not it is enabled.
|
|
|
Returns true (nonzero) if the left button was down last time the Mouse() or Motion() callback got called. |
|
|
Returns the GLUT ID for the right-click menu automatically installed by GLVU. This can be used with GLUT calls to modify the contents of the menu.
|
|
|
Return the next modelview matrix.
This gets the next modelview matrix that should be used for displaying. BeginFrame() calls this automatically, but if you aren't calling BeginFrame() from your Display() method, then you can call this directly to get the next modelview matrix to pass to OpenGL. The matrix is in OpenGL format, so you can pass it right to
GLfloat M[16];
glMatrixMode(GL_PROJECTION);
glLoadMatrixf( GetProjectionMatrix(M) );
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf( GetModelviewMatrix(M) );This innocuous-sounding getter function also plays a role in camera path playback. If playback mode is engaged, then the matrix returned to you will not be based on the user's mouse wigglings, but on recorded camera data loaded in from a file on demand. So this isn't your typical do-nothing getter function, it actually does some work to figure out what matrix to give you.
|
|
||||||||||||||||||||||||||||
|
Return the world space ray corresponding to a particular screen pixel. Given a screen pixel location (sx,sy) w/ (0,0) at the lower-left, and the screen dimensions, return the ray (start,dir) of the ray in world coords. A very handy routine for implementing ray-tracers.
|
|
|
Return whether or not playback mode is currently active. When playback mode is active, the modelview matrices for viewing are read from a previously recorded file instead of coming from the user's mousing.
|
|
|
Return the OpenGL-style projection matrix from the current camera.
The matrix is an array of 16 floats, suitable for passing to
|
|
|
Return whether or not playback mode is currently active. When record mode is active, every camera view change made by the user (through mouse manipulation) is written to a file. The resulting path can be played back later using StartPlayback().
|
|
|
Returns the global "up" vector, as set by SetViewUp() or SetAllCams(). This has some effect on the operation of certain mouse navigation modes.
|
|
|
Return the GLUT window ID associated with this GLVU.
Sometimes it is necessary to get the GLUT window ID for a GLVU window, and when you do, you can call this method. If all you want to do is make this the active GLUT window (i.e. call
|
|
|
Returns the global "center" of the world, as set by SetWorldCenter() or (indirectly) by SetAllCams(). |
|
|
Returns the current world navigation mode, (i.e. camera control mode). Return value is one of the WorldNavMode enum constants.
|
|
|
Returns the global "radius" of the world, as set by SetWorldRadius() or (indirectly) by SetAllCams(). |
|
||||||||||||
|
Handler for inertia events. The default implementation calls the Motion() method, causing the camera to move a little more in the direction it was moving when inertia kicked in. This method only gets called when inertia has been triggered by an appropriate mouse drag and release action.
|
|
||||||||||||||||||||||||||||
|
Initialize a viewer.
Create a GLVU window and initialize it, via GLUT calls. This must be done before calling Also set up default keyboard, mouse, and reshape callback with GLUT.
|
|
|
Sets up all of the default GLVU menu choices. These are bound to the GLUT right-click menu. You can subclass GLVU to override this method if you need to implement a custom menu. You can also get the GLUT ID for the menu by calling GetMainMenuID(). This method is called automatically from Init() and InitWin(). |
|
|
Initialize a viewer with an existing GLUT window.
Set a GLVU window to use the existing GLUT window referred to by Also set up default keyboard, mouse, and reshape callback with GLUT.
|
|
|
Returns true (nonzero) if the current world nav mode set is valid false (0) otherwise.
|
|
||||||||||||||||
|
Handler for keyboard events. The default implementation handles all the GLVU default key bindings. Override this method to add your own key bindings, but if you don't handle the key, be sure to call the superclass (i.e. call GLVU::Keyboard())
This only handles "normal" key events, i.e. those that correspond to a key with an ascii character. GLUT also has
Users not interested in creating an object-oriented app can simply call GLUT's
|
|
|
Make
Equivalent to
|
|
||||||||||||
|
Handler for 'active' mouse drag events, i.e. dragging with a button pressed. This method can be overridden to perform application specific funcionality (e.g. direct manipulation of scene objects). The default implementation does some important work for handling camera manipulation (world navigation), so if you override this method you should always call GLVU::Mouse() from your override if you wish to preserve the built-in navigation capabilities. The exact effect the default implementation has on the current camera depends upon the current world navigation mode. See SetWorldNavMode().
Users not interested in creating an object-oriented app can simply call GLUT's
This is hooked up to the
|
|
||||||||||||||||||||
|
Handler for mouse clicks (called when a button is pressed or released). This method can be overridden to perform application specific funcionality (e.g. picking). The default implementation does some important work for handling camera manipulation (world navigation), so if you override this method you should always call GLVU::Mouse() from your override.
Users not interested in creating an object-oriented app can simply call GLUT's
|
|
||||||||||||
|
Handler for changed window size.
Typically this method is overridden to handle setting up the perspective matrix and viewport matrix. It corresponds to the The default implementation is quite serviceable. It sets the viewport to be the whole visible window area, and adjusts all the Cameras so that the aspect ratio of the perspective transformation is not all whacked out. One reason you might have to override this is if you are implementing stereo using multiple viewports, or if you are using multiple viewports for any other reason. Rather than overriding this method, you could also call glutReshapeFunc directly, to register your function with GLUT. If you do so then this method will no longer get called. To invoke the default functionality from your callback you can call GetCurrent()->Reshape() or GLVU::DefaultReshapeFunc().
|
|
|
Switch to the specified camera.
Changes the camera from which the By default this method is bound to the 1,2,3, and 4 keys on the keyboard.
|
|
||||||||||||||||||||||||||||||||||||||||
|
Set all cameras to the same viewing parameters. Most every GLVU app will call this routine soon after Init(). It's the best way to get the camera perspecitve matrix parameters all set up. This method also saves these camera parameters into a separate member, so that these camera settings can be restored with a call to AllCamsResetToOrig()
|
|
|
Set the active camera.
|
|
|
Sets the navigation mode to either "inside looking out" (true) or "outside looking in" (false, the default).
|
|
|
Set the number of milliseconds to wait between inertia callbacks. Inertia callbacks are only made by GLVU when inertia is active and enabled. But when triggered, inertia callbacks are made repeatedly at regular intervals to animate the camera.
The implementation relies on
|
|
|
Enable or disable the GLVU's inertia feature.
|
|
|
Set the function to use as an inertia callback. The default implemntation works fine. There's really no reason to call this. |
|
|
Turn inertia on or off. This is not about whether inertia is enabled or not, but whether it is currently active. Usually called internally only.
|
|
|
Sets the gain factor used in translating mouse motion in pixels into world units.
|
|
|
Stores a copy of
|
|
|
Sets the global "up" vector.
|
|
|
Sets the global "center" of the world. Also set (indirectly) by SetAllCams().
|
|
|
Sets the current world navigation mode, (i.e. camera control mode).
NAV_MODE_TRACKBALL, NAV_MODE_HYPERBALL) use the "world center" as the center of rotation. See SetWorldCenter() and SetAllCams() for more information about the world center and camera settings.
GLVU uses the following default keyboard accelerators to switch between modes:
|
|
|
Sets the global "radius" of the world.
|
|
|
Starts the frame timer and resets the frame counter. You must call this once after creating the GLVU if you would like to take advantage of the built-in frame timing capabilities.
|
|
|
Begins path playback from the path file specified, or from "path0.dat" if none is specified. Updates the positions and orientations of all four Cameras. This relies on the use of GetModelviewMatrix() in the display routine.
|
|
|
Begins path recording. Records the position and orientation of all four Cameras to the file specified with SetPathFilename(), or to "path0.dat" if none is specified.
|
|
|
Stops the frame rate timer.
|
|