Main Page   Class Hierarchy   Compound List   All functions   Search  

Camera Class Reference

List of all members.

Position and orientation of the camera

Vec position () const
Quaternion orientation () const
void getPosition (float &x, float &y, float &z) const
void getOrientation (float &q0, float &q1, float &q2, float &q3) const
void setPosition (const Vec &pos)
void setPosition (float x, float y, float z)
void setOrientation (const Quaternion &q)
void setOrientation (float q0, float q1, float q2, float q3)
void setOrientation (float theta, float phi)
void setCameraFromProjectionMatrix (const float *const m)

Camera positioning tools

void setUpVector (float x, float y, float z, bool noMove=true)
void showEntireScene ()
void fitBoundingBox (const Vec &m, const Vec &M)
void fitSphere (const Vec &center, float radius)
void fitSphere (float x, float y, float z, float r)
void lookAt (const Vec &target)
void lookAt (float x, float y, float z)
void centerScene ()
void setUpVector (const Vec &up, bool noMove=true)
void setFOVToFitScene ()
void interpolateToZoomOnPixel (int x, int y)
void interpolateToFitScene ()

Camera intrinsic parameters

float fieldOfView () const
float flySpeed () const
Type type () const
ManipulatedCameraFrame::Mode mode () const
void setFieldOfView (float f)
void setFlySpeed (float s)
void setType (Type type)
void setMode (ManipulatedCameraFrame::Mode m)
void toggleMode ()

Camera associated parameters

virtual float zNear () const
virtual float zFar () const
float zNearCoef () const
void getOrthoWidthHeight (GLdouble &w, GLdouble &h) const
float aspectRatio () const
int screenWidth () const
int screenHeight () const
float pixelGLRatio (const Vec &pos)
float distanceToSceneCenter () const
Vec upVector () const
void getUpVector (float &x, float &y, float &z) const
Vec viewDirection () const
void getViewDirection (float &x, float &y, float &z) const
Vec pointUnderPixel (const int x, const int y, bool &found)
bool isManipulated () const
void setZNearCoef (float coef)

Revolve Around Point

Vec revolveAroundPoint () const
void getRevolveAroundPoint (float &x, float &y, float &z) const
void setRevolveAroundPoint (const Vec &rap)
void setRevolveAroundPoint (float x, float y, float z)
bool setRevolveAroundPointFromPixel (int x, int y)
void setRevolveAroundPointToSceneCenter ()

Camera Paths

A camera path is defined by a KeyFrameInterpolator. You can interactively addKeyFrame() to a given path using the default QGLViewer shortcut: Alt-F[1-12] (see QGLViewer::setKeyFrameKey()). Use playKeyFramePath() to make the camera follow the path (default shortcut is F[1-12]).

int nbPaths () const
KeyFrameInterpolatorkeyFrameInterpolator (unsigned short i) const
void setKeyFrameInterpolator (unsigned short i, KeyFrameInterpolator *const kfi)
virtual void addKeyFrame (int i)
virtual void playKeyFramePath (int i)
virtual void deleteKeyFramePath (int i)
virtual void resetKeyFramePath (int i)
virtual void drawAllPaths ()

Associated camera frame

ManipulatedCameraFrameframe () const
void setFrame (ManipulatedCameraFrame *const f)

OpenGL associated matrices

virtual void loadProjectionMatrix (bool reset=true) const
virtual void loadProjectionMatrixStereo (bool leftBuffer=true) const
virtual void loadModelViewMatrix (bool reset=true) const
virtual void loadModelViewMatrixStereo (bool leftBuffer=true) const
virtual void getProjectionMatrix (GLdouble m[16]) const
virtual void getProjectionMatrix (GLfloat m[16]) const
virtual void getModelViewMatrix (GLdouble m[16]) const
virtual void getModelViewMatrix (GLfloat m[16]) const
virtual void computeModelViewMatrix () const

World to Camera coordinate systems

Methods to go from the world to the camera coordinate systems, and vice-versa. Simply an interface for the Frame equivalent functions.

void getCameraCoordinatesOf (const float src[3], float res[3]) const
Vec cameraCoordinatesOf (const Vec &src) const
void getWorldCoordinatesOf (const float src[3], float res[3]) const
Vec worldCoordinatesOf (const Vec &src) const

2D screen to 3D world coordinate systems

Methods to go from the 2D screen to the 3D world coordinate systems, and vice-versa.

Vec projectedCoordinatesOf (const Vec &src) const
void getProjectedCoordinatesOf (const float src[3], float res[3]) const
Vec unprojectedCoordinatesOf (const Vec &src) const
void getUnprojectedCoordinatesOf (const float src[3], float res[3]) const
void convertClickToLine (int x, int y, float orig[3], float dir[3]) const
void convertClickToLine (int x, int y, Vec &orig, Vec &dir) const

Stereo mode parameters

float horizontalFieldOfView () const
float IODist () const
float distanceToScreen () const
float distanceToZeroParallaxPlane () const
float physicalScreenWidth () const
void setHorizontalFieldOfView (float hfov)
void setIODist (float iod)
void setDistanceToScreen (float dts)
void setDistanceToZeroParallaxPlane (float dtz)
void setPhysicalScreenWidth (float sw)

XML representation

virtual QDomElement domElement (const QString &name, QDomDocument &doc) const
virtual void initFromDOMElement (const QDomElement &de)

Scene radius and center

