Compare commits

..

2 Commits

Author SHA1 Message Date
3d87e2f885 Bump to c++20
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Remove KRMIN, KRMAX, and KRCLAMP helpers.
2026-05-17 14:23:26 -07:00
17b4ec2cde Add AABB::encapsulate(const Vector3& v)
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled
Add AABB::Create(const AABB& modelSpaceExtents, const Matrix4& modelMatrix)
2026-05-17 12:50:26 -07:00
9 changed files with 33 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
cmake_minimum_required (VERSION 3.16) cmake_minimum_required (VERSION 3.16)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

View File

@@ -53,6 +53,7 @@ public:
void init(); void init();
static AABB Create(const Vector3& minPoint, const Vector3& maxPoint); static AABB Create(const Vector3& minPoint, const Vector3& maxPoint);
static AABB Create(const Vector3& corner1, const Vector3& corner2, const Matrix4& modelMatrix); static AABB Create(const Vector3& corner1, const Vector3& corner2, const Matrix4& modelMatrix);
static AABB Create(const AABB& modelSpaceExtents, const Matrix4& modelMatrix);
static AABB Create(); static AABB Create();
void scale(const Vector3& s); void scale(const Vector3& s);
@@ -69,6 +70,7 @@ public:
bool intersectsRay(const Vector3& v1, const Vector3& dir) const; bool intersectsRay(const Vector3& v1, const Vector3& dir) const;
bool intersectsSphere(const Vector3& center, float radius) const; bool intersectsSphere(const Vector3& center, float radius) const;
void encapsulate(const AABB& b); void encapsulate(const AABB& b);
void encapsulate(const Vector3& v);
bool operator ==(const AABB& b) const; bool operator ==(const AABB& b) const;
bool operator !=(const AABB& b) const; bool operator !=(const AABB& b) const;

View File

@@ -32,6 +32,7 @@
#include "../include/hydra.h" #include "../include/hydra.h"
#include "assert.h" #include "assert.h"
#include "krhelpers.h" #include "krhelpers.h"
#include <algorithm>
namespace hydra { namespace hydra {
@@ -91,6 +92,13 @@ AABB AABB::Create(const Vector3& corner1, const Vector3& corner2, const Matrix4&
return r; return r;
} }
AABB AABB::Create(const AABB& modelSpaceExtents, const Matrix4& modelMatrix)
{
AABB r;
r.init(modelSpaceExtents.min, modelSpaceExtents.max, modelMatrix);
return r;
}
bool AABB::operator ==(const AABB& b) const bool AABB::operator ==(const AABB& b) const
{ {
return min == b.min && max == b.max; return min == b.min && max == b.max;
@@ -366,9 +374,20 @@ void AABB::encapsulate(const AABB& b)
if (b.max.z > max.z) max.z = b.max.z; if (b.max.z > max.z) max.z = b.max.z;
} }
void AABB::encapsulate(const Vector3& v)
{
if (v.x < min.x) min.x = v.x;
if (v.y < min.y) min.y = v.y;
if (v.z < min.z) min.z = v.z;
if (v.x > max.x) max.x = v.x;
if (v.y > max.y) max.y = v.y;
if (v.z > max.z) max.z = v.z;
}
Vector3 AABB::nearestPoint(const Vector3& v) const Vector3 AABB::nearestPoint(const Vector3& v) const
{ {
return Vector3::Create(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z)); return Vector3::Create(std::clamp(v.x, min.x, max.x), std::clamp(v.y, min.y, max.y), std::clamp(v.z, min.z, max.z));
} }
} // namespace hydra } // namespace hydra

View File

@@ -33,9 +33,6 @@
#include "../include/hydra.h" #include "../include/hydra.h"
#define KRMIN(x,y) ((x) < (y) ? (x) : (y))
#define KRMAX(x,y) ((x) > (y) ? (x) : (y))
#define KRCLAMP(x, min, max) (KRMAX(KRMIN(x, max), min))
#define KRALIGN(x) ((x + 3) & ~0x03) #define KRALIGN(x) ((x + 3) & ~0x03)
float const PI = 3.141592653589793f; float const PI = 3.141592653589793f;

View File

