API Documentation
Public Member Functions | Static Public Member Functions | List of all members
nkGraphics::Camera Class Reference

Offers all controls to model a camera. More...

Inheritance diagram for nkGraphics::Camera:
nkGraphics::Node nkExport::Exportable

Public Member Functions

const FrustumgetFrustum ()
 
nkMemory::StringView getName () const
 
PROJECTION_TYPE getProjectionType () const
 
float getPerspectiveFov () const
 
float getPerspectiveAspectRatio () const
 
float getPerspectiveOffCenterFovLeft () const
 
float getPerspectiveOffCenterFovRight () const
 
float getPerspectiveOffCenterFovTop () const
 
float getPerspectiveOffCenterFovBottom () const
 
float getOrthographicHeight () const
 
float getOrthographicAspectRatio () const
 
float getNear () const
 
float getFar () const
 
bool getAutoUpdateOnContextSwitch () const
 
bool getHidden () const
 
const nkMaths::MatrixgetViewMatrix () const
 
const nkMaths::MatrixgetProjectionMatrix () const
 
nkMaths::Matrix getViewProjMatrix () const
 
virtual void setPositionRelative (const nkMaths::Vector &value) override
 
virtual void setPositionAbsolute (const nkMaths::Vector &value) override
 
virtual void translateRelative (const nkMaths::Vector &value) override
 
virtual void translateAbsolute (const nkMaths::Vector &value) override
 
virtual void setOrientationRelative (const nkMaths::Quaternion &value) override
 
virtual void setOrientationAbsolute (const nkMaths::Quaternion &value) override
 
virtual void rotateRelative (const nkMaths::Quaternion &value) override
 
virtual void rotateAbsolute (const nkMaths::Quaternion &value) override
 
virtual void setScaleRelative (const nkMaths::Vector &value) override
 
virtual void setScaleAbsolute (const nkMaths::Vector &value) override
 
virtual void applyScale (const nkMaths::Vector &value) override
 
void setName (nkMemory::StringView name)
 
void setAsPerspective (float fovRadian, float aspectRatioWidthOverHeight)
 
void setAsPerspectiveOffCenter (float fovLeftRadian, float fovRightRadian, float fovTopRadian, float fovBottomRadian)
 
void setAsOrthographic (float height, float aspectRatioWidthOverHeight)
 
void setRange (float near, float far)
 
void prepareForContext (RenderContext *context)
 
void setAutoUpdateOnContextSwitch (bool value)
 
void setHidden (bool value)
 
void updateViewMatrix ()
 
void updateProjectionMatrix ()
 
void lookAt (const nkMaths::Vector &point, const nkMaths::Vector &enforcedUp=nkMaths::Vector(0, 0, 0, 0))
 
void getNearPlanePoints (nkMaths::Vector &a, nkMaths::Vector &b, nkMaths::Vector &c, nkMaths::Vector &d)
 
void getFarPlanePoints (nkMaths::Vector &a, nkMaths::Vector &b, nkMaths::Vector &c, nkMaths::Vector &d)
 
void getFrustumCornersDirectionsWorld (nkMaths::Vector &a, nkMaths::Vector &b, nkMaths::Vector &c, nkMaths::Vector &d)
 
void getFrustumCornersDirectionsView (nkMaths::Vector &a, nkMaths::Vector &b, nkMaths::Vector &c, nkMaths::Vector &d)
 
nkMaths::Vector getDirectionAtPixelWorld (int x, int y, RenderContext *fromContext=nullptr)
 
nkMaths::Vector getDirectionAtScreenCoordWorld (float x, float y)
 
nkMaths::Vector getDirectionAtPixelView (int x, int y, RenderContext *fromContext=nullptr)
 
nkMaths::Vector getDirectionAtScreenCoordView (float x, float y)
 
virtual void exportClassToTree (nkExport::Node *rootNode) override
 
virtual void importClassFromTree (nkExport::Node *rootNode) override
 
