2#include <muda/ext/eigen/eigen_core_cxx20.h>
3#include <Eigen/Geometry>
4#include <muda/muda_def.h>
6namespace muda::spatial_hash
10 using Vector3 = Eigen::Vector3f;
20 Vector3 o = Vector3::Zero();
27 using Vector3 = Eigen::Vector3f;
33 MUDA_GENERIC
AABB(
const Vector3& min,
const Vector3& max)
41 max = l.max.cwiseMax(r.max);
42 min = l.min.cwiseMin(r.min);
45 MUDA_GENERIC Vector3 center()
const {
return (max + min) / 2; }
47 MUDA_GENERIC
float radius()
const {
return (max - min).norm() / 2; }
50MUDA_INLINE MUDA_GENERIC
float squared_distance(
const Eigen::Vector3f& p,
AABB b)
54 for(
int i = 0; i < 3; i++)
59 sq_dist += (b.min[i] - v) * (b.min[i] - v);
61 sq_dist += (v - b.max[i]) * (v - b.max[i]);
66MUDA_INLINE MUDA_GENERIC
float distance(
const Eigen::Vector3f& p, AABB b)
68 return ::sqrt(squared_distance(p, b));
71MUDA_INLINE MUDA_GENERIC
bool intersect(
const BoundingSphere& s,
const AABB& b)
75 float sqDist = squared_distance(s.o, b);
79 return sqDist <= s.r * s.r;
82MUDA_INLINE MUDA_GENERIC
bool intersect(
const BoundingSphere& lhs,
const BoundingSphere& rhs)
84 float r = lhs.r + rhs.r;
85 return (lhs.o - rhs.o).squaredNorm() <= r * r;
88MUDA_INLINE MUDA_GENERIC
bool intersect(
const AABB& l,
const AABB& r)
92 for(
int i = 0; i < 3; ++i)
93 c[i] = l.min[i] <= r.max[i] && l.max[i] >= r.min[i];
Definition bounding_volume.h:26
Definition bounding_volume.h:9