Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

GLVU Class Reference

A convenient OpenGL/GLUT based 3D viewer. More...

#include <glvu.hpp>

List of all members.

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]


Detailed Description

A convenient OpenGL/GLUT based 3D viewer.

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.

See also:
QGLVU, Camera


Member Enumeration Documentation

enum GLVU::WorldNavMode
 

The world navigation modes. See SetWorldNavMode().

These are the different modes for manipulating the current camera with mouse input.


Constructor & Destructor Documentation

GLVU::GLVU  
 

The constructor.

Create a new GLVU object with default settings.

Note:
To actually do anything useful with it you will need to call either Init() or InitWin(), and probably SetAllCams() too.
See also:
Init, InitWin

GLVU::~GLVU   [virtual]
 

The destructor.

Virtual since GLVU has virtual methods and allocates some members on the heap.


Member Function Documentation

void GLVU::AllCamsPerspectiveAspectChange float   NewAspect
 

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().

Parameters:
NewAspect   A new aspect ratio (width over height)
See also:
SetAllCams, AllCamsPerspectiveChange, AllCamsResetToOrig, Reshape

void GLVU::AllCamsPerspectiveChange float   Yfov,
float   Aspect,
float   Ndist,
float   Fdist
 

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.

Parameters:
Yfov   vertical field-of-view in degrees.
Aspect   window width/height in pixels.
NDist, FDist   Near and far plane distances.
See also:
SetAllCams, AllCamsPerspectiveAspectChange, AllCamsResetToOrig

void GLVU::AllCamsResetToOrig  
 

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().

Parameters:
NewAspect   A new aspect ratio (width over height)
See also:
SetAllCams, AllCamsPerspectiveChange, AllCamsResetToOrig, Reshape

void GLVU::BeginFrame  
 

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.

See also:
EndFrame, GetModelviewMatrix, GetProjectionMatrix, Display

void GLVU::DefaultDisplayFunc   [static]
 

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.

See also:
Display, DefaultReshapeFunc, DefaultInertiaFunc, DefaultKeyboardFunc, DefaultMouseFunc, DefaultMotionFunc

void GLVU::DefaultInertiaFunc int   x,
int   y
[static]
 

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.

See also:
Inertia, DefaultDisplayFunc, DefaultReshapeFunc, DefaultKeyboardFunc, DefaultMouseFunc, DefaultMotionFunc

void GLVU::DefaultKeyboardFunc unsigned char   Key,
int   x,
int   y
[static]
 

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.

See also:
Keyboard, DefaultDisplayFunc, DefaultInertiaFunc, DefaultReshapeFunc, DefaultMouseFunc, DefaultMotionFunc

void GLVU::DefaultMotionFunc int   x,
int   y
[static]
 

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.

See also:
Motion, DefaultDisplayFunc, DefaultInertiaFunc, DefaultKeyboardFunc, DefaultMouseFunc, DefaultReshapeFunc

void GLVU::DefaultMouseFunc int   button,
int   state,
int   x,
int   y
[static]
 

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.

See also:
Mouse, DefaultDisplayFunc, DefaultInertiaFunc, DefaultKeyboardFunc, DefaultMotionFunc, DefaultReshapeFunc

void GLVU::DefaultReshapeFunc int   WW,
int   WH
[static]
 

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.

See also:
Reshape, DefaultDisplayFunc, DefaultInertiaFunc, DefaultKeyboardFunc, DefaultMouseFunc, DefaultMotionFunc

void GLVU::Display   [virtual]
 

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 glutDisplayFunc callback. Users can override this method, or register their own glut display callback with GLUT directly.

See also:
DefaultDisplayFunc, DefaultReshapeFunc, DefaultInertiaFunc, DefaultKeyboardFunc, DefaultMouseFunc, DefaultMotionFunc

int GLVU::DoInertia   [protected]
 

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.

See also:
SetInertiaOn, Inertia

void GLVU::DrawFPS int   x = 5,
int   y = 5
 

Draw the current frame rate in frames per second at position x, y.

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().

