Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
Camera.cpp
1/*
2Copyright (C) 2019,2021,2025 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#include <array>
18#include <cstring>
19#include <cmath>
20#include "Camera.h"
21#include "aeongames/AeonEngine.hpp"
23#include "aeongames/Buffer.hpp"
24#include "aeongames/Renderer.hpp"
25#include "aeongames/Scene.hpp"
26#include "aeongames/Node.hpp"
27
28namespace AeonGames
29{
30 static const StringId CameraStringId{"Camera"};
32 {
33 return CameraStringId;
34 }
35
37 {
38 }
39
40 Camera::~Camera() = default;
41
42 const StringId& Camera::GetId() const
43 {
44 return CameraStringId;
45 }
46
47 static constexpr std::array<const StringId, 3> CameraPropertyIds
48 {
49 {
50 {"Field of View"},
51 {"Near Plane"},
52 {"Far Plane"}
53 }
54 };
55
57 {
58 return CameraPropertyIds.size();
59 }
60
62 {
63 return CameraPropertyIds.data();
64 }
65
67 {
68 return mFieldOfView;
69 }
71 {
72 return mNearPlane;
73 }
74 float Camera::GetFarPlane() const
75 {
76 return mFarPlane;
77 }
78 void Camera::SetFieldOfView ( float aFieldOfView )
79 {
80 mFieldOfView = aFieldOfView;
81 }
82 void Camera::SetNearPlane ( float aNearPlane )
83 {
84 mNearPlane = aNearPlane;
85 }
86 void Camera::SetFarPlane ( float aFarPlane )
87 {
88 mFarPlane = aFarPlane;
89 }
90
92 {
93 switch ( aId )
94 {
95 case CameraPropertyIds[0]:
96 return GetFieldOfView();
97 case CameraPropertyIds[1]:
98 return GetNearPlane();
99 case CameraPropertyIds[2]:
100 return GetFarPlane();
101 }
102 return Property{};
103 }
104
105 void Camera::SetProperty ( uint32_t aId, const Property& aProperty )
106 {
107 switch ( aId )
108 {
109 case CameraPropertyIds[0]:
110 if ( std::holds_alternative<float> ( aProperty ) )
111 {
112 SetFieldOfView ( std::get<float> ( aProperty ) );
113 }
114 break;
115 case CameraPropertyIds[1]:
116 if ( std::holds_alternative<float> ( aProperty ) )
117 {
118 SetNearPlane ( std::get<float> ( aProperty ) );
119 }
120 break;
121 case CameraPropertyIds[2]:
122 if ( std::holds_alternative<float> ( aProperty ) )
123 {
124 SetFarPlane ( std::get<float> ( aProperty ) );
125 }
126 break;
127 }
128 }
129
130 void Camera::Update ( Node& aNode, double aDelta )
131 {
132 auto scene = aNode.GetScene();
133 if ( scene && scene->GetCamera() == &aNode )
134 {
135 scene->SetFieldOfView ( mFieldOfView );
136 scene->SetNear ( mNearPlane );
137 scene->SetFar ( mFarPlane );
138 }
139 }
140
141 void Camera::Render ( const Node& aNode, Renderer& aRenderer, void* aWindowId )
142 {
143 }
144
145 void Camera::ProcessMessage ( Node& aNode, uint32_t aMessageType, const void* aMessageData )
146 {
147 }
148}
Header for 4x4 matrix class.
Header for the Scene class.
void SetFarPlane(float aFarPlane)
Sets the far clipping plane distance.
Definition Camera.cpp:86
void SetFieldOfView(float aFieldOfView)
Sets the field of view.
Definition Camera.cpp:78
const StringId & GetId() const final
Get the unique identifier for this component type.
Definition Camera.cpp:42
void ProcessMessage(Node &aNode, uint32_t aMessageType, const void *aMessageData) final
Process an incoming message.
Definition Camera.cpp:145
size_t GetPropertyCount() const final
Get the number of properties exposed by this component.
Definition Camera.cpp:56
void SetProperty(uint32_t, const Property &aProperty) final
Set the value aProperty for the property identified by aId.
Definition Camera.cpp:105
void SetNearPlane(float aNearPlane)
Sets the near clipping plane distance.
Definition Camera.cpp:82
float GetNearPlane() const
Returns the near clipping plane distance.
Definition Camera.cpp:70
void Render(const Node &aNode, Renderer &aRenderer, void *aWindowId) final
Render the component.
Definition Camera.cpp:141
float GetFarPlane() const
Returns the far clipping plane distance.
Definition Camera.cpp:74
Camera()
Default constructor.
Definition Camera.cpp:36
Property GetProperty(const StringId &aId) const final
Get the value of a property.
Definition Camera.cpp:91
void Update(Node &aNode, double aDelta) final
Update the component state.
Definition Camera.cpp:130
static const StringId & GetClassId()
Returns the class identifier for the Camera component.
Definition Camera.cpp:31
const StringId * GetPropertyInfoArray() const final
Get the array of property identifiers.
Definition Camera.cpp:61
float GetFieldOfView() const
Returns the field of view in degrees.
Definition Camera.cpp:66
Abstract base class for node components.
Definition Component.hpp:39
Scene graph node representing an entity in the game world.
Definition Node.hpp:54
DLL Scene * GetScene() const
Retrieve a pointer to the scene containing the node instance.
Definition Node.cpp:95
Abstract base class for rendering backends.
Definition Renderer.hpp:44
CRC-based compile-time string identifier.
Definition StringId.hpp:31
<- This is here just for the literals
Definition AABB.hpp:31
std::variant< int, long, long long, unsigned, unsigned long, unsigned long long, float, double, std::string, std::filesystem::path > Property
A variant type that can hold any commonly used property value.
Definition Property.hpp:31