class TCamera

template<bool IsRenderProxy>
Inherits: CoreVariantType<CoreObject, IsRenderProxy>

Templated common base class for both main and render thread implementations of Camera.

Public

Constructors

TCamera<IsRenderProxy>

TCamera<IsRenderProxy>()

Methods

~TCamera<IsRenderProxy>

virtual ~TCamera<IsRenderProxy>() = default

SetFlags

void SetFlags(CameraFlags flags)

Determines flags used for controlling the camera behaviour.

GetFlags

CameraFlags GetFlags() const

SetHorizontalFOV

void SetHorizontalFOV(const Radian &fovy)

Determines the camera horizontal field of view.

This determines how wide the camera viewing angle is along the horizontal axis. Vertical FOV is calculated from the horizontal FOV and the aspect ratio.

GetHorizontalFOV

const Radian &GetHorizontalFOV() const

SetNearClipDistance

void SetNearClipDistance(float nearDist)

Determines the distance from the frustum to the near clipping plane.

Anything closer than the near clipping plane will not be rendered. Decreasing this value decreases depth buffer precision.

GetNearClipDistance

float GetNearClipDistance() const

SetFarClipDistance

void SetFarClipDistance(float farDist)

Determines the distance from the frustum to the far clipping plane.

Anything farther than the far clipping plane will not be rendered. Increasing this value decreases depth buffer precision.

GetFarClipDistance

float GetFarClipDistance() const

SetAspectRatio

void SetAspectRatio(float ratio)

Determines the current viewport aspect ratio (width / height).

GetAspectRatio

float GetAspectRatio() const

SetFrustumExtents

void SetFrustumExtents(float left, float right, float top, float bottom)

Manually set the extents of the frustum that will be used when calculating the projection matrix.

This will prevents extents for being automatically calculated from aspect and near plane so it is up to the caller to keep these values accurate.

left
The position where the left clip plane intersect the near clip plane, in view space.
right
The position where the right clip plane intersect the near clip plane, in view space.
top
The position where the top clip plane intersect the near clip plane, in view space.
bottom
The position where the bottom clip plane intersect the near clip plane, in view space.

ResetFrustumExtents

void ResetFrustumExtents()

Resets frustum extents so they are automatically derived from other values.

This is only relevant if you have previously set custom extents.

GetFrustumExtents

void GetFrustumExtents(float &outLeft, float &outRight, float &outTop, float &outBottom) const

Returns the extents of the frustum in view space at the near plane.

GetProjectionMatrix

const Matrix4 &GetProjectionMatrix() const

Returns the standard projection matrix that determines how are 3D points projected to two dimensions.

The layout of this matrix depends on currently used GPU backend.

GetUnadjustedProjectionMatrix

const Matrix4 &GetUnadjustedProjectionMatrix() const

Returns the standard projection matrix that determines how are 3D points projected to two dimensions.

Returned matrix is standard following right-hand rules and depth range of [-1, 1]. Note that currently used GPU backend might expect different rules, in which case use GetProjectionMatrix() to retrieve an adjusted matrix.

GetViewMatrix

const Matrix4 &GetViewMatrix() const

Gets the camera view matrix.

Used for positioning/orienting the camera.

SetCustomProjectionMatrix

void SetCustomProjectionMatrix(bool enable, const Matrix4 &projectionMatrix = Matrix4::kIdentity)

Sets whether the camera should use the custom projection matrix.

When this is enabled camera will no longer calculate its projection matrix based on field of view, aspect and other parameters and caller will be resonsible to keep the projection matrix up to date.

IsCustomProjectionMatrixEnabled

bool IsCustomProjectionMatrixEnabled() const

Returns the extents of the frustum in view space at the near plane.

SetCustomViewMatrix

void SetCustomViewMatrix(bool enable, const Matrix4 &viewMatrix = Matrix4::kIdentity)

Sets whether the camera should use the custom view matrix.

When this is enabled camera will no longer calculate its view matrix based on position/orientation and caller will be resonsible to keep the view matrix up to date.

IsCustomViewMatrixEnabled

bool IsCustomViewMatrixEnabled() const

Returns true if a custom view matrix is used.

GetFrustum

const ConvexVolume &GetFrustum() const

Returns a convex volume representing the visible area of the camera, in local space.

GetWorldFrustum

ConvexVolume GetWorldFrustum() const

Returns a convex volume representing the visible area of the camera, in world space.

GetBoundingBox

const AABox &GetBoundingBox() const

Returns the bounding of the frustum.

SetProjectionType

void SetProjectionType(ProjectionType pt)

Determines the type of projection used by the camera.

Projection type controls how is 3D geometry projected onto a 2D plane.

GetProjectionType

ProjectionType GetProjectionType() const

SetOrthographicSize

void SetOrthographicSize(float width, float height)

Sets the orthographic window size, for use with orthographic rendering only.

width
Width of the window in world units.
height
Height of the window in world units.

SetOrthographicHeight

void SetOrthographicHeight(float height)