Parameters:
x,y   The position for the lower left corner of the text, relative to the lower left corner of the screen.
See also:
StartFPSClock, StopFPSClock, BeginFrame, UpdateFPS

void GLVU::EndFrame  
 

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.

See also:
BeginFrame, GetModelviewMatrix, GetProjectionMatrix, Display

void GLVU::EndPlayback  
 

Ends camera path playback, and closes the file that was being read from.

See also:
StartPlayback, StartRecording, EndRecording

void GLVU::EndRecording  
 

Stops path recording and closes the file being recorded to.

See also:
StartRecording, StartPlayback, EndPlayback, SelectCam

Camera * GLVU::GetCam int   WhichCam [inline]
 

Return a pointer to the specified camera.

Parameters:
WhichCam   can be one of the CameraID identifiers CAMERA_1, CAMERA_2, CAMERA_3, or CAMERA_4, or just a number between zero and 3.

int GLVU::GetCamDisplayOn int   WhichCam const [inline]
 

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.

See also:
EndFrame

GLVU * GLVU::GetCurrent   [inline, static]
 

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.

See also:
MakeCurrent, GetGLVU(int)

float GLVU::GetFPS   const [inline]
 

Returns the last calculated Frames Per Second measurement.

See also:
StartFPSClock, StopFPSClock, UpdateFPS

GLVU * GLVU::GetGLVU void   [inline, static]
 

Returns the currently active GLVU window.

Deprecated:
This does the same thing as GetCurrent(). You should use that instead.
See also:
MakeCurrent

GLVU * GLVU::GetGLVU int   WindowID [inline, static]
 

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.

See also:
MakeCurrent, GetCurrent, GetWindowID

int GLVU::GetInOutMode   const [inline]
 

Returns a boolean specifying whether the navigation mode is "inside looking out" (true) or "outside looking in" (false, the default).

See also:
SetInOutMode, ToggleInOutMode

int GLVU::GetInertiaDelay   const [inline]
 

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.

See also:
SetInertiaDelay, GetInertiaOn, GetInertiaEnabled

int GLVU::GetInertiaEnabled   const [inline]
 

Return whether inertia is enabled.

Returns TRUE (1) if inertia is enabled, FALSE (0) otherwise.

See also:
SetInertiaEnabled

GLVU::InertiaFunc GLVU::GetInertiaFunc   const [inline]
 

Return the function being uses as the inertia callback.

See also:
SetInertiaFunc

int GLVU::GetInertiaOn   const [inline]
 

Returns true (nonzero) if inertia is currently active. Note that this is different from whether or not it is enabled.

See also:
SetInertiaEnabled

int GLVU::GetLeftButtonDown   const [inline]
 

Returns true (nonzero) if the left button was down last time the Mouse() or Motion() callback got called.

int GLVU::GetMainMenuID   const [inline]
 

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.

See also:
InitMenu

float * GLVU::GetModelviewMatrix float *   M
 

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 glLoadMatrix(). Here is what BeginFrame() does with the matrix stack for example:

    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.

See also:
GetProjectionMatrix, BeginFrame

void GLVU::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.

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.

See also:
Camera::GetPixelRay()

int GLVU::GetPlaybackOn   const [inline]
 

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.

See also:
GetRecordingOn, StartRecording, EndRecording, StartPlayback, EndPlayback, GetModelviewMatrix

float * GLVU::GetProjectionMatrix float *   M
 

Return the OpenGL-style projection matrix from the current camera.

The matrix is an array of 16 floats, suitable for passing to glLoadMatrixf()

See also:
GetModelviewMatrix, BeginFrame

int GLVU::GetRecordingOn   const [inline]
 

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().

See also:
GetPlaybackOn, StartRecording, EndRecording, StartPlayback, EndPlayback, GetModelviewMatrix

const Vec3f & GLVU::GetViewUp   const [inline]
 

Returns the global "up" vector, as set by SetViewUp() or SetAllCams(). This has some effect on the operation of certain mouse navigation modes.

