galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::graphics::Camera Class Referencefinal

Orthographic 2D camera. More...

#include <Camera.hpp>

+ Inheritance diagram for galaxy::graphics::Camera:
+ Collaboration diagram for galaxy::graphics::Camera:

Classes

struct  Data
 Camera data. More...
 

Public Member Functions

 Camera ()
 Constructor.
 
 Camera (const nlohmann::json &json)
 JSON constructor.
 
 Camera (Camera &&)
 Move constructor.
 
Cameraoperator= (Camera &&)
 Move assignment operator.
 
 Camera (const Camera &)
 Copy constructor.
 
Cameraoperator= (const Camera &)
 Copy assignment operator.
 
virtual ~Camera ()
 Destructor.
 
void set_viewport (const float width, const float height)
 Set Viewport.
 
void translate (const float x, const float y) override
 Translate (move) position.
 
void rotate (const float degrees) override
 Rotate entity.
 
const glm::vec2 & get_viewport () const
 Get camera viewport.
 
const glm::mat4 & get_model_view ()
 Retrieve internal transformation matrix.
 
const glm::mat4 & get_proj ()
 Get the Camera projection.
 
Dataget_data ()
 Get camera view and proj.
 
nlohmann::json serialize () override
 Serializes object.
 
void deserialize (const nlohmann::json &json) override
 Deserializes from object.
 
- Public Member Functions inherited from galaxy::graphics::Transform
 Transform ()
 Constructor.
 
 Transform (Transform &&)
 Move constructor.
 
Transformoperator= (Transform &&)
 Move assignment operator.
 
 Transform (const Transform &)
 Copy constructor.
 
Transformoperator= (const Transform &)
 Copy assignment operator.
 
virtual ~Transform ()
 Destructor.
 
void scale (const float scale)
 Set entity scale.
 
void set_scale_horizontal (const float x)
 Set entity scale.
 
void set_scale_vertical (const float y)
 Set entity scale.
 
void set_pos (const float x, const float y)
 Sets position without moving the entity.
 
void set_rotation (const float degrees)
 Set the entity rotation.
 
void set_origin (const float x, const float y)
 Set the origin point.
 
void reset ()
 Reset transform.
 
const glm::vec2 & get_pos () const
 Get stored position.
 
float get_rotation () const
 Get stored rotation.
 
const glm::vec2 & get_scale () const
 Get stored scale.
 
const glm::vec2 & get_origin () const
 Get origin point.
 
glm::mat4 & get_transform ()
 Retrieve internal transformation matrix.
 

Public Attributes

bool m_allow_rotation
 Allow camera to rotate.
 
float m_translation_speed
 Movement speed.
 
float m_rotation_speed
 Rotational speed.
 

Private Member Functions

void set_projection (const float left, const float right, const float bottom, const float top)
 Set camera projection.
 
void recalculate ()
 Recalculates the model view matrix.
 

Private Attributes

Data m_data
 Camera data.
 
glm::vec2 m_viewport
 Camera viewport size.
 

Additional Inherited Members

- Protected Attributes inherited from galaxy::graphics::Transform
glm::vec2 m_pos
 Cached for easy retrieval. Pos.
 
float m_rotation
 Cached for easy retrieval. Rotation.
 
glm::vec2 m_scale
 Cached for easy retrieval. Scale.
 
glm::vec2 m_origin
 Transform origin point.
 
bool m_dirty
 Flag to see if transform needs to be recalculated.
 
glm::mat4 m_transform
 Combined transform.
 

Detailed Description

Orthographic 2D camera.

Definition at line 27 of file Camera.hpp.

Constructor & Destructor Documentation

◆ Camera() [1/4]

galaxy::graphics::Camera::Camera ( )

Constructor.

Definition at line 17 of file Camera.cpp.

◆ Camera() [2/4]

galaxy::graphics::Camera::Camera ( const nlohmann::json & json)

JSON constructor.

Parameters
jsonJSON object.

Definition at line 24 of file Camera.cpp.

+ Here is the call graph for this function:

◆ Camera() [3/4]

galaxy::graphics::Camera::Camera ( Camera && c)

Move constructor.

Definition at line 32 of file Camera.cpp.

◆ Camera() [4/4]

galaxy::graphics::Camera::Camera ( const Camera & c)

