ezEngine  Milestone 7
ezCamera Class Reference

A camera class that stores the orientation and some basic camera settings. More...

#include <Camera.h>

Public Types

enum  CameraMode {
  None, PerspectiveFixedFovX, PerspectiveFixedFovY, OrthoFixedWidth,
  OrthoFixedHeight
}
 Specifies in which mode this camera is configured. More...
 

Public Member Functions

virtual ezVec3 GetPosition () const
 Returns the position of the camera that should be used for rendering etc. More...
 
virtual const ezVec3GetDirForwards () const
 Returns the forwards vector that should be used for rendering etc.
 
virtual const ezVec3GetDirUp () const
 Returns the up vector that should be used for rendering etc.
 
virtual const ezVec3GetDirRight () const
 Returns the right vector that should be used for rendering etc.
 
ezAngle GetFovX (float fAspectRatioWidthDivHeight) const
 Returns the horizontal FOV.
 
ezAngle GetFovY (float fAspectRatioWidthDivHeight) const
 Returns the vertical FOV.
 
const ezVec3GetCenterPosition () const
 Returns the actual camera position.
 
const ezVec3GetCenterDirForwards () const
 Returns the actual forwards vector.
 
const ezVec3GetCenterDirUp () const
 Returns the actual up vector.
 
const ezVec3GetCenterDirRight () const
 Returns the actual right vector.
 
float GetNearPlane () const
 Returns the near plane distance.
 
float GetFarPlane () const
 Returns the far plane distance.
 
void SetCameraMode (CameraMode Mode, float fFovOrDim, float fNearPlane, float fFarPlane)
 Specifies the mode and the basic settings that this camera uses. More...
 
float GetFovOrDim () const
 Returns the fFovOrDim parameter that was passed to SetCameraMode().
 
CameraMode GetCameraMode () const
 Returns the current camera mode.
 
void SetFromMatrix (const ezMat4 &mLookAtMatrix)
 Sets the camera position and rotation from the given look at matrix.
 
void LookAt (const ezVec3 &vCameraPos, const ezVec3 &vTargetPos, const ezVec3 &vUp)
 Repositions the camera such that it looks at the given target position.
 
void MoveLocally (float fForward, float fRight, float fUp)
 Moves the camera in its local space.
 
void MoveGlobally (const ezVec3 &vMove)
 Moves the camera in global space.
 
void RotateLocally (ezAngle X, ezAngle Y, ezAngle Z)
 Rotates the camera around the X (forward), Y (right) and Z (up) axis in its own local space. More...
 
void RotateGlobally (ezAngle X, ezAngle Y, ezAngle Z)
 Rotates the camera around the X, Y and Z axis in global space. More...
 
void GetViewMatrix (ezMat4 &out_viewMatrix) const
 Calculates the view matrix from the current camera properties and stores it in out_viewMatrix.
 
void GetProjectionMatrix (float fAspectRatioWidthDivHeight, ezMat4 &out_projectionMatrix, ezProjectionDepthRange::Enum depthRange=ezProjectionDepthRange::Default) const
 Calculates the projection matrix from the current camera properties and stores it in out_projectionMatrix.
 
ezUInt32 GetSettingsModificationCounter () const
 Returns a counter that is increased every time the camera settings are modified. More...
 
ezUInt32 GetOrientationModificationCounter () const
 Returns a counter that is increased every time the camera orientation is modified. More...
 

Private Member Functions

virtual void CameraOrientationChanged (bool bPosition, bool bRotation)
 This function is called whenever the camera position or rotation changed. Override this function to implement restrictions on the camera position or rotation.
 
virtual void CameraSettingsChanged ()
 This function is called when the camera mode changes (e.g. SetCameraMode was called). Override this to do sanity checks or restrict certain values.
 
virtual void ClampRotationAngles (bool bLocalSpace, ezAngle &X, ezAngle &Y, ezAngle &Z)
 This function is called by RotateLocally() and RotateGlobally() BEFORE the values are applied, and allows to adjust them (e.g. for limiting how far the camera can rotate).
 

Private Attributes

float m_fNearPlane
 
float m_fFarPlane
 
CameraMode m_Mode
 
float m_fFovOrDim
 
ezVec3 m_vPosition
 
ezVec3 m_vDirForwards
 
ezVec3 m_vDirUp
 
ezVec3 m_vDirRight
 
ezUInt32 m_uiSettingsModificationCounter
 
ezUInt32 m_uiOrientationModificationCounter
 

Detailed Description

A camera class that stores the orientation and some basic camera settings.

Member Enumeration Documentation

Specifies in which mode this camera is configured.

Enumerator
None 

Not initialized.

PerspectiveFixedFovX 

Perspective camera, the fov for X is fixed, Y depends on the aspect ratio.

PerspectiveFixedFovY 

Perspective camera, the fov for Y is fixed, X depends on the aspect ratio.

OrthoFixedWidth 

Orthographic camera, the width is fixed, the height depends on the aspect ratio.

OrthoFixedHeight 

Orthographic camera, the height is fixed, the width depends on the aspect ratio.

Member Function Documentation

ezUInt32 ezCamera::GetOrientationModificationCounter ( ) const
inline

Returns a counter that is increased every time the camera orientation is modified.

The camera orientation is used to compute the view matrix. This counter can be used to determine whether the view matrix has changed and thus whether cached values need to be updated.

ezVec3 ezCamera::GetPosition ( ) const
inlinevirtual

Returns the position of the camera that should be used for rendering etc.

Override this to implement different camera positions for stereo rendering, or to implement a camera shake effect, etc.

ezUInt32 ezCamera::GetSettingsModificationCounter ( ) const
inline

Returns a counter that is increased every time the camera settings are modified.

The camera settings are used to compute the projection matrix. This counter can be used to determine whether the projection matrix has changed and thus whether cached values need to be updated.

void ezCamera::RotateGlobally ( ezAngle  X,
ezAngle  Y,
ezAngle  Z 
)

Rotates the camera around the X, Y and Z axis in global space.

Rotate around Z for turning the camera left/right.

void ezCamera::RotateLocally ( ezAngle  X,
ezAngle  Y,
ezAngle  Z 
)

Rotates the camera around the X (forward), Y (right) and Z (up) axis in its own local space.

Rotate around Y for looking up/down. X is roll. For turning left/right use Z with RotateGlobally().

void ezCamera::SetCameraMode ( CameraMode  Mode,
float  fFovOrDim,
float  fNearPlane,
float  fFarPlane 
)

Specifies the mode and the basic settings that this camera uses.

Parameters
fFovOrDimFov X/Y in degree or width/height (depending on Mode)

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