10 : _position(
MOV(pos)),
11 _halfExtents(
MOV(hExtents)),
18 fromBoundingBox(aabb);
23 fromBoundingSphere(bSphere);
27 assert(0 <= cornerIndex && cornerIndex <= 7);
28 switch (cornerIndex) {
30 case 0:
return _position - _halfExtents.x * _axis[0] - _halfExtents.y * _axis[1] - _halfExtents.z * _axis[2];
31 case 1:
return _position - _halfExtents.x * _axis[0] - _halfExtents.y * _axis[1] + _halfExtents.z * _axis[2];
32 case 2:
return _position - _halfExtents.x * _axis[0] + _halfExtents.y * _axis[1] - _halfExtents.z * _axis[2];
33 case 3:
return _position - _halfExtents.x * _axis[0] + _halfExtents.y * _axis[1] + _halfExtents.z * _axis[2];
34 case 4:
return _position + _halfExtents.x * _axis[0] - _halfExtents.y * _axis[1] - _halfExtents.z * _axis[2];
35 case 5:
return _position + _halfExtents.x * _axis[0] - _halfExtents.y * _axis[1] + _halfExtents.z * _axis[2];
36 case 6:
return _position + _halfExtents.x * _axis[0] + _halfExtents.y * _axis[1] - _halfExtents.z * _axis[2];
37 case 7:
return _position + _halfExtents.x * _axis[0] + _halfExtents.y * _axis[1] + _halfExtents.z * _axis[2];
42 _position.set(aabb.getCenter());
43 _halfExtents.set(aabb.getHalfExtent());
51 _position = worldMatrix * _position;
58 _halfExtents *=
scale;
71 _position.set(sphere.getCenter());
72 _halfExtents.set(sphere.getRadius());
96 for (
U8 i = 0u; i < 3u; ++i) {
97 _axis[i] =
transform.transform((_halfExtents[i] * _axis[i]),
false);
98 _halfExtents[i] = _axis[i].length();
116 return BoundingSphere{ position(), halfExtents().minComponent() };
120 return _halfExtents * 2;
128 return _axis[0] * _halfExtents[0] +
129 _axis[1] * _halfExtents[1] +
130 _axis[2] * _halfExtents[2];
134 assert(0 <= edgeIndex && edgeIndex <= 11);
137 case 0:
return {cornerPoint(0), cornerPoint(1) };
138 case 1:
return {cornerPoint(0), cornerPoint(2) };
139 case 2:
return {cornerPoint(0), cornerPoint(4) };
140 case 3:
return {cornerPoint(1), cornerPoint(3) };
141 case 4:
return {cornerPoint(1), cornerPoint(5) };
142 case 5:
return {cornerPoint(2), cornerPoint(3) };
143 case 6:
return {cornerPoint(2), cornerPoint(6) };
144 case 7:
return {cornerPoint(3), cornerPoint(7) };
145 case 8:
return {cornerPoint(4), cornerPoint(5) };
146 case 9:
return {cornerPoint(4), cornerPoint(6) };
147 case 10:
return {cornerPoint(5), cornerPoint(7) };
148 case 11:
return {cornerPoint(6), cornerPoint(7) };
164 for (
U8 i = 0; i < 3; ++i) {
165 closestPoint +=
CLAMPED(
Dot(d, _axis[i]), -_halfExtents[i], _halfExtents[i]) * _axis[i];
172 return closestPoint(point).distance(point);
177 return std::abs(
Dot(pt, _axis[0])) <= _halfExtents[0] &&
178 std::abs(
Dot(pt, _axis[1])) <= _halfExtents[1] &&
179 std::abs(
Dot(pt, _axis[2])) <= _halfExtents[2];
183 for (
U8 i = 0; i < 8; ++i) {
193 for (
U8 i = 0; i < 8; ++i) {
194 if (!containsPoint(AABB.cornerPoint(i))) {
203 return distance(bSphere.getCenter()) - bSphere.getRadius() < 0.f;
209 for (
U8 i = 0; i < 3; ++i) {
213 const F32 r =
Dot(_axis[i], _position - ray._origin);
214 if (-r - _halfExtents[i] > 0.f ||
215 -r + _halfExtents[i] > 0.f)
220 const F32 r =
Dot(_axis[i], _position - ray._origin);
221 const F32 s =
Dot(_axis[i], ray._direction);
222 F32 t0 = (r + _halfExtents[i]) / s;
223 F32 t1 = (r - _halfExtents[i]) / s;
240 ret.
dist = tNear > 0.f ? tNear : tFar;
242 if (ret.
dist < 0.0f) {
LineSegment edge(U8 edgeIndex) const noexcept
vec3< F32 > size() const noexcept
F32 distance(const vec3< F32 > &point) const noexcept
void transform(const mat3< F32 > &transform)
bool containsPoint(const vec3< F32 > &point) const noexcept
BoundingSphere toEnclosedSphere() const noexcept
vec3< F32 > closestPoint(const vec3< F32 > &point) const noexcept
bool containsBox(const OBB &OBB) const noexcept
RayResult intersect(const Ray &ray, F32 t0In, F32 t1In) const noexcept
vec3< F32 > cornerPoint(U8 cornerIndex) const noexcept
void fromBoundingSphere(const BoundingSphere &sphere) noexcept
void translate(const vec3< F32 > &offset)
std::array< LineSegment, 12 > OOBBEdgeList
bool containsSphere(const BoundingSphere &bSphere) const noexcept
OOBBEdgeList edgeList() const noexcept
void fromBoundingBox(const BoundingBox &aabb) noexcept
BoundingSphere toEnclosingSphere() const noexcept
void scale(const vec3< F32 > ¢erPoint, F32 scaleFactor)
Uniform scaling.
std::array< vec3< F32 >, 3 > OBBAxis
vec3< F32 > halfDiagonal() const noexcept
BoundingBox toBoundingBox() const noexcept
vec3< F32 > diagonal() const noexcept
bool isColOrthogonal() const noexcept
vec3< U > transformNonHomogeneous(const vec3< U > &v) const noexcept
bool isColOrthogonal() const noexcept
T length() const noexcept
return the vector's length
bool decomposeMatrix(const mat4< F32 > &transform, vec3< F32 > &translationOut, vec3< F32 > &scaleOut, vec3< Angle::RADIANS< F32 > > &rotationOut, bool &isUniformScaleOut)
Handle console commands that start with a forward slash.
vec2< T > Normalized(vec2< T > vector) noexcept
static const vec3< F32 > WORLD_X_AXIS
bool IS_IN_RANGE_INCLUSIVE(const T x, const U min, const U max) noexcept
static const vec3< F32 > WORLD_Z_AXIS
T Dot(vec2< T > a, vec2< T > b) noexcept
general vec2 dot product
constexpr F32 EPSILON_F32
static const vec3< F32 > VECTOR3_UNIT
void OrthoNormalize(vec2< T > &n, vec2< T > &u) noexcept
::value constexpr T CLAMPED(T n, T min, T max) noexcept
mat3< T > GetMatrix(const Quaternion< T > &q) noexcept
static const vec3< F32 > VECTOR3_ZERO
static const vec3< F32 > WORLD_Y_AXIS