Easy3D 2.6.1
Loading...
Searching...
No Matches
Camera Class Reference

A perspective or orthographic camera. More...

#include <easy3d/renderer/camera.h>

Public Types

enum  Type { PERSPECTIVE , ORTHOGRAPHIC }
 Enumerates the two possible types of Camera. More...
 

Public Member Functions

 Camera ()
 Default constructor.
 
virtual ~Camera ()
 Destructor.
 
 Camera (const Camera &camera)
 Copy constructor.
 
Cameraoperator= (const Camera &camera)
 Assignment operator.
 
Position and orientation
vec3 position () const
 Get the position of the camera.
 
vec3 upVector () const
 Get the up vector of the camera.
 
vec3 viewDirection () const
 Get the view direction of the camera.
 
vec3 rightVector () const
 Get the right vector of the camera.
 
quat orientation () const
 Get the orientation of the camera.
 
void set_from_model_view_matrix (const mat4 &mv) const
 Sets the Camera's position() and orientation() from an OpenGL ModelView matrix.
 
void set_from_calibration (float fx, float fy, float skew, float cx, float cy, const mat3 &R, const vec3 &t, bool convert=true)
 Defines the position(), orientation() and fieldOfView() of the camera from calibrated camera intrinsic and extrinsic parameters. This function assumes the camera parameters were obtained by standard camera calibration, in which image coordinates are denoted in pixels, with the origin point (0, 0) corresponding to the top-left corner of the image. The X axis starts at the left edge of an image and goes towards the right edge. The Y axis starts at the top of the image towards image bottom. All image pixels have non-negative coordinates.
 
void set_from_calibration (const mat34 &proj)
 Defines the position(), orientation() and fieldOfView() of the camera from calibrated camera intrinsic and extrinsic parameters. This function assumes the camera parameters were obtained by standard camera calibration, in which image coordinates are denoted in pixels, with the origin point (0, 0) corresponding to the top-left corner of the image. The X axis starts at the left edge of an image and goes towards the right edge. The Y axis starts at the top of the image towards image bottom. All image pixels have non-negative coordinates.
 
void set_projection_matrix (const mat4 &proj)
 Temporally change the projection matrix.
 
void set_modelview_matrix (const mat4 &mv)
 Temporally change the modelview matrix.
 
void setPosition (const vec3 &pos) const
 Set the position of the camera.
 
void setOrientation (const quat &q) const
 Set the orientation of the camera.
 
void setOrientation (float theta, float phi) const
 Set the orientation of the camera.
 
void setUpVector (const vec3 &up, bool noMove=true) const
 Set the up vector of the camera.
 
void setViewDirection (const vec3 &direction) const
 Set the view direction of the camera.
 
Positioning tools
void lookAt (const vec3 &target) const
 Make the camera look at a target.
 
void showEntireScene () const
 Show the entire scene.
 
void fitSphere (const vec3 &center, float radius) const
 Move the camera so that entire sphere fits the screen.
 
void fitBoundingBox (const vec3 &min, const vec3 &max) const
 Move the camera so that entire box fits the screen.
 
void fitScreenRegion (int xmin, int ymin, int xmax, int ymax) const
 Moves the Camera so that the rectangular screen region fits the screen.
 
void centerScene () const
 Moves the Camera so that its sceneCenter() is projected in the center of the screen.
 
KeyFrameInterpolatorkeyframe_interpolator () const
 Get the keyframe interpolator.
 
void interpolateToLookAt (const vec3 &point)
 Perform keyframe interpolation to look at a point.
 
void interpolateToFitScene ()
 Perform keyframe interpolation to fit the scene.
 
void interpolateTo (const Frame *frame, float duration)
 Perform keyframe interpolation to a frame.
 
Type type () const
 Get the type of the camera.
 
float fieldOfView () const
 Returns the vertical field of view of the camera (in radians).
 
float horizontalFieldOfView () const
 Returns the horizontal field of view of the camera (in radians).
 
float aspectRatio () const
 Returns the Camera aspect ratio defined by screenWidth() / screenHeight().
 
