8#ifndef GLM_ENABLE_EXPERIMENTAL
9 #define GLM_ENABLE_EXPERIMENTAL 1
12#include <glm/gtc/matrix_transform.hpp>
13#include <glm/gtc/quaternion.hpp>
14#include <glm/gtx/quaternion.hpp>
15#include <glm/gtx/euler_angles.hpp>
16#include <glm/gtx/matrix_decompose.hpp>
23#include "components/ErrorUtils.hpp"
24#include "components/ColorTypes.hpp"
25#include "components/AssetTypes.hpp"
28#include "components/ErrorUtils.hpp"
36 glm::vec3 position = {0.0f, 0.0f, 0.0f};
37 glm::vec3 rotation = {0.0f, 0.0f, 0.0f};
38 glm::vec3 scale = {1.0f, 1.0f, 1.0f};
39 glm::quat m_rotationQuat = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
42 glm::mat4 cachedMatrix = glm::mat4(1.0f);
46 glm::vec3 position = {0.0f, 0.0f, 0.0f};
47 glm::quat m_rotationQuat = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
48 glm::vec3 scale = {1.0f, 1.0f, 1.0f};
50 bool lastTransformed =
true;
52 bool physicsAffected =
false;
53 glm::mat4 cachedMatrix = glm::mat4(1.0f);
59 : m_registry(other.m_registry),
60 position(other.position),
61 m_rotationQuat(other.m_rotationQuat),
69 position = other.position;
70 m_rotationQuat = other.m_rotationQuat;
72 parent = other.parent;
79 : m_registry(®istry) {}
83 : m_registry(®istry), position(pos), parent(p) {}
87 : m_registry(®istry), position(pos), m_rotationQuat(glm::normalize(glm::quat(glm::radians(rot)))), parent(p) {}
91 : m_registry(®istry), position(pos), m_rotationQuat(glm::normalize(glm::quat(glm::radians(rot)))), scale(s), parent(p) {}
95 : m_registry(®istry), parent(p) {}
103 if (!isReady()) [[unlikely]] {
104 log(
"TransformComponent is not ready, registry is not valid");
111 return (dirty || result);
119 bool isReady()
const {
120 return m_registry !=
nullptr;
147 return glm::degrees(glm::eulerAngles(m_rotationQuat));
158 position = newPosition;
164 m_rotationQuat = glm::normalize(glm::quat(glm::radians(newRotation)));
180 return m_rotationQuat;
189 glm::quat parentInverse = glm::inverse(parentWorldQuat);
190 m_rotationQuat = parentInverse * targetWorldQuat;
192 m_rotationQuat = targetWorldQuat;
194 m_rotationQuat = glm::normalize(m_rotationQuat);
202 glm::quat parentInverse = glm::inverse(parentWorldQuat);
203 m_rotationQuat = parentInverse * targetWorldQuat;
205 m_rotationQuat = targetWorldQuat;
207 m_rotationQuat = glm::normalize(m_rotationQuat);
213 return m_rotationQuat;
219 m_rotationQuat = glm::normalize(newRotation);
225 m_rotationQuat = glm::normalize(m_rotationQuat * deltaRotation);
230 glm::mat4 recalculateMatrix(){
231 glm::mat4 local = glm::mat4(1.0f);
232 local = glm::translate(local, position);
233 local *= glm::mat4_cast(m_rotationQuat);
234 local = glm::scale(local, scale);
239 cachedMatrix = local;
247 glm::mat4
matrix(
bool forceRecalculate =
false) {
248 if(isDirty() || forceRecalculate){
250 return recalculateMatrix();
258 return glm::vec3(
matrix()[3]);
270 glm::vec3 worldScale = scale;
285 glm::mat4 inverseParentMatrix = glm::inverse(parentWorldMatrix);
286 glm::vec4 newLocalPos4 = inverseParentMatrix * glm::vec4(newPosition, 1.0f);
287 position = glm::vec3(newLocalPos4);
289 position = newPosition;
298 glm::mat4 inverseParentMatrix = glm::inverse(parentWorldMatrix);
299 glm::vec4 newLocalPos4 = inverseParentMatrix * glm::vec4(newPosition, 1.0f);
300 position = glm::vec3(newLocalPos4);
302 position = newPosition;
310 glm::quat targetWorldQuat = glm::quat(glm::radians(newRotation));
320 scale = newScale / parentWorldScale;
330 position += newPosition;
337 glm::quat deltaQuat = glm::quat(glm::radians(newRotation));
338 m_rotationQuat = m_rotationQuat * deltaQuat;
339 m_rotationQuat = glm::normalize(m_rotationQuat);
353 glm::quat deltaQuat = glm::angleAxis(glm::radians(deltaPitch), glm::vec3(1.0f, 0.0f, 0.0f));
354 m_rotationQuat = m_rotationQuat * deltaQuat;
355 m_rotationQuat = glm::normalize(m_rotationQuat);
362 glm::quat deltaQuat = glm::angleAxis(glm::radians(deltaYaw), glm::vec3(0.0f, 1.0f, 0.0f));
363 m_rotationQuat = deltaQuat * m_rotationQuat;
364 m_rotationQuat = glm::normalize(m_rotationQuat);
371 glm::quat deltaQuat = glm::angleAxis(glm::radians(deltaRoll), glm::vec3(0.0f, 0.0f, 1.0f));
372 m_rotationQuat = m_rotationQuat * deltaQuat;
373 m_rotationQuat = glm::normalize(m_rotationQuat);
377 glm::vec3 getForwardVector() {
378 return glm::normalize(-glm::vec3(
matrix()[2]));
384 return glm::normalize(glm::vec3(
matrix()[0]));
390 return glm::normalize(glm::vec3(
matrix()[1]));
395 void enableLastTransformed() {
405#if defined(TRANSPARENT)
421 uint32_t
id = UINT32_MAX;
422 std::vector<std::string> textureNames;
426 std::map<int, texture_asset_path> textureOverrides;
429 glm::vec3 localCenter = glm::vec3(0.0f);
430 float localRadius = 1.0f;
432 glm::vec3 worldCenter = glm::vec3(0.0f);
433 float worldRadius = 1.0f;
457 float intensity = 1.f;
464 float density = 0.5f;
477 float nearPlane = 0.1f;
478 float farPlane = 100.0f;
479 uint32_t
id = UINT32_MAX;
Main header for the Entity Component System (ECS) framework.
This file defines MeshData struct and all other structs needed for it.
Central registry for managing entities and their components in the ECS system.
bool has(Entity entity)
Checks if an entity has a component of type T.
T & get(Entity entity)
Retrieves a component from an entity.
RenderType
Enum class for different types of rendering. It internally switches used pipeline.
uint32_t Entity
Type alias representing a unique entity identifier in the ECS system.
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
constexpr Entity NULL_ENTITY
Special entity value indicating an invalid or null entity.
Struct that contains camera properties. Used by build in CameraObject, but needed for any custom one ...
Struct containing fog properties.
Struct containing light properties.
Struct containing raw meshData, mesh id, texture paths and material properties. It just template and ...
void forceRefresh()
(used internally by the engine, DO NOT CALL) forces the component to be refreshed.
void setRendered()
(used internally by the engine, DO NOT CALL) sets the component as rendered.
bool getIsFresh()
(used internally by the engine, DO NOT CALL) returns true if the component is fresh.
Mesh data structure for loading and managing mesh data.
Struct that simply contains name of the entity. It is used to identify entity and needs to be unique.
Represents an RGB color value. Used mainly for fancy rendering in editor.
Represents an RGBA color value. Used mainly for fancy rendering in editor.