Determines the type of projection used by the camera.

Projection type controls how is 3D geometry projected onto a 2D plane.

GetOrthographicHeight

float GetOrthographicHeight() const

SetOrthographicWidth

void SetOrthographicWidth(float width)

Determines the orthographic window width, for use with orthographic rendering only.

The height of the window will be calculated from the aspect ratio. Value is specified in world units.

GetOrthographicWidth

float GetOrthographicWidth() const

SetPriority

void SetPriority(i32 priority)

Determines a priority that determines in which orders the cameras are rendered.

This only applies to cameras rendering to the same render target. Higher value means the camera will be rendered sooner.

GetPriority

i32 GetPriority() const

SetLayers

void SetLayers(u64 layers)

Determines layer bitfield that is used when determining which object should the camera render.

GetLayers

u64 GetLayers() const

SetSampleCount

void SetSampleCount(u32 count)

Determines number of samples to use when rendering to this camera.

Values larger than 1 will enable MSAA rendering.

GetSampleCount

u32 GetSampleCount() const

GetViewport

SPtr<ViewportType> GetViewport() const

Returns the viewport used by the camera.

SetRenderSettings

void SetRenderSettings(const SPtr<RenderSettingsType> &settings)

Settings that control rendering for this view.

They determine how will the renderer process this view, which effects will be enabled, and what properties will those effects use.

GetRenderSettings

const SPtr<RenderSettingsType> &GetRenderSettings() const

NotifyNeedsRedraw

void NotifyNeedsRedraw()

Notifies a on-demand camera that it should re-draw its contents on the next frame.

Ignored for a camera that isn't on-demand.

WorldToScreenPoint

Vector2I WorldToScreenPoint(const Vector3 &worldPoint) const

Converts a point in world space to screen coordinates.

worldPoint
3D point in world space.

Returns: 2D point on the render target attached to the camera's viewport, in pixels.

WorldToNDCPoint

Vector2 WorldToNDCPoint(const Vector3 &worldPoint) const

Converts a point in world space to normalized device coordinates.

worldPoint
3D point in world space.

Returns: 2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

WorldToViewPoint

Vector3 WorldToViewPoint(const Vector3 &worldPoint) const

Converts a point in world space to view space coordinates.

worldPoint
3D point in world space.

Returns: 3D point relative to the camera's coordinate system.

ScreenToWorldPoint

Vector3 ScreenToWorldPoint(const Vector2I &screenPoint, float depth = 0.5F) const

Converts a point in screen space to a point in world space.

screenPoint
2D point on the render target attached to the camera's viewport, in pixels.
depth
Depth to place the world point at, in world coordinates. The depth is applied to the vector going from camera origin to the point on the near plane.

Returns: 3D point in world space.

ScreenToWorldPointDeviceDepth

Vector3 ScreenToWorldPointDeviceDepth(const Vector2I &screenPoint, float deviceDepth = 0.5F) const

Converts a point in screen space (pixels corresponding to render target attached to the camera) to a point in world space.

screenPoint
Point to transform.
deviceDepth
Depth to place the world point at, in normalized device coordinates.

Returns: 3D point in world space.

ScreenToViewPoint

Vector3 ScreenToViewPoint(const Vector2I &screenPoint, float depth = 0.5F) const

Converts a point in screen space to a point in view space.

screenPoint
2D point on the render target attached to the camera's viewport, in pixels.
depth
Depth to place the world point at, in device depth. The depth is applied to the vector going from camera origin to the point on the near plane.

Returns: 3D point relative to the camera's coordinate system.

ScreenToNDCPoint

Vector2 ScreenToNDCPoint(const Vector2I &screenPoint) const

Converts a point in screen space to normalized device coordinates.

screenPoint
2D point on the render target attached to the camera's viewport, in pixels.

Returns: 2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

ViewToWorldPoint

Vector3 ViewToWorldPoint(const Vector3 &viewPoint) const

Converts a point in view space to world space.

viewPoint
3D point relative to the camera's coordinate system.

Returns: 3D point in world space.

ViewToScreenPoint

Vector2I ViewToScreenPoint(const Vector3 &viewPoint) const

Converts a point in view space to screen space.

viewPoint
3D point relative to the camera's coordinate system.

Returns: 2D point on the render target attached to the camera's viewport, in pixels.

ViewToNDCPoint

Vector2 ViewToNDCPoint(const Vector3 &viewPoint) const

Converts a point in view space to normalized device coordinates.

viewPoint
3D point relative to the camera's coordinate system.

Returns: 2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

NDCToWorldPoint

Vector3 NDCToWorldPoint(const Vector2 &ndcPoint, float depth = 0.5F) const

Converts a point in normalized device coordinates to world space.

ndcPoint
2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.
depth
Depth to place the world point at. The depth is applied to the vector going from camera origin to the point on the near plane.

Returns: 3D point in world space.

NDCToViewPoint

Vector3 NDCToViewPoint(const Vector2 &ndcPoint, float depth = 0.5F) const

