Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

GLWorldViewer Class Reference

Inherits QGLViewer to provide an extended viewer that is more suited to simply displaying the contents of a world scene. More...

#include <glworldviewer.h>

Inheritance diagram for GLWorldViewer:

QGLViewer List of all members.

Public Member Functions

 GLWorldViewer (const GLScene *s, GLScreenViewer *screenViewer, QWidget *parent)
 GLWorldViewer (const GLScene *s, GLScreenViewer *screenViewer, const QGLFormat &format, QWidget *parent)
void resetCamera ()
bool autoGLClearEnabled () const
bool autoGLFlushEnabled () const
bool frustumIsDrawn () const
void setDrawFrustum (bool enable)
void setAutoGLClearEnabled (bool enable)
void setAutoGLFlushEnabled (bool enable)
qglviewer::Vec backgroundColor () const
void getBackgroundColor (float &r, float &g, float &b) const
void getBackgroundColor (QColor &c) const
void setBackgroundColor (const qglviewer::Vec &color)
void setBackgroundColor (float r, float g, float b)
void setBackgroundColor (const QColor &c)

Protected Member Functions

void sharedInit ()
void drawFrustum (GLdouble *inverseProjectionMatrix)
virtual void init ()
virtual void draw ()
virtual void preDraw ()
virtual void postDraw ()
virtual void keyPressEvent (QKeyEvent *e)
virtual void keyReleaseEvent (QKeyEvent *e)
virtual void mousePressEvent (QMouseEvent *e)
virtual void mouseReleaseEvent (QMouseEvent *e)
virtual void mouseDoubleClickEvent (QMouseEvent *e)
virtual void mouseMoveEvent (QMouseEvent *e)
void mouseEventTranslator (QMouseEvent *e, QEvent::Type mouseEventType)
GLboolean invert (const GLdouble src[16], GLdouble inverse[16])

Protected Attributes

const GLScenemyScene
GLScreenViewermyScreenViewer
const GLdouble * myScreenViewersProjection
bool reinitRequired
qglviewer::Vec myBackgroundColour
bool autoGLClear
bool autoGLFlush
bool frustumEnabled
int extModifierKey

Detailed Description

Inherits QGLViewer to provide an extended viewer that is more suited to simply displaying the contents of a world scene.

Note: This viewer relies upon / requires a pointer to a valid GLScreenViewer instance. This is because it requires its post-draw projection matrix values, so that it can draw the projection frustum. The reason that we don't know these values is because we deliberately prevent modifications to be made to the projection when we draw the scene, as we want to DRAW the projection (as the frustum), not EXECUTE it.

Note: The scene is reinitialized EVERY time GLWorldViewer::draw() is called, as the camera has an effect on the initizliation commands and the most common reason that GLWorldViewer::draw() will be called is because the camera has been repositioned / rotated, etc. This behavior is unlike GLScreenViewer::draw()'s.

Note: OpenGL viewports are NOT supported by this viewer, as they would not make sense in this context. Hence glViewport commands will be ignored when the scene is executed/drawn.

Note: Display lists are NOT used to cache the initialization and display commands, as they would enfore too many limitations. For example, many OpenGL commands cannot be placed in display lists, such as those that pass parameters by reference (as they may be out of scope). It would also prevent the user from working with display lists themselves.

Note: The GLWorldViewer::invert() method, used to get the inverse of a 4x4 matrix actually came from Nate Robins' OpenGL Tutors.
I contacted him via email (nate@pobox.com) on Sunday 25, January 2004 and got the OK from him to use it before I went ahead and used it.
Beginning of the source code file projection.c:

     projection.c
     Nate Robins, 1997

     Tool for teaching about OpenGL projections.


Constructor & Destructor Documentation

GLWorldViewer::GLWorldViewer const GLScene s,
GLScreenViewer screenViewer,
QWidget *  parent
 

Constructor.

See the class's detailed description for why we need a pointer to an instance of GLScreenViewer.

GLWorldViewer::GLWorldViewer const GLScene s,
GLScreenViewer screenViewer,
const QGLFormat &  format,
QWidget *  parent
 

Constructor.

This constructor takes a QGLFormat parameter, so that special format options such as double buffering can be enabled and disabled.