int screenWidth () const
 Returns the width (in pixels) of the Camera screen.
 
int screenHeight () const
 Returns the height (in pixels) of the Camera screen.
 
float pixelGLRatio (const vec3 &position) const
 Get the pixel GL ratio at a position.
 
float zNearCoefficient () const
 Returns the coefficient which is used to set zNear() when the Camera is inside the sphere defined by sceneCenter() and zClippingCoefficient() * sceneRadius().
 
float zClippingCoefficient () const
 Returns the coefficient used to position the near and far clipping planes.
 
virtual float zNear () const
 Get the near clipping plane distance.
 
virtual float zFar () const
 Get the far clipping plane distance.
 
virtual void getOrthoWidthHeight (float &halfWidth, float &halfHeight) const
 Get the orthographic width and height.
 
void getFrustumPlanesCoefficients (float coef[6][4]) const
 Get the frustum planes coefficients.
 
void getFrustumPlanesCoefficients2 (float coef[6][4]) const
 Get the frustum planes coefficients (alternative version).
 
void setType (Type type)
 Set the type of the camera.
 
void setFieldOfView (float fov)
 Set the field of view of the camera.
 
void setHorizontalFieldOfView (float hfov)
 Sets the horizontalFieldOfView() of the Camera (in radians).
 
void setFOVToFitScene ()
 Set the field of view to fit the scene.
 
void setAspectRatio (float aspect)
 Defines the Camera aspectRatio().
 
void setScreenWidthAndHeight (int width, int height)
 Set the screen width and height.
 
void setZNearCoefficient (float coef)
 Set the zNear coefficient.
 
void setZClippingCoefficient (float coef)
 Set the zClipping coefficient.
 
Scene radius and center
float sceneRadius () const
 Returns the radius of the scene observed by the Camera.
 
vec3 sceneCenter () const
 Returns the position of the scene center, defined in the world coordinate system.
 
float distanceToSceneCenter () const
 Get the distance to the scene center.
 
void setSceneRadius (float radius)
 Set the radius of the scene.
 
void setSceneCenter (const vec3 &center)
 Set the center of the scene.
 
void setSceneBoundingBox (const vec3 &min, const vec3 &max)
 Set the bounding box of the scene.
 
void setPivotPoint (const vec3 &point)
 Set the pivot point of the camera. After this method is called, the Camera rotates around this point.
 
vec3 pivotPoint () const
 Get the pivot point of the camera.
 
ManipulatedCameraFrameframe () const
 Returns the ManipulatedFrame attached to the Camera.
 
void setFrame (ManipulatedCameraFrame *const mcf)
 Set the manipulated frame of the camera.
 
void computeProjectionMatrix ()
 Compute the projection matrix.
 
void computeModelViewMatrix ()
 Compute the model view matrix.
 
const mat4projectionMatrix () const
 Get the projection matrix.
 
const mat4modelViewMatrix () const
 Get the model view matrix.
 
mat4 modelViewProjectionMatrix () const
 Get the model view projection matrix.
 
World to Camera coordinate systems conversions
vec3 cameraCoordinatesOf (const vec3 &src) const
 Convert world coordinates to camera coordinates.
 
vec3 worldCoordinatesOf (const vec3 &src) const
 Convert camera coordinates to world coordinates.
 

2D screen to 3D world coordinate systems conversions

Signal frame_modified
 A signal indicating the frame has been modified.
 
vec3 projectedCoordinatesOf (const vec3 &src, const Frame *frame=nullptr) const
 Returns the screen projected coordinates of a 3D point defined in the frame coordinate system. When frame in NULL (default), src is expressed in the world coordinate system.
 
vec3 unprojectedCoordinatesOf (const vec3 &src, const Frame *frame=nullptr) const
 Returns the world unprojected coordinates of a point defined in the screen coordinate system. The result is expressed in the frame coordinate system. When frame is NULL (default), the result is expressed in the world coordinate system.
 
void convertClickToLine (int x, int y, vec3 &orig, vec3 &dir) const
 Returns the coefficients of a 3D half-line passing through the Camera eye and pixel (x, y).
 

