Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
PlacementBounds.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
7#pragma once
8
10#include <glm/glm.hpp>
11#include <algorithm>
12#include <cmath>
13
15
17inline f32 radius(const glm::vec3& lo, const glm::vec3& hi, f32 displacement) {
18 return glm::length(glm::max(glm::abs(lo), glm::abs(hi)) + glm::vec3(std::max(displacement, 0.0f)));
19}
20
22inline f32 stretchSquared(const f32* rows) {
23 const glm::vec3 a(rows[0], rows[4], rows[8]);
24 const glm::vec3 b(rows[1], rows[5], rows[9]);
25 const glm::vec3 c(rows[2], rows[6], rows[10]);
26 const f32 ab = std::abs(glm::dot(a, b));
27 const f32 ac = std::abs(glm::dot(a, c));
28 const f32 bc = std::abs(glm::dot(b, c));
29 // The maximum absolute row sum of A^T A bounds its largest eigenvalue.
30 // Orthogonal TRS columns retain the exact longest scale; shears remain conservative.
31 return std::max({glm::dot(a, a) + ab + ac, glm::dot(b, b) + ab + bc, glm::dot(c, c) + ac + bc});
32}
33
35inline void transformedBox(const glm::mat3& parent, const f32* rows, const glm::vec3& origin,
36 const glm::vec3& localCentre, const glm::vec3& localHalf,
37 glm::vec3& centre, glm::vec3& half) {
38 const glm::vec3 a = parent * glm::vec3(rows[0], rows[4], rows[8]);
39 const glm::vec3 b = parent * glm::vec3(rows[1], rows[5], rows[9]);
40 const glm::vec3 c = parent * glm::vec3(rows[2], rows[6], rows[10]);
41 centre = origin + a * localCentre.x + b * localCentre.y + c * localCentre.z;
42 half = glm::abs(a) * localHalf.x + glm::abs(b) * localHalf.y + glm::abs(c) * localHalf.z;
43}
44
45} // namespace esengine::placement_bounds
Core type definitions and utilities for ESEngine.
void transformedBox(const glm::mat3 &parent, const f32 *rows, const glm::vec3 &origin, const glm::vec3 &localCentre, const glm::vec3 &localHalf, glm::vec3 &centre, glm::vec3 &half)
f32 stretchSquared(const f32 *rows)
f32 radius(const glm::vec3 &lo, const glm::vec3 &hi, f32 displacement)
float f32
32-bit floating point
Definition Types.hpp:59