eXperiment robotics framework

Camera Struct Reference

#include <camera.h>

Collaboration diagram for Camera:

Collaboration graph

List of all members.


virtual void draw (bool fitNearPlane=false) const
static void drawCamera (float scale=1.0, float aspectRatio=1.33, float fieldOfView=M_PI/4.0)

Public Types


Public Member Functions

 Camera ()
virtual ~Camera ()
Vec3 position () const
Vec3 upVector () const
Vec3 viewDirection () const
Quaternion orientation () const
void setFromProjectionMatrix (const float matrix[12])
void setPosition (const Vec3 &pos)
void setOrientation (const Quaternion &q)
void setOrientation (float theta, float phi)
void setUpVector (const Vec3 &up, bool noMove=true)
void setViewDirection (const Vec3 &direction)
Positioning tools

void lookAt (const Vec3 &target)
void showEntireScene ()
void fitSphere (const Vec3 &center, float radius)
void fitBoundingBox (const Vec3 &min, const Vec3 &max)
void fitScreenRegion (const fltk::Rectangle &rectangle)
void centerScene ()
void interpolateToZoomOnPixel (const Vec3 &pixel)
void interpolateToFitScene ()
Frustum parameters

Type type () const
float fieldOfView () const
float horizontalFieldOfView () const
float aspectRatio () const
int screenWidth () const
int screenHeight () const
void getViewport (GLint viewport[4]) const
float pixelGLRatio (const Vec3 &position) const
float zNearCoefficient () const
float zClippingCoefficient () const
virtual float zNear () const
virtual float zFar () const
void setType (Type type)
void setFieldOfView (float fov)
void setFocusDistance (float distance)
void setHorizontalFieldOfView (float hfov)
void setFOVToFitScene ()
void setAspectRatio (float aspect)
void setScreenWidthAndHeight (int width, int height)
void setZNearCoefficient (float coef)
void setZClippingCoefficient (float coef)
Scene radius and center

float sceneRadius () const
Vec3 sceneCenter () const
float distanceToSceneCenter () const
void setSceneRadius (float radius)
void setSceneCenter (const Vec3 &center)
bool setSceneCenterFromPixel (const Vec3 &pixel)
void setSceneBoundingBox (const Vec3 &min, const Vec3 &max)
Revolve Around Point

void setRevolveAroundPoint (const Vec3 &rap)
bool setRevolveAroundPointFromPixel (const Vec3 &pixel)
Associated frame
The point the Camera revolves around with the Viewer::ROTATE mouse binding. Defined in world coordinate system.

Default value is the sceneCenter().

setSceneCenter() changes this value.

Frameframe () const
void setFrame (Frame *const mcf)
OpenGL matrices

virtual void loadProjectionMatrix (bool reset=true) const
virtual void loadModelViewMatrix (bool reset=true) const
void computeProjectionMatrix () const
void computeModelViewMatrix () const
void getProjectionMatrix (GLdouble m[16]) const
void getModelViewMatrix (GLdouble m[16]) const
void getProjectionMatrix (GLfloat m[16]) const
void getModelViewMatrix (GLfloat m[16]) const
World to Camera coordinate systems conversions

Vec3 cameraCoordinatesOf (const Vec3 &src) const
Vec3 worldCoordinatesOf (const Vec3 &src) const
void getCameraCoordinatesOf (const float src[3], float res[3]) const
void getWorldCoordinatesOf (const float src[3], float res[3]) const
2D screen to 3D world coordinate systems conversions

Vec3 projectedCoordinatesOf (const Vec3 &src, const Frame *frame=NULL) const
Vec3 unprojectedCoordinatesOf (const Vec3 &src, const Frame *frame=NULL) const
void getProjectedCoordinatesOf (const float src[3], float res[3], const Frame *frame=NULL) const
void getUnprojectedCoordinatesOf (const float src[3], float res[3], const Frame *frame=NULL) const
void convertClickToLine (const Vec3 &pixel, Vec3 &orig, Vec3 &dir) const
Vec3 pointUnderPixel (const Vec3 &pixel, bool &found) const

Public Attributes

float focusDistance_
int screenWidth_
int screenHeight_
float fieldOfView_
Vec3 sceneCenter_
float sceneRadius_
float zNearCoef_
float zClippingCoef_
float orthoCoef_
Type type_
GLdouble modelViewMatrix_ [16]
GLdouble projectionMatrix_ [16]

Detailed Description

Definition at line 15 of file camera.h.

Member Enumeration Documentation


Definition at line 19 of file camera.h.

Constructor & Destructor Documentation

Camera::Camera (  ) 

virtual Camera::~Camera (  )  [virtual]

Member Function Documentation

Vec3 Camera::position (  )  const [inline]

Definition at line 21 of file camera.h.

References frame(), and Frame::position().