Detailed Description

A perspective or orthographic camera.

A Camera defines some intrinsic parameters (fieldOfView(), position(), viewDirection(), upVector()...) and useful positioning tools that ease its placement (showEntireScene(), fitSphere(), lookAt()...). It exports its associated OpenGL projection and modelview matrices and can interactively be modified using the mouse.

Mouse manipulation

The position() and orientation() of the Camera are defined by a ManipulatedFrame (retrieved using frame()). These methods are just convenient wrappers to the equivalent Frame methods. This also means that the Camera frame() can be attached to a Frame::referenceFrame() which enables complex Camera setups.

If a pivotPoint() has been set, the Camera observes a scene and rotates around its pivotPoint().

Other functionalities

The type() of the Camera can be Camera::ORTHOGRAPHIC or Camera::PERSPECTIVE (see Type()). fieldOfView() is meaningless with Camera::ORTHOGRAPHIC.

The near and far planes of the Camera are fitted to the scene and determined from scene radius, scene center, and zClippingCoefficient() by the zNear() and zFar() methods. Reasonable values on the scene extends hence have to be provided to the Camera to correctly display the scene. High level positioning methods also use this information (showEntireScene(), centerScene()...).

A Camera holds KeyFrameInterpolator that can be used to save Camera positions and paths. You can interactively addKeyFrameToPath() to a given path. Use playPath() to make the Camera follow the path.

Use cameraCoordinatesOf() and 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.

A Camera can also be used outside a viewer or even without OpenGL for its coordinate system conversion capabilities. Note however that some of them explicitly rely on the presence of a Z-buffer.

To use the camera, you need to do the following:

  • Create and (if necessary) setup camera in the constructor of your viewer.
    camera_ = new Camera;
    camera_->setType(Camera::PERSPECTIVE);
    camera_->setUpVector(vec3(0, 0, 1)); // Z pointing up
    camera_->setViewDirection(vec3(-1, 0, 0)); // X pointing out
    camera_->showEntireScene(); // position and orient the camera
    camera_->connect(this, &Viewer::update); // connect the viewer's update function
    @ PERSPECTIVE
    Perspective camera.
    Definition camera.h:144
    Camera()
    Default constructor.
    void update() const
    Update the display (i.e., repaint).
    Definition viewer.cpp:630
    Vec< 3, float > vec3
    A 3D point/vector of float type.
    Definition types.h:44
  • Call camera_->setScreenWidthAndHeight() at both
    • creation or initialization (i.e., before the viewer appears) of the application;
    • change of the window size.
  • Call camera_->frame()->action_start() on mouse down and camera_->frame()->action_end() on mouse up.
  • Call camera_->frame()->action_rotate() on mouse move for rotation and camera_->frame()->action_translate() on mouse move for translation and camera_->frame()->action_zoom() on mouse move for zoom

To make the entire scene visible, call camera_->setSceneBoundingBox() and camera_->showEntireScene() ;

To retrieve the model view projection matrix, call camera_->modelViewProjectionMatrix()

Examples
Tutorial_207_RealCamera/main.cpp.

Member Enumeration Documentation

◆ Type

enum Type

Enumerates the two possible types of Camera.

See type() and setType(). This type mainly defines different Camera projection matrix (see loadProjectionMatrix()). Many other methods (convertClickToLine(), projectedCoordinatesOf(), pixelGLRatio()...) are affected by this Type.

Enumerator
PERSPECTIVE 

Perspective camera.

ORTHOGRAPHIC 

Orthographic camera.

Constructor & Destructor Documentation

◆ Camera()

Camera ( const Camera & camera)

Copy constructor.

Parameters
cameraThe camera to copy.

Member Function Documentation

◆ aspectRatio()

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

Returns
The aspect ratio.

◆ cameraCoordinatesOf()

vec3 cameraCoordinatesOf ( const vec3 & src) const

Convert world coordinates to camera coordinates.

Parameters
srcThe source coordinates in world space.
Returns
The coordinates in camera space.

◆ centerScene()

void centerScene ( ) const

