Workspace 6.21.5
Public Types | Public Member Functions | Protected Member Functions | List of all members
Camera Class Reference

Defines a positionable, orientable camera for a scene. More...

#include <Rendering/SceneComponents/Cameras/camera.h>

Inheritance diagram for Camera:
[legend]

Public Types

enum  ProjectionMode { Perspective , Orthographic }
 

Public Member Functions

 Camera (const Camera &camera)
 
 Camera (const QString &id="")
 
 ~Camera () override
 
void calcGlobalVectors (Mesh::Vector3d &position, Mesh::Vector3d &view, Mesh::Vector3d &up, Mesh::Vector3d &across) const
 
Cameraclone () const override
 
double getFarClippingPlane () const
 
double getFieldOfViewX () const
 
double getFieldOfViewY () const
 
const CameraInteractionOptionsgetInteractionOptions () const
 
CameraInteractionsFactory::InteractionTypes getInteractionTypeFlags () const
 
double getLodDistanceBias () const
 
Mesh::TransformMatrix getMatrix () const
 
Mesh::TransformMatrix getMatrixGlobal () const override
 
Mesh::TransformMatrix getMatrixLocal () const override
 
double getNearClippingPlane () const
 
Mesh::Vector3d getOrientation () const
 
double getOrthoViewVolume () const
 
Mesh::Vector3d getPosition () const
 
virtual Mesh::TransformMatrix getProjectionMatrix (int viewportWidth, int viewportHeight) const
 
ProjectionMode getProjectionMode () const
 
ShadergetSymbolShader () const
 
const SceneItemgetTrackingTarget () const
 
Mesh::TransformByComponents getTransform () const
 
Mesh::Vector3d getUpVector () const
 
bool getUseFieldOfViewX () const
 
virtual Mesh::TransformMatrix getViewMatrixInverse () const
 
Cameraoperator= (const Camera &camera)
 
void setFarClippingPlane (double zFar)
 
void setFieldOfViewX (double fov)
 
void setFieldOfViewY (double fov)
 
void setInteractionOptions (const CameraInteractionOptions &options)
 
void setLodDistanceBias (double bias)
 
void setMatrix (const Mesh::TransformMatrix &m)
 
void setNearClippingPlane (double zNear)
 
void setOrthoViewVolume (double size)
 
void setProjectionMode (ProjectionMode mode)
 
void setShowSymbol (bool show)
 
void setSymbolShader (Shader *shader)
 
void setTrackingTarget (const SceneItem *target)
 
void setTransform (const Mesh::TransformByComponents &transform)
 
void setUseFieldOfViewX (bool b)
 
bool showSymbol () const
 
void updateGlobalMatrix () override
 
bool visit (SceneProcessor &processor) override
 
- Public Member Functions inherited from SceneItem
 ~SceneItem () override
 
SceneItemclone () const override=0
 
bool getEnabled () const
 
const QString & getId () const
 
const Mesh::BoundingBoxMinimalgetLocalBoundingBox () const
 
virtual Mesh::TransformMatrix getMatrixGlobal () const
 
virtual Mesh::TransformMatrix getMatrixLocal () const
 
const QString & getName () const
 
Mesh::TransformMatrix getParentMatrixGlobal () const
 
TransformgetParentTransform ()
 
void setEnabled (bool b)
 
void setId (const QString &itemId)
 
virtual void setLocalBoundingBox (const Mesh::BoundingBoxMinimal &bb)
 
void setName (const QString &name)
 
virtual TransformtoTransform ()
 
virtual const TransformtoTransform () const
 
virtual void updateGlobalMatrix ()
 
virtual bool visit (SceneProcessor &processor)=0
 
- Public Member Functions inherited from Observable
virtual ~Observable ()
 
void attachObserver (Observer &observer)
 
void destroy ()
 
void detachObserver (Observer &observer)
 
void notifyEvent (const ObservableEvent &event)
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()=default
 
virtual Clonableclone () const =0
 

Protected Member Functions