Definition of the size of the scene.

float sceneRadius () const
Vec sceneCenter () const
void setSceneRadius (float r)
void setSceneBoundingBox (const Vec &m, const Vec &M)
void setSceneCenter (const Vec &sc)
void setSceneCenter (float x, float y, float z)
bool setSceneCenterFromPixel (int x, int y)

Internal methods

Used by the QGLViewer to transmit to the Camera some scene related values.

bool cameraPathIsEdited () const
void editCameraPath (bool edit)
void setWindowWidthAndHeight (int w, int h)

Public Types

enum  Type { PERSPECTIVE, ORTHO }

Public Methods

 Camera ()
virtual ~Camera ()

Detailed Description

An OpenGL camera, with positioning tools.

A Camera defines some intrinsic camera parameters, such as fieldOfView(), position(), viewDirection(), upVector()... It also provides useful positioning tools that ease its placement : showEntireScene(), fitSphere(), fitBoundingBox(),, ...

The type() of the Camera can be ORTHO or PERSPECTIVE (see Type()). fieldOfView() is meaningless in ORTHO.

The position() and orientation() of the Camera are defined by a ManipulatedCameraFrame that can be retrieved with frame(). These functions are just a convenient interface for the associated Frame functions. This also means that the Camera frame() can be attached to a Frame::referenceFrame() which enable complex Camera setups.

The mode() of the Camera is also simply the one of its frame(). Current possible values are REVOLVE and FLY (see ManipulatedCameraFrame::Mode()).

See the ManipulatedCameraFrame page or the mouse page for mouse button binding details. Press the CAMERA_MODE key (default is space) to toggle between the two modes. See the shortcut page and QGLViewer::setKeyFrameKey() for more details on key customization.

The near and far planes of the Camera are determined from the QGLViewer::sceneRadius() and QGLViewer::sceneCenter() by the zNear() and zFar() functions. Reasonable values on the scene extends hence have to be provided to the QGLViewer in order for the Camera to correctly display the scene. High level positioning functions can then be automated (showEntireScene(), centerScene()...). Once again, see the mouse page for details.

A Camera holds 12 KeyFrameInterpolator that can be used to save camera positions and paths. See the shortcut page for default key bindings.

Use cameraCoordinatesOf() ans worldCoordinatesOf() to convert to and from the Camera frame() coordinate system. projectedCoordinatesOf() and unprojectedCoordinatesOf() will convert from screen to 3D coordinates. convertClickToLine() is very useful for analytical object selection.

Stereo display is possible on machines with quad buffer capabilities (with PERSPECTIVE type() only). Test the stereoViewer example to check.


Member Enumeration Documentation

enum Type
 

The type of camera used by the QGLViewer, set by setType(). This type will be use in loadProjectionMatrix().

See also:
setFieldOfView, setSceneRadius, type, setType, loadProjectionMatrix
Enumeration values:
PERSPECTIVE 
ORTHO 


Constructor & Destructor Documentation

Camera  
 

Default values are given to the camera parameters : sceneCenter=0, sceneRadius=1, camera type = PERSPECTIVE, default stereo value, ....

virtual ~Camera   [inline, virtual]
 

Virtual destructor. Empty.


Member Function Documentation

void addKeyFrame int    i [virtual, slot]
 

Adds the current camera frame as a key frame to the path number i. This function can also be used if you simply want to save a camera point of view, as it is simply a key frame path made of one key frame.

The default shortcut for this function is Alt-F[1-12]. Set QGLViewer::setKeyFrameKey() and QGLViewer::setAddKeyFrameStateKey().

Use playKeyFramePath() to make the camera play the key frame path (resp. restore point of view). Use deleteKeyFramePath() to clear the key frame path.

See also keyFrameInterpolator() and setKeyFrameInterpolator() to directly define a complete path.

float aspectRatio   const [inline]
 

Returns the currents camera aspect ratio (screenWidth() / screenHeight()), determined from the QGLViewer window size.

Vec cameraCoordinatesOf const Vec   src const [inline]
 

Returns the camera frame coordinates of a point src defined in world coordinates. worldCoordinatesOf() performs the inverse transformation.

bool cameraPathIsEdited   const [inline]
 

Returns true if the camera paths are being edited in the viewer. Set by QGLViewer::editCameraPath() or QGLViewer::toggleCameraPathEditor(). See QGLViewer::cameraPathIsEdited() for details.

void centerScene   [slot]
 

Move the camera so that the sceneCenter() is projected on the center of the window. The orientation() and fieldOfView() are unchanged.

ManipulatedCameraFrame::mouseDoubleClickEvent() calls this function after a right button double click.

See also showEntireScene().

void computeModelViewMatrix   const [virtual]
 

Computes the model view matrix associated with the camera state. Called by loadModelViewMatrix() before each drawing. You may need to call this (unlikely) if you use the model view matrix out of the main drawing loop, for a (un) projectedCoordinatesOf() or a getModelViewMatrix() for instance.

void convertClickToLine int    x,
int    y,
Vec   orig,
Vec   dir
const
 

This function should be called by your selection function to transform a window x,y coordinate to a (world coordinates) half line, for analytical intersection process.

The origin of the half line (eye position) is stored in orig, while dir contains the properly oriented and normalized direction of the half line.

Typical usage would be:

 convertClickToLine(e->x(), e->y(), orig, dir);
 