Moves the Camera so that its sceneCenter() is projected in the center of the screen.

This method simply projects the current position on a line passing through sceneCenter(). The orientation() and fieldOfView() are unchanged.

See also
showEntireScene()

◆ convertClickToLine()

void convertClickToLine ( int x,
int y,
vec3 & orig,
vec3 & dir ) const

Returns the coefficients of a 3D half-line passing through the Camera eye and pixel (x, y).

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. x and y are expressed as the origin defined in the upper left corner. Use screenHeight() - y - 1 to convert to OpenGL units.

Parameters
xThe x coordinate of the click.
yThe y coordinate of the click.
origThe origin of the line.
dirThe direction of the line.

◆ distanceToSceneCenter()

float distanceToSceneCenter ( ) const

Get the distance to the scene center.

Returns
The distance to the scene center.

◆ fieldOfView()

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

Examples
Tutorial_207_RealCamera/main.cpp.

◆ fitBoundingBox()

void fitBoundingBox ( const vec3 & min,
const vec3 & max ) const

Move the camera so that entire box fits the screen.

Parameters
minThe minimum corner of the bounding box.
maxThe maximum corner of the bounding box.

◆ fitScreenRegion()

void fitScreenRegion ( int xmin,
int ymin,
int xmax,
int ymax ) const

Moves the Camera so that the rectangular screen region fits the screen.

The rectangular screen region is defined in pixel units, with origin in the upper left corner. The Camera is translated (its orientation() is unchanged) so that rectangle is entirely visible. Since the pixel coordinates only define a frustum in 3D, it's the intersection of this frustum with a plane (orthogonal to the viewDirection() and passing through the sceneCenter()) that is used to define the 3D rectangle that is eventually fitted.

Parameters
xminThe minimum x coordinate.
yminThe minimum y coordinate.
xmaxThe maximum x coordinate.
ymaxThe maximum y coordinate.

◆ fitSphere()

void fitSphere ( const vec3 & center,
float radius ) const

Move the camera so that entire sphere fits the screen.

Parameters
centerThe center of the sphere.
radiusThe radius of the sphere.

◆ frame()

ManipulatedCameraFrame * frame ( ) const
inline

Returns the ManipulatedFrame attached to the Camera.

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

Returns
The manipulated frame.
Examples
Tutorial_204_Viewer_Qt/main.cpp, and Tutorial_207_RealCamera/main.cpp.

◆ getFrustumPlanesCoefficients()

void getFrustumPlanesCoefficients ( float coef[6][4]) const

Get the frustum planes coefficients.

Parameters
coefThe coefficients. The six 4-component vectors of coef respectively correspond to the left, right, near, far, top and bottom Camera frustum planes. Each vector holds a plane equation of the form:
a*x + b*y + c*z + d = 0
where a,b, c, and d are the 4 components of each vector, in that order.

◆ getFrustumPlanesCoefficients2()

void getFrustumPlanesCoefficients2 ( float coef[6][4]) const

Get the frustum planes coefficients (alternative version).

Parameters
coefThe coefficients. The six 4-component vectors of coef respectively correspond to the left, right, near, far, top and bottom Camera frustum planes. Each vector holds a plane equation of the form:
a*x + b*y + c*z + d = 0
where a,b, c, and d are the 4 components of each vector, in that order.

◆ getOrthoWidthHeight()

virtual void getOrthoWidthHeight ( float & halfWidth,
float & halfHeight ) const
virtual

Get the orthographic width and height.

Parameters
halfWidthThe half width.
halfHeightThe half height.

◆ horizontalFieldOfView()

float horizontalFieldOfView ( ) const
inline

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

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

horizontalFieldOfView() = 2.0 * std::atan( std::tan(fieldOfView()/2.0) * aspectRatio() ).
float aspectRatio() const
Returns the Camera aspect ratio defined by screenWidth() / screenHeight().
Definition camera.h:396
float fieldOfView() const
Returns the vertical field of view of the camera (in radians).
Definition camera.h:376
float horizontalFieldOfView() const
Returns the horizontal field of view of the camera (in radians).
Definition camera.h:386
Returns
The horizontal field of view in radians.

