CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
SceneObject.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
10#include "Forward.hpp"
11
13
20
21namespace CeresEngine {
22
23 struct CE_SCRIPT_EXPORT() TransformComponent final : public Component<TransformComponent> {
25 struct Accessor;
26
29 Vector3 position = Vector3(0.0);
30
33 Quaternion rotation = Quaternion(Vector3(0.0));
34
37 Vector3 scale = Vector3(1.0);
38
39 public: // Reflection
42 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
43 CE_REFL_DATA(position);
44 CE_REFL_DATA(rotation);
46 }
47 };
48
49 struct CE_SCRIPT_EXPORT() TransformComponent::Accessor : public Component<TransformComponent>::Accessor {
50 using Component<TransformComponent>::Accessor::Accessor;
51
52 public: // Local space
54 [[nodiscard]] const Vector3& getPosition() const noexcept;
55
57 void setPosition(const Vector3& position) noexcept;
58
60 [[nodiscard]] const Quaternion& getRotation() const noexcept;
61
63 void setRotation(const Quaternion& rotation) noexcept;
64
66 [[nodiscard]] const Vector3& getScale() const noexcept;
67
69 void setScale(const Vector3& scale) noexcept;
70
73 [[nodiscard]] Transform getTransform() const noexcept;
74
77 void setTransform(const Transform& transform) noexcept;
78
81 [[nodiscard]] Transform getInverseTransform() const noexcept;
82
87 [[nodiscard]] Vector3 getDirection() const noexcept {
88 const Matrix3 rotationMatrix = transpose(Matrix3(getRotation()));
89 return normalize(rotationMatrix[2]); // front-facing vector.
90 }
91
92 public: // World space
94 [[nodiscard]] Vector3 getWorldPosition() const noexcept;
95
97 void setWorldPosition(const Vector3& position) noexcept;
98
100 [[nodiscard]] Quaternion getWorldRotation() const noexcept;
101
103 void setWorldRotation(const Quaternion& rotation) noexcept;
104
106 [[nodiscard]] Vector3 getWorldScale() const noexcept;
107
109 void setWorldScale(const Vector3& scale) noexcept;
110
113 [[nodiscard]] Transform getWorldTransform() const noexcept;
114
117 void setWorldTransform(const Transform& transform) noexcept;
118
121 [[nodiscard]] Transform getInverseWorldTransform() const noexcept;
122
127 [[nodiscard]] Vector3 getWorldDirection() const noexcept { return getWorldTransform().getDirection(); }
128
129 public: // Apply transformations
131 void move(const Vector3& distance);
132
134 void move(const Vector3& direction, double distance);
135
137 void rotate(const Quaternion& quaternion);
138
140 void rotate(const Vector3& axis, const Radian& angle);
141
143 void roll(const Radian& angle);
144
146 void yaw(const Radian& angle);
147
149 void pitch(const Radian& angle);
150
152 void turn(const Radian& angle);
153
155 void scale(const Vector3& factor);
156
158 void scale(double factor);
159
161 void transform(const Transform& transform);
162
163 public: // Look at
167 void lookAt(const Vector3& point) noexcept;
168
173 void lookAt(const SceneObject& entity) noexcept;
174
175 public: // Rotation
177 [[nodiscard]] CE_SCRIPT_EXPORT()
178 Radian getLocalPitch() const noexcept;
179
182 void setLocalPitch(const Radian& pitch) noexcept;
183
185 [[nodiscard]] CE_SCRIPT_EXPORT()
186 Radian getLocalYaw() const noexcept;
187
190 void setLocalYaw(const Radian& yaw) noexcept;
191
193 [[nodiscard]] CE_SCRIPT_EXPORT()
194 Radian getLocalRoll() const noexcept;
195
198 void setLocalRoll(const Radian& roll) noexcept;
199
201 [[nodiscard]] CE_SCRIPT_EXPORT()
202 Radian getWorldPitch() const noexcept;
203
206 void setWorldPitch(const Radian& pitch) noexcept;
207
209 [[nodiscard]] CE_SCRIPT_EXPORT()
210 Radian getWorldYaw() const noexcept;
211
214 void setWorldYaw(const Radian& yaw) noexcept;
215
217 [[nodiscard]] CE_SCRIPT_EXPORT()
218 Radian getWorldRoll() const noexcept;
219
222 void setWorldRoll(const Radian& roll) noexcept;
223
224 public: // Coordinate Transformation
229 [[nodiscard]] Vector3 toWorld(const Vector3& localVector) const noexcept;
230
235 [[nodiscard]] CE_SCRIPT_EXPORT()
236 Vector3 toLocal(const Vector3& worldVector) const noexcept;
237
238 public: // Facing direction vectors
240 [[nodiscard]] Facing getFacing() const noexcept;
241
243 [[nodiscard]] CE_SCRIPT_EXPORT()
244 Vector3 getFront() const noexcept;
245
247 [[nodiscard]] CE_SCRIPT_EXPORT()
248 Vector3 getBack() const noexcept;
249
251 [[nodiscard]] CE_SCRIPT_EXPORT()
252 Vector3 getUp() const noexcept;
253
255 [[nodiscard]] CE_SCRIPT_EXPORT()
256 Vector3 getDown() const noexcept;
257
259 [[nodiscard]] CE_SCRIPT_EXPORT()
260 Vector3 getRight() const noexcept;
261
263 [[nodiscard]] CE_SCRIPT_EXPORT()
264 Vector3 getLeft() const noexcept;
265
267 [[nodiscard]] Facing getWorldFacing() const noexcept;
268
270 [[nodiscard]] CE_SCRIPT_EXPORT()
271 Vector3 getWorldFront() const noexcept;
272
274 [[nodiscard]] CE_SCRIPT_EXPORT()
275 Vector3 getWorldBack() const noexcept;
276
278 [[nodiscard]] CE_SCRIPT_EXPORT()
279 Vector3 getWorldUp() const noexcept;
280
282 [[nodiscard]] CE_SCRIPT_EXPORT()
283 Vector3 getWorldDown() const noexcept;
284
286 [[nodiscard]] CE_SCRIPT_EXPORT()
287 Vector3 getWorldRight() const noexcept;
288
290 [[nodiscard]] CE_SCRIPT_EXPORT()
291 Vector3 getWorldLeft() const noexcept;
292
293 public: // Reflection
296 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
297 CE_REFL_DATA_GETSET(position, getPosition, setPosition);
298 CE_REFL_DATA_GETSET(rotation, getRotation, setRotation);
299 CE_REFL_DATA_GETSET(scale, getScale, setScale);
300
301 CE_REFL_DATA_GETSET(worldPosition, getWorldPosition, setWorldPosition);
302 CE_REFL_DATA_GETSET(worldRotation, getWorldRotation, setWorldRotation);
303 CE_REFL_DATA_GETSET(worldScale, getWorldScale, setWorldScale);
304
305 CE_REFL_DATA_GETSET(transform, getTransform, setTransform);
306 CE_REFL_DATA_GET(inverseTransform, getInverseTransform);
307 CE_REFL_DATA_GETSET(worldTransform, getWorldTransform, setWorldTransform);
308 CE_REFL_DATA_GET(inverseWorldTransform, getInverseWorldTransform);
309
310 CE_REFL_DATA_GET(front, getFront);
311 CE_REFL_DATA_GET(back, getBack);
312 CE_REFL_DATA_GET(up, getUp);
313 CE_REFL_DATA_GET(down, getDown);
314 CE_REFL_DATA_GET(right, getRight);
315 CE_REFL_DATA_GET(left, getLeft);
316 }
317 };
318
323 template<typename... Cs> class TSceneObject : public EntityObject<TransformComponent, Cs...> {
324 public:
326
327 public:
330 };
331 extern template class TSceneObject<>;
332
336
337} // namespace CeresEngine
338
341
344
347
#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_REFL_DATA_GET(N, G)
Definition Macros.hpp:548
#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
A type-safe entity type.
Definition Entity.hpp:538
EntityObject()=default
Creates a new entity object.
static constexpr Facing facingConvention
Definition SceneObject.hpp:329
Definition Application.hpp:19
auto scale(Vector3 scale)
Applies a scale to the entity.
Definition Helpers.hpp:32
auto transform(Container &container, Transform &&transform)
Returns an iterable object that iterates over the values of the container and applies transform to ev...
Definition Iterator.hpp:436
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Components serve as the base for data storage for an entity.
Definition Component.hpp:68
Definition SceneObject.hpp:49
void scale(double factor)
Scales the object on all axes by the given factor.
void rotate(const Vector3 &axis, const Radian &angle)
Rotates the object angle radians on the given axis.
void move(const Vector3 &distance)
Moves the object by the given distance.
void pitch(const Radian &angle)
Pitches the object by angle radians.
void move(const Vector3 &direction, double distance)
Moves the object by distance in the given direction.
void transform(const Transform &transform)
Applies the given transform to the object transform.
void roll(const Radian &angle)
Rolls the object by angle radians.
void turn(const Radian &angle)
Turns the object by angle radians.
const Vector3 & getPosition() const noexcept
The entity position. Relative to its parent.
void yaw(const Radian &angle)
Yaws the object by angle radians.
void rotate(const Quaternion &quaternion)
Rotates the object by the given quaternion.
void scale(const Vector3 &factor)
Scales the object by the given factor.
Vector3 getWorldPosition() const noexcept
The entity position. Relative to its parent.
Definition SceneObject.hpp:23