The x and y coordinates origin is in the window's upper left corner.

See the select example for an illustration.

void convertClickToLine int    x,
int    y,
float    orig[3],
float    dir[3]
const
 

Same as convertClickToLine(), but the result is returned as a float[3].

void deleteKeyFramePath int    i [virtual, slot]
 

Deletes the KeyFrameInterpolator of index i. Use addKeyFrame() to define a key frame path.

float distanceToSceneCenter   const
 

Returns the distance from the camera center to sceneCenter(), projected along the camera Z axis. Used by zNear() and zFar() to optimize the Z range.

float distanceToScreen   const [inline]
 

Returns the physical distance to screen (used for stereo mode only). Value is set using setDistanceToScreen()

float distanceToZeroParallaxPlane   const [inline]
 

Returns the distance to 0 parallax plane (used for stereo mode only). Value is set using setDistanceToZeroParallaxPlane()

QDomElement domElement const QString &    name,
QDomDocument &    doc
const [virtual]
 

Creates an XML QDomElement that represents the Camera. name is the name of the QDomElement tag. You need to provide the QDomDocument doc that will hold the resulting element.

Use initFromDOMElement() to restore the Camera state from the resulting domElement.

See also KeyFrameInterpolator::domElement(), Frame::domElement()...

If you want to save the camera state in a file, use

  QDomDocument doc("myCAMERA");
  doc.appendChild( myCamera->domElement("Camera", doc) );
  ofstream file("myCamera.xml");
  file << doc.toString();
 
Note that this is done automatically by QGLViewer::saveToFile() when a QGLViewer is closed (default shortcut key is Escape). See also QGLViewer::saveToFileForAllViewers().

Use the following code to retrieve state from the saved file:

 // Load DOM from file
 QDomDocument doc;
 QFile f("myCamera.xml");
 f.open(IO_ReadOnly);
 doc.setContent(&f);
 f.close();
 // Parse the DOM tree
 QDomElement main = doc.documentElement();
 myCamera->initFromDOMElement(main);
 

void drawAllPaths   [virtual, slot]
 

Draws the camera paths defined by the keyFrameInterpolator(). Simply calls KeyFrameInterpolator::drawPathModifyGLState() for all the defined path. See addKeyFrame() and setKeyFrameInterpolator() to define a path.

The path color is the current glColor().

Attention:
The GL state is modified by this function : see KeyFrameInterpolator::drawPathModifyGLState().

void editCameraPath bool    edit [inline, slot]
 

Starts or stops the edition of the camera paths. Called by QGLViewer::editCameraPath() and QGLViewer::toggleCameraPathEditor(). Get current value with cameraPathIsEdited().

float fieldOfView   const [inline]
 

Returns the vertical field of view of the camera (in radians). Value is set using setFieldOfView(), default value is pi/4 radians.

void fitBoundingBox const Vec   m,
const Vec   M
[slot]
 

Moves the camera so that the bounding box m,M is entirely visible, using fitSphere().

m and M are two extremal corners of the Bounding Box.

void fitSphere float    x,
float    y,
float    z,
float    r
[inline, slot]
 

Same as fitSphere(), but with float parameters.

void fitSphere const Vec   center,
float    radius
[slot]
 

Move the camera so that the sphere (center, radius) is visible and fits the window. The camera is translated so that the sphere fits the screen, its orientation() and fieldOfView() are unchanged.

float flySpeed   const [inline]
 

Returns the current fly speed (used when mode() is FLY). Set with setFlySpeed(). Set to 0.5% of the sceneRadius in setSceneRadius().

ManipulatedCameraFrame* frame   const [inline]
 

The ManipulatedCameraFrame attached to the camera and which defines its position and orientation. See setFrame().

void getCameraCoordinatesOf const float    src[3],
float    res[3]
const
 

Same as cameraCoordinatesOf(), but the parameters are float[3] (src and res may be identical pointers).

void getModelViewMatrix GLfloat    m[16] const [virtual]
 

Set m to the current camera model view matrix. This modelView matrix is usually not the one you would get from a glGetFloatv(GL_MODELVIEW_MATRIX). Instead, it only represents the Camera to world coordinate system transformation matrix. As soon as you modify the GL_MODELVIEW_MATRIX in your QGLViewer::draw() function, the two matrices differ.

This matrix actually represents the state of the GL_MODELVIEW_MATRIX after QGLViewer::preDraw(), at the beginning of QGLViewer::draw().

Attention:
If you call this function out of the classical drawing loop (QGLViewer::draw() or QGLViewer::postDraw()), you need to call computeModelViewMatrix() before this function, so that the model view matrix is properly updated.

The result is an openGL 4x4 matrix, which is given in column-major order (see glMultMatrix man page for details).

See also getModelViewMatrix(GLdouble m[16]) and loadModelViewMatrix().

void getModelViewMatrix GLdouble    m[16] const [virtual]
 

This function is provided for convenience, in case you want to work with double instead of floats, see getModelViewMatrix(GLfloat m[16]) for explanations.

void getOrientation float &    q0,
float &    q1,
float &    q2,
float &    q3
const
 

float version of orientation().

void getOrthoWidthHeight GLdouble &    w,
GLdouble &    h
const
 

Returns the half width w and half height h of the camera frustum. These results are only valid when the Camera is in ORTHO type(). Results are expressed in openGL units. These values are used by loadProjectionMatrix() to define the glOrtho( -w, w, -h, h, zNear(), zFar() ) projection matrix.