◆ interpolateTo()

void interpolateTo ( const Frame * frame,
float duration )

Perform keyframe interpolation to a frame.

Parameters
frameThe frame to interpolate to.
durationThe duration of the interpolation.

◆ interpolateToLookAt()

void interpolateToLookAt ( const vec3 & point)

Perform keyframe interpolation to look at a point.

Parameters
pointThe point to look at.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ keyframe_interpolator()

KeyFrameInterpolator * keyframe_interpolator ( ) const
inline

Get the keyframe interpolator.

Returns
The keyframe interpolator.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ lookAt()

void lookAt ( const vec3 & target) const

Make the camera look at a target.

Parameters
targetThe target to look at.

◆ modelViewMatrix()

const mat4 & modelViewMatrix ( ) const

Get the model view matrix.

Returns
The model view matrix.

◆ modelViewProjectionMatrix()

mat4 modelViewProjectionMatrix ( ) const

Get the model view projection matrix.

Returns
The model view projection matrix.

◆ operator=()

Camera & operator= ( const Camera & camera)

Assignment operator.

Parameters
cameraThe camera to assign.
Returns
A reference to this camera.

◆ orientation()

quat orientation ( ) const

Get the orientation of the camera.

Returns
The orientation of the camera.

◆ pivotPoint()

vec3 pivotPoint ( ) const

Get the pivot point of the camera.

Returns
The pivot point.

◆ pixelGLRatio()

float pixelGLRatio ( const vec3 & position) const

Get the pixel GL ratio at a position.

Parameters
positionThe position.
Returns
The pixel GL ratio.

◆ position()

vec3 position ( ) const

Get the position of the camera.

Returns
The position of the camera.

◆ projectedCoordinatesOf()

vec3 projectedCoordinatesOf ( const vec3 & src,
const Frame * frame = nullptr ) const

Returns the screen projected coordinates of a 3D point defined in the frame coordinate system. When frame in NULL (default), src is expressed in the world coordinate system.

Parameters
srcThe source coordinates in world space.
frameThe frame to use for the conversion.
Returns
The coordinates in screen space.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ projectionMatrix()

const mat4 & projectionMatrix ( ) const

Get the projection matrix.

Returns
The projection matrix.

◆ rightVector()

vec3 rightVector ( ) const

Get the right vector of the camera.

Returns
The right vector of the camera.

◆ sceneCenter()

vec3 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.

Returns
The center of the scene.
See also
setSceneBoundingBox().

◆ sceneRadius()

float 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.

Returns
The radius of the scene.
See also
setSceneBoundingBox().
Examples
Tutorial_204_Viewer_Qt/main.cpp, and Tutorial_207_RealCamera/main.cpp.

◆ screenHeight()

int 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.

Returns
The height in pixels.

◆ screenWidth()

int 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.

Returns
The width in pixels.

◆ set_from_calibration() [1/2]

void set_from_calibration ( const mat34 & proj)

Defines the position(), orientation() and fieldOfView() of the camera from calibrated camera intrinsic and extrinsic parameters. This function assumes the camera parameters were obtained by standard camera calibration, in which image coordinates are denoted in pixels, with the origin point (0, 0) corresponding to the top-left corner of the image. The X axis starts at the left edge of an image and goes towards the right edge. The Y axis starts at the top of the image towards image bottom. All image pixels have non-negative coordinates.

Parameters
projThe projection matrix, which can be computed as P = K * M * [R|t], where R is a 3x3 matrix representing the camera rotation, and t is a 3D vector describing the camera translation (rotation first then translation).
Attention
The additional M is a 3 by 3 matrix that converts the coordinate system from the vision convention to the OpenGL convention (i.e., inverting Y and Z axes), i.e., M(1, 1) = -1; // invert the Y axis M(2, 2) = -1; // invert the Z axis This is because the camera coordinates in computer vision goes X right, Y down, Z forward, while the camera coordinates in OpenGL goes X right, Y up, Z inward.
See also
set_from_calibration.