See also:
SetWorldNavMode

int GLVU::GetWindowID   const [inline]
 

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 glutSetWindow() on it) then you can call MakeCurrent() instead.

See also:
MakeCurrent, GetGLVU(int), GetGLVU

const Vec3f & GLVU::GetWorldCenter   const [inline]
 

Returns the global "center" of the world, as set by SetWorldCenter() or (indirectly) by SetAllCams().

int GLVU::GetWorldNavMode   const [inline]
 

Returns the current world navigation mode, (i.e. camera control mode). Return value is one of the WorldNavMode enum constants.

See also:
SetWorldNavMode

float GLVU::GetWorldRadius   const [inline]
 

Returns the global "radius" of the world, as set by SetWorldRadius() or (indirectly) by SetAllCams().

void GLVU::Inertia int   x,
int   y
[virtual]
 

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.

Parameters:
x, y  
See also:
DefaultInertiaFunc, Motion, Mouse, Keyboard, Reshape, Display

int GLVU::Init char *   WindowTitle,
unsigned int   VisualMode,
int   WindowStartX,
int   WindowStartY,
int   WindowWidth,
int   WindowHeight
 

Initialize a viewer.

Create a GLVU window and initialize it, via GLUT calls. This must be done before calling glutMainLoop(). OpenGL calls can be made after this to set state for lights, textures, materials, etc. This version creates its own GLUT window with a call to glutCreateWindow(). If you already have a glut window handy for whatever reason, you can call InitWin() instead, to wrap a GLVU around that window.

Also set up default keyboard, mouse, and reshape callback with GLUT.

Parameters:
WindowTitle   What should appear on the window's title bar (and in the task manager on Windows, or on the icon on an XWindows desktop).
VisualMode   a set of GLUT flags combined with logical or'ing. These are passed to glutIinitDisplayMode before creating the window. Possible values include GLUT_DEPTH, \c, GLUT_DOUBLE, GLUT_ALPHA, GLUT_ACCUM, and on SGIs the all-important GLUT_MULTISAMPLE. See GLUT documentation for more information.
WindowStartX   Desired X position for the window's upper left corner.
WindowStartX   Desired Y position for the window's upper left corner.
WindowWidth   Desired width of window in pixels
WindowHeight   Desired height of window in pixels
Note:
Every GLVU object should have this method called on it (this or InitWin()).
See also:
InitWin

void GLVU::InitMenu   [protected, virtual]
 

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().

int GLVU::InitWin int   wID [virtual]
 

Initialize a viewer with an existing GLUT window.

Set a GLVU window to use the existing GLUT window referred to by wID. This is something you way wish to do if you are integrating with a legacy GLUT application, for instance, or if you need to use some special GLUT functionality to create a window with a particular display mode.

Also set up default keyboard, mouse, and reshape callback with GLUT.

Parameters:
wID   The window identifier obtained from GLUT.
See also:
Init

int GLVU::IsWorldNavMode   const [inline]
 

Returns true (nonzero) if the current world nav mode set is valid false (0) otherwise.

See also:
SetWorldNavMode

void GLVU::Keyboard unsigned char   Key,
int   x,
int   y
[virtual]
 

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 glutSpecialFunc that can be called to set a handler for other key events like the F-keys, or arrow keys. There are also "Up" versions of the key events in GLUT that can be used to detect key release as well as key press.

Users not interested in creating an object-oriented app can simply call GLUT's glutKeyboardFunc to set a callback directly. If you do so, however, you should call GetCurrent()->Keyboard() or GLVU::DefaultKeyboardFunc(), in your handler when you don't use the key.

See also:
DefaultKeyboardFunc, DefaultReshapeFunc, DefaultDisplayFunc, DefaultInertiaFunc, DefaultMouseFunc, DefaultMotionFunc

void GLVU::MakeCurrent   [inline]
 

Make this the currently active GL context.

Equivalent to glutSetWindow(GetWindowID()).

