Brunot
Loading...
Searching...
No Matches
Camera.h
Go to the documentation of this file.
1// File: Camera.h
2// Description: A system for setting up a callback to opengl for window resizing and calculating the view transforms
3// Author(s): Aidan Hartman (aidan.hartman@digipen.edu)
4// 2025 / 10 / 06
5// (C) Digipen 2025
6// ____ __ __ __
7// /\__ _\/\ \ /\ \/\ \
8// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
9// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
10// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
11// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
12// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
13#pragma once
14#include "opengl.h"
15#include "Eigen/Dense"
16#include "Framework/System.h"
17
18//Forward declarations
19struct GLFWwindow;
20
21
22namespace sys
23{
24class Camera : public System
25{
26public:
27#pragma region static_functions
28 static float farPlane;
29 static float nearPlane;
30
34 static auto getEnum() -> Type
35 {
36 return Type::Camera;
37 }
38
39 static auto init(GLFWwindow* window, int width, int height) -> void;
40
45 static auto view() -> const Eigen::Matrix4f&;
50 static auto projection() -> const Eigen::Matrix4f&;
51
52 static auto screen() -> const Eigen::Matrix4f&;
53#pragma endregion
54
55 Camera();
56 ~Camera() override = default;
57 Camera(const Camera& other) = default;
58 Camera(Camera&& other) noexcept;
59 auto operator=(const Camera& other) -> Camera&;
60 auto operator=(Camera&& other) noexcept -> Camera& = default;
61
62
63#pragma region overridden_functions
64
65 auto clone() const -> std::unique_ptr<GameObject> override
66 {
67 return std::make_unique<Camera>(*this);
68 }
69
70 auto onUpdate(float dt) -> void override;
71
72 auto endWindow() -> void override
73 {
74 }; // for debug ImGUI
75
76protected:
77 auto systemShowMenu() -> void override;
78
79public:
80 auto onRender() -> void override;
81 auto load(const Stream& stream) -> void override;
82 auto save(Stream& stream) const -> void override;
83
84#pragma endregion
85
86#pragma region Camera_Functions
87
93 static void calculateAllTransforms(int width, int height);
94
95#pragma endregion
96
97private:
98#pragma region member_variables
99
100#pragma endregion
101
102#pragma region helper_functions
103
110 static auto resizeViewport(GLFWwindow* window, int width, int height) -> void;
111
118 static auto calculateProjection(int width, int height, Eigen::Vector3f cameraPos) -> void;
119
125 static auto calculateScreen(int w, int h) -> void;
126
134 static auto lookAt(const Eigen::Vector3f& eye, const Eigen::Vector3f center,
135 const Eigen::Vector3f up) -> Eigen::Matrix4f;
136
137
138#pragma endregion
139
140#pragma region static_variables
141
143 static Eigen::Matrix4f viewTransform;
145 static Eigen::Matrix4f projectionTransform;
147 static Eigen::Matrix4f NDCToScreen;
148
149#pragma endregion
150
151
152};
153}
154
sys::Json Stream
Definition AudioObject.h:20
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Type
Definition System.h:20
@ Camera
Definition System.h:27
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
auto systemShowMenu() -> void override
Specific systems should override this function to show their specific menu for the system.
Definition Camera.cpp:61
static Eigen::Matrix4f projectionTransform
the camera space to NDC transform
Definition Camera.h:145
static auto init(GLFWwindow *window, int width, int height) -> void
Definition Camera.cpp:225
static auto screen() -> const Eigen::Matrix4f &
Definition Camera.cpp:241
static Eigen::Matrix4f viewTransform
the world to camera space transform
Definition Camera.h:143
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Camera.cpp:70
static auto resizeViewport(GLFWwindow *window, int width, int height) -> void
callback function that opengl calls when the window resizes
Definition Camera.cpp:199
Camera(const Camera &other)=default
auto operator=(const Camera &other) -> Camera &
Definition Camera.cpp:43
static void calculateAllTransforms(int width, int height)
helper function to update all the camera transforms based on camera's position, and new width and hei...
Definition Camera.cpp:176
static auto calculateScreen(int w, int h) -> void
helper function to calculate the screen matrix transform
Definition Camera.cpp:106
static auto getEnum() -> Type
function required by all systems
Definition Camera.h:34
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Camera.h:65
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Camera.cpp:75
static auto lookAt(const Eigen::Vector3f &eye, const Eigen::Vector3f center, const Eigen::Vector3f up) -> Eigen::Matrix4f
calculate the camera matrix transform, based on pointing to a specific object
Definition Camera.cpp:85
auto operator=(Camera &&other) noexcept -> Camera &=default
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Camera.cpp:66
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Camera.h:72
static auto view() -> const Eigen::Matrix4f &
gets the view transform for the camera
Definition Camera.cpp:231
Camera()
Definition Camera.cpp:31
static float nearPlane
Definition Camera.h:29
static Eigen::Matrix4f NDCToScreen
the NDC to screen transform
Definition Camera.h:147
static auto projection() -> const Eigen::Matrix4f &
Gets the orthogonal projection matrix for the camera.
Definition Camera.cpp:236
static float farPlane
Definition Camera.h:28
~Camera() override=default
static auto calculateProjection(int width, int height, Eigen::Vector3f cameraPos) -> void
helper function to calculate the projection matrix transform
Definition Camera.cpp:133
auto onUpdate(float dt) -> void override
called once every frame.
Definition Camera.cpp:56
the type of elements in a basic_json container
Definition GameObject.h:37