◆ set_from_calibration() [2/2]

void set_from_calibration ( float fx,
float fy,
float skew,
float cx,
float cy,
const mat3 & R,
const vec3 & t,
bool convert = true )

Defines the position(), orientation() and fieldOfView() of the camera from calibrated camera intrinsic and extrinsic parameters. This function assumes the camera parameters were obtained by standard camera calibration, in which image coordinates are denoted in pixels, with the origin point (0, 0) corresponding to the top-left corner of the image. The X axis starts at the left edge of an image and goes towards the right edge. The Y axis starts at the top of the image towards image bottom. All image pixels have non-negative coordinates.

Parameters
fxThe focal length in the x direction.
fyThe focal length in the y direction.
skewThe skew coefficient.
cxThe principal point in the x direction.
cyThe principal point in the y direction.
RThe rotation matrix. It denotes the coordinate system transformation from 3D world coordinates to 3D camera coordinates.
tThe translation vector. It is the position of the origin of the world coordinate system expressed in the camera coordinate system.
Note
t is often mistakenly considered the position of the camera. The position of the camera expressed in world coordinates is C = -inverse(R) * t = -transpose(R) * t.
Parameters
convertTrue to convert from vision convention to OpenGL convention (i.e., invert Y and Z axes). This is because the camera coordinates of computer vision goes X right, Y down, Z forward, while the camera coordinates of OpenGL goes X right, Y up, Z inward.
See also
set_from_calibration.
Examples
Tutorial_207_RealCamera/main.cpp.

◆ set_from_model_view_matrix()

void set_from_model_view_matrix ( const mat4 & mv) const

Sets the Camera's position() and orientation() from an OpenGL ModelView matrix.

This enables a Camera initialisation from another OpenGL application. After this method has been called, getModelViewMatrix() returns a matrix equivalent to mv. Only the orientation() and position() of the Camera are modified.

Parameters
mvThe model view matrix.

◆ set_modelview_matrix()

void set_modelview_matrix ( const mat4 & mv)

Temporally change the modelview matrix.

Parameters
mvThe modelview matrix.
Attention
This function directly changes the modelview matrix. It actually doesn't change any of the camera parameters (i.e., position, orientation, fov, zFar, zNear, etc.). This is only useful if you want to temporally use a different modelview matrix for rendering (e.g., grabbing a snapshot from the framebuffer).

◆ set_projection_matrix()

void set_projection_matrix ( const mat4 & proj)

Temporally change the projection matrix.

Parameters
projThe projection matrix.
Attention
This function directly changes the projection matrix. It actually doesn't change any of the camera parameters (i.e., position, orientation, fov, zFar, zNear, etc.). This is only useful if you want to temporally use a different projection matrix for rendering (e.g., grabbing a snapshot from the framebuffer).

◆ setAspectRatio()

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

Parameters
aspectThe aspect ratio.
Note
If you absolutely need an aspectRatio() that does not correspond to your viewer's window dimensions, overload loadProjectionMatrix() or multiply the created OpenGL projection matrix by a scaled diagonal matrix in your viewer's draw() method.

◆ setFieldOfView()

void setFieldOfView ( float fov)

Set the field of view of the camera.

Parameters
fovThe field of view in radians.
Examples
Tutorial_207_RealCamera/main.cpp.

◆ setFrame()

void setFrame ( ManipulatedCameraFrame *const mcf)

Set the manipulated frame of the camera.

Parameters
mcfThe manipulated frame.

◆ setHorizontalFieldOfView()

void 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 * std::atan (std::tan(hfov / 2.0) / aspectRatio()) )) so that a call to horizontalFieldOfView() returns the expected value.

Parameters
hfovThe horizontal field of view in radians.

◆ setOrientation() [1/2]

void setOrientation ( const quat & q) const

Set the orientation of the camera.

Parameters
qThe orientation of the camera.
Examples
Tutorial_207_RealCamera/main.cpp.

◆ setOrientation() [2/2]

void setOrientation ( float theta,
float phi ) const

Set the orientation of the camera.

Parameters
thetaThe theta angle.
phiThe phi angle.