@@ -291,12 +291,12 @@ float Vector2::Dot(const Vector2& v1, const Vector2& v2)
Vector2 Vector2::Min(const Vector2& v1, const Vector2& v2) Vector2 Vector2::Min(const Vector2& v1, const Vector2& v2)
{ {
return Vector2::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y)); return Vector2::Create(std::min(v1.x, v2.x), std::min(v1.y, v2.y));
} }
Vector2 Vector2::Max(const Vector2& v1, const Vector2& v2) Vector2 Vector2::Max(const Vector2& v1, const Vector2& v2)
{ {
return Vector2::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y)); return Vector2::Create(std::max(v1.x, v2.x), std::max(v1.y, v2.y));
} }
} // namepsace hydra } // namepsace hydra

View File

@@ -285,12 +285,12 @@ int Vector2i::Dot(const Vector2i& v1, const Vector2i& v2)
Vector2i Vector2i::Min(const Vector2i& v1, const Vector2i& v2) Vector2i Vector2i::Min(const Vector2i& v1, const Vector2i& v2)
{ {
return Vector2i::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y)); return Vector2i::Create(std::min(v1.x, v2.x), std::min(v1.y, v2.y));
} }
Vector2i Vector2i::Max(const Vector2i& v1, const Vector2i& v2) Vector2i Vector2i::Max(const Vector2i& v1, const Vector2i& v2)
{ {
return Vector2i::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y)); return Vector2i::Create(std::max(v1.x, v2.x), std::max(v1.y, v2.y));
} }
} // namepsace hydra } // namepsace hydra

View File

@@ -458,12 +458,12 @@ float Vector3::Dot(const Vector3& v1, const Vector3& v2)
Vector3 Vector3::Min(const Vector3& v1, const Vector3& v2) Vector3 Vector3::Min(const Vector3& v1, const Vector3& v2)
{ {
return Vector3::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z)); return Vector3::Create(std::min(v1.x, v2.x), std::min(v1.y, v2.y), std::min(v1.z, v2.z));
} }
Vector3 Vector3::Max(const Vector3& v1, const Vector3& v2) Vector3 Vector3::Max(const Vector3& v1, const Vector3& v2)
{ {
return Vector3::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z)); return Vector3::Create(std::max(v1.x, v2.x), std::max(v1.y, v2.y), std::max(v1.z, v2.z));
} }
bool Vector3::operator >(const Vector3& b) const bool Vector3::operator >(const Vector3& b) const

View File

@@ -373,12 +373,12 @@ int Vector3i::Dot(const Vector3i& v1, const Vector3i& v2)
Vector3i Vector3i::Min(const Vector3i& v1, const Vector3i& v2) Vector3i Vector3i::Min(const Vector3i& v1, const Vector3i& v2)
{ {
return Vector3i::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z)); return Vector3i::Create(std::min(v1.x, v2.x), std::min(v1.y, v2.y), std::min(v1.z, v2.z));
} }
Vector3i Vector3i::Max(const Vector3i& v1, const Vector3i& v2) Vector3i Vector3i::Max(const Vector3i& v1, const Vector3i& v2)
{ {
return Vector3i::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z)); return Vector3i::Create(std::max(v1.x, v2.x), std::max(v1.y, v2.y), std::max(v1.z, v2.z));
} }
bool Vector3i::operator >(const Vector3i& b) const bool Vector3i::operator >(const Vector3i& b) const

View File

@@ -351,12 +351,12 @@ float Vector4::Dot(const Vector4& v1, const Vector4& v2)
Vector4 Vector4::Min(const Vector4& v1, const Vector4& v2) Vector4 Vector4::Min(const Vector4& v1, const Vector4& v2)
{ {
return Vector4::Create(KRMIN(v1.x, v2.x), KRMIN(v1.y, v2.y), KRMIN(v1.z, v2.z), KRMIN(v1.w, v2.w)); return Vector4::Create(std::min(v1.x, v2.x), std::min(v1.y, v2.y), std::min(v1.z, v2.z), std::min(v1.w, v2.w));
} }
Vector4 Vector4::Max(const Vector4& v1, const Vector4& v2) Vector4 Vector4::Max(const Vector4& v1, const Vector4& v2)
{ {
return Vector4::Create(KRMAX(v1.x, v2.x), KRMAX(v1.y, v2.y), KRMAX(v1.z, v2.z), KRMAX(v1.w, v2.w)); return Vector4::Create(std::max(v1.x, v2.x), std::max(v1.y, v2.y), std::max(v1.z, v2.z), std::max(v1.w, v2.w));
} }
bool Vector4::operator >(const Vector4& b) const bool Vector4::operator >(const Vector4& b) const