Calamity Engine 1.0.0
A cross-platform 2D game engine written in C++ and SDL3.
Loading...
Searching...
No Matches
Camera Class Reference

#include <components.hpp>

Inheritance diagram for Camera:
Component

Public Member Functions

void setActive ()
 
void update (float deltaTime) override
 
void initialize () override
 
Vector2 getGlobalPosition ()
 
Transform getCameraTransform () const
 
Vector2 screenToWorld (Vector2 screen) const
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 
- Public Member Functions inherited from Component
virtual ~Component ()=default
 
virtual void render (std::shared_ptr< Window > window)
 
virtual void physicsUpdate ()
 
virtual void input (InputEvent &event)
 
virtual void postLoad ()
 
virtual void exit ()
 
NodegetNode () const
 
void setNode (Node *n)
 
template<class Archive >
void save (Archive &ar) const
 
template<class Archive >
void load (Archive &ar)
 

Public Attributes

bool active = true
 
Vector2 origin = {0.5f, 0.5f}
 
float smoothing = 0.0f
 

Detailed Description

Camera component

The camera component it a virtual camera that defines the positions and scale/rotation of everything rendered on screen. Just like how cameras work in real life and in every other game engine!

Example usage:

std::shared_ptr<Node> node = std::make_shared<Node>("cameraNode");
std::shared_ptr<Camera> camera = std::make_shared<Camera>();
node->addComponent(camera);

Properties and usages

The Camera component has an origin attribute, which allows you to render the camera offset depending on the position of its parent node:

camera->origin = {0.0f, 0.0f}; // The camera's top left position will now be the position of the node, as opposed to the default origin of {0.5f, 0.5f} which means the middle of the camera will be the position of the node.

The Camera component also exposes a smoothing attribute, which allows you to smooth the cameras position.

camera->smoothing = 0.3f; // Now, whenever you move the camera, instead of moving linearly the camera will smoothly move over to the target position.

Member Function Documentation

◆ getCameraTransform()

Transform Camera::getCameraTransform ( ) const

◆ getGlobalPosition()

Vector2 Camera::getGlobalPosition ( )

◆ initialize()

void Camera::initialize ( )
overridevirtual

Reimplemented from Component.

◆ load()

template<class Archive >
void Camera::load ( Archive &  ar)
inline

◆ save()

template<class Archive >
void Camera::save ( Archive &  ar) const
inline

◆ screenToWorld()

Vector2 Camera::screenToWorld ( Vector2  screen) const

◆ setActive()

void Camera::setActive ( )

◆ update()

void Camera::update ( float  deltaTime)
overridevirtual

Reimplemented from Component.

Member Data Documentation

◆ active

bool Camera::active = true

◆ origin

Vector2 Camera::origin = {0.5f, 0.5f}

◆ smoothing

float Camera::smoothing = 0.0f

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