Note:
This bites most people at some point or other in their glutIdleFunc. Many new GLUT users aren't aware that the glutIdleFunc is global -- one per application. All the other GLUT callbacks are per window, but not the idle func. When your idle func gets called there is no guarantee which glut window will be current. If you do a glutPostRedisplay() that redisplay event could be sent to a window other than the one you were intending unless you call MakeCurrent() first.
None of the other GLUT callbacks have this problem. They are all per-window, and GLUT guarantees that that window will be current when your callback is called.

See also:
GetGLVU(void)

void GLVU::Motion int   x,
int   y
[virtual]
 

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 glutMotionFunc to set a callback directly. If you do so you can still call GetCurrent()->Motion() or GLVU::DefaultMotionFunc(), in your handler to get the default behavior back.

This is hooked up to the glutMotionFunc(). GLUT also provides a glutPassiveMotionFunc() which can be used to handle mouse motion when there are no mouse buttons pressed. GLVU does not have a wrapper for that one, however.

Parameters:
x,y   The most recent location of the pointer.
See also:
DefaultMouseFunc, Motion, SetWorldNavMode

void GLVU::Mouse int   button,
int   state,
int   x,
int   y
[virtual]
 

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 glutMouseFunc to set a callback directly. If you do so you can still call GetCurrent()->Mouse() or GLVU::DefaultMouseFunc(), in your handler to get the default behavior back.

Parameters:
button   One of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON
state   One of GLUT_UP or GLUT_DOWN
x,y   The pointer location when the event took place in window coordinates.
See also:
DefaultMouseFunc, Motion, SetWorldNavMode

void GLVU::Reshape int   WW,
int   WH
[virtual]
 

Handler for changed window size.

Typically this method is overridden to handle setting up the perspective matrix and viewport matrix. It corresponds to the \c glutReshapeFunc(), and is indirectly called via that very mechanism.

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().

See also:
DefaultReshapeFunc, DefaultDisplayFunc, DefaultInertiaFunc, DefaultKeyboardFunc, DefaultMouseFunc, DefaultMotionFunc

void GLVU::SelectCam int   WhichCam [inline]
 

Switch to the specified camera.

Changes the camera from which the GLVU renders the scene.

By default this method is bound to the 1,2,3, and 4 keys on the keyboard.

Parameters:
WhichCam   can be one of the CameraID enum values.
See also:
GetModelviewMatrix, BeginFrame, EndFrame

void GLVU::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.

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()