virtual Mesh::TransformMatrix getPerspectiveProjectionMatrix (int viewportWidth, int viewportHeight) const
 
- Protected Member Functions inherited from SceneItem
 SceneItem (const QString &id)
 
 SceneItem (const SceneItem &item)
 
virtual void addToScene (Scene &scene, const QString &opIdPath="")
 
bool isTransformModified () const
 
SceneItemoperator= (const SceneItem &item)
 
void setTransformModified (bool b)
 
- Protected Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 

Detailed Description

The default transform of the camera results in it being initially:

The transform matrix can be manipulated to change the position and orientation of the camera, but scaling the camera will probably lead to unexpected effects.

Other camera properties such as the field of view and the near and far clipping planes can also be set to customize the image produced in the viewport during rendering.

Member Enumeration Documentation

◆ ProjectionMode

Enumerator
Perspective 
Orthographic 

Constructor & Destructor Documentation

◆ Camera() [1/2]

Camera ( const QString &  id = "")

◆ Camera() [2/2]

Camera ( const Camera camera)

◆ ~Camera()

~Camera ( )
override

Member Function Documentation

◆ calcGlobalVectors()

void calcGlobalVectors ( Mesh::Vector3d position,
Mesh::Vector3d view,
Mesh::Vector3d up,
Mesh::Vector3d across 
) const
Parameters
upUpon exit, this will hold the camera's up vector in global co-ordinates.
acrossUpon exit, this will hold the camera's across vector in global co-ordinates (ie to the right)
viewUpon exit, this will hold the camera's view vector in global co-ordinates (ie the direction in which the camera is looking)
positionUpon exit, this will hold the global position of the camera.

◆ clone()

Camera * clone ( ) const
overridevirtual
Returns
A clone of this object.
Note
Subclasses would normally return their own type rather than the Clonable type. The C++ language rules allow a more derived type to be returned from a virtual function and the compiler will still treat it as a valid override.

Implements SceneItem.

◆ getFarClippingPlane()

double getFarClippingPlane ( ) const
Returns
The far clipping plane Z distance.
See also
setFarClippingPlane(), setNearClippingPlane()

◆ getFieldOfViewX()

double getFieldOfViewX ( ) const
Returns
The current horizontal field of view value.

◆ getFieldOfViewY()

double getFieldOfViewY ( ) const
Returns
The current vertical field of view value.
See also
setFieldOfViewY()

◆ getInteractionOptions()

const CameraInteractionOptions & getInteractionOptions ( ) const
Returns
The interaction options provided by the camera.

◆ getInteractionTypeFlags()

CameraInteractionsFactory::InteractionTypes getInteractionTypeFlags ( ) const
Returns

◆ getLodDistanceBias()

double getLodDistanceBias ( ) const
Returns
The distance bias that will be added to the computed LOD distance.
See also
setLodDistanceBias

Set a LOD bias in order to modify the distance at which different LOD levels are selected for view for this particular camera. A larger value leads to a longer view distance before a lower resolution LOD is picked.

◆ getMatrix()

TransformMatrix getMatrix ( ) const
Returns
The currently set local transform matrix.

This function is thread-safe (which is related to why the matrix is returned by value instead of by reference).

◆ getMatrixGlobal()

Mesh::TransformMatrix getMatrixGlobal ( ) const
overridevirtual
Returns
The camera's transform matrix in global (world) coordinates. This is equivalent to multiplying all its parent transforms' transform matrices together along with the camera's own transform matrix.

Reimplemented from SceneItem.

◆ getMatrixLocal()

Mesh::TransformMatrix getMatrixLocal ( ) const
overridevirtual
Returns
The camera's local transform matrix.

Reimplemented from SceneItem.

◆ getNearClippingPlane()

double getNearClippingPlane ( ) const
Returns
The near clipping plane Z distance.
See also
setNearClippingPlane(), setFarClippingPlane()

◆ getOrientation()

Vector3d getOrientation ( ) const
Returns
The camera orientation in global co-ordinates of the scene it is part of. If it is not part of a scene, then just its local transformation will determine its orientation because it will have no parent transform.