Copy constructor.

Definition at line 60 of file Camera.cpp.

◆ ~Camera()

galaxy::graphics::Camera::~Camera ( )
virtual

Destructor.

Definition at line 88 of file Camera.cpp.

Member Function Documentation

◆ operator=() [1/2]

Camera & galaxy::graphics::Camera::operator= ( Camera && c)

Move assignment operator.

Definition at line 43 of file Camera.cpp.

+ Here is the call graph for this function:

◆ operator=() [2/2]

Camera & galaxy::graphics::Camera::operator= ( const Camera & c)

Copy assignment operator.

Definition at line 71 of file Camera.cpp.

+ Here is the call graph for this function:

◆ set_viewport()

void galaxy::graphics::Camera::set_viewport ( const float width,
const float height )

Set Viewport.

Calls set_projection().

Parameters
widthWidth of viewport, independant of window size.
heightHeight of viewport, independant of window size.

Definition at line 92 of file Camera.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translate()

void galaxy::graphics::Camera::translate ( const float x,
const float y )
overridevirtual

Translate (move) position.

Parameters
xHow far to translate on x axis.
yHow far to translate on y axis.

Reimplemented from galaxy::graphics::Transform.

Definition at line 97 of file Camera.cpp.

+ Here is the caller graph for this function:

◆ rotate()

void galaxy::graphics::Camera::rotate ( const float degrees)
overridevirtual

Rotate entity.

Parameters
degreesAdditive. Min -360, max 360.

Reimplemented from galaxy::graphics::Transform.

Definition at line 105 of file Camera.cpp.

+ Here is the caller graph for this function:

◆ get_viewport()

const glm::vec2 & galaxy::graphics::Camera::get_viewport ( ) const
nodiscard

Get camera viewport.

Returns
glm::vec2 reference.

Definition at line 113 of file Camera.cpp.

+ Here is the caller graph for this function:

◆ get_model_view()

const glm::mat4 & galaxy::graphics::Camera::get_model_view ( )
nodiscard

Retrieve internal transformation matrix.

Returns
Reference to internal glm::mat4.

Definition at line 118 of file Camera.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_proj()

const glm::mat4 & galaxy::graphics::Camera::get_proj ( )
nodiscard

Get the Camera projection.

Returns
Const glm::mat4 reference.

Definition at line 124 of file Camera.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_data()

Camera::Data & galaxy::graphics::Camera::get_data ( )
nodiscard

Get camera view and proj.

Returns
Reference to camera data.

Definition at line 130 of file Camera.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

nlohmann::json galaxy::graphics::Camera::serialize ( )
nodiscardoverride

Serializes object.

Returns
JSON object containing data to be serialized.

Definition at line 158 of file Camera.cpp.

+ Here is the caller graph for this function:

◆ deserialize()

void galaxy::graphics::Camera::deserialize ( const nlohmann::json & json)
override

Deserializes from object.

Parameters
jsonJson object to retrieve data from.

Definition at line 173 of file Camera.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_projection()

void galaxy::graphics::Camera::set_projection ( const float left,
const float right,
const float bottom,
const float top )
private

Set camera projection.

Parameters
leftLeft point of ortho perspective.
rightRight point of ortho perspective.
bottomBottom point of ortho perspective.
topTop point of ortho perspective.

Definition at line 136 of file Camera.cpp.

+ Here is the caller graph for this function:

◆ recalculate()

void galaxy::graphics::Camera::recalculate ( )
private

Recalculates the model view matrix.

Definition at line 149 of file Camera.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_allow_rotation

bool galaxy::graphics::Camera::m_allow_rotation

Allow camera to rotate.

Definition at line 177 of file Camera.hpp.

◆ m_translation_speed

float galaxy::graphics::Camera::m_translation_speed

Movement speed.

Definition at line 182 of file Camera.hpp.

◆ m_rotation_speed

float galaxy::graphics::Camera::m_rotation_speed

Rotational speed.

Definition at line 187 of file Camera.hpp.

◆ m_data

Data galaxy::graphics::Camera::m_data
private

Camera data.

Definition at line 193 of file Camera.hpp.

◆ m_viewport

glm::vec2 galaxy::graphics::Camera::m_viewport
private

Camera viewport size.

Definition at line 198 of file Camera.hpp.


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