Skip to content

Class Camera

ClassList > Camera

Camera object defining viewpoint and projection for rendering.More...

  • #include <Camera.h>

Inherits the following classes: ObjectID, Transform3D

Public Types inherited from ObjectID

See ObjectID

Type Name
enum GOType
Enumeration of scene object types.

Public Types inherited from Transform

See Transform

Type Name
enum TransType
Flags for enabling/disabling transform components.

Public Attributes

Type Name
float cam_far
Far clipping plane distance.
std::vector< float > cam_floatData
Serialized camera data for GPU upload.
float cam_foc
Focal length (for depth of field effects)
glm::mat4 cam_frustum = glm::mat4(-1.0f)
Cached projection matrix.
float cam_h
Viewport height in pixels.
float cam_near
Near clipping plane distance.
float cam_pers
Perspective field of view in degrees.
glm::vec3 cam_tar = glm::vec3(0.0f, 0.0f, 0.0f)
Look-at target position.
float cam_w
Viewport width in pixels.
bool is_frustum_changed = true
Dirty flag indicating frustum needs recomputation.

Public Attributes inherited from ObjectID

See ObjectID

Type Name
bool is_rendered = true
Included in rendering pipeline.
bool is_viewport = true
Visible in viewport (editor-only)
std::string o_name
Display name in editor UI .
GOType o_type = NONE\_GO
Runtime type identifier.

Public Attributes inherited from Transform3D

See Transform3D

Type Name
glm::mat4 o_InvTransform = { 1.0f }
Cached inverse world transform matrix.
glm::mat4 o_Transform = { 1.0f }
Cached world transform matrix.
glm::vec3 o_dir_right = { 1.0f, 0.0f, 0.0f }
Right direction vector (X+)
glm::vec3 o_dir_up = { 0.0f, 1.0f, 0.0f }
Up direction vector (Y+)
glm::vec3 o_position = { 0.0f }
World position.
glm::vec3 o_rot = { 0.0f }
Euler rotation angles (radians): pitch, yaw, roll.
glm::vec3 o_scale = { 1.0f }
Local scale (non-uniform allowed)

Public Attributes inherited from Transform

See Transform

Type Name
bool is_TransF_changed = true
Transform matrix needs recomputation.
bool is_Uniform_changed = true
Uniform (non-scaled) transform needs recomputation.
bool is_invTransF_changed = true
Inverse transform needs recomputation.
bool is_invUniform_changed = true
Inverse uniform transform needs recomputation.
bool use_position = { true }
Enable position component in transform computation.
bool use_rotation = { true }
Enable rotation component in transform computation.
bool use_scale = { true }
Enable scale component in transform computation.

Public Functions

Type Name
Camera (float w, float h, float per, float n, float f)
Constructs a camera with explicit parameters.
Camera ()
Constructs a camera with default parameters.
void ChangeCamPersp (float persp)
Updates perspective field of view.
void ChangeCamRatio (float w, float h)
Updates aspect ratio from width and height.
void ChangeCamRatio (const glm::vec2 & size)
Updates aspect ratio from 2D size vector.
void GenFloatData ()
Generates float array of camera parameters for GPU.
virtual void * GetTransform () override
Returns pointer to Transform component.
void SetCamPos (const glm::vec3 & _pos)
Sets camera position in world space.
void SetCamTrans (const glm::mat4 & _trans, bool pos=true, bool rot=true)
Sets camera transform from 4x4 matrix.
void SetTarPos (const glm::vec3 & _pos)
Sets look-at target position.
~Camera ()
Destroys the camera.

Public Functions inherited from ObjectID

See ObjectID

Type Name
virtual void * GetMaterial ()
Returns pointer to object's material, if applicable.
virtual void * GetShader ()
Returns pointer to object's shader, if applicable.
virtual void * GetTransform ()
Returns pointer to object's transform, if applicable.
ObjectID ()
Constructs an ObjectID with default values.
void SetVisible (bool v, bool r)
Sets visibility flags for viewport and rendering.
~ObjectID ()
Destroys the ObjectID .

Public Functions inherited from UID

See UID

Type Name
int GetObjectID () const
Returns the unique ID of this object.
UID ()
Constructs a UID and assigns a unique ID.
virtual ~UID () = default
Virtual destructor for polymorphic use.

Public Functions inherited from Transform3D

See Transform3D

Type Name
virtual bool ApplyAllTransform () override
Recomputes transform and all parent transforms.
virtual bool ApplyTransform (bool _forced=false) override
Recomputes transform matrix if dirty.
Transform3D * GetChildTransPtr ()
Returns pointer to first child transform.
virtual bool GetInvTransform () override const
Computes inverse transform matrix.
Transform3D * GetParentTransPtr ()
Returns pointer to parent transform.
Transform3D * GetTransformPtr ()
Returns pointer to this transform.
void LookAt (const glm::vec3 & tar, const glm::vec3 & up={0, 0, 1})
Orients transform to look at target position.
void Move (const glm::vec3 & d_pos)
Translates position by offset.
void SetParent (Transform3D * _p_trans, bool _keep_offset=true)
Sets parent transform for hierarchy.
bool SetPos (const glm::vec3 & pos)
Sets world position.
bool SetPos1D (float _1d, GLuint _dim)
Sets single axis of position.
bool SetRot (const glm::vec3 & rot)
Sets rotation via Euler angles.
bool SetRot1D (float _1d, GLuint _dim)
Sets single axis of rotation.
bool SetScale (const glm::vec3 & scale)
Sets local scale.
bool SetScale1D (float _1d, GLuint _dim)
Sets single axis of scale.
bool SetTrans (const glm::mat4 & _trans, bool pos=true, bool rot=true, bool scl=true)
Sets transform from 4x4 matrix.
void Spin (const glm::vec3 & anch, const glm::vec3 & axis, const float & angle)
Rotates around arbitrary axis through anchor point.
void Spin (const glm::vec3 & anch, const glm::vec2 & angle, bool global_up=true)
Rotates around anchor with pitch/yaw.
void Trans (const glm::mat4 & _trans)
Applies transformation matrix to current transform.
Transform3D ()
Constructs a Transform3D with identity values.
virtual void UnsetParent (bool _keep_offset=true) override
Removes parent transform relationship.
virtual int _debug () override const
Debug utility for transform state inspection.
~Transform3D ()
Destroys the Transform3D .

