Skylicht Engine
Loading...
Searching...
No Matches
Skylicht::CCamera Class Reference

This is an object class used to set up the camera, including its position, viewing angle, and viewing distance. More...

#include <Camera/CCamera.h>

Inheritance diagram for Skylicht::CCamera:
Skylicht::CComponentSystem Skylicht::IActivatorObject

Public Types

enum  ECameraProjection {
  Ortho , Frustum , Perspective , OrthoUI ,
  Custom
}
 Supported projection modes for the camera. More...

Public Member Functions

virtual void initComponent ()
virtual void updateComponent ()
virtual void endUpdate ()
 Finalizes transform and recalculates matrices. Called at the end of the frame update.
void setProjectionType (ECameraProjection projection)
 Sets the projection mode.
ECameraProjection getProjectionType ()
 Gets the current projection mode.
const core::matrix4 & getProjectionMatrix () const
 Returns the calculated projection matrix.
const core::matrix4 & getViewMatrix () const
 Returns the calculated view matrix.
void setViewMatrix (const core::matrix4 &view, const core::vector3df &position)
 Manually sets the view matrix and camera position.
void setProjectionMatrix (const core::matrix4 &prj)
 Manually sets the projection matrix. Switches mode to 'Custom'.
void setPosition (const core::vector3df &position)
 Sets the world position of the camera.
core::vector3df getPosition ()
 Gets the current world position of the camera.
void copyProjection (CCamera *target)
 Copies all projection parameters from another camera.
void lookAt (const core::vector3df &position, const core::vector3df &target, const core::vector3df &up)
 Configures the camera to look at a target from a specific position.
void lookAt (const core::vector3df &target, const core::vector3df &up)
 Configures the camera to look at a target from its current position.
void setUpVector (const core::vector3df &up)
 Sets the 'up' vector for view matrix calculation.
void setLookVector (core::vector3df look)
 Rotates the camera to point in a specific direction.
const core::vector3df & getUpVector ()
 Gets the current 'up' vector.
core::vector3df getLookVector ()
 Gets the current forward viewing direction.
void setNearValue (float f)
 Sets the near clipping plane distance.
float getNearValue ()
 Gets the near clipping plane distance.
void setFarValue (float f)
 Sets the far clipping plane distance.
float getFarValue ()
 Gets the far clipping plane distance.
void setFOV (float fov)
 Sets the vertical Field of View (FOV).
float getFOV ()
 Gets the vertical FOV.
void setOrthoScale (float s)
 Sets the scale for orthographic projection.
float getOrthoScale ()
 Gets the orthographic scale factor.
void setOrthoUISize (float w, float h)
 Sets a custom viewport size for OrthoUI projection.
void enableCustomOrthoUISize (bool b)
 Enables or disables custom OrthoUI sizing.
void setAspect (float f)
 Sets the aspect ratio. Set to -1 to auto-calculate from viewport.
float getAspect ()
 Gets the effective aspect ratio.
u32 getCullingMask ()
 Gets the bitmask used for culling entities.
void setCullingMask (u32 mask)
 Sets the bitmask for entity culling.
void recalculateProjectionMatrix ()
 Forces recalculation of the projection matrix.
void recalculateViewMatrix ()
 Forces recalculation of the view matrix.
const SViewFrustum & getViewFrustum ()
 Gets the view frustum (planes and matrices).
void setInputReceiver (bool b)
 Enables or disables input reception for this camera.
bool isInputReceiverEnabled ()
 Checks if the camera is receiving input.
void setUseScaledTime (bool b)
 Sets whether camera updates should use the engine's time scale.
bool isUseScaledTime ()
 Checks if the camera uses scaled time.
Public Member Functions inherited from Skylicht::CComponentSystem
const char * getName ()
virtual void reset ()
virtual void startComponent ()
virtual void onEnable (bool b)
virtual void onUpdateCullingLayer (u32 mask)
virtual CObjectSerializablecreateSerializable ()
virtual void loadSerializable (CObjectSerializable *object)
void setEnable (bool b)
bool isEnable ()
CGameObject * getGameObject ()
void setEnableSerializable (bool b)
bool isSerializable ()
void addLinkComponent (CComponentSystem *comp)
void removeAllLink ()
Public Member Functions inherited from Skylicht::IActivatorObject
virtual ~IActivatorObject ()
 Virtual destructor for polymorphic activator objects.

Protected Attributes

ECameraProjection m_projectionType
 Current projection mode.
float m_nearValue
 Near clipping plane distance.
float m_farValue
 Far clipping plane distance.
float m_fov
 Field of View in degrees.
float m_aspect
 Aspect ratio (width/height).
float m_viewportAspect
 Actual viewport aspect ratio from render target.