void getPosition float &    x,
float &    y,
float &    z
const
 

Same as position(), but with float parameters.

void getProjectedCoordinatesOf const float    src[3],
float    res[3]
const
 

float version of projectedCoordinatesOf() (src and res may be identical pointers).

void getProjectionMatrix GLfloat    m[16] const [virtual]
 

Set m to the current projection matrix. m is an array of 16 floats. See also getProjectionMatrix(GLdouble m[16]).

Attention:
glMatrixMode is set to GL_PROJECTION.

void getProjectionMatrix GLdouble    m[16] const [virtual]
 

This function is provided for convenience, in case you want to work with double instead of floats, see getProjectionMatrix(GLfloat m[16]) for explanations.

void getRevolveAroundPoint float &    x,
float &    y,
float &    z
const
 

float version of revolveAroundPoint().

void getUnprojectedCoordinatesOf const float    src[3],
float    res[3]
const
 

Same as getUnprojectedCoordinatesOf(), but with float parameters (src and res may be identical pointers).

void getUpVector float &    x,
float &    y,
float &    z
const
 

Same as upVector(), but with float parameters.

void getViewDirection float &    x,
float &    y,
float &    z
const
 

void getWorldCoordinatesOf const float    src[3],
float    res[3]
const
 

Same as worldCoordinatesOf(), but the parameters are float[3] (src and res may be identical pointers).

float horizontalFieldOfView   const [inline]
 

Returns the horizontal (X camera frame direction) field of view used by the camera (in radians). Value is set using setHorizontalFieldOfView() or setFieldOfView(). The values are always linked by :

    horizontalFieldOfView() = 2.0 * atan ( tan(fieldOfView()/2.0) * aspectRatio() ).
    

void initFromDOMElement const QDomElement &    de [virtual]
 

Restore the Camera state from a QDomElement created by domElement(). See also KeyFrameInterpolator::initFromDOMElement(), Frame::initFromDOMElement().

void interpolateToFitScene   [slot]
 

Inperpolates the camera position on a one second KeyFrameInterpolator path stating from the current position, so that at the end the entire scene is visible and fits in screen (see showEntireScene()). See also interpolateToFitScene().

This function is binded to the right then middle double simple click. See mouse page for details. See also zoomOnPixel().

void interpolateToZoomOnPixel int    x,
int    y
[slot]
 

Make the camera zoom on the selected pixel (if an object is actually drawn in this pixel, see pointUnderPixel()). A KeyFrameInterpolator is created and animates the camera on a one second path that brings the camera closer to the selected pixel. See also interpolateToFitScene().

This function is binded to the middle then right double simple click. See mouse page for details. See also interpolateToFitScene().

float IODist   const [inline]
 

Returns the inter-ocular distance used for stereo (in meters). Value set using setIODist()

bool isManipulated   const [inline]
 

true when the camera is being manipulated with the mouse. Useful for switching to fast draw mode. See QGLViewer::fastDraw().

KeyFrameInterpolator * keyFrameInterpolator unsigned short    i const
 

Returns the current KeyFrameInterpolator that defines the camera path number i.

If the path is not defined for this index, the method returns a NULL pointer.

Use the following code to remove the connection between the KeyFrameInterpolator::interpolated() signal and the viewer:

disconnectSignalToAllViewers(keyFrameInterpolator(i), SIGNAL(interpolated()));
Attention:
index must be in the range 0..nbPaths()-1.

void loadModelViewMatrix bool    reset = true const [virtual]
 

Loads the current camera GL_MODELVIEW matrix.

When reset is true (default), it clears the previous projection matrix by calling glLoadMatrixd. Setting reset to false simply calls glMultMatrixd (might be useful for some applications).

getModelViewMatrix() returns the current 4x4 model view matrix.

Attention:
glMatrixMode is set to GL_MODELVIEW

makeCurrent() must be called by every calling method if this function is used out of the main drawing loop (i.e. not in QGLViewer::draw() or in QGLViewer::preDraw()).

void loadModelViewMatrixStereo bool    leftBuffer = true const [virtual]
 

Loads the GL_MODELVIEW matrix for stereo mode. It clears the previous modelview matrix by calling glLoadIdentity before setting the matrix. When leftBuffer is true (resp. false), it performs a left (resp. right) buffer translation by modifying the translation term directly in the modelView matrix.

Attention:
glMatrixMode is set to GL_MODELVIEW

makeCurrent() must be called by every calling method if this function is used out of the main drawing loop (i.e. not in QGLViewer::draw() or in QGLViewer::preDraw())..

void loadProjectionMatrix bool    reset = true const [virtual]
 

Load the current camera GL_PROJECTION matrix. Default method set camera according to fieldOfView(), and window aspect ratio in PERSPECTIVE type(). See getOrthoWidthHeight() for ORTHO type().

Uses zNear() and zFar() which are determined from sceneRadius() and sceneCenter() so that they best fit the scene size.

Camera type is returned by type(), and is set with setType().

When reset is true (default), it clears the previous projection matrix by calling glLoadIdentity before setting the matrix. Setting reset to false is usefull for GL_SELECT mode, to combine the matrix with a picking matrix.

getProjectionMatrix() returns the 4x4 projection matrix.

Attention:
glMatrixMode is set to GL_PROJECTION

makeCurrent() must be called by every calling method.

