11#ifndef FOOLSENGINE_CAMERASYSTEM_H
12#define FOOLSENGINE_CAMERASYSTEM_H
15#include <nlohmann/json.hpp>
120 {CameraProperties::ProjectionType::FRUSTUM,
"frustum"},
121 {CameraProperties::ProjectionType::ORTHOGRAPHIC,
"orthographic"},
129 class CameraSystem:
public System<CameraSystem, std::tuple<Transform, CameraProperties>, std::tuple<>> {
219 float simulationProgress
225 .mFov { simulationProgress * nextState.
mFov + (1.f-simulationProgress) * previousState.
mFov },
226 .mAspect { simulationProgress * nextState.
mAspect + (1.f-simulationProgress) * previousState.
mAspect},
227 .mOrthographicDimensions {
241 + ((1.f-simulationProgress) * previousState.
mViewMatrix)
249 inline void from_json(
const nlohmann::json& json,
CameraProperties& cameraProperties) {
252 json.at(
"fov").get_to(cameraProperties.
mFov);
253 json.at(
"aspect").get_to(cameraProperties.
mAspect);
254 json.at(
"orthographic_dimensions")
257 json.at(
"orthographic_dimensions")
260 json.at(
"near_far_planes").at(
"near").get_to(cameraProperties.
mNearFarPlanes.x);
261 json.at(
"near_far_planes").at(
"far").get_to(cameraProperties.
mNearFarPlanes.y);
265 inline void to_json(nlohmann::json& json,
const CameraProperties& cameraProperties) {
268 {
"projection_mode", cameraProperties.mProjectionType},
269 {
"fov", cameraProperties.mFov},
270 {
"aspect", cameraProperties.mAspect},
271 {
"orthographic_dimensions", {
272 {
"horizontal", cameraProperties.mOrthographicDimensions.x},
273 {
"vertical", cameraProperties.mOrthographicDimensions.y},
275 {
"near_far_planes", {
276 {
"near", cameraProperties.mNearFarPlanes.x},
277 {
"far", cameraProperties.mNearFarPlanes.y},
CameraSystem(std::weak_ptr< ECSWorld > world)
Construct a new CameraSystem object.
Definition camera_system.hpp:136
static std::string getSystemTypeName()
Returns the ECS system type string for this object.
Definition camera_system.hpp:153
std::set< EntityID > mProjectionUpdateQueue
Entities whose camera properties were updated this frame, whose projection matrix should be recompute...
Definition camera_system.hpp:197
void onEntityEnabled(EntityID entityID) override
Adds enabled entity to the projection update and view update queues.
Definition camera_system.cpp:52
void updateActiveCameraMatrices()
Updates all matrices associated with active cameras in this world per their properties and positions.
Definition camera_system.cpp:12
void onSimulationActivated() override
Initializes the CameraSystem, querying and adding all eligible entities to update queues.
Definition camera_system.cpp:71
std::set< EntityID > mViewUpdateQueue
Entities whose position or rotation were updated this frame, whose view matrix should be recomputed a...
Definition camera_system.hpp:203
void onPreRenderStep(float simulationProgress) override
The step in which new projection and view matrices are actually computed for all active cameras.
Definition camera_system.cpp:66
void onEntityUpdated(EntityID entityID) override
Adds entity to projection and view update queues.
Definition camera_system.cpp:61
void onEntityDisabled(EntityID entityID) override
Removes extra entity related structures from system bookkeeping, if necessary.
Definition camera_system.cpp:56
RangeMapperLinear mProgressLimits
a functor that performs the actual interpolation in the default case
Definition ecs_world.hpp:354
A system template that disables systems with this form of declaration.
Definition ecs_world.hpp:1062
ToyMaker Engine's implementation of an ECS system.
T operator()(const T &previousState, const T &nextState, float simulationProgress=1.f) const
Returns an interpolated value for a component between two given states.
Definition ecs_world.hpp:2346
std::uint64_t EntityID
A single unsigned integer used as a name for an entity managed by an ECS system.
Definition ecs_world.hpp:68
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
Stores structs and classes for common components used by the SceneSystem and other related Systems.
Struct that encapsulates properties which define the (geometric) aspects of a scene camera.
Definition camera_system.hpp:51
glm::mat4 mProjectionMatrix
The projection matrix of the camera, computed based on its other properties.
Definition camera_system.hpp:97
ProjectionType mProjectionType
The type of projection used by the camera.
Definition camera_system.hpp:67
glm::mat4 mViewMatrix
The view matrix of the camera, which transforms all vertices from their world coordinates to their co...
Definition camera_system.hpp:103
glm::vec2 mNearFarPlanes
The distance, in scene units, at which the near and far planes of the viewing volume of are located r...
Definition camera_system.hpp:91
float mAspect
The ratio of the x dimension to the y dimension of the screen or image associated with the camera.
Definition camera_system.hpp:79
float mFov
(If ProjectionType::FRUSTUM) The vertical Field of View described by the camera, used to calculate mP...
Definition camera_system.hpp:73
ProjectionType
The type of projection used by this camera.
Definition camera_system.hpp:56
static std::string getComponentTypeName()
The component type string of the camera properties component.
Definition camera_system.hpp:112
glm::vec2 mOrthographicDimensions
(If ProjectionType::ORTHOGRAPHIC) The dimensions, in scene units, of the screen face of the viewing v...
Definition camera_system.hpp:85