- Public Member Functions inherited from nkGraphics::Node
virtual ~Node ()
 
nkMaths::Vector getPositionRelative () const
 
nkMaths::Vector getPositionAbsolute ()
 
nkMaths::Quaternion getOrientationRelative () const
 
nkMaths::Quaternion getOrientationAbsolute ()
 
nkMaths::Vector getScaleRelative () const
 
nkMaths::Vector getScaleAbsolute ()
 
void setRelativeTransform (const nkMaths::Matrix &value)
 
void setAbsoluteTransform (const nkMaths::Matrix &value)
 
nkMaths::Matrix getRelativeTransform ()
 
nkMaths::Matrix getAbsoluteTransform ()
 
void updateTransformations ()
 
void dispatchDirtyTransform ()
 
bool getTransformDirty () const
 
nkMaths::Vector getAbsoluteUp ()
 
nkMaths::Vector getAbsoluteFront ()
 
nkMaths::Vector getAbsoluteRight ()
 
void setParentNode (Node *parent)
 
NodegetParentNode () const
 
NodegetChildNode (unsigned int index) const
 
unsigned int getNumChildNode () const
 
void setName (nkMemory::StringView value)
 
nkMemory::StringView getName () const
 
bool getHidden () const
 
void setHidden (bool value)
 
void addEntityToTrack (Entity *entity)
 
void stopEntityTracking (Entity *entity)
 
unsigned int getTrackedEntityCount () const
 
EntitygetTrackedEntity (unsigned int index) const
 
void registerListener (NodeChangeListener *listener)
 
void unregisterListener (NodeChangeListener *listener)
 
- Public Member Functions inherited from nkExport::Exportable
 Exportable () noexcept
 
virtual ~Exportable ()
 

Static Public Member Functions

static nkMemory::UniquePtr< Cameracreate (System *system=nullptr)
 
- Static Public Member Functions inherited from nkGraphics::Node
static nkMemory::UniquePtr< Nodecreate (System *system=nullptr)
 

Detailed Description

Offers all controls to model a camera.

See CameraManager::createOrRetrieve() or Camera::create() for instantiation.

Member Function Documentation

◆ getFrustum()

const Frustum& nkGraphics::Camera::getFrustum ( )
Returns
The frustum representing the field of view of the camera.

◆ getName()

nkMemory::StringView nkGraphics::Camera::getName ( ) const
Returns
The camera's name.

◆ getProjectionType()

PROJECTION_TYPE nkGraphics::Camera::getProjectionType ( ) const
Returns
The projection type currently used by the camera.

◆ getPerspectiveFov()

float nkGraphics::Camera::getPerspectiveFov ( ) const
Returns
The vertical field of view of the camera, in radians, for a perspective projection type.

◆ getPerspectiveAspectRatio()

float nkGraphics::Camera::getPerspectiveAspectRatio ( ) const
Returns
The currently used aspect ratio (width / height), for a perspective projection type.

◆ getPerspectiveOffCenterFovLeft()

float nkGraphics::Camera::getPerspectiveOffCenterFovLeft ( ) const
Returns
The horizontal left field of view of the camera, in radians, for a perspective off-center projection type.

◆ getPerspectiveOffCenterFovRight()

float nkGraphics::Camera::getPerspectiveOffCenterFovRight ( ) const
Returns
The horizontal right field of view of the camera, in radians, for a perspective off-center projection type.

◆ getPerspectiveOffCenterFovTop()

float nkGraphics::Camera::getPerspectiveOffCenterFovTop ( ) const
Returns
The vertical top field of view of the camera, in radians, for a perspective off-center projection type.

◆ getPerspectiveOffCenterFovBottom()

float nkGraphics::Camera::getPerspectiveOffCenterFovBottom ( ) const
Returns
The vertical bottom field of view of the camera, in radians, for a perspective off-center projection type.

◆ getOrthographicHeight()