void loadProjectionMatrixStereo bool    leftBuffer = true const [virtual]
 

Load the current camera GL_PROJECTION matrix for Stereo mode. Only PERSPECTIVE camera type() case is handled.

Uses zNear() and zFar() which are determined from sceneRadius() and sceneCenter() so that they best fit the scene size.

Uses distanceToZeroParallaxPlane(), IODist(), and physicalScreenWidth() to compute cameras offset for stereovision, as well as asymmetric frustums

Camera type is returned by type(), and is set with setType().

When leftBuffer is true (default), computes the projection matrix for left camera (right camera otherwise).

getProjectionMatrix() will always return the 4x4 mono projection matrix.

Attention:
glMatrixMode is set to GL_PROJECTION

makeCurrent() must be called by every calling method.

void lookAt float    x,
float    y,
float    z
[inline, slot]
 

Same as lookAt(), but with float parameters.

void lookAt const Vec   target [slot]
 

Set the camera orientation, so that it looks at point target (defined in the world coordinate system). The camera position is not modified. The camera is rotated so that the horizon is preserved. See also setOrientation(), showEntireScene(), fitSphere() and fitBoundingBox().

ManipulatedCameraFrame::Mode mode   const [inline]
 

Returns the value of frame mode, set by setMode() or toggleMode(). This mode determines the behavior or the camera when the mouse is moved.

int nbPaths   const [inline]
 

Returns the number of camera paths that can be defined. This is the maximum number of KeyFrameInterpolator that can be saved (index range is 0..nbPaths()-1), but some of them may not be defined (keyFrameInterpolator() will return NULL).

Quaternion orientation   const [inline]
 

Returns the camera current orientation, defined in the world coordinate system. Actually returns frame()->orientation(). Use setOrientation(), setUpVector() or lookAt() to set the camera orientation.

float physicalScreenWidth   const [inline]
 

Returns the physical screen width (used for stereo mode only). Value is set using setPhysicalScreenWidth()

float pixelGLRatio const Vec   pos
 

Returns the pixel to GL unit ratio. A line of pixelGLRatio() GL unit, located at position pos in the world coordinates system, will be projected with a size of 1 pixel on the screen. Use this function to scale objects so that they have a constant pixel size on screen.

The following code will draw a 20 pixel line, starting at sceneCenter() and always directed along the screen vertical direction.

  glBegin(GL_LINES);
  glVertex3fv(sceneCenter().address());
  glVertex3fv((sceneCenter() + 20*pixelGLRatio(sceneCenter())*upVector()).address());
  glEnd();
  

Attention:
The resulting value is only valid for a given Camera and a given pos. It also naturally depends on the current screen height (see screenHeight()).

void playKeyFramePath int    i [virtual, slot]
 

Make the camera follow the key frame path number i. The key Frames are defined using addKeyFrame(). Use deleteKeyFramePath() to clear a path.

The default shortcut for this function is F[1-12]. Set QGLViewer::setKeyFrameKey() and QGLViewer::setPlayKeyFramePathStateKey().

See also keyFrameInterpolator() and setKeyFrameInterpolator() to directly define a complete path.

Vec pointUnderPixel const int    x,
const int    y,
bool &    found
 

