VenomEngine
Cross-Platform Modern Graphics Engine
Loading...
Searching...
No Matches
Camera.h
Go to the documentation of this file.
1
8#pragma once
9
11#include <venom/common/Error.h>
12
14
16
17namespace venom
18{
19namespace common
20{
21class Camera;
22
24{
25 // Frustums and positions of near and far corners of each cascade
26 vcm::Vec3 cascadeFrustumsCorners[VENOM_CSM_TOTAL_CASCADES + 1][4];
27 vcm::Vec3 cascadeFrustumsCenters[VENOM_CSM_TOTAL_CASCADES];
28 // The ones delimiting each cascade and the near and far planes
29 vcm::Vec3 cascadeFrustumsPlanes[VENOM_CSM_TOTAL_CASCADES][4];
30 // As in the name, the radius of each cascade (max distance from the center at it still has effect)
31 float cascadeFrustumsRadius[VENOM_CSM_TOTAL_CASCADES];
32};
33
35{
36 vc::Entity entity;
37 vcm::Vec3 planeNormal;
38};
39
40class VENOM_COMMON_API CameraImpl : public PluginObjectImpl, public GraphicsPluginObject
41{
42public:
43 CameraImpl();
44 virtual ~CameraImpl();
45
46 // View matrix generation
47 const vcm::Mat4 & GetViewMatrix(); // Generate and return the view matrix
48 vcm::Mat4 & GetViewMatrixMut(); // Generate and return the view matrix
49
50 // Projection matrix generation
51 void SetPerspective(float fovY, float aspectRatio, float nearPlane, float farPlane); // Set perspective projection
52 const vcm::Mat4 & GetProjectionMatrix(); // Generate and return the projection matrix
53
54 void SetPosition(const vcm::Vec3& position);
55 void Move(const vcm::Vec3& delta);
56 void MoveForward(const float delta);
57 void MoveRight(const float delta);
58 void MoveUp(const float delta);
59 const vcm::Vec3 & GetPosition();
60
61 void SetYaw(float angle);
62 void SetPitch(float angle);
63 void SetRoll(float angle);
64 void SetRotation(const vcm::Vec3& rotation);
65 inline void SetRawRotation(const vcm::Vec3& rotation) { __transform->SetRawRotation(rotation); }
66 void RotateYaw(float angle);
67 void RotatePitch(float angle);
68 void RotateRoll(float angle);
69 void Rotate(const vcm::Vec3 & rotation);
70 const vcm::Quat & GetRotationQuat() const;
71 const vcm::Vec3 & GetRotation() const;
72
73 vcm::Vec3 GetForwardVector() const;
74 vcm::Vec3 GetUpVector() const;
75 vcm::Vec3 GetRightVector() const;
76
77 void RotateAround(const vcm::Vec3& target, const vcm::Vec3& planeNormal, float angle);
78
79 void SetFocusEntity(vc::Entity entity);
80 vc::Entity GetFocusEntity();
81 void RemoveFocusEntity();
82
83 // Camera configuration
84 void SetFieldOfView(float fovY); // Set field of view (vertical)
85 float GetFieldOfView() const; // Get field of view
86
87 void SetAspectRatio(float aspectRatio); // Set aspect ratio (width / height)
88 float GetAspectRatio() const; // Get aspect ratio
89
90 void SetNearPlane(float nearPlane); // Set near clipping plane distance
91 float GetNearPlane() const; // Get near clipping plane
92
93 void SetFarPlane(float farPlane); // Set far clipping plane distance
94 float GetFarPlane() const; // Get far clipping plane
95
96 void LookAt(const vcm::Vec3& target); // Point camera towards a specific target
97
98 const CameraCascadedShadowMapData & GetCascadedShadowMapData();
99
100private:
101 Transform3D * __transform;
102
103 CameraFocusData __focusData;
104
105 vcm::Mat4 __viewMatrix;
106 vcm::Mat4 __projectionMatrix;
107
108 // Projection parameters
109 float __fov;
110 float __aspect;
111 float __near;
112 float __far;
113
114 // Internal state
115 bool __projectionMatrixDirty;
116 bool __viewMatrixDirty;
117 bool __csmDataDirty;
118
119 void __UpdateViewMatrix();
120 void __UpdateProjectionMatrix();
121
123
124 friend class Camera;
125};
126
131class VENOM_COMMON_API Camera : public Component, public PluginObjectImplWrapper
132{
133public:
134 Camera();
135 ~Camera();
136 static void SetMainCamera(const Camera & camera);
137 static Camera * GetMainCamera();
138
139 void _GUI(const Entity entity) override;
140 void Init(Entity entity) override;
141 void Update(Entity entity) override;
142 bool CanRemove(Entity entity) override;
143 vc::String _GetComponentTitle() override;
144
145 inline void SetPosition(const vcm::Vec3& position) { _impl->As<CameraImpl>()->SetPosition(position); }
146 inline void Move(const vcm::Vec3& delta) { _impl->As<CameraImpl>()->Move(delta); }
147 inline void MoveForward(const float delta) { _impl->As<CameraImpl>()->MoveForward(delta); }
148 inline void MoveRight(const float delta) { _impl->As<CameraImpl>()->MoveRight(delta); }
149 inline void MoveUp(const float delta) { _impl->As<CameraImpl>()->MoveUp(delta); }
150 inline const vcm::Vec3 & GetPosition() const { return _impl->As<CameraImpl>()->GetPosition(); }
151
152 inline void SetYaw(float angle) { _impl->As<CameraImpl>()->SetYaw(angle); }
153 inline void SetPitch(float angle) { _impl->As<CameraImpl>()->SetPitch(angle); }
154 inline void SetRoll(float angle) { _impl->As<CameraImpl>()->SetRoll(angle); }
155 inline void SetRotation(const vcm::Vec3& rotation) { _impl->As<CameraImpl>()->SetRotation(rotation); }
156 inline void SetRawRotation(const vcm::Vec3& rotation) { _impl->As<CameraImpl>()->SetRawRotation(rotation); }
157 inline void RotateYaw(float angle) { _impl->As<CameraImpl>()->RotateYaw(angle); }
158 inline void RotatePitch(float angle) { _impl->As<CameraImpl>()->RotatePitch(angle); }
159 inline void RotateRoll(float angle) { _impl->As<CameraImpl>()->RotateRoll(angle); }
160 inline void Rotate(const vcm::Vec3 & rotation) { _impl->As<CameraImpl>()->Rotate(rotation); }
161 inline const vcm::Quat & GetRotationQuat() const { return _impl->As<CameraImpl>()->GetRotationQuat(); }
162 inline const vcm::Vec3 & GetRotation() const { return _impl->As<CameraImpl>()->GetRotation(); }
163
164 inline vcm::Vec3 GetForwardVector() const { return _impl->As<CameraImpl>()->GetForwardVector(); }
165 inline vcm::Vec3 GetUpVector() const { return _impl->As<CameraImpl>()->GetUpVector(); }
166 inline vcm::Vec3 GetRightVector() const { return _impl->As<CameraImpl>()->GetRightVector(); }
167
168 inline void RotateAround(const vcm::Vec3& target, const vcm::Vec3& planeNormal, float angle) { _impl->As<CameraImpl>()->RotateAround(target, planeNormal, angle); }
169
170 inline const vcm::Mat4 & GetViewMatrix() const { return _impl->As<CameraImpl>()->GetViewMatrix(); }
171 inline vcm::Mat4 & GetViewMatrixMut() { return _impl->As<CameraImpl>()->GetViewMatrixMut(); }
172 inline void SetPerspective(float fovY, float aspectRatio, float nearPlane, float farPlane) { _impl->As<CameraImpl>()->SetPerspective(fovY, aspectRatio, nearPlane, farPlane); }
173 inline const vcm::Mat4 & GetProjectionMatrix() const { return _impl->As<CameraImpl>()->GetProjectionMatrix(); }
174
175 inline void SetFieldOfView(float fovY) { _impl->As<CameraImpl>()->SetFieldOfView(fovY); }
176 inline float GetFieldOfView() const { return _impl->As<CameraImpl>()->GetFieldOfView(); }
177
178 inline void SetAspectRatio(float aspectRatio) { _impl->As<CameraImpl>()->SetAspectRatio(aspectRatio); }
179 inline float GetAspectRatio() const { return _impl->As<CameraImpl>()->GetAspectRatio(); }
180
181 inline void SetNearPlane(float nearPlane) { _impl->As<CameraImpl>()->SetNearPlane(nearPlane); }
182 inline float GetNearPlane() const { return _impl->As<CameraImpl>()->GetNearPlane(); }
183
184 inline void SetFarPlane(float farPlane) { _impl->As<CameraImpl>()->SetFarPlane(farPlane); }
185 inline float GetFarPlane() const { return _impl->As<CameraImpl>()->GetFarPlane(); }
186
187 inline void LookAt(const vcm::Vec3& target) { _impl->As<CameraImpl>()->LookAt(target); }
188
189 inline void SetFocusEntity(vc::Entity entity) { _impl->As<CameraImpl>()->SetFocusEntity(entity); }
190 inline vc::Entity GetFocusEntity() const { return _impl->As<CameraImpl>()->GetFocusEntity(); }
191 inline void RemoveFocusEntity() { _impl->As<CameraImpl>()->RemoveFocusEntity(); }
192};
193}
194}
Camera class Classic layout with position, rotation and projection matrices.
Definition Camera.h:132
Definition Camera.h:41
Definition Transform3D.h:18
High-Level Frontend of the VenomEngine project. It also contains all the code shared between every AP...
Definition Callback.h:15
Contains the entirety of the code of the VenomEngine project.
Definition Callback.h:13
Definition Camera.h:35