Vec3 Camera::upVector (  )  const

Vec3 Camera::viewDirection (  )  const [inline]

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

Change this value using setViewDirection(), lookAt() or setOrientation(). Simply returns frame()->inverseTransformOf(Vec(0.0, 0.0, -1.0)).

Definition at line 33 of file camera.h.

References frame(), and Frame::inverseTransformOf().

Quaternion Camera::orientation (  )  const [inline]

Returns the Camera orientation, defined in the world coordinate system.

Actually returns frame()->orientation(). Use setOrientation(), setUpVector() or lookAt() to set the Camera orientation.

Definition at line 42 of file camera.h.

References frame(), and Frame::orientation().

void Camera::setFromProjectionMatrix ( const float  matrix[12]  ) 

void Camera::setPosition ( const Vec3 pos  )  [inline]

Sets the Camera position() (the eye), defined in the world coordinate system.

Definition at line 50 of file camera.h.

References frame(), and Frame::setPosition().

void Camera::setOrientation ( const Quaternion q  ) 

void Camera::setOrientation ( float  theta,
float  phi 

void Camera::setUpVector ( const Vec3 up,
bool  noMove = true 

void Camera::setViewDirection ( const Vec3 direction  ) 

void Camera::lookAt ( const Vec3 target  ) 

void Camera::showEntireScene (  ) 

void Camera::fitSphere ( const Vec3 center,
float  radius 

void Camera::fitBoundingBox ( const Vec3 min,
const Vec3 max 

void Camera::fitScreenRegion ( const fltk::Rectangle &  rectangle  ) 

void Camera::centerScene (  ) 

void Camera::interpolateToZoomOnPixel ( const Vec3 pixel  ) 

void Camera::interpolateToFitScene (  ) 

Type Camera::type (  )  const [inline]

Returns the Camera::Type of the Camera.

Set by setType(). Mainly used by loadProjectionMatrix().

A Camera::PERSPECTIVE Camera uses a classical projection mainly defined by its fieldOfView().

With a Camera::ORTHOGRAPHIC type(), the fieldOfView() is meaningless and the width and height of the Camera frustum are inferred from the distance to the revolveAroundPoint() using getOrthoWidthHeight().

Both types use zNear() and zFar() (to define their clipping planes) and aspectRatio() (for frustum shape).

Definition at line 90 of file camera.h.

References type_.

float Camera::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. This value is meaningless if the Camera type() is Camera::ORTHOGRAPHIC.

The field of view corresponds the one used in gluPerspective (see manual). It sets 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() to a given scene.

Definition at line 105 of file camera.h.

References fieldOfView_.

Referenced by horizontalFieldOfView().

float Camera::horizontalFieldOfView (  )  const [inline]

Returns the horizontal field of view of the Camera (in radians).

Value is set using setHorizontalFieldOfView() or setFieldOfView(). These values are always linked by:

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

Definition at line 117 of file camera.h.

References aspectRatio(), and fieldOfView().

float Camera::aspectRatio (  )  const [inline]

Returns the Camera aspect ratio defined by screenWidth() / screenHeight().

When the Camera is attached to a Viewer, these values and hence the aspectRatio() are automatically fitted to the viewer's window aspect ratio using setScreenWidthAndHeight().

Definition at line 126 of file camera.h.

References screenHeight_, and screenWidth_.

Referenced by horizontalFieldOfView(), and setHorizontalFieldOfView().

int Camera::screenWidth (  )  const [inline]

Returns the width (in pixels) of the Camera screen.

Set using setScreenWidthAndHeight(). This value is automatically fitted to the Viewer's window dimensions when the Camera is attached to a Viewer. See also QGLWidget::width()

Definition at line 134 of file camera.h.

References screenWidth_.

int Camera::screenHeight (  )  const [inline]

Returns the height (in pixels) of the Camera screen.

Set using setScreenWidthAndHeight(). This value is automatically fitted to the Viewer's window dimensions when the Camera is attached to a Viewer. See also QGLWidget::height()

Definition at line 142 of file camera.h.

References screenHeight_.

void Camera::getViewport ( GLint  viewport[4]  )  const

float Camera::pixelGLRatio ( const Vec3 position  )  const

float Camera::zNearCoefficient (  )  const [inline]

Returns the coefficient which is used to set zNear() when the Camera is inside the sphere defined by sceneCenter() and zClippingCoefficient() * sceneRadius().

In that case, the zNear() value is set to zNearCoefficient() * zClippingCoefficient() * sceneRadius(). See the zNear() documentation for details.

Default value is 0.005, which is appropriate for most 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.

Only meaningful when Camera type is Camera::PERSPECTIVE.

Definition at line 160 of file camera.h.

References zNearCoef_.

float Camera::zClippingCoefficient (  )  const [inline]

Returns the coefficient used to position the near and far clipping planes.

The near (resp. far) clipping plane is positioned at a distance equal to zClippingCoefficient() sceneRadius() in front of (resp. behind) the sceneCenter(). This garantees an optimal use of the z-buffer range and minimizes aliasing. See the zNear() and zFar() documentations.

Default value is square root of 3.0 (so that a cube of size sceneRadius() is not clipped).

However, since the sceneRadius() is used for other purposes (see showEntireScene(), flySpeed(), ...) and you may want to change this value to define more precisely the location of the clipping planes. See also zNearCoefficient().

When Viewer::cameraPathAreEdited(), this value is set to 5.0 so that the Camera paths are not clipped. The previous zClippingCoefficient() value is restored back when you leave this mode.

Definition at line 179 of file camera.h.

References zClippingCoef_.

virtual float Camera::zNear (  )  const [virtual]

virtual float Camera::zFar (  )  const [virtual]

void Camera::setType ( Type  type  ) 

void Camera::setFieldOfView ( float  fov  )  [inline]

Sets the vertical fieldOfView() of the Camera (in radians).

Note that focusDistance() is set to sceneRadius() / tan(fieldOfView()/2) by this method.

Definition at line 194 of file camera.h.

References fieldOfView_, sceneRadius(), and setFocusDistance().

Referenced by setHorizontalFieldOfView().

void Camera::setFocusDistance ( float  distance  )  [inline]

Definition at line 199 of file camera.h.

References focusDistance_.

Referenced by setFieldOfView().

void Camera::setHorizontalFieldOfView ( float  hfov  )  [inline]

Sets the horizontalFieldOfView() of the Camera (in radians).

horizontalFieldOfView() and fieldOfView() are linked by the aspectRatio(). This method actually calls setFieldOfView(( 2.0 * atan (tan(hfov / 2.0) / aspectRatio()) )) so that a call to horizontalFieldOfView() returns the expected value.

Definition at line 208 of file camera.h.

References aspectRatio(), and setFieldOfView().

void Camera::setFOVToFitScene (  ) 

void Camera::setAspectRatio ( float  aspect  )  [inline]

Defines the Camera aspectRatio().

This value is actually inferred from the screenWidth() / screenHeight() ratio. You should use setScreenWidthAndHeight() instead.

This method might however be convenient when the Camera is not associated with a Viewer. It actually sets the screenHeight() to 100 and the screenWidth() accordingly. See also setFOVToFitScene().

If you absolutely need an aspectRatio() that does not correspond to your viewer's window dimensions, overload loadProjectionMatrix() or multiply the created GL_PROJECTION matrix by a scaled diagonal matrix in your Viewer::draw() method.

Definition at line 227 of file camera.h.

References setScreenWidthAndHeight().

void Camera::setScreenWidthAndHeight ( int  width,
int  height 

Referenced by setAspectRatio().

void Camera::setZNearCoefficient ( float  coef  )  [inline]

Sets the zNearCoefficient() value.

Definition at line 234 of file camera.h.

References zNearCoef_.

void Camera::setZClippingCoefficient ( float  coef  )  [inline]

Sets the zClippingCoefficient() value.

Definition at line 239 of file camera.h.

References zClippingCoef_.

float Camera::sceneRadius (  )  const [inline]

Returns the radius of the scene observed by the Camera.

You need to provide such an approximation of the scene dimensions so that the Camera can adapt its zNear() and zFar() values. See the sceneCenter() documentation.

See also setSceneBoundingBox().

Note that Viewer::sceneRadius() (resp. Viewer::setSceneRadius()) simply call this method (resp. setSceneRadius()) on its associated Viewer::camera().

Definition at line 258 of file camera.h.

References sceneRadius_.

Referenced by setFieldOfView().

Vec3 Camera::sceneCenter (  )  const [inline]

Returns the position of the scene center, defined in the world coordinate system.

The scene observed by the Camera should be roughly centered on this position, and included in a sceneRadius() sphere. This approximate description of the scene permits a zNear() and zFar() clipping planes definition, and allows convenient positioning methods such as showEntireScene().

Default value is (0,0,0) (world origin). Use setSceneCenter() to change it. See also setSceneBoundingBox().

Note that Viewer::sceneCenter() (resp. Viewer::setSceneCenter()) simply call this method (resp. setSceneCenter()) on its associated Viewer::camera().

Definition at line 274 of file camera.h.

References sceneCenter_.

float Camera::distanceToSceneCenter (  )  const

void Camera::setSceneRadius ( float  radius  ) 

void Camera::setSceneCenter ( const Vec3 center  ) 

bool Camera::setSceneCenterFromPixel ( const Vec3 pixel  ) 

void Camera::setSceneBoundingBox ( const Vec3 min,
const Vec3 max 

void Camera::setRevolveAroundPoint ( const Vec3 rap  ) 

bool Camera::setRevolveAroundPointFromPixel ( const Vec3 pixel  ) 

Frame* Camera::frame (  )  const [inline]

Returns the ManipulatedCameraFrame attached to the Camera.

This ManipulatedCameraFrame defines its position() and orientation() and can translate mouse events into Camera displacement. Set using setFrame().

Definition at line 314 of file camera.h.

References frame_.

Referenced by cameraCoordinatesOf(), orientation(), position(), setPosition(), viewDirection(), and worldCoordinatesOf().

void Camera::setFrame ( Frame *const   mcf  ) 

virtual void Camera::loadProjectionMatrix ( bool  reset = true  )  const [virtual]

virtual void Camera::loadModelViewMatrix ( bool  reset = true  )  const [virtual]

void Camera::computeProjectionMatrix (  )  const

void Camera::computeModelViewMatrix (  )  const

void Camera::getProjectionMatrix ( GLdouble  m[16]  )  const

void Camera::getModelViewMatrix ( GLdouble  m[16]  )  const

void Camera::getProjectionMatrix ( GLfloat  m[16]  )  const

void Camera::getModelViewMatrix ( GLfloat  m[16]  )  const

Vec3 Camera::cameraCoordinatesOf ( const Vec3 src  )  const [inline]

Returns the Camera frame coordinates of a point src defined in world coordinates.

worldCoordinatesOf() performs the inverse transformation.

Note that the point coordinates are simply converted in a different coordinate system. They are not projected on screen. Use projectedCoordinatesOf() for that.

Definition at line 347 of file camera.h.

References Frame::coordinatesOf(), and frame().

Vec3 Camera::worldCoordinatesOf ( const Vec3 src  )  const [inline]

Returns the world coordinates of the point whose position src is defined in the Camera coordinate system.

cameraCoordinatesOf() performs the inverse transformation.

Definition at line 355 of file camera.h.

References frame(), and Frame::inverseCoordinatesOf().

void Camera::getCameraCoordinatesOf ( const float  src[3],
float  res[3] 
) const

void Camera::getWorldCoordinatesOf ( const float  src[3],
float  res[3] 
) const

Vec3 Camera::projectedCoordinatesOf ( const Vec3 src,
const Frame frame = NULL 
) const

Vec3 Camera::unprojectedCoordinatesOf ( const Vec3 src,
const Frame frame = NULL 
) const

void Camera::getProjectedCoordinatesOf ( const float  src[3],
float  res[3],
const Frame frame = NULL 
) const

void Camera::getUnprojectedCoordinatesOf ( const float  src[3],
float  res[3],
const Frame frame = NULL 
) const

void Camera::convertClickToLine ( const Vec3 pixel,
Vec3 orig,
Vec3 dir 
) const

Vec3 Camera::pointUnderPixel ( const Vec3 pixel,
bool &  found 
) const

static void Camera::drawCamera ( float  scale = 1.0,
float  aspectRatio = 1.33,
float  fieldOfView = M_PI/4.0 
) [static]

virtual void Camera::draw ( bool  fitNearPlane = false  )  const [virtual]

Member Data Documentation

Returns the fly speed of the Camera.

Simply returns frame()->flySpeed(). See the ManipulatedCameraFrame::flySpeed() documentation. This value is only meaningful when the MouseAction bindings is Viewer::MOVE_FORWARD or Viewer::MOVE_BACKWARD.

Set to 0.5% of the sceneRadius() by setSceneRadius(). See also setFlySpeed().

Sets the Camera flySpeed().

This value is modified by setSceneRadius().

Definition at line 411 of file camera.h.

Referenced by frame().

Definition at line 412 of file camera.h.

Referenced by setFocusDistance().

Definition at line 414 of file camera.h.

Referenced by aspectRatio(), and screenWidth().

Definition at line 414 of file camera.h.

Referenced by aspectRatio(), and screenHeight().

Definition at line 415 of file camera.h.

Referenced by fieldOfView(), and setFieldOfView().

Definition at line 416 of file camera.h.

Referenced by sceneCenter().

Definition at line 417 of file camera.h.

Referenced by sceneRadius().

Definition at line 418 of file camera.h.

Referenced by setZNearCoefficient(), and zNearCoefficient().

Definition at line 419 of file camera.h.

Referenced by setZClippingCoefficient(), and zClippingCoefficient().

Definition at line 420 of file camera.h.

Definition at line 421 of file camera.h.

Referenced by type().

GLdouble Camera::modelViewMatrix_[16] [mutable]

Definition at line 422 of file camera.h.

GLdouble Camera::projectionMatrix_[16] [mutable]

Definition at line 423 of file camera.h.

The documentation for this struct was generated from the following file:

The miarn project - written by Joao Xavier