See the class's detailed description for why we need a pointer to an instance of GLScreenViewer.


Member Function Documentation

bool GLWorldViewer::autoGLClearEnabled  )  const [inline]
 

bool GLWorldViewer::autoGLFlushEnabled  )  const [inline]
 

qglviewer::Vec GLWorldViewer::backgroundColor  )  const [inline]
 

Reimplemented, due to GLWorldViewer::setBackgroundColor() having to be reimplemented.

Reimplemented from QGLViewer.

void GLWorldViewer::draw  )  [protected, virtual]
 

Execute the OpenGL scene, though with some possible modifications, see below.

Note: The scene is reinitialized EVERY time this is called, as the camera has an effect on the initizliation commands and the most common reason that this will be called is because the camera has been repositioned / rotated, etc. This behaviour is unlike GLScreenViewer::draw()'s.

Note: We prevent modifications to projection from being executed by the scene, as we will be DRAWING the projection in the form of its frustum instead in GLWorldViewer::postDraw().

Note: OpenGL viewports are NOTE supported by this viewer, as they would not make sense in this context. Hence glViewport commands will be ignored.

Note: This method will perfrom:

 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) 
if and only if autoGLClear == true.

Reimplemented from QGLViewer.

void GLWorldViewer::drawFrustum GLdouble *  inverseProjectionMatrix  )  [protected]
 

Draw the viewing frustum for a given projection matrix.

Note: This method takes the INVERSE of the projection matrix as its parameter.

bool GLWorldViewer::frustumIsDrawn  )  const [inline]
 

void GLWorldViewer::getBackgroundColor QColor &  c  )  const [inline]
 

Same as backgroundColor(), but result is returned as a QColor attribute.

void GLWorldViewer::getBackgroundColor float &  r,
float &  g,
float &  b
const [inline]
 

Same as backgroundColor(), but result is returned as three floats.

Reimplemented from QGLViewer.

void GLWorldViewer::init  )  [protected, virtual]
 

Initialize OpenGL for the context.

This method is called by QGLViewer::initializeGL().

The main reason that this has been implemented, is to undo the non-standard modifications that QGLViewer::initializeGL() makes to the OpenGL initial state.

Reimplemented from QGLViewer.

GLboolean GLWorldViewer::invert const GLdouble  src[16],
GLdouble  inverse[16]
[protected]
 

This method is used to get the inverse of a 4x4 matrix.

It actually came from from Nate Robins' OpenGL Tutors.
I contacted him via email (nate@pobox.com) on Sunday 25, January 2004 and got the OK from him to use it before I went ahead and used it.

Beginning of the source code file projection.c:

     projection.c
     Nate Robins, 1997

     Tool for teaching about OpenGL projections.

void GLWorldViewer::keyPressEvent QKeyEvent *  e  )  [protected, virtual]
 

Used to extend Qt's mouse button modifier keys to include the "1", "2" and "3" number keys. This method will handle a key press event and filter it to check if one of these extended modifier keys has been pressed. If one has been, then the current extended modifier key variable will be set to the Qt key code.

This reimplementation also disables QGLViewer's key bindings.

Reimplemented from QGLViewer.

void GLWorldViewer::keyReleaseEvent QKeyEvent *  e  )  [protected, virtual]
 

Used to extend Qt's mouse button modifier keys to include "1", "2" and "3" number keys. This method will handle a key release event and filter it to check if one of these extended modifier keys has been released. If one has been, then the current extended modifier key variable will be set to = 0 (no key).

This reimplementation also disables QGLViewer's key bindings.

void GLWorldViewer::mouseDoubleClickEvent QMouseEvent *  e  )  [protected, virtual]
 

Re-implemented, as to use the mouse event translator. See GLWorldViewer::mouseEventTranslator() for details.

Reimplemented from QGLViewer.

void GLWorldViewer::mouseEventTranslator QMouseEvent *  e,
QEvent::Type  mouseEventType
[protected]
 

This is used to translate mouse events, as to support all of the control features of a 3-button mouse by adding the "1", "2" and "3" number keys as modifiers to the left mouse button.