float nkGraphics::Camera::getOrthographicHeight ( ) const
Returns
The orthographic height used by the camera, in world units.

◆ getOrthographicAspectRatio()

float nkGraphics::Camera::getOrthographicAspectRatio ( ) const
Returns
The currently used aspect ratio (width / height), for an orthographic projection type.

◆ getNear()

float nkGraphics::Camera::getNear ( ) const
Returns
Current near plane distance used.

◆ getFar()

float nkGraphics::Camera::getFar ( ) const
Returns
Current far plance distance used.

◆ getAutoUpdateOnContextSwitch()

bool nkGraphics::Camera::getAutoUpdateOnContextSwitch ( ) const
Returns
Whether the camera will auto update its aspect ratio before being used in a context (true) or not (false).

◆ getHidden()

bool nkGraphics::Camera::getHidden ( ) const
Returns
Whether the camera is hidden from project saving or not.

◆ getViewMatrix()

const nkMaths::Matrix& nkGraphics::Camera::getViewMatrix ( ) const
Returns
The current view matrix.

◆ getProjectionMatrix()

const nkMaths::Matrix& nkGraphics::Camera::getProjectionMatrix ( ) const
Returns
The current projection matrix.

◆ getViewProjMatrix()

nkMaths::Matrix nkGraphics::Camera::getViewProjMatrix ( ) const
Returns
The view * proj matrix.

◆ setPositionRelative()

virtual void nkGraphics::Camera::setPositionRelative ( const nkMaths::Vector value)
overridevirtual

◆ setPositionAbsolute()

virtual void nkGraphics::Camera::setPositionAbsolute ( const nkMaths::Vector value)
overridevirtual

◆ translateRelative()

virtual void nkGraphics::Camera::translateRelative ( const nkMaths::Vector value)
overridevirtual

See Node::translateRelative().

Reimplemented from nkGraphics::Node.

◆ translateAbsolute()

virtual void nkGraphics::Camera::translateAbsolute ( const nkMaths::Vector value)
overridevirtual

See Node::translateAbsolute().

Reimplemented from nkGraphics::Node.

◆ setOrientationRelative()

virtual void nkGraphics::Camera::setOrientationRelative ( const nkMaths::Quaternion value)
overridevirtual

◆ setOrientationAbsolute()

virtual void nkGraphics::Camera::setOrientationAbsolute ( const nkMaths::Quaternion value)
overridevirtual

◆ rotateRelative()

virtual void nkGraphics::Camera::rotateRelative ( const nkMaths::Quaternion value)
overridevirtual

See Node::rotateRelative().

Reimplemented from nkGraphics::Node.

◆ rotateAbsolute()

virtual void nkGraphics::Camera::rotateAbsolute ( const nkMaths::Quaternion value)
overridevirtual

See Node::rotateAbsolute().

Reimplemented from nkGraphics::Node.

◆ setScaleRelative()

virtual void nkGraphics::Camera::setScaleRelative ( const nkMaths::Vector value)
overridevirtual

See Node::setScaleRelative().

Reimplemented from nkGraphics::Node.

◆ setScaleAbsolute()

virtual void nkGraphics::Camera::setScaleAbsolute ( const nkMaths::Vector value)
overridevirtual

See Node::setScaleAbsolute().

Reimplemented from nkGraphics::Node.

◆ applyScale()

virtual void nkGraphics::Camera::applyScale ( const nkMaths::Vector value)
overridevirtual

See Node::applyScale().

Reimplemented from nkGraphics::Node.

◆ setName()

void nkGraphics::Camera::setName ( nkMemory::StringView  name)

Sets the name of the camera.

Parameters
nameThe name to assign.
Remarks
In theory, should never be called by external code.

◆ setAsPerspective()

void nkGraphics::Camera::setAsPerspective ( float  fovRadian,
float  aspectRatioWidthOverHeight 
)

Sets the camera up for perspective projection.