A camera with no transformation points in the direction of the negative Z axis and has its up vector along the positive Y axis. This is the convention used by OpenGL.

See also
getPosition(), getUpVector()

◆ getOrthoViewVolume()

double getOrthoViewVolume ( ) const
Returns
The size of the view volume for an orthographic camera.

◆ getPerspectiveProjectionMatrix()

Mesh::TransformMatrix getPerspectiveProjectionMatrix ( int  viewportWidth,
int  viewportHeight 
) const
protectedvirtual
Parameters
viewportWidthThe width of the target viewport
viewportHeightThe height of the target viewport
Returns
Returns the perspective projection matrix corresponding to the camera's settings. This method should be overridden by subclasses that wish to provide a more advanced computation than the simple "virtual" camera provided here, for example, to replicate the intrinsic parameters of a physical camera.

◆ getPosition()

Vector3d getPosition ( ) const
Returns
The camera position in global co-ordinates of the scene it is part of. If it is not part of a scene, then just its local transformation will determine its position because it will have no parent transform.

This is essentially the translation component of the result of multiplying the parent matrix by the local matrix.

See also
getOrientation(), getUpVector()

◆ getProjectionMatrix()

Mesh::TransformMatrix getProjectionMatrix ( int  viewportWidth,
int  viewportHeight 
) const
virtual
Parameters
viewportWidthThe width of the target viewport
viewportHeightThe height of the target viewport
Returns
The projection matrix corresponding to the camera's settings. If the camera is orthographic, this will be a simple orthographic projection matrix. If it's a perspective projection, this could vary depending upon the settings of the camera.

◆ getProjectionMode()

Camera::ProjectionMode getProjectionMode ( ) const
Returns
The projection mode of the camera: Orthographic or Perspective.

◆ getSymbolShader()

Shader * getSymbolShader ( ) const
Returns

◆ getTrackingTarget()

const SceneItem * getTrackingTarget ( ) const
Returns

◆ getTransform()

Mesh::TransformByComponents getTransform ( ) const
Returns
The currently set local transform.

This function is thread-safe (which is related to why the result is returned by value instead of by reference).

◆ getUpVector()

Vector3d getUpVector ( ) const
Returns
The up vector of the camera in global co-ordinates of the scene it is part of. If it is not part of a scene, then just its local transformation will determine its up vector because it will have no parent transform.

A camera with no transformation points in the direction of the negative Z axis and has its up vector along the positive Y axis. This is the convention used by OpenGL.

See also
getPosition(), getOrientation()

◆ getUseFieldOfViewX()

bool getUseFieldOfViewX ( ) const
Returns
Whether or not to use the horizontal field of view.

◆ getViewMatrixInverse()

Mesh::TransformMatrix getViewMatrixInverse ( ) const
virtual
Returns

◆ operator=()

Camera & operator= ( const Camera camera)

◆ setFarClippingPlane()

void setFarClippingPlane ( double  zFar)
Parameters
zFarThe far clipping plane Z distance. It must always be positive and greater than the near clipping plane.

The far clipping plane specifies the distance along the camera's line of sight from the camera to the furthest point to be kept visible. Anything further than this from the camera will be clipped and not rendered.

Specifying a far clipping plane that is too close can result in the scene being truncated or clipped away entirely. If set a little too close, it may seem that some parts of the scene are unexplainably missing, since closer objects still appear just fine. In such cases, their camera-facing surfaces may be close enough to be in front of the far clipping plane, but the rear-facing surfaces may be getting clipped without the viewer's knowledge. Objects towards the rear of the scene may be clipped away and thus appear to be missing from the scene.

Conversely, setting the far clipping plane too far away can degrade the calculation of the depth buffer during rendering, resulting in poor image quality where surfaces are close to each other or where they intersect.

The distance between the near and far clipping planes is very important from the point of view of rendering quality. The larger the distance between them, the greater the loss in precision when determining the depth ordering of pixels. A rough guide would be to aim to have the near and far distances no more than a few orders of magnitude apart.

