Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_orthographic_camera_component_2d.hpp
1#pragma once
2
3#include "structure/engine/2d/spk_component_2d.hpp"
4#include "structure/engine/2d/spk_transform_2d.hpp"
5#include "structure/engine/spk_camera.hpp"
6#include "structure/graphics/spk_extend_2d.hpp"
7#include "structure/math/spk_vector2.hpp"
8#include "structure/opengl/spk_uniform_buffer_object.hpp"
9
10namespace spk
11{
17 {
18 private:
19 static spk::OpenGL::UBO &_cameraUBO();
20
21 static inline const OrthographicCameraComponent2D *_activeCamera = nullptr;
22
23 spk::ContractProvider::Contract _onTransformEditContract;
24 spk::ContractProvider::Contract _onCameraProjectionEditContract;
25 Camera _camera;
26 spk::Extend2D _geometry;
27 bool _hasGeometry = false;
28
29 struct ProjectionPolicy
30 {
31 spk::Vector2 pixelsPerUnit = {1.0f, 1.0f};
32 float nearPlane = 0.1f;
33 float farPlane = 1000.0f;
34 };
35
36 ProjectionPolicy _policy;
37
38 void _applyProjection();
39 void _onGeometryChange(const spk::Extend2D &p_geometry) override;
40
41 public:
46 explicit OrthographicCameraComponent2D(const std::wstring &p_name);
47
49 void start() override;
50
55 void setPixelsPerUnit(const spk::Vector2 &p_pixelsPerUnit);
60 const spk::Vector2 &pixelsPerUnit() const;
66 void setNearFar(float p_nearPlane, float p_farPlane);
68 void setAsActive() const;
69 };
70}
Stores projection matrices and converts screen coordinates.
Definition spk_camera.hpp:16
Component2D(const std::wstring &p_name)
Builds a 2D component with a name.
Definition spk_component_2d.cpp:9
const spk::Vector2 & pixelsPerUnit() const
Returns the pixels-per-unit scale.
Definition spk_orthographic_camera_component_2d.cpp:88
void setNearFar(float p_nearPlane, float p_farPlane)
Sets the near and far clipping planes.
Definition spk_orthographic_camera_component_2d.cpp:93
void setPixelsPerUnit(const spk::Vector2 &p_pixelsPerUnit)
Sets the pixels-per-unit scale.
Definition spk_orthographic_camera_component_2d.cpp:82
void start() override
Initializes camera resources and registers update hooks.
Definition spk_orthographic_camera_component_2d.cpp:62
OrthographicCameraComponent2D(const std::wstring &p_name)
Creates an orthographic camera component.
Definition spk_orthographic_camera_component_2d.cpp:53
void setAsActive() const
Marks this camera as the active camera.
Definition spk_orthographic_camera_component_2d.cpp:100
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24