bool m_customOrthoSize
 Whether a custom orthographic size is used for OrthoUI.
float m_orthoUIW
float m_orthoUIH
bool m_projectionChanged
 Flag indicating the projection matrix needs recalculation.
float m_orthoScale
 Scale factor for orthographic projection.
core::vector3df m_up
 Current 'up' vector for the view matrix.
SViewFrustum m_viewArea
 Internal view frustum data (planes, matrices).
core::dimension2du m_screenSize
 Last known screen size.
bool m_inputReceiver
 Whether this camera receives input events.
u32 m_cullingMask
 Bitmask for layer-based culling.
bool m_useScaledTime
 Whether to use scaled or unscaled time for updates.
Protected Attributes inherited from Skylicht::CComponentSystem
CGameObject * m_gameObject
bool m_enable
bool m_serializable
std::vector< CComponentSystem * > m_linkComponent

Additional Inherited Members

Static Public Member Functions inherited from Skylicht::CComponentSystem
static int useComponent (CComponentSystem *used)
Protected Member Functions inherited from Skylicht::CComponentSystem
void setOwner (CGameObject *obj)

Detailed Description

This is an object class used to set up the camera, including its position, viewing angle, and viewing distance.

Example of setting up a 3D camera

CGameObject* camObj = zone->createEmptyObject();
CCamera* camera = camObj->addComponent<CCamera>();
// setup camera position
camera->setPosition(core::vector3df(10.0f, 5.0f, 10.0f));
// setup camera target
camera->lookAt(core::vector3df(0.0f, 0.0f, 0.0f), core::vector3df(0.0f, 1.0f, 0.0f));
..
..
// and render the scene with the camera that has been set up
getRenderPipeline()->render(NULL, camera, scene->getEntityManager(), core::recti())
void lookAt(const core::vector3df &position, const core::vector3df &target, const core::vector3df &up)
Configures the camera to look at a target from a specific position.
void setPosition(const core::vector3df &position)
Sets the world position of the camera.

Example of setting up a 2D orthographic camera for drawing a GUI

CGameObject* guiCameraObj = zone->createEmptyObject();
guiCameraObj->addComponent<CCamera>();
CCamera* guiCamera = guiCameraObj->getComponent<CCamera>();
guiCamera->setProjectionType(CCamera::OrthoUI);
...
...
// and render the GUI with the 2D camera.
CGraphics2D::getInstance()->render(guiCamera);
@ OrthoUI
Standard perspective projection.
Definition CCamera.h:80

Member Enumeration Documentation

◆ ECameraProjection

Supported projection modes for the camera.

Enumerator
Frustum 

Orthographic projection (for 2D or stylized 3D).

Perspective 

Custom frustum projection.

OrthoUI 

Standard perspective projection.

Custom 

Screen-space orthographic projection for UI.

Member Function Documentation

◆ copyProjection()

void Skylicht::CCamera::copyProjection ( CCamera * target)

Copies all projection parameters from another camera.

Parameters
targetSource camera.

◆ enableCustomOrthoUISize()

void Skylicht::CCamera::enableCustomOrthoUISize ( bool b)
inline

Enables or disables custom OrthoUI sizing.

Parameters
bTrue to use custom size, false to use screen size.

◆ endUpdate()

virtual void Skylicht::CCamera::endUpdate ( )
virtual

Finalizes transform and recalculates matrices. Called at the end of the frame update.

Reimplemented from Skylicht::CComponentSystem.

◆ getAspect()

float Skylicht::CCamera::getAspect ( )
inline

Gets the effective aspect ratio.

Returns
Aspect ratio.

◆ getCullingMask()

u32 Skylicht::CCamera::getCullingMask ( )
inline

Gets the bitmask used for culling entities.

Returns
Bitmask.

◆ getFarValue()

float Skylicht::CCamera::getFarValue ( )
inline

Gets the far clipping plane distance.

Returns
Distance.

◆ getFOV()

float Skylicht::CCamera::getFOV ( )
inline

Gets the vertical FOV.

Returns
FOV in degrees.

◆ getLookVector()

core::vector3df Skylicht::CCamera::getLookVector ( )

Gets the current forward viewing direction.

Returns
Direction vector.

◆ getNearValue()

float Skylicht::CCamera::getNearValue ( )
inline

Gets the near clipping plane distance.

Returns
Distance.

◆ getOrthoScale()

float Skylicht::CCamera::getOrthoScale ( )
inline

Gets the orthographic scale factor.

Returns
Scale.

◆ getPosition()

core::vector3df Skylicht::CCamera::getPosition ( )

Gets the current world position of the camera.

Returns
Position vector.

◆ getProjectionMatrix()

const core::matrix4 & Skylicht::CCamera::getProjectionMatrix ( ) const