◆ setFieldOfViewX()

void setFieldOfViewX ( double  fov)
Parameters
fov

◆ setFieldOfViewY()

void setFieldOfViewY ( double  fov)
Parameters
fovThe vertical field of view to use for this camera, specified in degrees. It must be between 0 and 180 degrees, althought typical values would be somewhere around 20 degrees.

Most people know of the field of view through things like a wide-angle lens. It defines how much of a scene should fit within a particular viewing window assumed to be of a particular size. Changing the field of view essentially corresponds to moving that fixed-size viewing window forward or back. Alternatively, if the viewing window is kept in a fixed position, changing the field of view is like changing the size of that window.

Mathematically, the field of view is the angle at the camera between the top and bottom of the viewing window. The larger the angle, the closer the viewer tends to feel to an object. A wide-angle lens would tend to have a large field of view. Note that having an unrealistically large field of view will distort the image.

For more information on the field of view, consult the OpenGL Programming Guide, Chapter 3: Viewing.

◆ setInteractionOptions()

void setInteractionOptions ( const CameraInteractionOptions options)
Parameters
optionsThe options to limit camera interactions.

◆ setLodDistanceBias()

void setLodDistanceBias ( double  bias)
Parameters
biasThe distance bias to add to the LOD distance computation.
See also
getLodDistanceBias

Set a LOD bias in order to modify the distance at which different LOD levels are selected for view for this particular camera. A larger value leads to a longer view distance before a lower resolution LOD is picked.

◆ setMatrix()

void setMatrix ( const Mesh::TransformMatrix m)
Parameters
mThe new local transform matrix. Any shear or scale components will be ignored.

This function is thread-safe.

Note
It is generally more efficient to work with the translation and rotation directly rather than passing in a transform matrix. This function only exists to facilitate code that needs to calculate things in the global co-ordinate frame and then work out a local transform for the camera, which is what the CameraInteraction class typically does.

◆ setNearClippingPlane()

void setNearClippingPlane ( double  zNear)
Parameters
zNearThe near clipping plane Z distance. It must always be positive and less than the far clipping plane.

The near clipping plane specifies the distance along the camera's line of sight from the camera to the closest point to be kept visible. Anything closer than this to the camera will be clipped and not rendered.

Specifying a near clipping plane that is too far away can result in the scene being truncated or clipped away entirely. Conversely, setting the near clipping plane too close can degrade the calculation of the depth buffer during rendering, resulting in poor image quality where surfaces are close to each other or where they intersect. See setFarClippingPlane() for more on this.

◆ setOrthoViewVolume()

void setOrthoViewVolume ( double  size)
Parameters
sizeThe size of the view volume for an orthographic camera.

◆ setProjectionMode()

void setProjectionMode ( ProjectionMode  mode)
Parameters
modeThe projection mode of the camera; Perspective or Orthographic.

◆ setShowSymbol()

void setShowSymbol ( bool  show)

◆ setSymbolShader()

void setSymbolShader ( Shader shader)
Parameters
shader

◆ setTrackingTarget()

void setTrackingTarget ( const SceneItem target)
Parameters
target

◆ setTransform()

void setTransform ( const Mesh::TransformByComponents t)
Parameters
tThe new local transform.

This function is thread-safe.

◆ setUseFieldOfViewX()

void setUseFieldOfViewX ( bool  b)
Parameters
bWhether or not to use the horizontal field of view.

By default, renderers will only use the vertical field of view to compute the projection matrix. The horizontal field of view is automatically computed using the aspect ratio. There are occasions, however, when we do want to define a horizontal field of view, and instead derive the aspect ratio from that. Note that the aspect ratio of pixels is not the same aspect ratio between the vertical / horizontal field of views.

◆ showSymbol()

bool showSymbol ( ) const

◆ updateGlobalMatrix()

void updateGlobalMatrix ( )
overridevirtual

Reimplemented from SceneItem.

◆ visit()

bool visit ( SceneProcessor processor)
overridevirtual

Implements SceneItem.