Translated events:

  • Key 1 + Left Mouse Button => Middle Mouse Button (reposition camera's z position)
  • Key 2 + Left Mouse Button => Right Mouse Button (reposition camera's x & y position)
  • Key 3 + Left Mouse Button => Left + Middle Mouse Button (rotate camera on z-axis)

Note: The ordering of the modifiers, where key 1 was chosen for the middle button, followed by key 2 for the right mouse button, was implemented, as that is the same ordering of the buttons on a mouse (right-hand setup).

void GLWorldViewer::mouseMoveEvent QMouseEvent *  e  )  [protected, virtual]
 

Re-implemented, as to use the mouse event translator. See GLWorldViewer::mouseEventTranslator() for details.

Reimplemented from QGLViewer.

void GLWorldViewer::mousePressEvent QMouseEvent *  e  )  [protected, virtual]
 

Re-implemented, as to use the mouse event translator. See GLWorldViewer::mouseEventTranslator() for details.

Reimplemented from QGLViewer.

void GLWorldViewer::mouseReleaseEvent QMouseEvent *  e  )  [protected, virtual]
 

Re-implemented, as to use the mouse event translator. See GLWorldViewer::mouseEventTranslator() for details.

Reimplemented from QGLViewer.

void GLWorldViewer::postDraw  )  [protected, virtual]
 

Draw post-scene objects and visual hints, such as the axis, Z=0 grid, projection frustum and possibly the contents of the Z-buffer.

Reimplemented from QGLViewer.

void GLWorldViewer::preDraw  )  [protected, virtual]
 

Prep the OpenGL context for drawing to.

This method will make a call for its GLScreenViewer instance counterpart to update itself (via an GLScreenViewer::updateGL() call).
Hence if you want both this viewer and the screen space viewer to be updated, you need ONLY call updateGL() on THIS viewer.
(The updateGL() call on the screen view is needed to keep matrix synchronization)
Getting the matrix values like this seems to be the most efficient, as the scene's OpenGL commands need to be executed as to get them, so we get them from the screen viewer, which we can rely on being a direct / pure representation of the scene.

Note: This will delete any existing display lists.

Reimplemented from QGLViewer.

void GLWorldViewer::resetCamera  ) 
 

Stop the camera from spinning (if it is) and reposition it so that it is located at (0.0, 0.0, 4.0), looking at (0.0, 0.0, 0.0) (i.e. the origin) and has an up vector of (0.0, 1.0, 0.0).

void GLWorldViewer::setAutoGLClearEnabled bool  enable  )  [inline]
 

void GLWorldViewer::setAutoGLFlushEnabled bool  enable  )  [inline]
 

void GLWorldViewer::setBackgroundColor const QColor &  c  )  [inline]
 

Same as setBackgroundColor, but with a QColor attribute.

Reimplemented from QGLViewer.

void GLWorldViewer::setBackgroundColor float  r,
float  g,
float  b
[inline]
 

Same as setBackgroundColor(), but with float parameters.

Reimplemented from QGLViewer.

void GLWorldViewer::setBackgroundColor const qglviewer::Vec color  )  [inline]
 

Reimplemented, as to gain more control over when the glClearColor call is made (so that the user can override it if they call it) and also to overcome a bug in QGLViewer, where a makeCurrent() call is not made before glClearColor is called, hence any viewer could otherwise end-up being effected.

Reimplemented from QGLViewer.

void GLWorldViewer::setDrawFrustum bool  enable  )  [inline]
 

void GLWorldViewer::sharedInit  )  [protected]
 

This method is used by the constructors to perform tasks that are common to all of them.


Member Data Documentation

bool GLWorldViewer::autoGLClear [protected]
 

bool GLWorldViewer::autoGLFlush [protected]
 

int GLWorldViewer::extModifierKey [protected]
 

bool GLWorldViewer::frustumEnabled [protected]
 

qglviewer::Vec GLWorldViewer::myBackgroundColour [protected]
 

const GLScene* GLWorldViewer::myScene [protected]
 

GLScreenViewer* GLWorldViewer::myScreenViewer [protected]
 

const GLdouble* GLWorldViewer::myScreenViewersProjection [protected]
 

bool GLWorldViewer::reinitRequired [protected]
 


The documentation for this class was generated from the following files:
Generated on Fri Feb 27 12:01:40 2004 for Glitch by doxygen 1.3.2