◆ setPivotPoint()

void setPivotPoint ( const vec3 & point)

Set the pivot point of the camera. After this method is called, the Camera rotates around this point.

Parameters
pointThe pivot point.

◆ setPosition()

void setPosition ( const vec3 & pos) const

Set the position of the camera.

Parameters
posThe position of the camera.
Examples
Tutorial_207_RealCamera/main.cpp.

◆ setSceneBoundingBox()

void setSceneBoundingBox ( const vec3 & min,
const vec3 & max )

Set the bounding box of the scene.

This method sets the scene center and radius from the bounding box.

Parameters
minThe minimum corner of the bounding box.
maxThe maximum corner of the bounding box.

◆ setSceneCenter()

void setSceneCenter ( const vec3 & center)

Set the center of the scene.

Parameters
centerThe center of the scene.

◆ setSceneRadius()

void setSceneRadius ( float radius)

Set the radius of the scene.

Parameters
radiusThe radius of the scene.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ setScreenWidthAndHeight()

void setScreenWidthAndHeight ( int width,
int height )

Set the screen width and height.

Parameters
widthThe width in pixels.
heightThe height in pixels.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ setType()

void setType ( Type type)

Set the type of the camera.

Parameters
typeThe type of the camera.

◆ setUpVector()

void setUpVector ( const vec3 & up,
bool noMove = true ) const

Set the up vector of the camera.

Parameters
upThe up vector.
noMoveTrue to not move the camera.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ setViewDirection()

void setViewDirection ( const vec3 & direction) const

Set the view direction of the camera.

Parameters
directionThe view direction.
Examples
Tutorial_204_Viewer_Qt/main.cpp.

◆ setZClippingCoefficient()

void setZClippingCoefficient ( float coef)
inline

Set the zClipping coefficient.

Parameters
coefThe zClipping coefficient.

◆ setZNearCoefficient()

void setZNearCoefficient ( float coef)
inline

Set the zNear coefficient.

Parameters
coefThe zNear coefficient.

◆ type()

Type type ( ) const
inline

Get the type of the camera.

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 pivotPoint() using getOrthoWidthHeight(). Both types use zNear() and zFar() (to define their clipping planes) and aspectRatio() (for frustum shape).

Returns
The type of the camera.

◆ unprojectedCoordinatesOf()

vec3 unprojectedCoordinatesOf ( const vec3 & src,
const Frame * frame = nullptr ) const

Returns the world unprojected coordinates of a point defined in the screen coordinate system. The result is expressed in the frame coordinate system. When frame is NULL (default), the result is expressed in the world coordinate system.

Parameters
srcThe source coordinates in screen space.
frameThe frame to use for the conversion.
Returns
The unprojected coordinates.

◆ upVector()

vec3 upVector ( ) const

Get the up vector of the camera.

Returns
The up vector of the camera.

◆ viewDirection()

vec3 viewDirection ( ) const

Get the view direction of the camera.

Returns
The view direction of the camera.

◆ worldCoordinatesOf()

vec3 worldCoordinatesOf ( const vec3 & src) const

Convert camera coordinates to world coordinates.

Parameters
srcThe source coordinates in camera space.
Returns
The coordinates in world space.

◆ zClippingCoefficient()

float 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 guarantees 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. For a total control on clipping planes' positions, another option is to overload the zNear() and zFar() methods.

Attention
When you visualize the Camera paths, set a larger value (suggested value is 5.0) so that the Camera paths are not clipped. Don't forget to restore the previous zClippingCoefficient() value back when you leave this mode.
Returns
The zClipping coefficient.
See also
zNearCoefficient().

◆ zFar()

virtual float zFar ( ) const
virtual

Get the far clipping plane distance.

Returns
The far clipping plane distance.

◆ zNear()

virtual float zNear ( ) const
virtual

Get the near clipping plane distance.

Returns
The near clipping plane distance.

◆ zNearCoefficient()

float 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.001, 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 the worst Z precision. Only meaningful when Camera type is Camera::PERSPECTIVE.

Returns
The zNear coefficient.

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