Returns the coordinates of the 3D point located at pixel (x,y) on screen. Calls a glReadPixel to get the pixel depth and applies an unprojectedCoordinatesOf() to the result. found indicates whether a point was found or not (i.e. background pixel, result's depth is zFar() in that case).

Attention:
The precision of the ZBuffer highly depends on how tight to your scene are the zNear() and zFar() values. Imprecision may result along the viewing direction otherwise. See QGLViewer::setSceneCenter(), QGLViewer::setSceneRadius() and setZNearCoef().

Vec position   const [inline]
 

Returns the camera position (the eye), defined in the world coordinate system. Use setPosition() to set the camera position. Other convenient functions are showEntireScene(), fitBoundingBox() or fitSphere(). Actually returns frame()->position().

Vec projectedCoordinatesOf const Vec   src const
 

Returns the screen projected coordinates of a point src defined in the world coordinate system. See the gluProject man page for details. The x and y returned values are expressed in pixel, (0,0) being the lower left corner (QT QMouseEvent has (0,0) in the upper left corner).

This method is not computationally optimized. If you call it several times with no change in the matrices, you should buffer the entire projection matrix (modelview, projection and then viewport) to speed-up the queries. See the gluProject man page for details.

unprojectedCoordinatesOf() performs the inverse transformation.

Attention:
When used in conjunction with QGLViewer::startScreenCoordinatesSystem(), the computations of the projected coordinates must be done before entering the screen coordinate mode, as the camera matrix is no longer a 3D projection in this mode. See the screenCoordSystem example.

If not used in QGLViewer::draw() or similar functions, call makeCurrent() and computeModelViewMatrix() before calling this function.

void resetKeyFramePath int    i [virtual, slot]
 

If this keyFrame path is not being played (see playKeyFramePath() ), reset it to is its starting position (see KeyFrameInterpolator::resetInterpolation()). If the path is played, simply stop interpolation.

Vec revolveAroundPoint   const [inline]
 

When the camera is in REVOLVE mode (see mode()), this is the point the camera revolves around (defined in world coordinate system). Default value is the sceneCenter(). Camera mode can be changed with toggleMode() or with setMode().

Attention:
setSceneCenter() changes this value.

Vec sceneCenter   const [inline]
 

Returns the position of the scene center. This value is set setSceneCenter(), which is called by QGLViewer::setSceneCenter(). Default is 0,0,0 (world origin).

float sceneRadius   const [inline]
 

Returns the scene radius used by the camera. Used to set the camera near and far planes (see zNear() and zFar()). This value is modifed by QGLViewer::setSceneRadius(), which simply calls setSceneRadius().

int screenHeight   const [inline]
 

Returns the current height (in pixels) of the camera screen. See also QGLWidget::height().

int screenWidth   const [inline]
 

Returns the current width (in pixels) of the camera screen. See also QGLWidget::width()

void setCameraFromProjectionMatrix const float *const    m [slot]
 

m is the projection matrix as used in vision algorithm. It has 3 lines and 4 columns. It transforms a point in the world homogeneous coordinate system (4 coordinates: sx, sy, sz and s) in a point in the screen homogeneous coordinate system (3 coordinates: sx, sy, and s, where x and y are the pixel coordinates on the screen).

m is a pointer to the elements of the matrix ordered in line major order. If you define your matrix as a float matrix[3][4], you should call : setCameraFromProjectionMatrix(&(matrix[0][0]));

This code was written by Sylvain Paris (Sylvain.Paris@imag.fr).

void setDistanceToScreen float    dts [inline, slot]
 

Defines the distance in real world between the observer eyes and the screen -monitor or projection wall- in meters. Default value is 0.5m.

loadProjectionMatrixStereo() uses this value to define the camera offset and frustum.

void setDistanceToZeroParallaxPlane float    dtz [inline, slot]
 

Defines the distance in virtual world between the viewpoint and the plane where the horizontal parallax is null, that's to say where the stereo left and right images are superimposed.

loadProjectionMatrixStereo() uses this value to define the camera offset and frustum.

Attention:
This value is modified by QGLViewer::setSceneRadius(), setSceneRadius() and setFieldOfView(). When one of these values is modified, distanceToZeroParallaxPlane() is set to sceneRadius() / tan(fieldOfView()/2).

void setFieldOfView float    f [inline, slot]
 

Defines the vertical field of view of the camera (in radians). Also used to fit the scene and mouse translations. fieldOfView() returns the current value. The default value is pi/4 radians. loadProjectionMatrix() uses this value to define the camera.

The field of view corresponds the one used in gluPerspective (see manual). It set the Y (vertical) aperture of the camera. The X (horizontal) angle is inferred from the window aspect ratio (see aspectRatio() and horizontalFieldOfView()).

Use setFOVToFitScene() to adapt the fieldOfView(). This is not the normal way of zooming in or out. All the other positioning camera function (showEntireScene(), fitSphere()...) move the camera instead of changing its fieldOfView().

distanceToZeroParallaxPlane() is set to sceneRadius() / tan(fieldOfView()/2) (used only for stereo mode, see QGLViewer::setStereoDisplay(), setSceneRadius() and setDistanceToZeroParallaxPlane()).

void setFlySpeed float    s [inline, slot]
 

When camera is in FLY mode (see mode()), tunes the speed of the displacement. Current value is given by flySpeed(). Note that is value is also set in setSceneRadius().

void setFOVToFitScene   [slot]
 

Change the camera fieldOfView() so that the entire scene (defined by QGLViewer;;sceneCenter() and QGLViewer::sceneRadius()) would be visible from the current camera position(). The position() and orientation() of the camera are not modified and you have to properly orientate the camera in order to actually see the scene (see lookAt()). See also showEntireScene() and fitSphere().

This function is especially useful for shadow maps computation. Use the camera positionning tools (setPosition(), lookAt(), setUpVector()) to position the camera at the light position. Use setFOVToFitScene() to define an optimal fieldOfView() that best use the shadow map resolution.

Use showZBuffer() to actually see the computed shadow map. See the shadowMap example (TODO).

Note:
If the camera is inside the scene sphere, the fieldOfView() is clamped to pi.

void setFrame ManipulatedCameraFrame *const    f [inline, slot]
 

Changes the ManipulatedCameraFrame that defines the position and orientation of the camera. If you simply want to move the camera, use setPosition() and setOrientation() or one of the camera positioning functions : lookAt(), fitSphere(), fitBoundingBox(), showEntireScene()...

If you want to save camera positions, there's no real need to call this function either. Use addKeyFrame() and playKeyFramePath() for this.

This function is actually mainly useful if you derive the ManipulatedCameraFrame class and want to use an instance of your new class to move the camera.

A NULL frame pointer will silently be ignored. The calling function is responsible for deleting the previous frame() pointer if needed in order to prevent memory leaks :

    delete camera()->frame();
    camera()->setFrame(myManipulatedCameraFrame());
    

void setHorizontalFieldOfView float    hfov [inline, slot]
 

Defines the horizontal field of view of the camera (in radians) by calling setFieldOfView() scaled by 1/aspectRatio() to keep consistency.

loadProjectionMatrixStereo() uses this value to define the camera offset and frustum.

void setIODist float    iod [inline, slot]
 

Defines the real inter-ocular distance (in meters). The default value used is 0.062m, which fits most people.

loadProjectionMatrixStereo() uses this value to define the camera offset and frustum

void setKeyFrameInterpolator unsigned short    i,
KeyFrameInterpolator *const    kfi
[slot]
 

Changes the KeyFrameInterpolator that currently defines the camera path of index i. The previous keyFrameInterpolator() is lost and the pointer should be deleted by the calling function if needed:

deleteKeyFramePath(3);
setKeyFrameInterpolator(3, myKeyFrameInterpolator);

Attention:
Index i must be in the range 0..nbPaths()-1.

void setMode ManipulatedCameraFrame::Mode    m [inline, slot]
 

Set the displacement mode of the camera, defined from ManipulatedCameraFrame::Mode().

See the mouse behavior and customization HTML page for details.

void setOrientation float    theta,
float    phi
[slot]
 

Set the orientation of the camera using polar coordinates theta and phi (in radians). theta rotates around the camera Y axis, and then phi rotates around the camera X axis. theta = phi = 0 means that the camera is directed towards the world Z axis. See also setUpVector(). The position() of the camera is unchanged, you may want to call showEntireScene() after this function to move the camera.

This function can be useful to create Quicktime VR panoramic sequences, see saveSnapshot() for details.

void setOrientation float    q0,
float    q1,
float    q2,
float    q3
[inline, slot]
 

Same as setOrientation(), but with float parameters.

void setOrientation const Quaternion   q [slot]
 

Set the camera orientation, defined with respect to the world coordinate system. The current camera orientation can be obtained from orientation(). The camera position() is not modified by this function. See also lookAt() and setUpVector().

void setPhysicalScreenWidth float    sw [inline, slot]
 

Defines the width of the real screen (in meters). Typically 0.4m (default value) for a monitor and 10m for the cylindrical wall in Reality Center.

loadProjectionMatrixStereo() uses this value to define the camera offset and frustum.

void setPosition float    x,
float    y,
float    z
[inline, slot]
 

Same as setPosition(), but with float parameters.

void setPosition const Vec   pos [inline, slot]
 

Set the camera position (the eye), defined in the world coordinate system. The current camera position can be obtained from position().

void setRevolveAroundPoint float    x,
float    y,
float    z
[inline, slot]
 

float version of setRevolveAroundPoint().

void setRevolveAroundPoint const Vec   rap [slot]
 

Changes the revolveAroundPoint(), which defines the position (in world coordinates) of the 3D point the camera revolves around in REVOLVE camera mode (see mode() and setMode()). Current value can be get from revolveAroundPoint(). Default value is sceneCenter(), which default value is (0,0,0).

The zNear() and zFar() values are fitted to the scene, which will be entirely visible if revolveAroundPoint() is located inside a sceneRadius() sphere centered on sceneCenter().

The camera position and orientation are not modified so that the image displayed by the camera is not affected by the revolveAroundPoint() change.

Attention:
This value is modified by setSceneCenter().

bool setRevolveAroundPointFromPixel int    x,
int    y
[slot]
 

The revolveAroundPoint() is set to the point located at pixel (x,y) on screen.

Returns true if a pointUnderPixel() was found. If no point was found under the pixel, the revolveAroundPoint() is unchanged.

This function is binded to the left then right double simple click. See mouse page for details.

void setRevolveAroundPointToSceneCenter   [slot]
 

The name says it all. See setRevolveAroundPoint() and sceneCenter().

void setSceneBoundingBox const Vec   m,
const Vec   M
 

Similar to setSceneRadius() and setSceneCenter(), but the scene limits are defined by a bounding box.

void setSceneCenter float    x,
float    y,
float    z
 

Same as setSceneCenter(), but with float parameters.

void setSceneCenter const Vec   sc
 

Changes the sceneCenter value (used for zNear() and zFar()). This value is set from QGLViewer::setSceneCenter().

Attention:
revolveAroundPoint() is set to sceneCenter() by this method. See setRevolveAroundPointToSceneCenter().

bool setSceneCenterFromPixel int    x,
int    y
 

setSceneCenter() to the result of pointUnderPixel() (if a point was found).

Returns true if a pointUnderPixel() was found and sceneCenter() was changed.

void setSceneRadius float    r
 

Scene radius (see sceneRadius()) scales axis and grid display and is used by zNear() and zFar(). Should be set according to the displayed scene radius. This value is updated by the QGLViewer::setSceneRadius().

distanceToZeroParallaxPlane() is set to sceneRadius()/tan(fieldOfView()/2) (used only for stereo mode, see QGLViewer::setStereoDisplay(), setFieldOfView() and setDistanceToZeroParallaxPlane()).

See also setSceneBoundingBox().

void setType Type    type [inline, slot]
 

Defines the camera type. Supported types are defined by the Type() enum. loadProjectionMatrix() will create the camera accordingly. Use type() to get the current value.

    myViewer.camera()->setType(qglviewer::Camera::ORTHO);
    myViewer.camera()->showEntireScene();
    
In ORTHO mode, the fieldOfView() is meaningless and the width and height of the camera are inferred from the distance to the revolveAroundPoint() (see getOrthoWidthHeight()).

void setUpVector float    x,
float    y,
float    z,
bool    noMove = true
[inline]
 

Same as setUpVector(), but with float parameters.

void setUpVector const Vec   up,
bool    noMove = true
[slot]
 

Rotate the camera such that its up vector becomes up (defined in the world coordinate system). Only the orientation (not the position) of the camera is changed. The camera will be rotated around an axis orthogonal to up and to the current upVector() direction.

Use this function in order to define the horizontal plane in FLY mode. See setMode() for details.

However it might be interesting to compensate the orientation modification by a translation, so that the revolveAroundPoint() stays projected at the same position on screen. This is especially useful in the camera REVOLVE mode (see setMode()) and can be achieved when noMove is set to false. The default value for noMove is true, which results in an intuitive behavior when the camera is in FLY mode.

void setWindowWidthAndHeight int    w,
int    h
[slot]
 

Update a copy of the QGLViewer window dimensions. Called by the QGLViewer when it is resized.

You should not call this function directly, as the QGLViewer does it. However, if your Camera is used outside of a QGLViewer (offscreen rendering, shadow maps), you need to provide the screen width and height (see screenWidth() and screenHeight()) in order to define the camera aspectRatio() which is used to define the projection matrix in loadProjectionMatrix().

void setZNearCoef float    coef [inline, slot]
 

This value is used when the camera is inside the sceneRadius(), sceneCenter() sphere. The zNear() value is then set to zNearCoef() * sceneRadius(). Default value is 0.001, which is appropriate for walkthrough applications. In case you need a high dynamic ZBuffer precision, you can increase this value (~0.1). A lower value will prevent clipping of very close objects at the expense of a worst Z precision.

void showEntireScene   [slot]
 

Adjust the camera so that the entire scene is visible. The camera is translated to make the entire scene fit the window, its orientation() is unchanged. The scene is defined by the QGLViewer::sceneCenter() and QGLViewer::sceneRadius(). The fieldOfView() is not modified by this function.

QGLViewer::showEntireScene() simply calls this function. See also setFOVToFitScene().

You will typically use this function in QGLViewer::init():

You should orientate the camera before you call this function. See lookAt(), setOrientation() and setUpVector().

By default the QGLViewer::sceneRadius() is 1.0, and the QGLViewer constructor calls this function. See also centerScene().

ManipulatedCameraFrame::mouseDoubleClickEvent() calls this function after a middle button double click.

void toggleMode   [inline, slot]
 

Change camera mode (defined by the ManipulatedCameraFrame::Mode() enum), see mode() and setMode().

Type type   const [inline]
 

Returns the type of the camera used by the QGLViewer. Set by setType(). Supported types are defined by the Type() enum. Used by loadProjectionMatrix().

Vec unprojectedCoordinatesOf const Vec   src const
 

Returns the world unprojected coordinates of a point src defined in the screen coordinate system. The x and y input values are expressed in pixel, (0,0) being the lower left corner (QT QMouseEvent has (0,0) in the upper left corner). See the gluUnProject man page for details.

This method is not computationally optimized. If you call it several times with no change in the matrices, you should buffer the entire inverse projection matrix (modelview, projection and then viewport) to speed-up the queries. See the gluUnProject man page for details.

projectedCoordinatesOf() performs the inverse transformation.

Attention:
If not used in QGLViewer::draw() or similar functions, call makeCurrent() and computeModelViewMatrix() before calling this function.

Vec upVector   const
 

Return the current up vector of the camera, defined in the world coordinate system. See also setUpVector().

Simply returns :

  frame()->inverseTransformOf(Vec(0.0,1.0,0.0));
  

Vec viewDirection   const [inline]
 

Returns the normalized view direction of the camera (negative Z axis), defined in the world coordinate system.

Vec worldCoordinatesOf const Vec   src const [inline]
 

Returns the world coordinates of the point whose position is src, defined in the camera coordinate system. cameraCoordinatesOf() performs the inverse transformation.

float zFar   const [virtual]
 

Returns the zFar value used by the projection matrix. This value is fitted to sceneCenter() and sceneRadius() in order to ensure an optimal z sampling:

  float coef = sqrt(2.0); // so that a 1x1 grid fits
  if (cameraPathIsEdited())
    coef = 5.0;
  zFar=distanceToSceneCenter() + coef*sceneRadius();

The coef of 5.0 in front of sceneRadius() is used to prevent a clipping of the camera paths when QGLViewer::cameraPathIsEdited().

Attention:
The value is always positive and is the opposite of the camera frame actual value which is always negative. This is done in order to fit the gluPerspective positive standard.

float zNear   const [virtual]
 

Returns the zNear value used by the projection matrix. This value is fitted to sceneCenter() and sceneRadius() in order to ensure an optimal z sampling:

float coef = sqrt(2.0); // so that a 1x1 grid fits
if (cameraPathIsEdited())
  coef = 5.0;
zNear = distanceToSceneCenter() - coef*sceneRadius();

// Prevents negative or null zNear values.
if (zNear < zNearCoef() * sceneRadius())
   switch (type())
   {
   case Camera::PERSPECTIVE : z = zNearCoef() * sceneRadius(); break;
   case Camera::ORTHO       : z = 0.0; break;
   }

Returned value is clipped when the camera is inside the scene sphere to prevent negative or too small zNear() values (see setZNearCoef()).

The coef of 5.0 in front of sceneRadius() is used to prevent a clipping of the camera paths when QGLViewer::cameraPathIsEdited().

Attention:
The value is always positive and is the opposite of the camera frame actual value (always negative). This is done in order to fit the gluPerspective positive standard.

float zNearCoef   const [inline]
 

Returns the coefficient which is used to set zNear() when the camera is inside the sceneRadius() sphere. Set with setZNearCoef().


Generated on Fri Jun 27 18:34:03 2003 for libQGLViewer by doxygen1.3-rc2