Public Functions inherited from Transform

See Transform

Type Name
virtual bool ApplyAllTransform () = 0
Recomputes transform and all parent transforms.
virtual bool ApplyTransform (bool _forced=false) = 0
Recomputes transform matrix if dirty.
virtual bool GetInvTransform () const = 0
Computes inverse transform matrix.
virtual void UnsetParent (bool _keep_offset=true) = 0
Removes parent transform relationship.
void UseTranformComp (bool _enable, TransType _type)
Enables or disables specific transform components.
virtual int _debug () const = 0
Debug utility for transform state inspection.

Public Static Functions inherited from UID

See UID

Type Name
int GetTotalAllocated ()
Returns total number of UIDs allocated.

Detailed Description

Camera provides perspective projection with configurable FOV, aspect ratio, and near/far clip planes. It also supports orthographic projection (TODO). Transform3D provides position/rotation via standard scene graph interface.

Frustum matrices are cached and recomputed only when parameters change. Camera data can be serialized to float array for GPU upload.

Note:

Inheritance: Inherits identity from ObjectID, transform from Transform3D.

Note:

Frustum culling: Camera frustum can be used for visibility tests (TODO: implement).

Public Attributes Documentation

variable cam_far

Far clipping plane distance.

float Camera::cam_far;


variable cam_floatData

Serialized camera data for GPU upload.

std::vector<float> Camera::cam_floatData;


variable cam_foc

Focal length (for depth of field effects)

float Camera::cam_foc;


variable cam_frustum

Cached projection matrix.

glm::mat4 Camera::cam_frustum;


variable cam_h

Viewport height in pixels.

float Camera::cam_h;


variable cam_near

Near clipping plane distance.

float Camera::cam_near;


variable cam_pers

Perspective field of view in degrees.

float Camera::cam_pers;


variable cam_tar

Look-at target position.

glm::vec3 Camera::cam_tar;


variable cam_w

Viewport width in pixels.

float Camera::cam_w;


variable is_frustum_changed

Dirty flag indicating frustum needs recomputation.

bool Camera::is_frustum_changed;


Public Functions Documentation

function Camera [1/2]

Constructs a camera with explicit parameters.

Camera::Camera (
    float w,
    float h,
    float per,
    float n,
    float f
) 

Parameters:

  • w Viewport width in pixels
  • h Viewport height in pixels
  • per Perspective FOV in degrees
  • n Near clipping plane distance
  • f Far clipping plane distance

function Camera [2/2]

Constructs a camera with default parameters.

Camera::Camera () 

Note:

Default values are defined in implementation.


function ChangeCamPersp

Updates perspective field of view.

void Camera::ChangeCamPersp (
    float persp
) 

Parameters:

  • persp New FOV in degrees

Note:

Marks frustum as dirty for recomputation.


function ChangeCamRatio [1/2]

Updates aspect ratio from width and height.

void Camera::ChangeCamRatio (
    float w,
    float h
) 

Parameters:

  • w New viewport width
  • h New viewport height

Note:

Marks frustum as dirty for recomputation.


function ChangeCamRatio [2/2]

Updates aspect ratio from 2D size vector.

void Camera::ChangeCamRatio (
    const glm::vec2 & size
) 

Parameters:

Note:

Marks frustum as dirty for recomputation.


function GenFloatData

Generates float array of camera parameters for GPU.

void Camera::GenFloatData () 

Serializes camera state into cam_floatData: * 6 floats: position (3) + rotation (3) * 1 float: aspect ratio (w/h) * 1 float: FOV angle in radians

Note:

Total size: 8 floats


function GetTransform

Returns pointer to Transform component.

inline virtual void * Camera::GetTransform () override

Returns:

Pointer to Transform3D as void* (cast required)

Note:

Overrides ObjectID::GetTransform() for polymorphic access.

Implements ObjectID::GetTransform


function SetCamPos

Sets camera position in world space.

void Camera::SetCamPos (
    const glm::vec3 & _pos
) 

Parameters:

  • _pos New camera position

Note:

Updates Transform3D position.


function SetCamTrans

Sets camera transform from 4x4 matrix.

void Camera::SetCamTrans (
    const glm::mat4 & _trans,
    bool pos=true,
    bool rot=true
) 

Parameters:

  • _trans Transformation matrix
  • pos Apply position component (default: true)
  • rot Apply rotation component (default: true)

Note:

Does not apply scale component (cameras ignore scale).


function SetTarPos

Sets look-at target position.

void Camera::SetTarPos (
    const glm::vec3 & _pos
) 

Parameters:

  • _pos Target position to look at

Note:

Updates camera rotation to face target.


function ~Camera

Destroys the camera.

Camera::~Camera () 



The documentation for this class was generated from the following file src/scene/Camera.h