Parameters
fovRadianThe vertical field of view, in radian.
aspectRatioWidthOverHeightThe aspect ratio, given as width / height.
Remarks
If one of the perspective parameter needs to be changed, this method needs to be called again. It is useful in such case to use the getters for associated parameters that should remain the same.

◆ setAsPerspectiveOffCenter()

void nkGraphics::Camera::setAsPerspectiveOffCenter ( float  fovLeftRadian,
float  fovRightRadian,
float  fovTopRadian,
float  fovBottomRadian 
)

Sets the camera up for off-center perspective projection.

Parameters
fovLeftRadianThe horizontal left field of view angle from the theoretical projection center, in radians.
fovRightRadianThe horizontal right field of view angle from the theoretical projection center, in radians.
fovTopRadianThe vertical top field of view angle from the theoretical projection center, in radians.
fovBottomRadianThe vertical bottom field of view angle from the theoretical projection center, in radians.
Remarks
If one of the perspective parameter needs to be changed, this method needs to be called again. It is useful in such case to use the getters for associated parameters that should remain the same.

◆ setAsOrthographic()

void nkGraphics::Camera::setAsOrthographic ( float  height,
float  aspectRatioWidthOverHeight 
)

Sets the camera up for orthographic projection.

Parameters
heightThe projection's height, in world units.
aspectRatioWidthOverHeightThe aspect ratio, given as width / height.
Remarks
If one of the perspective parameter needs to be changed, this method needs to be called again. It is useful in such case to use the getters for associated parameters that should remain the same.

◆ setRange()

void nkGraphics::Camera::setRange ( float  near,
float  far 
)

Sets the projection's distance range interval.

Parameters
nearThe near plane distance in world units.
farThe far plane distance in world units.

◆ prepareForContext()

void nkGraphics::Camera::prepareForContext ( RenderContext context)

Prepare the camera to be used by a render context. Will update values like the aspect ratio to be compatible with the rendering surface associated.

Parameters
contextThe context to adapt to.

◆ setAutoUpdateOnContextSwitch()

void nkGraphics::Camera::setAutoUpdateOnContextSwitch ( bool  value)

Sets whether the camera should be updated for the context given before rendering. For instance, this will update the aspect ratio to fit the dimension of the render target.

Parameters
valueWhether the camera should be updated (true) or not (false) when a context switch is done.
Remarks
This can be useful when using a camera to render a scene on different windows / textures, for instance. In case rendering has to take specific aspect ratio for any purpose, this flag can remain off.

◆ setHidden()

void nkGraphics::Camera::setHidden ( bool  value)

Sets whether the camera is hidden from project exporting. If enabled, the camera won't be exported in the decl files of the project. This can be useful when a camera is created programmatically in an application, and should not be duplicated in the declaration files.

Parameters
valueIf the camera should be hidden (true) or not (false).

◆ updateViewMatrix()

void nkGraphics::Camera::updateViewMatrix ( )

Updates the view matrix after new changes in parameters occurred.

◆ updateProjectionMatrix()

void nkGraphics::Camera::updateProjectionMatrix ( )

Updates the projection matrix after new changes in parameters occurred.

◆ lookAt()

void nkGraphics::Camera::lookAt ( const nkMaths::Vector point,
const nkMaths::Vector enforcedUp = nkMaths::Vector(0, 0, 0, 0) 
)

Sets the camera to look at a coordinate.

Parameters
pointThe point to look at.
enforcedUpThe up direction to take. If left blank, an automatic up is computed.

◆ getNearPlanePoints()

void nkGraphics::Camera::getNearPlanePoints ( nkMaths::Vector a,
nkMaths::Vector b,
nkMaths::Vector c,
nkMaths::Vector d 
)

Fills up the 4 points of the near plane.

Parameters
aThe first point.
bThe second point.
cThe third point.
dThe fourth point.

◆ getFarPlanePoints()

void nkGraphics::Camera::getFarPlanePoints ( nkMaths::Vector a,
nkMaths::Vector b,
nkMaths::Vector c,
nkMaths::Vector d 
)

