CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Camera.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
12#include "SceneObject.hpp"
13
15
18
32
33namespace CeresEngine {
34
37 enum class CameraProjection {
43
48 };
49
57
65
68 Extent2 sensorSize;
69
72 Offset2 lensShift;
73
75 double nearPlane = 0.1;
76
78 double farPlane = std::numeric_limits<double>::infinity();
79 };
80
81 struct CE_SCRIPT_EXPORT() CameraComponent final : public Component<CameraComponent> {
83 struct Accessor;
84
87 double fieldOfView = 45.0;
88
91 double nearPlane = 0.1;
92
95 double farPlane = std::numeric_limits<double>::infinity();
96
99 double aspectRatio = 4.0 / 3.0;
100
102 GPUImagePtr renderImage;
103
106 RendererCameraSettings rendererSettings;
107
111
112 // Destroys the camera component.
113 ~CameraComponent() noexcept final;
114
115 public: // Reflection
118 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
119 CE_REFL_DATA(fieldOfView);
120 CE_REFL_DATA(nearPlane);
121 CE_REFL_DATA(farPlane);
122 CE_REFL_DATA(aspectRatio);
123 CE_REFL_DATA(renderImage);
124 CE_REFL_DATA(rendererSettings);
125 }
126 };
127
129 struct CE_SCRIPT_EXPORT() CameraComponent::Accessor : public Component<CameraComponent>::Accessor {
130 using Component<CameraComponent>::Accessor::Accessor;
131
133 [[nodiscard]] CE_SCRIPT_EXPORT()
134 double getFieldOfView() const noexcept;
135
139 void setFieldOfView(double fieldOfView) noexcept;
140
143 [[nodiscard]] CE_SCRIPT_EXPORT()
144 double getNearPlane() const noexcept;
145
150 void setNearPlane(double nearPlane) noexcept;
151
155 [[nodiscard]] CE_SCRIPT_EXPORT()
156 double getFarPlane() const noexcept;
157
162 void setFarPlane(double farPlane) noexcept;
163
165 [[nodiscard]] CE_SCRIPT_EXPORT()
166 double getAspectRatio() const noexcept;
167
170 void setAspectRatio(double aspectRatio) noexcept;
171
173 [[nodiscard]] const GPUImagePtr& getRenderImage() const;
174
176 void setRenderImage(GPUImagePtr renderImage);
177
179 [[nodiscard]] const RendererCameraSettings& getRendererSettings() const;
180
182 void setRendererSettings(const RendererCameraSettings& rendererSettings);
183
185 template<CInvocable<RendererCameraSettings&> Func> decltype(auto) updateRendererSettings(Func&& func) noexcept {
186 RendererCameraSettings settings = getRendererSettings();
187 const ScopeExit commitSettings([&]() { setRendererSettings(settings); });
188 return func(settings);
189 }
190
195 void changeViewportAspectRatio(double width, double height) noexcept;
196
197 public: // Transforms
199 [[nodiscard]] Matrix4 getProjection() const noexcept;
200
202 [[nodiscard]] Transform getView() const noexcept;
203
209 [[nodiscard]] Vector3 unproject(Vector3 screenSpaceVector) const noexcept;
210
214 // transformed
216 [[nodiscard]] CE_SCRIPT_EXPORT()
217 Vector3 project(Vector3 worldSpaceVector) const noexcept;
218
219 [[nodiscard]] Ray toRay(const Point2& point) const noexcept;
220
226 [[nodiscard]] CE_SCRIPT_EXPORT()
227 bool visible(Vector3 worldSpaceVector) const noexcept;
228
232 [[nodiscard]] bool visible(const AABox& boundingBox) const noexcept;
233
234 public: // Reflection
237 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
238 CE_REFL_DATA_GETSET(fieldOfView, getFieldOfView, setFieldOfView);
239 CE_REFL_DATA_GETSET(nearPlane, getNearPlane, setNearPlane);
240 CE_REFL_DATA_GETSET(farPlane, getFarPlane, setFarPlane);
241 CE_REFL_DATA_GETSET(aspectRatio, getAspectRatio, setAspectRatio);
242 CE_REFL_DATA_GETSET(renderImage, getRenderImage, setRenderImage);
243 CE_REFL_DATA_GETSET(rendererSettings, getRendererSettings, setRendererSettings);
244 }
245 };
246
247 class CE_SCRIPT_EXPORT() Camera final : public TSceneObject<CameraComponent> {
248 public:
249 using TSceneObject::TSceneObject;
250
251 public:
255 [[nodiscard]] CE_SCRIPT_EXPORT()
256 static Camera find(const EntityManager& entityManager) noexcept;
257 };
258
259} // namespace CeresEngine
260
263
266
269
#define CE_EXTERN_COMPONENT(T)
Definition Component.hpp:600
#define CE_ENTITY_OBJECT_HASH(T)
Definition Entity.hpp:784
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFLECTABLE_STRUCT
Definition IReflectable.hpp:47
#define CE_REFL_DATA_GETSET(N, G, S)
Definition Macros.hpp:549
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition Camera.hpp:247
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition EntityManager.hpp:49
The SceneObject template class is a helper class that EntityObjects might choose to use to provide so...
Definition SceneObject.hpp:323
Definition Concepts.hpp:43
Definition Application.hpp:19
CameraProjection
The camera lens options control the way 3D objects are represented in a 2D image.
Definition Camera.hpp:37
@ Orthographic
With Orthographic perspective objects always appear at their actual size, regardless of distance.
@ Perspective
Projects the shadow map to all objects visible in the camera's view frustum.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
A class that describes access to a CameraComponent.
Definition Camera.hpp:129
Definition Camera.hpp:81
A structure that contains settins for a camera.
Definition Camera.hpp:51
Offset2 lensShift
Allows for the adjustment of vanishing points.
Definition Camera.hpp:72
Extent2 sensorSize
This setting is an alternative way to control the field of view, as opposed to modifying the focal le...
Definition Camera.hpp:68
double orthographicScale
This controls the apparent size of objects projected on the image.
Definition Camera.hpp:64
double focalLength
The Focal Length controls the amount of zoom, i.e.
Definition Camera.hpp:56
double farPlane
The furthest point relative to the camera that drawing will occur.
Definition Camera.hpp:78
double nearPlane
The closest point relative to the camera that drawing will occur.
Definition Camera.hpp:75
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
A structure that holds renderer-specific settings for a Camera.
Definition RendererCameraSettings.hpp:274
Definition ScopeExit.hpp:15