Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
FlatGeometry.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
7#include "Registry.hpp"
8
9#include <cmath>
10
11namespace esengine::ecs {
12
13// Derived by TransformSystem; never serialized or exposed as an authored component.
15
16// A flat local box has area only when its two transformed axes span a plane.
17// Double products preserve tiny finite spans without an arbitrary epsilon cutoff.
18inline bool hasFlatGeometryArea(Transform& transform, bool parented) {
19 transform.ensureDecomposed();
20 if (!parented) {
21 return transform.worldScale.x != 0 && transform.worldScale.y != 0
22 && std::isfinite(transform.worldScale.x) && std::isfinite(transform.worldScale.y);
23 }
24 const glm::dvec3 x(transform.cachedMatrix_[0]), y(transform.cachedMatrix_[1]);
25 const auto cross = glm::cross(x, y);
26 return (cross.x != 0 || cross.y != 0 || cross.z != 0)
27 && std::isfinite(cross.x) && std::isfinite(cross.y) && std::isfinite(cross.z);
28}
29
30inline bool hasFlatGeometryArea(Registry& registry, Entity entity, Transform& transform) {
31 return !registry.has<FlatGeometryCollapsed>(entity)
32 && hasFlatGeometryArea(transform, registry.has<Parent>(entity));
33}
34
35inline bool copyFlatRenderMatrix(Registry& registry, Entity entity, glm::mat4& output) {
36 auto* transform = registry.tryGet<Transform>(entity);
37 if (!transform || !hasFlatGeometryArea(registry, entity, *transform)) return false;
38 output = registry.has<Parent>(entity) ? transform->cachedMatrix_
39 : math::compose(transform->worldPosition, transform->worldRotation, transform->worldScale);
40 return true;
41}
42
43} // namespace esengine::ecs
Hierarchy components for parent-child relationships.
Central ECS registry for entity and component management.
Unified Transform component with local and world-space data.
Central container for all entities and components.
Definition Registry.hpp:73
bool has(Entity entity) const
Checks if an entity has a specific component.
Definition Registry.hpp:711
T * tryGet(Entity entity)
Tries to get a component from an entity.
Definition Registry.hpp:670
bool hasFlatGeometryArea(Transform &transform, bool parented)
bool copyFlatRenderMatrix(Registry &registry, Entity entity, glm::mat4 &output)
glm::mat4 compose(const glm::vec3 &position, const glm::quat &rotation, const glm::vec3 &scale)
Constructs a transformation matrix from TRS components.
Definition Math.hpp:395
Entity identifier with packed index + generation.
Definition Types.hpp:135
Parent reference component.
Definition Hierarchy.hpp:46
Unified transform component.
Definition Transform.hpp:45