Nameless Engine
Loading...
Searching...
No Matches
SpatialNode.h
1#pragma once
2
3// Custom.
4#include "game/node/Node.h"
5#include "math/GLMath.hpp"
6#include "misc/Globals.h"
7
8#include "SpatialNode.generated.h"
9
10namespace ne RNAMESPACE() {
12 class RCLASS(Guid("150d647c-f385-4a11-b585-d059d2be88aa")) SpatialNode : public Node {
13 // Calls `applyAttachmentRule`.
14 friend class Node;
15
16 public:
18
24 SpatialNode(const std::string& sNodeName);
25
26 virtual ~SpatialNode() override = default;
27
35 void setRelativeLocation(const glm::vec3& location);
36
44 void setRelativeRotation(const glm::vec3& rotation);
45
53 void setRelativeScale(const glm::vec3& scale);
54
63 void setWorldLocation(const glm::vec3& location);
64
73 void setWorldRotation(const glm::vec3& rotation);
74
83 void setWorldScale(const glm::vec3& scale);
84
90 inline glm::vec3 getRelativeLocation() const { return relativeLocation; }
91
98 inline glm::vec3 getRelativeRotation() const { return relativeRotation; }
99
105 inline glm::vec3 getRelativeScale() const { return relativeScale; }
106
112 glm::mat4x4 getRelativeRotationMatrix();
113
122 glm::vec3 getWorldLocation();
123
133 glm::vec3 getWorldRotation();
134
140 glm::quat getWorldRotationQuaternion();
141
150 glm::vec3 getWorldScale();
151
157 glm::vec3 getWorldForwardDirection();
158
164 glm::vec3 getWorldRightDirection();
165
171 glm::vec3 getWorldUpDirection();
172
179 glm::mat4x4 getWorldMatrix();
180
194 std::pair<std::recursive_mutex, sgc::GcPtr<SpatialNode>>* getClosestSpatialParent();
195
196 protected:
204 virtual void onAfterDeserialized() override;
205
216 virtual void onSpawning() override;
217
231 virtual void onAfterAttachedToNewParent(bool bThisNodeBeingAttached) override;
232
243
244 private:
256 void applyAttachmentRule(
257 Node::AttachmentRule locationRule,
258 const glm::vec3& worldLocationBeforeAttachment,
259 Node::AttachmentRule rotationRule,
260 const glm::vec3& worldRotationBeforeAttachment,
261 Node::AttachmentRule scaleRule,
262 const glm::vec3& worldScaleBeforeAttachment);
263
273 void recalculateWorldMatrix(bool bNotifyChildren = true);
274
276 void recalculateLocalMatrix();
277
284 void recalculateWorldMatrixForNodeAndNotifyChildren(Node* pNode);
285
286#if defined(DEBUG)
288 void warnIfExceedingWorldBounds();
289#endif
290
293 WorldMatrixInformation() = default;
294
299 glm::vec3 worldLocation = glm::vec3(0.0F, 0.0F, 0.0F);
300
305 glm::vec3 worldRotation = glm::vec3(0.0F, 0.0F, 0.0F);
306
311 glm::vec3 worldScale = glm::vec3(1.0F, 1.0F, 1.0F);
312
314 glm::vec3 worldForward = Globals::WorldDirection::forward;
315
317 glm::vec3 worldRight = Globals::WorldDirection::right;
318
320 glm::vec3 worldUp = Globals::WorldDirection::up;
321
323 glm::quat worldRotationQuaternion = glm::identity<glm::quat>();
324
329 glm::mat4x4 worldMatrix = glm::identity<glm::mat4x4>();
330
332 bool bInOnWorldLocationRotationScaleChanged = false;
333 };
334
337 LocalSpaceInformation() = default;
338
340 glm::mat4x4 relativeRotationMatrix = glm::identity<glm::mat4x4>();
341
343 glm::quat relativeRotationQuaternion = glm::identity<glm::quat>();
344 };
345
351 RPROPERTY(Serialize)
352 glm::vec3 relativeLocation = glm::vec3(0.0F, 0.0F, 0.0F);
353
359 RPROPERTY(Serialize)
360 glm::vec3 relativeRotation = glm::vec3(0.0F, 0.0F, 0.0F);
361
367 RPROPERTY(Serialize)
368 glm::vec3 relativeScale = glm::vec3(1.0F, 1.0F, 1.0F);
369
371 std::pair<std::recursive_mutex, sgc::GcPtr<SpatialNode>> mtxSpatialParent{};
372
374 std::pair<std::recursive_mutex, LocalSpaceInformation> mtxLocalSpace{};
375
377 std::pair<std::recursive_mutex, WorldMatrixInformation> mtxWorldMatrix{};
378
379 ne_SpatialNode_GENERATED
380 };
381} // namespace ne RNAMESPACE()
382
383File_SpatialNode_GENERATED
Definition: GuidProperty.h:30
Definition: Node.h:39
AttachmentRule
Definition: Node.h:51
Definition: SerializeProperty.h:42
Definition: SpatialNode.h:12
glm::vec3 getRelativeRotation() const
Definition: SpatialNode.h:98
glm::vec3 getRelativeScale() const
Definition: SpatialNode.h:105
virtual void onWorldLocationRotationScaleChanged()
Definition: SpatialNode.h:242
glm::vec3 getRelativeLocation() const
Definition: SpatialNode.h:90
Definition: SpatialNode.h:336
Definition: SpatialNode.h:292