Returns the calculated projection matrix.

Returns
4x4 matrix.

◆ getProjectionType()

ECameraProjection Skylicht::CCamera::getProjectionType ( )
inline

Gets the current projection mode.

Returns
ECameraProjection.

◆ getUpVector()

const core::vector3df & Skylicht::CCamera::getUpVector ( )
inline

Gets the current 'up' vector.

Returns
Up vector.

◆ getViewFrustum()

const SViewFrustum & Skylicht::CCamera::getViewFrustum ( )
inline

Gets the view frustum (planes and matrices).

Returns
Reference to SViewFrustum.

◆ getViewMatrix()

const core::matrix4 & Skylicht::CCamera::getViewMatrix ( ) const

Returns the calculated view matrix.

Returns
4x4 matrix.

◆ initComponent()

virtual void Skylicht::CCamera::initComponent ( )
virtual

◆ isInputReceiverEnabled()

bool Skylicht::CCamera::isInputReceiverEnabled ( )
inline

Checks if the camera is receiving input.

Returns
True if input is enabled.

◆ isUseScaledTime()

bool Skylicht::CCamera::isUseScaledTime ( )
inline

Checks if the camera uses scaled time.

Returns
True if using scaled time.

◆ lookAt() [1/2]

void Skylicht::CCamera::lookAt ( const core::vector3df & position,
const core::vector3df & target,
const core::vector3df & up )

Configures the camera to look at a target from a specific position.

Parameters
positionWorld position of the camera.
targetWorld position of the look-at target.
upUp vector (default: Y-up).

◆ lookAt() [2/2]

void Skylicht::CCamera::lookAt ( const core::vector3df & target,
const core::vector3df & up )

Configures the camera to look at a target from its current position.

Parameters
targetWorld position of the look-at target.
upUp vector (default: Y-up).

◆ setAspect()

void Skylicht::CCamera::setAspect ( float f)
inline

Sets the aspect ratio. Set to -1 to auto-calculate from viewport.

Parameters
fAspect ratio (W/H).

◆ setCullingMask()

void Skylicht::CCamera::setCullingMask ( u32 mask)
inline

Sets the bitmask for entity culling.

Parameters
maskBitmask.

◆ setFarValue()

void Skylicht::CCamera::setFarValue ( float f)
inline

Sets the far clipping plane distance.

Parameters
fDistance.

◆ setFOV()

void Skylicht::CCamera::setFOV ( float fov)
inline

Sets the vertical Field of View (FOV).

Parameters
fovFOV in degrees.

◆ setInputReceiver()

void Skylicht::CCamera::setInputReceiver ( bool b)
inline

Enables or disables input reception for this camera.

Parameters
bInput status.

◆ setLookVector()

void Skylicht::CCamera::setLookVector ( core::vector3df look)

Rotates the camera to point in a specific direction.

Parameters
lookDirection vector.

◆ setNearValue()

void Skylicht::CCamera::setNearValue ( float f)
inline

Sets the near clipping plane distance.

Parameters
fDistance.

◆ setOrthoScale()

void Skylicht::CCamera::setOrthoScale ( float s)
inline

Sets the scale for orthographic projection.

Parameters
sScale factor.

◆ setOrthoUISize()

void Skylicht::CCamera::setOrthoUISize ( float w,
float h )
inline

Sets a custom viewport size for OrthoUI projection.

Parameters
wWidth.
hHeight.

◆ setPosition()

void Skylicht::CCamera::setPosition ( const core::vector3df & position)

Sets the world position of the camera.

Parameters
positionWorld position vector.

◆ setProjectionMatrix()

void Skylicht::CCamera::setProjectionMatrix ( const core::matrix4 & prj)

Manually sets the projection matrix. Switches mode to 'Custom'.

Parameters
prjThe 4x4 projection matrix.

◆ setProjectionType()

void Skylicht::CCamera::setProjectionType ( ECameraProjection projection)

Sets the projection mode.

Parameters
projectionMode to set.

◆ setUpVector()

void Skylicht::CCamera::setUpVector ( const core::vector3df & up)

Sets the 'up' vector for view matrix calculation.

Parameters
upUp vector.

◆ setUseScaledTime()

void Skylicht::CCamera::setUseScaledTime ( bool b)
inline

Sets whether camera updates should use the engine's time scale.

Parameters
bTrue for scaled time, false for raw time.

◆ setViewMatrix()

void Skylicht::CCamera::setViewMatrix ( const core::matrix4 & view,
const core::vector3df & position )

Manually sets the view matrix and camera position.

Parameters
viewThe 4x4 view matrix.
positionWorld position of the camera.

◆ updateComponent()

virtual void Skylicht::CCamera::updateComponent ( )
virtual

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