SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Camera.cpp
Go to the documentation of this file.
1#include <Camera/Camera.hpp>
4#include <Math/Math.hpp>
5#include <Core/Window.hpp>
6
7namespace Sleak {
8
13
14 Camera::Camera(std::string Name, Math::Vector3D Position, float Fov, float Near, float Far) : GameObject(Name) {
15 this->Position = Position;
16 fieldOfView = Fov;
17 nearPlane = Near;
18 farPlane = Far;
19
20 width = static_cast<float>(Window::GetWidth());
21 height = static_cast<float>(Window::GetHeight());
22 }
23
30
31 void Camera::Update(float DeltaTime) {
33 return;
34
35 GameObject::Update(DeltaTime);
36
37 if(IsActive())
38 {
39 RecalculateViewMatrix(); // TODO: Temporary, will be replaced with dirty flag later
41 }
42
43 }
44
45 void Camera::OnResize(uint32_t width, uint32_t height ) {
46 this->width = width;
47 this->height = height;
48
50 }
51
54
55 View = Matrix4::LookAt(Position.BaseVector(), // Position
56 LookTarget.BaseVector(), // Target
57 Up.BaseVector()); // Up
58
59 // Update view frustum from VP = View * Projection (row-vector convention)
61 s_frustum.ExtractFromVP(VP);
62
64 }
65
69 width/height, // Aspect Ratio
70 nearPlane, // Near Plane
71 farPlane); // Far Plane
72 else
74 -height / 2.0f, height / 2.0f,
76 }
77}
#define D2R
Definition Math.hpp:8
void Update(float DeltaTime) override
Recalculates the view/projection matrices and frustum while active.
Definition Camera.cpp:31
static Math::Matrix4 Projection
Definition Camera.hpp:138
void RecalculateProjectionMatrix()
Rebuilds the static projection matrix from FOV/aspect/near/far or the orthographic extents.
Definition Camera.cpp:66
void OnResize(uint32_t width, uint32_t height)
Updates the viewport dimensions and recomputes the projection matrix.
Definition Camera.cpp:45
void RecalculateViewMatrix()
Rebuilds the static view matrix and view frustum from position/target/up, and begins culling for the ...
Definition Camera.cpp:52
float farPlane
Definition Camera.hpp:127
static ViewFrustum s_frustum
Definition Camera.hpp:140
static Math::Matrix4 View
Definition Camera.hpp:137
static Math::Vector3D MainPosition
Definition Camera.hpp:139
Math::Vector3D Position
Definition Camera.hpp:133
float nearPlane
Definition Camera.hpp:126
ProjectionType type
Definition Camera.hpp:131
float fieldOfView
Definition Camera.hpp:125
Math::Vector3D LookTarget
Definition Camera.hpp:134
Math::Vector3D Up
Definition Camera.hpp:135
Camera(std::string name="Camera", Math::Vector3D Position=Math::Vector3D(0, 0, -3.5), float fov=60, float near=1.0f, float far=1000.0f)
Definition Camera.cpp:14
void Initialize() override
Initializes the object and its components; called once before the first Update.
Definition Camera.cpp:24
static void BeginFrame(const ViewFrustum &frustum, const Math::Matrix4 &viewProj, const Math::Vector3D &cameraPos)
virtual void Initialize()
Initializes the object and its components; called once before the first Update.
bool IsActive() const
virtual void Update(float deltaTime)
GameObject(const std::string &name="GameObject")
static Matrix< float, Rows, Rows > Identity()
Definition Matrix.hpp:203
static Matrix< float, 4, 4 > Perspective(float fovY, float aspectRatio, float nearPlane, float farPlane)
Definition Matrix.hpp:211
static Matrix< float, 4, 4 > Orthographic(float left, float right, float bottom, float top, float nearPlane, float farPlane)
Definition Matrix.hpp:231
static Matrix< float, 4, 4 > LookAt(const Vector< float, 3 > &eye, const Vector< float, 3 > &center, const Vector< float, 3 > &up)
Definition Matrix.hpp:250
static int GetHeight()
Definition Window.hpp:48
static int GetWidth()
Definition Window.hpp:47
Matrix< float, 4, 4 > Matrix4
Definition Matrix.hpp:413
Root namespace for everything the engine exposes.
Definition Camera.hpp:10