Parameters:
ModelMin, ModelMax   axis-aligned bounding box of the world
Eye   starting location of the camera origin (eye)
LookAtCntr   starting world point to look towards (usually model center)
ViewUp   starting world up vector (usually [0,1,0])
Yfov   vertical field-of-view in degrees.
Aspect   pixel width/height.
Nearfactor, Farfactor   determine the distances to the near and far planes as a factor times the world bounding sphere radius (sphere that surrounds the given (WorldMin,WorldMax).
Note:
Eye cannot equal LookAtCntr!! Earth-shattering Kaboom!!
See also:
AllCamsPerspectiveChange, AllCamsPerspectiveAspectChange, AllCamsResetToOrig

void GLVU::SetCurrentCam Camera *   NewCam [inline]
 

Set the active camera.

Parameters:
NewCam   the new camera to set.
Note:
The new camera will not be owned by GLVU. This sets the current camera temporarily to NewCam.
See also:
SelectCam

void GLVU::SetInOutMode int   Bool [inline]
 

Sets the navigation mode to either "inside looking out" (true) or "outside looking in" (false, the default).

See also:
SetInOutMode, ToggleInOutMode.

void GLVU::SetInertiaDelay int   msec [inline]
 

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 glutTimerFunc().

See also:
GetInertiaDelay, GetInertiaOn, GetInertiaEnabled

void GLVU::SetInertiaEnabled int   Bool [inline]
 

Enable or disable the GLVU's inertia feature.

See also:
GetInertiaEnabled

void GLVU::SetInertiaFunc GLVU::InertiaFunc   f [inline]
 

Set the function to use as an inertia callback.

The default implemntation works fine. There's really no reason to call this.

void GLVU::SetInertiaOn int   onOrOff
 

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.

See also:
Inertia, DoInertia, SetInertiaEnabled

void GLVU::SetMoveSpeed float   speed [inline]
 

Sets the gain factor used in translating mouse motion in pixels into world units.

Bug:
There seems to be no getter for this
See also:
SetWorldNavMode

void GLVU::SetOrigCam Camera *   Cam [inline]
 

Stores a copy of Cam so that Cameras can be reset to its parameters at a later time using AllCamsResetToOrig(). Called from SetAllCams().

See also:
AllCamsResetToOrig, SetAllCams

void GLVU::SetViewUp Vec3f   viewup [inline]
 

Sets the global "up" vector.

See also:
GetViewUp

void GLVU::SetWorldCenter const Vec3f &   center [inline]
 

Sets the global "center" of the world. Also set (indirectly) by SetAllCams().

See also:
GetWorldCenter, SetWorldNavMode

void GLVU::SetWorldNavMode int   mode [inline]
 

Sets the current world navigation mode, (i.e. camera control mode).

Parameters:
mode   One of the WorldNavMode enum constants.

  • NAV_MODE_TRACKBALL: a simple trackball. This is primarily for rotating the model, but by holding down CTRL you can move in and out as well. The rotation generated by the trackball mode depends only upon the relative motion of the mouse, not the absolute location. The drawback is that this mode has no good way to make a model upright. The Hyperball is better for that.
  • NAV_MODE_HYPERBALL: an "SGI-style" trackball. The effect of this trackball is different depending on where on the screen you drag the mouse. On the edge of the screen, rotation happens mostly in the screen plane, but near the middle of the window, rotation happens perpendicular to the screen plane. Hold down CTRL to move in and out.
  • NAV_MODE_DRIVE: Left / Right to steer, Up / Down to move fore and aft.
  • NAV_MODE_TRANSLATE: translate the camera parallel to the view plane.
  • NAV_MODE_LOOK: Rotation about a fixed eye position.
The outside-looking-in rotational modes (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:

  • 'z' : NAV_MODE_TRACKBALL
  • 'x' : NAV_MODE_DRIVE
  • 'c' : NAV_MODE_TRANSLATE
  • 'v' : NAV_MODE_LOOK
  • 'h' : NAV_MODE_TRACKBALL
See also:
GetWorldNavMode

void GLVU::SetWorldRadius float   newRadius [inline]
 

Sets the global "radius" of the world.

See also:
GetWorldRadius

void GLVU::StartFPSClock   [inline]
 

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.

See also:
StopFPSClock, UpdateFPS, BeginFrame

void GLVU::StartPlayback const char *   FileName = "path0.dat"
 

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.

See also:
EndPlayback, StartRecording, EndRecording

void GLVU::StartRecording const char *   FileName = "path0.dat"
 

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.

Parameters:
FileName   The name of the file to open and write to.
See also:
EndRecording, StartPlayback, EndPlayback, SelectCam

void GLVU::StopFPSClock   [inline]
 

Stops the frame rate timer.

See also:
StartFPSClock

void GLVU::StopRecordingPlayback  
 

Stops both camera path recording and playback. Equivalent to calling both EndPlayback() and EndRecording(). Just a convenience method.

See also:
StartPlayback, StartRecording, EndPlayback, EndRecording

void GLVU::ToggleInOutMode   [inline]
 

Toggles the display mode between "inside looking out" and "outside looking in".

See also:
SetInOutMode, GetInOutMode

void GLVU::UpdateFPS  
 

If FPS calculation is enabled (StartFPSClock()), then this function updates the current Frames Per Second calculation. Call only if you are not using the default implementation of BeginFrame(), because it calls this for you.

See also:
StartFPSClock, StopFPSClock, BeginFrame, DrawFPS


The documentation for this class was generated from the following files:
Generated at Fri Oct 12 15:12:22 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001