Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common/math/Bounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
//
///////////////////////////////////////////////////////////////////////////////

#include <algorithm>
#include <cmath>

#include "Bounds.hpp"

namespace nexo::math {
Expand Down Expand Up @@ -71,4 +74,20 @@ namespace nexo::math {
out.max = wc + we;
return out;
}

static float maxAxisScale(const glm::mat4& M)
{
const float sx = glm::length(glm::vec3(M[0])); // column 0
const float sy = glm::length(glm::vec3(M[1])); // column 1
const float sz = glm::length(glm::vec3(M[2])); // column 2
return std::max(sx, std::max(sy, sz));
}

BSphere sphereTransform(const BSphere& s, const glm::mat4& M)
{
BSphere out;
out.c = glm::vec3(M * glm::vec4(s.c, 1.0f));
out.r = s.r * maxAxisScale(M); // conservative under non-uniform scale
return out;
}
}
2 changes: 2 additions & 0 deletions common/math/Bounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,6 @@ namespace nexo::math {
* @return World-space AABB that encloses the transformed local box.
*/
AABB aabbTransform(const AABB& local, const glm::mat4& M);

BSphere sphereTransform(const BSphere& s, const glm::mat4& M);
}
Loading
Loading