Fills up the 4 points of the far plane.

Parameters
aThe first point.
bThe second point.
cThe third point.
dThe fourth point.

◆ getFrustumCornersDirectionsWorld()

void nkGraphics::Camera::getFrustumCornersDirectionsWorld ( nkMaths::Vector a,
nkMaths::Vector b,
nkMaths::Vector c,
nkMaths::Vector d 
)

Fills up the directions of the frustum corners, in world space. Can be seen as the directions from the near plane points, to their attached far plane points.

Parameters
aThe first direction.
bThe second direction.
cThe third direction.
dThe fourth direction.

◆ getFrustumCornersDirectionsView()

void nkGraphics::Camera::getFrustumCornersDirectionsView ( nkMaths::Vector a,
nkMaths::Vector b,
nkMaths::Vector c,
nkMaths::Vector d 
)

Fills up the directions of the frustum corners, in view space. Can be seen as the directions from the near plane points, to their attached far plane points.

Parameters
aThe first direction.
bThe second direction.
cThe third direction.
dThe fourth direction.

◆ getDirectionAtPixelWorld()

nkMaths::Vector nkGraphics::Camera::getDirectionAtPixelWorld ( int  x,
int  y,
RenderContext fromContext = nullptr 
)

Returns the direction, in world space, for one pixel.

Parameters
xThe x coordinate of the pixel.
yThe y coordinate of the pixel.
fromContextThe context from which the pixel size should be retrieved. If left nullptr, the active context will be queried.
Returns
The direction of the pixel, in world space.
Remarks
If a context is given, it will be used to deduce the relative coordinates to sample from. Note that no change in ratio or projection matrix will take place for the given context.

◆ getDirectionAtScreenCoordWorld()

nkMaths::Vector nkGraphics::Camera::getDirectionAtScreenCoordWorld ( float  x,
float  y 
)

Returns the direction, in world space, for a given position on screen.

Parameters
xThe x coordinate, in [0, 1].
yThe y coordinate, in [0, 1].
Returns
The direction on screen, in world space.

◆ getDirectionAtPixelView()

nkMaths::Vector nkGraphics::Camera::getDirectionAtPixelView ( int  x,
int  y,
RenderContext fromContext = nullptr 
)

Returns the direction, in view space, for one pixel.

Parameters
xThe x coordinate of the pixel.
yThe y coordinate of the pixel.
fromContextThe context from which the pixel size should be retrieved. If left nullptr, the active context will be queried.
Returns
The direction of the pixel, in view space.
Remarks
If a context is given, it will be used to deduce the relative coordinates to sample from. Note that no change in ratio or projection matrix will take place for the given context.

◆ getDirectionAtScreenCoordView()

nkMaths::Vector nkGraphics::Camera::getDirectionAtScreenCoordView ( float  x,
float  y 
)

Returns the direction, in view space, for a given position on screen. , in [

Parameters
xThe x coordinate0, 1].
yThe y coordinate, in [0, 1].
Returns
The direction on screen, in view space.

◆ exportClassToTree()

virtual void nkGraphics::Camera::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

Exports an item into a tree describing its structure and its data.

Parameters
rootNodeThe node into which the object has to write its related information.

Reimplemented from nkGraphics::Node.

◆ importClassFromTree()

virtual void nkGraphics::Camera::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

Imports information from a tree which is supposed to describe its structure and data.

Parameters
rootNodeThe root node of the tree holding the information.

Reimplemented from nkGraphics::Node.

◆ create()

static nkMemory::UniquePtr<Camera> nkGraphics::Camera::create ( System system = nullptr)
static

Creates a standalone resource, linking it to a system, but no manager. This method can be used to allocate a resource and manually manage its lifetime.

Parameters
systemThe system to create the resource into. If left to nullptr, then the Singleton instance will be used.
Returns
The created resource instance.

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