Converts a point in normalized device coordinates to view space.

ndcPoint
2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.
depth
Depth to place the world point at. The depth is applied to the vector going from camera origin to the point on the near plane.

Returns: 3D point relative to the camera's coordinate system.

NDCToScreenPoint

Vector2I NDCToScreenPoint(const Vector2 &ndcPoint) const

Converts a point in normalized device coordinates to screen space.

ndcPoint
2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.

Returns: 2D point on the render target attached to the camera's viewport, in pixels.

ScreenPointToRay

Ray ScreenPointToRay(const Vector2I &screenPoint) const

Converts a point in screen space to a ray in world space.

screenPoint
2D point on the render target attached to the camera's viewport, in pixels.

Returns: Ray in world space, originating at the selected point on the camera near plane.

ProjectPoint

Vector3 ProjectPoint(const Vector3 &point) const

Projects a point in view space to normalized device coordinates.

Similar to ViewToNDCPoint() but preserves the depth component.

point
3D point relative to the camera's coordinate system.

Returns: 3D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport. Z value range depends on active render API.

UnprojectPoint

Vector3 UnprojectPoint(const Vector3 &point) const

Un-projects a point in normalized device space to view space.

point
3D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport. Z value range depends on active render API.

Returns: 3D point relative to the camera's coordinate system.

Protected

Methods

MarkRenderProxyDataDirty

void MarkRenderProxyDataDirty(ComponentDirtyFlag flag = ComponentDirtyFlag::Everything)

Marks the render proxy data as dirty.

This causes the SyncToRenderProxy() method to trigger the next time objects are synced to the render thread.

flags
Flags in case you want to signal that only part of the internal data is dirty. SyncToRenderProxy() will be called regardless and it's up to the implementation to read the flags value if needed.

GetTransform

const Transform &GetTransform() const

Returns the world space transform of the object.

CalculateProjectionParameters

void CalculateProjectionParameters(float &left, float &right, float &bottom, float &top) const

Calculate projection parameters that are used when constructing the projection matrix.

UpdateFrustum

void UpdateFrustum() const

Recalculate frustum if dirty.

UpdateFrustumPlanes

void UpdateFrustumPlanes() const

Recalculate frustum planes if dirty.

IsFrustumOutOfDate

bool IsFrustumOutOfDate() const

Checks if the frustum requires updating.

InvalidateFrustum

void InvalidateFrustum() const

Notify camera that the frustum requires to be updated.

GetViewportArea

Area2I GetViewportArea() const

Returns a rectangle that defines the viewport position and size, in pixels.

Fields

mLayers

u64 mLayers

Bitfield that can be used for filtering what objects the camera sees.

mProjType

ProjectionType mProjType

Type of camera projection.

mHorzFOV

Radian mHorzFOV

Horizontal field of view represents how wide is the camera angle.

mFarDist

float mFarDist

Clip any objects further than this.

Larger value decreases depth precision at smaller depths.

mNearDist

float mNearDist

Clip any objects close than this.

Smaller value decreases depth precision at larger depths.

mAspect

float mAspect

Width/height viewport ratio.

mOrthoHeight

float mOrthoHeight

Height in world units used for orthographic cameras.

mPriority

i32 mPriority

Determines in what order will the camera be rendered.

Higher priority means the camera will be rendered sooner.

mMain

bool mMain

Determines does this camera render to the main render surface.

mCameraFlags

CameraFlags mCameraFlags

Flags for controlling various behaviour.

mCustomProjMatrix

bool mCustomProjMatrix

Is custom projection matrix set.

mCustomViewMatrix

bool mCustomViewMatrix

Is custom view matrix set.

mMSAA

u8 mMSAA

Number of samples to render the scene with.

mFrustumExtentsManuallySet

bool mFrustumExtentsManuallySet

Are frustum extents manually set.

mProjMatrixRS

Matrix4 mProjMatrixRS

Cached render-system specific projection matrix.

mProjMatrix

Matrix4 mProjMatrix

Cached projection matrix that determines how are 3D points projected to a 2D viewport.

mViewMatrix

Matrix4 mViewMatrix

Cached view matrix that determines camera position/orientation.

mRecalcView

bool mRecalcView

Should view matrix be recalculated.

mFrustum

ConvexVolume mFrustum

Main clipping planes describing cameras visible area.

mRecalcFrustum

bool mRecalcFrustum

Should frustum be recalculated.

mRecalcFrustumPlanes

bool mRecalcFrustumPlanes

Should frustum planes be recalculated.

mLeft

float mLeft

Frustum extents.

mRight

float mRight

Frustum extents.

mTop

float mTop

Frustum extents.

mBottom

float mBottom

Frustum extents.

mBoundingBox

AABox mBoundingBox

Frustum bounding box.

mViewport

SPtr<ViewportType> mViewport

Viewport that describes a 2D rendering surface.

mRenderSettings

SPtr<RenderSettingsType> mRenderSettings

Settings used to control rendering for this camera.