Compare commits
4 commits
4528053334
...
31ca241e5c
Author | SHA1 | Date | |
---|---|---|---|
31ca241e5c | |||
91a3783597 | |||
f3173d1bbf | |||
4070a4038e |
5 changed files with 294 additions and 298 deletions
|
@ -6,7 +6,7 @@ set(SC_3D_CollisionDetectionHelpers_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/sc_
|
||||||
|
|
||||||
add_library(SC_3D_CollisionDetectionHelpers ${SC_3D_CollisionDetectionHelpers_SOURCES})
|
add_library(SC_3D_CollisionDetectionHelpers ${SC_3D_CollisionDetectionHelpers_SOURCES})
|
||||||
|
|
||||||
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 2.2.1 SOVERSION 2)
|
set_target_properties(SC_3D_CollisionDetectionHelpers PROPERTIES VERSION 3.0.0 SOVERSION 3)
|
||||||
target_compile_features(SC_3D_CollisionDetectionHelpers PUBLIC cxx_std_20)
|
target_compile_features(SC_3D_CollisionDetectionHelpers PUBLIC cxx_std_20)
|
||||||
|
|
||||||
if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
if(NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||||
|
|
16
Changelog.md
16
Changelog.md
|
@ -1,5 +1,11 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## Version 3.0.0
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
Change pointer-parameters in API to non-pointer parameters.
|
||||||
|
|
||||||
## Version 2.2.1
|
## Version 2.2.1
|
||||||
|
|
||||||
Fix UnitTest for checking AABB.
|
Fix UnitTest for checking AABB.
|
||||||
|
@ -34,14 +40,18 @@ same center.
|
||||||
|
|
||||||
## Version 2.0.0
|
## Version 2.0.0
|
||||||
|
|
||||||
Add collision detection with Spheres.
|
### Breaking Changes
|
||||||
|
|
||||||
Add some more vector/matrix math stuff.
|
|
||||||
|
|
||||||
Replace Mat3 with Mat4.
|
Replace Mat3 with Mat4.
|
||||||
|
|
||||||
Replace xyz-axis rotation floats in GenericBox with Mat4.
|
Replace xyz-axis rotation floats in GenericBox with Mat4.
|
||||||
|
|
||||||
|
### Non-Breaking Changes
|
||||||
|
|
||||||
|
Add collision detection with Spheres.
|
||||||
|
|
||||||
|
Add some more vector/matrix math stuff.
|
||||||
|
|
||||||
## Version 1.0.0
|
## Version 1.0.0
|
||||||
|
|
||||||
First version of this library.
|
First version of this library.
|
||||||
|
|
263
src/sc_sacd.cpp
263
src/sc_sacd.cpp
|
@ -62,8 +62,7 @@ SC_SACD_Vec3 operator*(const SC_SACD_Mat4 &mat, const SC_SACD_Vec3 &vec) {
|
||||||
vec.x * mat.z0 + vec.y * mat.z1 + vec.z * mat.z2 + mat.z3};
|
vec.x * mat.z0 + vec.y * mat.z1 + vec.z * mat.z2 + mat.z3};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals(
|
std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals(SC_SACD_Generic_Box box) {
|
||||||
const SC_SACD_Generic_Box *box) {
|
|
||||||
SC_SACD_Vec3 a, b, c;
|
SC_SACD_Vec3 a, b, c;
|
||||||
|
|
||||||
// Facing positive x-axis.
|
// Facing positive x-axis.
|
||||||
|
@ -79,9 +78,9 @@ std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals(
|
||||||
c.y = 0.0F;
|
c.y = 0.0F;
|
||||||
c.z = 1.0F;
|
c.z = 1.0F;
|
||||||
|
|
||||||
a = box->transform * a;
|
a = box.transform * a;
|
||||||
b = box->transform * b;
|
b = box.transform * b;
|
||||||
c = box->transform * c;
|
c = box.transform * c;
|
||||||
|
|
||||||
b = b - a;
|
b = b - a;
|
||||||
c = c - a;
|
c = c - a;
|
||||||
|
@ -101,9 +100,9 @@ std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals(
|
||||||
c.y = 0.0F;
|
c.y = 0.0F;
|
||||||
c.z = -1.0F;
|
c.z = -1.0F;
|
||||||
|
|
||||||
a = box->transform * a;
|
a = box.transform * a;
|
||||||
b = box->transform * b;
|
b = box.transform * b;
|
||||||
c = box->transform * c;
|
c = box.transform * c;
|
||||||
|
|
||||||
b = b - a;
|
b = b - a;
|
||||||
c = c - a;
|
c = c - a;
|
||||||
|
@ -123,9 +122,9 @@ std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals(
|
||||||
c.y = 0.0F;
|
c.y = 0.0F;
|
||||||
c.z = 0.0F;
|
c.z = 0.0F;
|
||||||
|
|
||||||
a = box->transform * a;
|
a = box.transform * a;
|
||||||
b = box->transform * b;
|
b = box.transform * b;
|
||||||
c = box->transform * c;
|
c = box.transform * c;
|
||||||
|
|
||||||
b = b - a;
|
b = b - a;
|
||||||
c = c - a;
|
c = c - a;
|
||||||
|
@ -136,7 +135,7 @@ std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals_Normalized(
|
std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals_Normalized(
|
||||||
const SC_SACD_Generic_Box *box) {
|
SC_SACD_Generic_Box box) {
|
||||||
auto normals = SC_SACD_Get_Box_Normals(box);
|
auto normals = SC_SACD_Get_Box_Normals(box);
|
||||||
|
|
||||||
for (auto &normal : normals) {
|
for (auto &normal : normals) {
|
||||||
|
@ -146,63 +145,62 @@ std::array<SC_SACD_Vec3, 3> SC_SACD_Get_Box_Normals_Normalized(
|
||||||
return normals;
|
return normals;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<SC_SACD_Vec3, 8> SC_SACD_Get_Box_Corners(
|
std::array<SC_SACD_Vec3, 8> SC_SACD_Get_Box_Corners(SC_SACD_Generic_Box box) {
|
||||||
const SC_SACD_Generic_Box *box) {
|
|
||||||
SC_SACD_Vec3 corner_0 =
|
SC_SACD_Vec3 corner_0 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{-box->width / 2.0F, -box->height / 2.0F, -box->depth / 2.0F};
|
SC_SACD_Vec3{-box.width / 2.0F, -box.height / 2.0F, -box.depth / 2.0F};
|
||||||
corner_0.x += box->x;
|
corner_0.x += box.x;
|
||||||
corner_0.y += box->y;
|
corner_0.y += box.y;
|
||||||
corner_0.z += box->z;
|
corner_0.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_1 =
|
SC_SACD_Vec3 corner_1 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{box->width / 2.0F, -box->height / 2.0F, -box->depth / 2.0F};
|
SC_SACD_Vec3{box.width / 2.0F, -box.height / 2.0F, -box.depth / 2.0F};
|
||||||
corner_1.x += box->x;
|
corner_1.x += box.x;
|
||||||
corner_1.y += box->y;
|
corner_1.y += box.y;
|
||||||
corner_1.z += box->z;
|
corner_1.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_2 =
|
SC_SACD_Vec3 corner_2 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{-box->width / 2.0F, box->height / 2.0F, -box->depth / 2.0F};
|
SC_SACD_Vec3{-box.width / 2.0F, box.height / 2.0F, -box.depth / 2.0F};
|
||||||
corner_2.x += box->x;
|
corner_2.x += box.x;
|
||||||
corner_2.y += box->y;
|
corner_2.y += box.y;
|
||||||
corner_2.z += box->z;
|
corner_2.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_3 =
|
SC_SACD_Vec3 corner_3 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{box->width / 2.0F, box->height / 2.0F, -box->depth / 2.0F};
|
SC_SACD_Vec3{box.width / 2.0F, box.height / 2.0F, -box.depth / 2.0F};
|
||||||
corner_3.x += box->x;
|
corner_3.x += box.x;
|
||||||
corner_3.y += box->y;
|
corner_3.y += box.y;
|
||||||
corner_3.z += box->z;
|
corner_3.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_4 =
|
SC_SACD_Vec3 corner_4 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{-box->width / 2.0F, -box->height / 2.0F, box->depth / 2.0F};
|
SC_SACD_Vec3{-box.width / 2.0F, -box.height / 2.0F, box.depth / 2.0F};
|
||||||
corner_4.x += box->x;
|
corner_4.x += box.x;
|
||||||
corner_4.y += box->y;
|
corner_4.y += box.y;
|
||||||
corner_4.z += box->z;
|
corner_4.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_5 =
|
SC_SACD_Vec3 corner_5 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{box->width / 2.0F, -box->height / 2.0F, box->depth / 2.0F};
|
SC_SACD_Vec3{box.width / 2.0F, -box.height / 2.0F, box.depth / 2.0F};
|
||||||
corner_5.x += box->x;
|
corner_5.x += box.x;
|
||||||
corner_5.y += box->y;
|
corner_5.y += box.y;
|
||||||
corner_5.z += box->z;
|
corner_5.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_6 =
|
SC_SACD_Vec3 corner_6 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{-box->width / 2.0F, box->height / 2.0F, box->depth / 2.0F};
|
SC_SACD_Vec3{-box.width / 2.0F, box.height / 2.0F, box.depth / 2.0F};
|
||||||
corner_6.x += box->x;
|
corner_6.x += box.x;
|
||||||
corner_6.y += box->y;
|
corner_6.y += box.y;
|
||||||
corner_6.z += box->z;
|
corner_6.z += box.z;
|
||||||
|
|
||||||
SC_SACD_Vec3 corner_7 =
|
SC_SACD_Vec3 corner_7 =
|
||||||
box->transform *
|
box.transform *
|
||||||
SC_SACD_Vec3{box->width / 2.0F, box->height / 2.0F, box->depth / 2.0F};
|
SC_SACD_Vec3{box.width / 2.0F, box.height / 2.0F, box.depth / 2.0F};
|
||||||
corner_7.x += box->x;
|
corner_7.x += box.x;
|
||||||
corner_7.y += box->y;
|
corner_7.y += box.y;
|
||||||
corner_7.z += box->z;
|
corner_7.z += box.z;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
corner_0, corner_1, corner_2, corner_3,
|
corner_0, corner_1, corner_2, corner_3,
|
||||||
|
@ -215,7 +213,7 @@ struct SC_SACD_MinMax {
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<SC_SACD_MinMax> SC_SACD_Get_Box_MinMax(
|
std::vector<SC_SACD_MinMax> SC_SACD_Get_Box_MinMax(
|
||||||
const SC_SACD_Generic_Box *box, const std::span<SC_SACD_Vec3> normals) {
|
SC_SACD_Generic_Box box, const std::span<SC_SACD_Vec3> normals) {
|
||||||
std::vector<SC_SACD_MinMax> minmaxes;
|
std::vector<SC_SACD_MinMax> minmaxes;
|
||||||
|
|
||||||
auto corners = SC_SACD_Get_Box_Corners(box);
|
auto corners = SC_SACD_Get_Box_Corners(box);
|
||||||
|
@ -249,21 +247,20 @@ SC_SACD_Generic_Box SC_SACD_Generic_Box_Default() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
int SC_SACD_AABB_Box_Collision(const SC_SACD_AABB_Box *a,
|
int SC_SACD_AABB_Box_Collision(SC_SACD_AABB_Box a, SC_SACD_AABB_Box b) {
|
||||||
const SC_SACD_AABB_Box *b) {
|
float ax_min = a.x - a.width / 2.0F;
|
||||||
float ax_min = a->x - a->width / 2.0F;
|
float ax_max = a.x + a.width / 2.0F;
|
||||||
float ax_max = a->x + a->width / 2.0F;
|
float ay_min = a.y - a.height / 2.0F;
|
||||||
float ay_min = a->y - a->height / 2.0F;
|
float ay_max = a.y + a.height / 2.0F;
|
||||||
float ay_max = a->y + a->height / 2.0F;
|
float az_min = a.z - a.depth / 2.0F;
|
||||||
float az_min = a->z - a->depth / 2.0F;
|
float az_max = a.z + a.depth / 2.0F;
|
||||||
float az_max = a->z + a->depth / 2.0F;
|
|
||||||
|
|
||||||
float bx_min = b->x - b->width / 2.0F;
|
float bx_min = b.x - b.width / 2.0F;
|
||||||
float bx_max = b->x + b->width / 2.0F;
|
float bx_max = b.x + b.width / 2.0F;
|
||||||
float by_min = b->y - b->height / 2.0F;
|
float by_min = b.y - b.height / 2.0F;
|
||||||
float by_max = b->y + b->height / 2.0F;
|
float by_max = b.y + b.height / 2.0F;
|
||||||
float bz_min = b->z - b->depth / 2.0F;
|
float bz_min = b.z - b.depth / 2.0F;
|
||||||
float bz_max = b->z + b->depth / 2.0F;
|
float bz_max = b.z + b.depth / 2.0F;
|
||||||
|
|
||||||
return (ax_min < bx_max && ax_max > bx_min && ay_min < by_max &&
|
return (ax_min < bx_max && ax_max > bx_min && ay_min < by_max &&
|
||||||
ay_max > by_min && az_min < bz_max && az_max > bz_min)
|
ay_max > by_min && az_min < bz_max && az_max > bz_min)
|
||||||
|
@ -271,8 +268,8 @@ int SC_SACD_AABB_Box_Collision(const SC_SACD_AABB_Box *a,
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SC_SACD_Generic_Box_Collision(const SC_SACD_Generic_Box *a,
|
int SC_SACD_Generic_Box_Collision(SC_SACD_Generic_Box a,
|
||||||
const SC_SACD_Generic_Box *b) {
|
SC_SACD_Generic_Box b) {
|
||||||
// Get all normals.
|
// Get all normals.
|
||||||
std::vector<SC_SACD_Vec3> normals;
|
std::vector<SC_SACD_Vec3> normals;
|
||||||
{
|
{
|
||||||
|
@ -299,60 +296,60 @@ int SC_SACD_Generic_Box_Collision(const SC_SACD_Generic_Box *a,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SC_SACD_AABB_Generic_Box_Collision(const SC_SACD_AABB_Box *a,
|
int SC_SACD_AABB_Generic_Box_Collision(SC_SACD_AABB_Box a,
|
||||||
const SC_SACD_Generic_Box *b) {
|
SC_SACD_Generic_Box b) {
|
||||||
SC_SACD_Generic_Box a_conv;
|
SC_SACD_Generic_Box a_conv;
|
||||||
|
|
||||||
a_conv.x = a->x;
|
a_conv.x = a.x;
|
||||||
a_conv.y = a->y;
|
a_conv.y = a.y;
|
||||||
a_conv.z = a->z;
|
a_conv.z = a.z;
|
||||||
a_conv.width = a->width;
|
a_conv.width = a.width;
|
||||||
a_conv.height = a->height;
|
a_conv.height = a.height;
|
||||||
a_conv.depth = a->depth;
|
a_conv.depth = a.depth;
|
||||||
a_conv.transform = SC_SACD_Mat4_Identity();
|
a_conv.transform = SC_SACD_Mat4_Identity();
|
||||||
return SC_SACD_Generic_Box_Collision(&a_conv, b);
|
return SC_SACD_Generic_Box_Collision(a_conv, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SC_SACD_Sphere_Collision(const SC_SACD_Sphere *a, const SC_SACD_Sphere *b) {
|
int SC_SACD_Sphere_Collision(SC_SACD_Sphere a, SC_SACD_Sphere b) {
|
||||||
SC_SACD_Vec3 vec{a->x - b->x, a->y - b->y, a->z - b->z};
|
SC_SACD_Vec3 vec{a.x - b.x, a.y - b.y, a.z - b.z};
|
||||||
|
|
||||||
return (a->radius + b->radius) > std::sqrt(SC_SACD_Dot_Product(vec, vec)) ? 1
|
return (a.radius + b.radius) > std::sqrt(SC_SACD_Dot_Product(vec, vec)) ? 1
|
||||||
: 0;
|
: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SC_SACD_Sphere_AABB_Box_Collision(const SC_SACD_Sphere *sphere,
|
int SC_SACD_Sphere_AABB_Box_Collision(SC_SACD_Sphere sphere,
|
||||||
const SC_SACD_AABB_Box *box) {
|
SC_SACD_AABB_Box box) {
|
||||||
SC_SACD_Vec3 box_min{
|
SC_SACD_Vec3 box_min{
|
||||||
box->x - box->width / 2.0F,
|
box.x - box.width / 2.0F,
|
||||||
box->y - box->height / 2.0F,
|
box.y - box.height / 2.0F,
|
||||||
box->z - box->depth / 2.0F,
|
box.z - box.depth / 2.0F,
|
||||||
};
|
};
|
||||||
SC_SACD_Vec3 box_max{
|
SC_SACD_Vec3 box_max{
|
||||||
box->x + box->width / 2.0F,
|
box.x + box.width / 2.0F,
|
||||||
box->y + box->height / 2.0F,
|
box.y + box.height / 2.0F,
|
||||||
box->z + box->depth / 2.0F,
|
box.z + box.depth / 2.0F,
|
||||||
};
|
};
|
||||||
|
|
||||||
SC_SACD_Vec3 clamped{std::max(box_min.x, std::min(sphere->x, box_max.x)),
|
SC_SACD_Vec3 clamped{std::max(box_min.x, std::min(sphere.x, box_max.x)),
|
||||||
std::max(box_min.y, std::min(sphere->y, box_max.y)),
|
std::max(box_min.y, std::min(sphere.y, box_max.y)),
|
||||||
std::max(box_min.z, std::min(sphere->z, box_max.z))};
|
std::max(box_min.z, std::min(sphere.z, box_max.z))};
|
||||||
|
|
||||||
SC_SACD_Vec3 diff = clamped - SC_SACD_Vec3{sphere->x, sphere->y, sphere->z};
|
SC_SACD_Vec3 diff = clamped - SC_SACD_Vec3{sphere.x, sphere.y, sphere.z};
|
||||||
|
|
||||||
float dist = std::sqrt(SC_SACD_Dot_Product(diff, diff));
|
float dist = std::sqrt(SC_SACD_Dot_Product(diff, diff));
|
||||||
|
|
||||||
return dist < sphere->radius;
|
return dist < sphere.radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SC_SACD_Sphere_Box_Collision(const SC_SACD_Sphere *sphere,
|
int SC_SACD_Sphere_Box_Collision(SC_SACD_Sphere sphere,
|
||||||
const SC_SACD_Generic_Box *box) {
|
SC_SACD_Generic_Box box) {
|
||||||
// Adapted from Generic_Box/Generic_Box collision.
|
// Adapted from Generic_Box/Generic_Box collision.
|
||||||
|
|
||||||
// First check plane where normal = box_pos - sphere_pos.
|
// First check plane where normal = box_pos - sphere_pos.
|
||||||
|
|
||||||
SC_SACD_Vec3 sphere_pos{sphere->x, sphere->y, sphere->z};
|
SC_SACD_Vec3 sphere_pos{sphere.x, sphere.y, sphere.z};
|
||||||
std::array<SC_SACD_Vec3, 1> sphere_box_normal = {
|
std::array<SC_SACD_Vec3, 1> sphere_box_normal = {
|
||||||
SC_SACD_Vec3{box->x, box->y, box->z} - sphere_pos};
|
SC_SACD_Vec3{box.x, box.y, box.z} - sphere_pos};
|
||||||
if (sphere_box_normal[0].x < 0.0001F && sphere_box_normal[0].x > -0.0001F &&
|
if (sphere_box_normal[0].x < 0.0001F && sphere_box_normal[0].x > -0.0001F &&
|
||||||
sphere_box_normal[0].y < 0.0001F && sphere_box_normal[0].y > -0.0001F &&
|
sphere_box_normal[0].y < 0.0001F && sphere_box_normal[0].y > -0.0001F &&
|
||||||
sphere_box_normal[0].z < 0.0001F && sphere_box_normal[0].z > -0.0001F) {
|
sphere_box_normal[0].z < 0.0001F && sphere_box_normal[0].z > -0.0001F) {
|
||||||
|
@ -367,9 +364,9 @@ int SC_SACD_Sphere_Box_Collision(const SC_SACD_Sphere *sphere,
|
||||||
SC_SACD_Get_Box_MinMax(box, sphere_box_normal);
|
SC_SACD_Get_Box_MinMax(box, sphere_box_normal);
|
||||||
|
|
||||||
float projected_0 = SC_SACD_Dot_Product(
|
float projected_0 = SC_SACD_Dot_Product(
|
||||||
sphere_box_normal[0], sphere_pos + sphere_box_normal[0] * sphere->radius);
|
sphere_box_normal[0], sphere_pos + sphere_box_normal[0] * sphere.radius);
|
||||||
float projected_1 = SC_SACD_Dot_Product(
|
float projected_1 = SC_SACD_Dot_Product(
|
||||||
sphere_box_normal[0], sphere_pos - sphere_box_normal[0] * sphere->radius);
|
sphere_box_normal[0], sphere_pos - sphere_box_normal[0] * sphere.radius);
|
||||||
if (projected_0 < projected_1) {
|
if (projected_0 < projected_1) {
|
||||||
if (box_minmaxes[0].max < projected_0 ||
|
if (box_minmaxes[0].max < projected_0 ||
|
||||||
box_minmaxes[0].min > projected_1) {
|
box_minmaxes[0].min > projected_1) {
|
||||||
|
@ -386,9 +383,9 @@ int SC_SACD_Sphere_Box_Collision(const SC_SACD_Sphere *sphere,
|
||||||
box_minmaxes = SC_SACD_Get_Box_MinMax(box, box_normals);
|
box_minmaxes = SC_SACD_Get_Box_MinMax(box, box_normals);
|
||||||
for (unsigned int i = 0; i < box_normals.size(); ++i) {
|
for (unsigned int i = 0; i < box_normals.size(); ++i) {
|
||||||
projected_0 = SC_SACD_Dot_Product(
|
projected_0 = SC_SACD_Dot_Product(
|
||||||
box_normals[i], sphere_pos + box_normals[i] * sphere->radius);
|
box_normals[i], sphere_pos + box_normals[i] * sphere.radius);
|
||||||
projected_1 = SC_SACD_Dot_Product(
|
projected_1 = SC_SACD_Dot_Product(
|
||||||
box_normals[i], sphere_pos - box_normals[i] * sphere->radius);
|
box_normals[i], sphere_pos - box_normals[i] * sphere.radius);
|
||||||
if (projected_0 < projected_1) {
|
if (projected_0 < projected_1) {
|
||||||
if (box_minmaxes[i].max < projected_0 ||
|
if (box_minmaxes[i].max < projected_0 ||
|
||||||
box_minmaxes[i].min > projected_1) {
|
box_minmaxes[i].min > projected_1) {
|
||||||
|
@ -403,11 +400,11 @@ int SC_SACD_Sphere_Box_Collision(const SC_SACD_Sphere *sphere,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
float SC_SACD_Dot_Product(const SC_SACD_Vec3 a, const SC_SACD_Vec3 b) {
|
float SC_SACD_Dot_Product(SC_SACD_Vec3 a, SC_SACD_Vec3 b) {
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_Vec3 SC_SACD_Cross_Product(const SC_SACD_Vec3 a, const SC_SACD_Vec3 b) {
|
SC_SACD_Vec3 SC_SACD_Cross_Product(SC_SACD_Vec3 a, SC_SACD_Vec3 b) {
|
||||||
return SC_SACD_Vec3{a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
|
return SC_SACD_Vec3{a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
|
||||||
a.x * b.y - a.y * b.x};
|
a.x * b.y - a.y * b.x};
|
||||||
}
|
}
|
||||||
|
@ -417,17 +414,14 @@ SC_SACD_Mat4 SC_SACD_Mat4_Identity(void) {
|
||||||
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_Mat4 SC_SACD_Mat4_Mult(const SC_SACD_Mat4 *a, const SC_SACD_Mat4 *b) {
|
SC_SACD_Mat4 SC_SACD_Mat4_Mult(SC_SACD_Mat4 a, SC_SACD_Mat4 b) { return a * b; }
|
||||||
return (*a) * (*b);
|
|
||||||
|
SC_SACD_Vec3 SC_SACD_Mat4_Vec3_Mult(SC_SACD_Mat4 mat, SC_SACD_Vec3 vec) {
|
||||||
|
return mat * vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_Vec3 SC_SACD_Mat4_Vec3_Mult(const SC_SACD_Mat4 *mat,
|
SC_SACD_Vec3 SC_SACD_Vec3_Rotate(SC_SACD_Vec3 vec, float x_axis, float y_axis,
|
||||||
const SC_SACD_Vec3 vec) {
|
float z_axis) {
|
||||||
return (*mat) * vec;
|
|
||||||
}
|
|
||||||
|
|
||||||
SC_SACD_Vec3 SC_SACD_Vec3_Rotate(const SC_SACD_Vec3 vec, float x_axis,
|
|
||||||
float y_axis, float z_axis) {
|
|
||||||
/*
|
/*
|
||||||
* z_axis counter-clockwise affects x and y.
|
* z_axis counter-clockwise affects x and y.
|
||||||
* [ cos, -sin, 0 ]
|
* [ cos, -sin, 0 ]
|
||||||
|
@ -451,17 +445,17 @@ SC_SACD_Vec3 SC_SACD_Vec3_Rotate(const SC_SACD_Vec3 vec, float x_axis,
|
||||||
// About x_axis.
|
// About x_axis.
|
||||||
mat = SC_SACD_Rotation_Mat4_XAxis(x_axis);
|
mat = SC_SACD_Rotation_Mat4_XAxis(x_axis);
|
||||||
|
|
||||||
result = SC_SACD_Mat4_Vec3_Mult(&mat, vec);
|
result = SC_SACD_Mat4_Vec3_Mult(mat, vec);
|
||||||
|
|
||||||
// About y_axis.
|
// About y_axis.
|
||||||
mat = SC_SACD_Rotation_Mat4_YAxis(y_axis);
|
mat = SC_SACD_Rotation_Mat4_YAxis(y_axis);
|
||||||
|
|
||||||
result = SC_SACD_Mat4_Vec3_Mult(&mat, result);
|
result = SC_SACD_Mat4_Vec3_Mult(mat, result);
|
||||||
|
|
||||||
// About z_axis.
|
// About z_axis.
|
||||||
mat = SC_SACD_Rotation_Mat4_ZAxis(z_axis);
|
mat = SC_SACD_Rotation_Mat4_ZAxis(z_axis);
|
||||||
|
|
||||||
return SC_SACD_Mat4_Vec3_Mult(&mat, result);
|
return SC_SACD_Mat4_Vec3_Mult(mat, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_Mat4 SC_SACD_Rotation_Mat4_XAxis(float x_radians) {
|
SC_SACD_Mat4 SC_SACD_Rotation_Mat4_XAxis(float x_radians) {
|
||||||
|
@ -552,28 +546,26 @@ SC_SACD_Mat4 SC_SACD_Scale_Mat4(float x, float y, float z) {
|
||||||
0.0F, 0.0F, z, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
0.0F, 0.0F, z, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_Vec3 SC_SACD_Closest_Point_Dir_Normalized(const SC_SACD_Vec3 *pos,
|
SC_SACD_Vec3 SC_SACD_Closest_Point_Dir_Normalized(SC_SACD_Vec3 pos,
|
||||||
const SC_SACD_Vec3 *dir,
|
SC_SACD_Vec3 dir,
|
||||||
const SC_SACD_Vec3 *point) {
|
SC_SACD_Vec3 point) {
|
||||||
float alpha =
|
float alpha = SC_SACD_Dot_Product(dir, point) - SC_SACD_Dot_Product(dir, pos);
|
||||||
SC_SACD_Dot_Product(*dir, *point) - SC_SACD_Dot_Product(*dir, *pos);
|
return pos + dir * alpha;
|
||||||
return *pos + *dir * alpha;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_Vec3 SC_SACD_Closest_Point(const SC_SACD_Vec3 *pos,
|
SC_SACD_Vec3 SC_SACD_Closest_Point(SC_SACD_Vec3 pos, SC_SACD_Vec3 dir,
|
||||||
const SC_SACD_Vec3 *dir,
|
SC_SACD_Vec3 point) {
|
||||||
const SC_SACD_Vec3 *point) {
|
|
||||||
float alpha =
|
float alpha =
|
||||||
(SC_SACD_Dot_Product(*dir, *point) - SC_SACD_Dot_Product(*dir, *pos)) /
|
(SC_SACD_Dot_Product(dir, point) - SC_SACD_Dot_Product(dir, pos)) /
|
||||||
SC_SACD_Dot_Product(*dir, *dir);
|
SC_SACD_Dot_Product(dir, dir);
|
||||||
return *pos + *dir * alpha;
|
return pos + dir * alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
float SC_SACD_Vec3_Length(const SC_SACD_Vec3 vec) {
|
float SC_SACD_Vec3_Length(SC_SACD_Vec3 vec) {
|
||||||
return std::sqrt(SC_SACD_Dot_Product(vec, vec));
|
return std::sqrt(SC_SACD_Dot_Product(vec, vec));
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_AABB_Box SC_SACD_Sphere_To_AABB(const SC_SACD_Sphere s) {
|
SC_SACD_AABB_Box SC_SACD_Sphere_To_AABB(SC_SACD_Sphere s) {
|
||||||
SC_SACD_AABB_Box aabb{};
|
SC_SACD_AABB_Box aabb{};
|
||||||
|
|
||||||
aabb.x = s.x;
|
aabb.x = s.x;
|
||||||
|
@ -587,10 +579,10 @@ SC_SACD_AABB_Box SC_SACD_Sphere_To_AABB(const SC_SACD_Sphere s) {
|
||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_AABB_Box SC_SACD_Generic_Box_To_AABB(const SC_SACD_Generic_Box s) {
|
SC_SACD_AABB_Box SC_SACD_Generic_Box_To_AABB(SC_SACD_Generic_Box s) {
|
||||||
SC_SACD_AABB_Box aabb{};
|
SC_SACD_AABB_Box aabb{};
|
||||||
|
|
||||||
auto corners = SC_SACD_Get_Box_Corners(&s);
|
auto corners = SC_SACD_Get_Box_Corners(s);
|
||||||
|
|
||||||
SC_SACD_Vec3 min{INFINITY, INFINITY, INFINITY};
|
SC_SACD_Vec3 min{INFINITY, INFINITY, INFINITY};
|
||||||
SC_SACD_Vec3 max{-INFINITY, -INFINITY, -INFINITY};
|
SC_SACD_Vec3 max{-INFINITY, -INFINITY, -INFINITY};
|
||||||
|
@ -628,8 +620,7 @@ SC_SACD_AABB_Box SC_SACD_Generic_Box_To_AABB(const SC_SACD_Generic_Box s) {
|
||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
SC_SACD_AABB_Box SC_SACD_AABB_Combine(const SC_SACD_AABB_Box a,
|
SC_SACD_AABB_Box SC_SACD_AABB_Combine(SC_SACD_AABB_Box a, SC_SACD_AABB_Box b) {
|
||||||
const SC_SACD_AABB_Box b) {
|
|
||||||
SC_SACD_Vec3 min, max;
|
SC_SACD_Vec3 min, max;
|
||||||
|
|
||||||
// Populate min values.
|
// Populate min values.
|
||||||
|
|
|
@ -71,47 +71,43 @@ typedef struct SC_SACD_EXPORT SC_SACD_Sphere {
|
||||||
SC_SACD_EXPORT SC_SACD_Generic_Box SC_SACD_Generic_Box_Default(void);
|
SC_SACD_EXPORT SC_SACD_Generic_Box SC_SACD_Generic_Box_Default(void);
|
||||||
|
|
||||||
/// Returns non-zero if there is collision.
|
/// Returns non-zero if there is collision.
|
||||||
SC_SACD_EXPORT int SC_SACD_AABB_Box_Collision(const SC_SACD_AABB_Box *a,
|
SC_SACD_EXPORT int SC_SACD_AABB_Box_Collision(SC_SACD_AABB_Box a,
|
||||||
const SC_SACD_AABB_Box *b);
|
SC_SACD_AABB_Box b);
|
||||||
|
|
||||||
/// Returns non-zero if there is collision.
|
/// Returns non-zero if there is collision.
|
||||||
SC_SACD_EXPORT int SC_SACD_Generic_Box_Collision(const SC_SACD_Generic_Box *a,
|
SC_SACD_EXPORT int SC_SACD_Generic_Box_Collision(SC_SACD_Generic_Box a,
|
||||||
const SC_SACD_Generic_Box *b);
|
SC_SACD_Generic_Box b);
|
||||||
|
|
||||||
/// Returns non-zero if there is collision.
|
/// Returns non-zero if there is collision.
|
||||||
SC_SACD_EXPORT int SC_SACD_AABB_Generic_Box_Collision(
|
SC_SACD_EXPORT int SC_SACD_AABB_Generic_Box_Collision(SC_SACD_AABB_Box a,
|
||||||
const SC_SACD_AABB_Box *a, const SC_SACD_Generic_Box *b);
|
SC_SACD_Generic_Box b);
|
||||||
|
|
||||||
/// Returns non-zero if there is collision.
|
/// Returns non-zero if there is collision.
|
||||||
SC_SACD_EXPORT int SC_SACD_Sphere_Collision(const SC_SACD_Sphere *a,
|
SC_SACD_EXPORT int SC_SACD_Sphere_Collision(SC_SACD_Sphere a, SC_SACD_Sphere b);
|
||||||
const SC_SACD_Sphere *b);
|
|
||||||
|
|
||||||
/// Returns non-zero if there is collision.
|
/// Returns non-zero if there is collision.
|
||||||
SC_SACD_EXPORT int SC_SACD_Sphere_AABB_Box_Collision(
|
SC_SACD_EXPORT int SC_SACD_Sphere_AABB_Box_Collision(SC_SACD_Sphere sphere,
|
||||||
const SC_SACD_Sphere *sphere, const SC_SACD_AABB_Box *box);
|
SC_SACD_AABB_Box box);
|
||||||
|
|
||||||
/// Returns non-zero if there is collision.
|
/// Returns non-zero if there is collision.
|
||||||
SC_SACD_EXPORT int SC_SACD_Sphere_Box_Collision(const SC_SACD_Sphere *sphere,
|
SC_SACD_EXPORT int SC_SACD_Sphere_Box_Collision(SC_SACD_Sphere sphere,
|
||||||
const SC_SACD_Generic_Box *box);
|
SC_SACD_Generic_Box box);
|
||||||
|
|
||||||
SC_SACD_EXPORT float SC_SACD_Dot_Product(const SC_SACD_Vec3 a,
|
SC_SACD_EXPORT float SC_SACD_Dot_Product(SC_SACD_Vec3 a, SC_SACD_Vec3 b);
|
||||||
const SC_SACD_Vec3 b);
|
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Cross_Product(const SC_SACD_Vec3 a,
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Cross_Product(SC_SACD_Vec3 a,
|
||||||
const SC_SACD_Vec3 b);
|
SC_SACD_Vec3 b);
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Mat4_Identity(void);
|
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Mat4_Identity(void);
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Mat4_Mult(const SC_SACD_Mat4 *a,
|
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Mat4_Mult(SC_SACD_Mat4 a, SC_SACD_Mat4 b);
|
||||||
const SC_SACD_Mat4 *b);
|
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Mat4_Vec3_Mult(const SC_SACD_Mat4 *mat,
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Mat4_Vec3_Mult(SC_SACD_Mat4 mat,
|
||||||
const SC_SACD_Vec3 vec);
|
SC_SACD_Vec3 vec);
|
||||||
|
|
||||||
/// Rotates by x-axis first, then y-axis, then finally z-axis.
|
/// Rotates by x-axis first, then y-axis, then finally z-axis.
|
||||||
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Rotate(const SC_SACD_Vec3 vec,
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Rotate(SC_SACD_Vec3 vec, float x_axis,
|
||||||
float x_axis, float y_axis,
|
float y_axis, float z_axis);
|
||||||
float z_axis);
|
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Rotation_Mat4_XAxis(float x_radians);
|
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Rotation_Mat4_XAxis(float x_radians);
|
||||||
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Rotation_Mat4_YAxis(float y_radians);
|
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Rotation_Mat4_YAxis(float y_radians);
|
||||||
|
@ -123,23 +119,22 @@ SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Scale_Mat4(float x, float y, float z);
|
||||||
|
|
||||||
/// This variant of Closest_Point expects "dir" to be a unit vector.
|
/// This variant of Closest_Point expects "dir" to be a unit vector.
|
||||||
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Closest_Point_Dir_Normalized(
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Closest_Point_Dir_Normalized(
|
||||||
const SC_SACD_Vec3 *pos, const SC_SACD_Vec3 *dir,
|
SC_SACD_Vec3 pos, SC_SACD_Vec3 dir, SC_SACD_Vec3 point);
|
||||||
const SC_SACD_Vec3 *point);
|
|
||||||
|
|
||||||
/// This variant of Closest_Point expects "dir" to NOT be a unit vector.
|
/// This variant of Closest_Point expects "dir" to NOT be a unit vector.
|
||||||
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Closest_Point(const SC_SACD_Vec3 *pos,
|
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Closest_Point(SC_SACD_Vec3 pos,
|
||||||
const SC_SACD_Vec3 *dir,
|
SC_SACD_Vec3 dir,
|
||||||
const SC_SACD_Vec3 *point);
|
SC_SACD_Vec3 point);
|
||||||
|
|
||||||
SC_SACD_EXPORT float SC_SACD_Vec3_Length(const SC_SACD_Vec3 vec);
|
SC_SACD_EXPORT float SC_SACD_Vec3_Length(SC_SACD_Vec3 vec);
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_AABB_Box SC_SACD_Sphere_To_AABB(const SC_SACD_Sphere s);
|
SC_SACD_EXPORT SC_SACD_AABB_Box SC_SACD_Sphere_To_AABB(SC_SACD_Sphere s);
|
||||||
SC_SACD_EXPORT SC_SACD_AABB_Box
|
SC_SACD_EXPORT SC_SACD_AABB_Box
|
||||||
SC_SACD_Generic_Box_To_AABB(const SC_SACD_Generic_Box s);
|
SC_SACD_Generic_Box_To_AABB(SC_SACD_Generic_Box s);
|
||||||
|
|
||||||
/// Combines AABB's such that the new AABB encompasses the two AABB's.
|
/// Combines AABB's such that the new AABB encompasses the two AABB's.
|
||||||
SC_SACD_EXPORT SC_SACD_AABB_Box SC_SACD_AABB_Combine(const SC_SACD_AABB_Box a,
|
SC_SACD_EXPORT SC_SACD_AABB_Box SC_SACD_AABB_Combine(SC_SACD_AABB_Box a,
|
||||||
const SC_SACD_AABB_Box b);
|
SC_SACD_AABB_Box b);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
248
src/test.cpp
248
src/test.cpp
|
@ -44,54 +44,54 @@ int main() {
|
||||||
SC_SACD_AABB_Box a{0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F};
|
SC_SACD_AABB_Box a{0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F};
|
||||||
SC_SACD_AABB_Box b{2.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F};
|
SC_SACD_AABB_Box b{2.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F};
|
||||||
|
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.x = -2.0F;
|
b.x = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.x = 0.5F;
|
b.x = 0.5F;
|
||||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
b.x = -0.5F;
|
b.x = -0.5F;
|
||||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.x = 0.0F;
|
b.x = 0.0F;
|
||||||
b.y = 2.0F;
|
b.y = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
b.y = -2.0F;
|
b.y = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.y = 0.5F;
|
b.y = 0.5F;
|
||||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
b.y = -0.5F;
|
b.y = -0.5F;
|
||||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.y = 0.0F;
|
b.y = 0.0F;
|
||||||
b.z = 2.0F;
|
b.z = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.z = -2.0F;
|
b.z = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.z = 0.5F;
|
b.z = 0.5F;
|
||||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.z = -0.5F;
|
b.z = -0.5F;
|
||||||
CHECK_TRUE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.z = 0.0F;
|
b.z = 0.0F;
|
||||||
b.x = 0.5F;
|
b.x = 0.5F;
|
||||||
b.y = 2.0F;
|
b.y = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.y = -2.0F;
|
b.y = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.x = -0.5F;
|
b.x = -0.5F;
|
||||||
b.y = 2.0F;
|
b.y = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
|
|
||||||
b.y = -2.0F;
|
b.y = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_AABB_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_AABB_Box_Collision(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Separating_Axis_Collision check.
|
// Test Separating_Axis_Collision check.
|
||||||
|
@ -101,54 +101,54 @@ int main() {
|
||||||
SC_SACD_Generic_Box b{
|
SC_SACD_Generic_Box b{
|
||||||
0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F, SC_SACD_Mat4_Identity()};
|
0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F, SC_SACD_Mat4_Identity()};
|
||||||
|
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
b.x = 1.1F;
|
b.x = 1.1F;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
b.x = -1.1F;
|
b.x = -1.1F;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
a.transform = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
b.transform = a.transform;
|
b.transform = a.transform;
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
b.x = 1.1F;
|
b.x = 1.1F;
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
b.x = 0.0F;
|
b.x = 0.0F;
|
||||||
b.y = 1.1F;
|
b.y = 1.1F;
|
||||||
a.transform = SC_SACD_Mat4_Identity();
|
a.transform = SC_SACD_Mat4_Identity();
|
||||||
b.transform = a.transform;
|
b.transform = a.transform;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
b.y = -1.1F;
|
b.y = -1.1F;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
a.transform = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
b.transform = a.transform;
|
b.transform = a.transform;
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
b.y = 1.1F;
|
b.y = 1.1F;
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
b.y = 0.0F;
|
b.y = 0.0F;
|
||||||
a.transform = SC_SACD_Mat4_Identity();
|
a.transform = SC_SACD_Mat4_Identity();
|
||||||
b.transform = a.transform;
|
b.transform = a.transform;
|
||||||
|
|
||||||
b.z = 1.1F;
|
b.z = 1.1F;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
b.z = -1.1F;
|
b.z = -1.1F;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> / 4.0F);
|
a.transform = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
b.transform = a.transform;
|
b.transform = a.transform;
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
b.z = 1.1F;
|
b.z = 1.1F;
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Sphere/Sphere collision check.
|
// Test Sphere/Sphere collision check.
|
||||||
{
|
{
|
||||||
SC_SACD_Sphere a{0.0F, 0.0F, 0.0F, 1.0F};
|
SC_SACD_Sphere a{0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
SC_SACD_Sphere b{0.0F, 0.0F, 0.0F, 1.0F};
|
SC_SACD_Sphere b{0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Sphere_Collision(a, b));
|
||||||
|
|
||||||
a.x = 10.0F;
|
a.x = 10.0F;
|
||||||
a.y = 10.0F;
|
a.y = 10.0F;
|
||||||
|
@ -156,13 +156,13 @@ int main() {
|
||||||
b.x = 10.0F;
|
b.x = 10.0F;
|
||||||
b.y = 10.5F;
|
b.y = 10.5F;
|
||||||
b.z = 10.0F;
|
b.z = 10.0F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Sphere_Collision(a, b));
|
||||||
b.y = 12.0F;
|
b.y = 12.0F;
|
||||||
b.z = 12.0F;
|
b.z = 12.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Sphere_Collision(a, b));
|
||||||
b.y = 11.0F;
|
b.y = 11.0F;
|
||||||
b.z = 11.0F;
|
b.z = 11.0F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Sphere_Collision(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Sphere/AABB collision check.
|
// Test Sphere/AABB collision check.
|
||||||
|
@ -170,69 +170,69 @@ int main() {
|
||||||
SC_SACD_Sphere sphere{0.0F, 0.0F, 0.0F, 1.0F};
|
SC_SACD_Sphere sphere{0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
SC_SACD_AABB_Box box{0.0F, 0.0F, 0.0F, 2.0F, 2.0F, 2.0F};
|
SC_SACD_AABB_Box box{0.0F, 0.0F, 0.0F, 2.0F, 2.0F, 2.0F};
|
||||||
|
|
||||||
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 2.1F;
|
sphere.x = 2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -2.1F;
|
sphere.x = -2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 0.0F;
|
sphere.x = 0.0F;
|
||||||
sphere.y = 2.1F;
|
sphere.y = 2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.y = -2.1F;
|
sphere.y = -2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.y = 0.0F;
|
sphere.y = 0.0F;
|
||||||
sphere.z = 2.1F;
|
sphere.z = 2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.z = -2.1F;
|
sphere.z = -2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.z = 0.0F;
|
sphere.z = 0.0F;
|
||||||
sphere.x = 1.0F;
|
sphere.x = 1.0F;
|
||||||
sphere.y = 1.0F;
|
sphere.y = 1.0F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -1.0F;
|
sphere.x = -1.0F;
|
||||||
sphere.y = -1.0F;
|
sphere.y = -1.0F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 2.0F;
|
sphere.x = 2.0F;
|
||||||
sphere.y = 2.0F;
|
sphere.y = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -2.0F;
|
sphere.x = -2.0F;
|
||||||
sphere.y = -2.0F;
|
sphere.y = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 1.0F;
|
sphere.x = 1.0F;
|
||||||
sphere.y = 0.0F;
|
sphere.y = 0.0F;
|
||||||
sphere.z = 1.0F;
|
sphere.z = 1.0F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -1.0F;
|
sphere.x = -1.0F;
|
||||||
sphere.z = -1.0F;
|
sphere.z = -1.0F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 2.0F;
|
sphere.x = 2.0F;
|
||||||
sphere.z = 2.0F;
|
sphere.z = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -2.0F;
|
sphere.x = -2.0F;
|
||||||
sphere.z = -2.0F;
|
sphere.z = -2.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 1.0F;
|
sphere.x = 1.0F;
|
||||||
sphere.z = 1.5F;
|
sphere.z = 1.5F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 1.0F;
|
sphere.x = 1.0F;
|
||||||
sphere.z = 2.0F;
|
sphere.z = 2.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_AABB_Box_Collision(sphere, box));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Sphere/Generic_Box collision check.
|
// Test Sphere/Generic_Box collision check.
|
||||||
|
@ -247,67 +247,67 @@ int main() {
|
||||||
2.0F,
|
2.0F,
|
||||||
SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F)};
|
SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F)};
|
||||||
|
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 2.5F;
|
sphere.x = 2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = -2.5F;
|
sphere.x = -2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 2.3F;
|
sphere.x = 2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = -2.3F;
|
sphere.x = -2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 0.0F;
|
sphere.x = 0.0F;
|
||||||
sphere.y = 2.5F;
|
sphere.y = 2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.y = -2.5F;
|
sphere.y = -2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.y = 2.3F;
|
sphere.y = 2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.y = -2.3F;
|
sphere.y = -2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.y = 0.0F;
|
sphere.y = 0.0F;
|
||||||
sphere.z = 2.1F;
|
sphere.z = 2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.z = -2.1F;
|
sphere.z = -2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.z = 1.9F;
|
sphere.z = 1.9F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.z = -1.9F;
|
sphere.z = -1.9F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 1.5F;
|
sphere.x = 1.5F;
|
||||||
sphere.y = 1.5F;
|
sphere.y = 1.5F;
|
||||||
sphere.z = 0.0F;
|
sphere.z = 0.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 1.4F;
|
sphere.x = 1.4F;
|
||||||
sphere.y = 1.4F;
|
sphere.y = 1.4F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 2.2F;
|
sphere.x = 2.2F;
|
||||||
sphere.y = 0.7929F;
|
sphere.y = 0.7929F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 2.1F;
|
sphere.x = 2.1F;
|
||||||
sphere.y = 0.6929F;
|
sphere.y = 0.6929F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -1.5F;
|
sphere.x = -1.5F;
|
||||||
sphere.y = -1.5F;
|
sphere.y = -1.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = -1.4F;
|
sphere.x = -1.4F;
|
||||||
sphere.y = -1.4F;
|
sphere.y = -1.4F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -2.2F;
|
sphere.x = -2.2F;
|
||||||
sphere.y = -0.7929F;
|
sphere.y = -0.7929F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = -2.1F;
|
sphere.x = -2.1F;
|
||||||
sphere.y = -0.6929F;
|
sphere.y = -0.6929F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
box.x = 10.0F;
|
box.x = 10.0F;
|
||||||
box.y = -10.0F;
|
box.y = -10.0F;
|
||||||
|
@ -316,64 +316,64 @@ int main() {
|
||||||
sphere.y = -10.0F;
|
sphere.y = -10.0F;
|
||||||
sphere.z = 13.0F;
|
sphere.z = 13.0F;
|
||||||
sphere.x = 10.0F + 2.5F;
|
sphere.x = 10.0F + 2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 10.0F + -2.5F;
|
sphere.x = 10.0F + -2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 10.0F + 2.3F;
|
sphere.x = 10.0F + 2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 10.0F + -2.3F;
|
sphere.x = 10.0F + -2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + 0.0F;
|
sphere.x = 10.0F + 0.0F;
|
||||||
sphere.y = -10.0F + 2.5F;
|
sphere.y = -10.0F + 2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.y = -10.0F + -2.5F;
|
sphere.y = -10.0F + -2.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.y = -10.0F + 2.3F;
|
sphere.y = -10.0F + 2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.y = -10.0F + -2.3F;
|
sphere.y = -10.0F + -2.3F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.y = -10.0F + 0.0F;
|
sphere.y = -10.0F + 0.0F;
|
||||||
sphere.z = 13.0F + 2.1F;
|
sphere.z = 13.0F + 2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.z = 13.0F + -2.1F;
|
sphere.z = 13.0F + -2.1F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.z = 13.0F + 1.9F;
|
sphere.z = 13.0F + 1.9F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.z = 13.0F + -1.9F;
|
sphere.z = 13.0F + -1.9F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + 1.5F;
|
sphere.x = 10.0F + 1.5F;
|
||||||
sphere.y = -10.0F + 1.5F;
|
sphere.y = -10.0F + 1.5F;
|
||||||
sphere.z = 13.0F + 0.0F;
|
sphere.z = 13.0F + 0.0F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 10.0F + 1.4F;
|
sphere.x = 10.0F + 1.4F;
|
||||||
sphere.y = -10.0F + 1.4F;
|
sphere.y = -10.0F + 1.4F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + 2.2F;
|
sphere.x = 10.0F + 2.2F;
|
||||||
sphere.y = -10.0F + 0.7929F;
|
sphere.y = -10.0F + 0.7929F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + 2.1F;
|
sphere.x = 10.0F + 2.1F;
|
||||||
sphere.y = -10.0F + 0.6929F;
|
sphere.y = -10.0F + 0.6929F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + -1.5F;
|
sphere.x = 10.0F + -1.5F;
|
||||||
sphere.y = -10.0F + -1.5F;
|
sphere.y = -10.0F + -1.5F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
sphere.x = 10.0F + -1.4F;
|
sphere.x = 10.0F + -1.4F;
|
||||||
sphere.y = -10.0F + -1.4F;
|
sphere.y = -10.0F + -1.4F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + -2.2F;
|
sphere.x = 10.0F + -2.2F;
|
||||||
sphere.y = -10.0F + -0.7929F;
|
sphere.y = -10.0F + -0.7929F;
|
||||||
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_FALSE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
|
|
||||||
sphere.x = 10.0F + -2.1F;
|
sphere.x = 10.0F + -2.1F;
|
||||||
sphere.y = -10.0F + -0.6929F;
|
sphere.y = -10.0F + -0.6929F;
|
||||||
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(&sphere, &box));
|
CHECK_TRUE(SC_SACD_Sphere_Box_Collision(sphere, box));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test matrix/vector multiplication.
|
// Test matrix/vector multiplication.
|
||||||
|
@ -384,7 +384,7 @@ int main() {
|
||||||
SC_SACD_Mat4 mat_b = SC_SACD_Mat4_Identity();
|
SC_SACD_Mat4 mat_b = SC_SACD_Mat4_Identity();
|
||||||
|
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Mult(&mat_a, &mat_b);
|
auto result = SC_SACD_Mat4_Mult(mat_a, mat_b);
|
||||||
CHECK_TRUE(mat_a.x0 == result.x0);
|
CHECK_TRUE(mat_a.x0 == result.x0);
|
||||||
CHECK_TRUE(mat_a.x1 == result.x1);
|
CHECK_TRUE(mat_a.x1 == result.x1);
|
||||||
CHECK_TRUE(mat_a.x2 == result.x2);
|
CHECK_TRUE(mat_a.x2 == result.x2);
|
||||||
|
@ -407,7 +407,7 @@ int main() {
|
||||||
mat_b.y1 = 0.0F;
|
mat_b.y1 = 0.0F;
|
||||||
mat_b.z2 = 0.0F;
|
mat_b.z2 = 0.0F;
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Mult(&mat_a, &mat_b);
|
auto result = SC_SACD_Mat4_Mult(mat_a, mat_b);
|
||||||
CHECK_FLOAT(result.x0, 2.0F);
|
CHECK_FLOAT(result.x0, 2.0F);
|
||||||
CHECK_FLOAT(result.y0, 10.0F);
|
CHECK_FLOAT(result.y0, 10.0F);
|
||||||
CHECK_FLOAT(result.z0, 18.0F);
|
CHECK_FLOAT(result.z0, 18.0F);
|
||||||
|
@ -429,7 +429,7 @@ int main() {
|
||||||
mat_b = SC_SACD_Mat4_Identity();
|
mat_b = SC_SACD_Mat4_Identity();
|
||||||
SC_SACD_Vec3 vec_a{1.0F, 0.0F, 0.0F};
|
SC_SACD_Vec3 vec_a{1.0F, 0.0F, 0.0F};
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_b, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_b, vec_a);
|
||||||
CHECK_TRUE(result.x == vec_a.x);
|
CHECK_TRUE(result.x == vec_a.x);
|
||||||
CHECK_TRUE(result.y == vec_a.y);
|
CHECK_TRUE(result.y == vec_a.y);
|
||||||
CHECK_TRUE(result.z == vec_a.z);
|
CHECK_TRUE(result.z == vec_a.z);
|
||||||
|
@ -438,7 +438,7 @@ int main() {
|
||||||
// Rotations about each axis.
|
// Rotations about each axis.
|
||||||
mat_a = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 2.0F);
|
mat_a = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 2.0F);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
||||||
CHECK_TRUE(result.y < 1.0001F && result.y > 0.9999F);
|
CHECK_TRUE(result.y < 1.0001F && result.y > 0.9999F);
|
||||||
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
||||||
|
@ -446,7 +446,7 @@ int main() {
|
||||||
|
|
||||||
mat_a = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float>);
|
mat_a = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float>);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < -0.9999F && result.x > -1.0001F);
|
CHECK_TRUE(result.x < -0.9999F && result.x > -1.0001F);
|
||||||
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
||||||
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
||||||
|
@ -455,7 +455,7 @@ int main() {
|
||||||
mat_a =
|
mat_a =
|
||||||
SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> * 3.0F / 2.0F);
|
SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> * 3.0F / 2.0F);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
||||||
CHECK_TRUE(result.y < -0.9999F && result.y > -1.0001F);
|
CHECK_TRUE(result.y < -0.9999F && result.y > -1.0001F);
|
||||||
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
||||||
|
@ -466,7 +466,7 @@ int main() {
|
||||||
vec_a.y = 1.0F;
|
vec_a.y = 1.0F;
|
||||||
vec_a.z = 0.0F;
|
vec_a.z = 0.0F;
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
||||||
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
||||||
CHECK_TRUE(result.z < 1.0001F && result.z > 0.9999F);
|
CHECK_TRUE(result.z < 1.0001F && result.z > 0.9999F);
|
||||||
|
@ -474,7 +474,7 @@ int main() {
|
||||||
|
|
||||||
mat_a = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float>);
|
mat_a = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float>);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
||||||
CHECK_TRUE(result.y < -0.9999F && result.y > -1.0001F);
|
CHECK_TRUE(result.y < -0.9999F && result.y > -1.0001F);
|
||||||
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
||||||
|
@ -483,7 +483,7 @@ int main() {
|
||||||
mat_a =
|
mat_a =
|
||||||
SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float> * 3.0F / 2.0F);
|
SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float> * 3.0F / 2.0F);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
||||||
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
||||||
CHECK_TRUE(result.z < -0.9999F && result.z > -1.0001F);
|
CHECK_TRUE(result.z < -0.9999F && result.z > -1.0001F);
|
||||||
|
@ -494,7 +494,7 @@ int main() {
|
||||||
vec_a.y = 0.0F;
|
vec_a.y = 0.0F;
|
||||||
vec_a.z = 1.0F;
|
vec_a.z = 1.0F;
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 1.0001F && result.x > 0.9999F);
|
CHECK_TRUE(result.x < 1.0001F && result.x > 0.9999F);
|
||||||
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
||||||
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
||||||
|
@ -502,7 +502,7 @@ int main() {
|
||||||
|
|
||||||
mat_a = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float>);
|
mat_a = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float>);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
CHECK_TRUE(result.x < 0.0001F && result.x > -0.0001F);
|
||||||
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
||||||
CHECK_TRUE(result.z < -0.9999F && result.z > -1.0001F);
|
CHECK_TRUE(result.z < -0.9999F && result.z > -1.0001F);
|
||||||
|
@ -511,7 +511,7 @@ int main() {
|
||||||
mat_a =
|
mat_a =
|
||||||
SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> * 3.0F / 2.0F);
|
SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> * 3.0F / 2.0F);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_TRUE(result.x < -0.9999F && result.x > -1.0001F);
|
CHECK_TRUE(result.x < -0.9999F && result.x > -1.0001F);
|
||||||
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
CHECK_TRUE(result.y < 0.0001F && result.y > -0.0001F);
|
||||||
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
|
||||||
|
@ -524,27 +524,27 @@ int main() {
|
||||||
mat_a = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> / 4.0F);
|
mat_a = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
mat_b = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
mat_b = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
// Apply mat_a, then mat_b.
|
// Apply mat_a, then mat_b.
|
||||||
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
|
mat_a = SC_SACD_Mat4_Mult(mat_b, mat_a);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_FLOAT(result.x, 0.5F);
|
CHECK_FLOAT(result.x, 0.5F);
|
||||||
CHECK_FLOAT(result.y, 0.5F);
|
CHECK_FLOAT(result.y, 0.5F);
|
||||||
CHECK_FLOAT(result.z, -std::sqrt(2.0F) / 2.0F);
|
CHECK_FLOAT(result.z, -std::sqrt(2.0F) / 2.0F);
|
||||||
}
|
}
|
||||||
// Apply another rotation on combined mat_a.
|
// Apply another rotation on combined mat_a.
|
||||||
mat_b = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
mat_b = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
|
mat_a = SC_SACD_Mat4_Mult(mat_b, mat_a);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_FLOAT(result.x, 0.0F);
|
CHECK_FLOAT(result.x, 0.0F);
|
||||||
CHECK_FLOAT(result.y, std::sqrt(2.0F) / 2.0F);
|
CHECK_FLOAT(result.y, std::sqrt(2.0F) / 2.0F);
|
||||||
CHECK_FLOAT(result.z, -std::sqrt(2.0F) / 2.0F);
|
CHECK_FLOAT(result.z, -std::sqrt(2.0F) / 2.0F);
|
||||||
}
|
}
|
||||||
// Apply another rotation on combined mat_a.
|
// Apply another rotation on combined mat_a.
|
||||||
mat_b = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float> / 2.0F);
|
mat_b = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float> / 2.0F);
|
||||||
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
|
mat_a = SC_SACD_Mat4_Mult(mat_b, mat_a);
|
||||||
{
|
{
|
||||||
auto result = SC_SACD_Mat4_Vec3_Mult(&mat_a, vec_a);
|
auto result = SC_SACD_Mat4_Vec3_Mult(mat_a, vec_a);
|
||||||
CHECK_FLOAT(result.x, 0.0F);
|
CHECK_FLOAT(result.x, 0.0F);
|
||||||
CHECK_FLOAT(result.y, std::sqrt(2.0F) / 2.0F);
|
CHECK_FLOAT(result.y, std::sqrt(2.0F) / 2.0F);
|
||||||
CHECK_FLOAT(result.z, std::sqrt(2.0F) / 2.0F);
|
CHECK_FLOAT(result.z, std::sqrt(2.0F) / 2.0F);
|
||||||
|
@ -556,13 +556,13 @@ int main() {
|
||||||
SC_SACD_Mat4 mat_a = SC_SACD_Translate_Mat4(1.0F, 1.0F, 1.0F);
|
SC_SACD_Mat4 mat_a = SC_SACD_Translate_Mat4(1.0F, 1.0F, 1.0F);
|
||||||
SC_SACD_Mat4 mat_b =
|
SC_SACD_Mat4 mat_b =
|
||||||
SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
|
||||||
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
|
mat_a = SC_SACD_Mat4_Mult(mat_b, mat_a);
|
||||||
mat_b = SC_SACD_Translate_Mat4(0.0F, 0.0F, -1.0F);
|
mat_b = SC_SACD_Translate_Mat4(0.0F, 0.0F, -1.0F);
|
||||||
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
|
mat_a = SC_SACD_Mat4_Mult(mat_b, mat_a);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto result =
|
auto result =
|
||||||
SC_SACD_Mat4_Vec3_Mult(&mat_a, SC_SACD_Vec3{0.0F, 0.0F, 0.0F});
|
SC_SACD_Mat4_Vec3_Mult(mat_a, SC_SACD_Vec3{0.0F, 0.0F, 0.0F});
|
||||||
CHECK_FLOAT(result.x, 0.0F);
|
CHECK_FLOAT(result.x, 0.0F);
|
||||||
CHECK_FLOAT(result.z, 0.0F);
|
CHECK_FLOAT(result.z, 0.0F);
|
||||||
CHECK_FLOAT(result.y, std::sqrt(2.0F));
|
CHECK_FLOAT(result.y, std::sqrt(2.0F));
|
||||||
|
@ -581,14 +581,14 @@ int main() {
|
||||||
a.transform = SC_SACD_Translate_Mat4(-1.0F, 0.0F, 0.0F);
|
a.transform = SC_SACD_Translate_Mat4(-1.0F, 0.0F, 0.0F);
|
||||||
b.transform = SC_SACD_Translate_Mat4(0.0F, -1.0F, 0.0F);
|
b.transform = SC_SACD_Translate_Mat4(0.0F, -1.0F, 0.0F);
|
||||||
|
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.width = 0.9F;
|
a.width = 0.9F;
|
||||||
a.height = 0.9F;
|
a.height = 0.9F;
|
||||||
b.width = 0.9F;
|
b.width = 0.9F;
|
||||||
b.height = 0.9F;
|
b.height = 0.9F;
|
||||||
|
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Box with Scale Mat4.
|
// Box with Scale Mat4.
|
||||||
|
@ -598,39 +598,39 @@ int main() {
|
||||||
|
|
||||||
a.x = 1.1F;
|
a.x = 1.1F;
|
||||||
b.x = -1.1F;
|
b.x = -1.1F;
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Scale_Mat4(2.0F, 1.0F, 1.0F);
|
a.transform = SC_SACD_Scale_Mat4(2.0F, 1.0F, 1.0F);
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Scale_Mat4(-2.0F, 1.0F, 1.0F);
|
a.transform = SC_SACD_Scale_Mat4(-2.0F, 1.0F, 1.0F);
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.x = 0.0F;
|
a.x = 0.0F;
|
||||||
b.x = 0.0F;
|
b.x = 0.0F;
|
||||||
a.y = 1.1F;
|
a.y = 1.1F;
|
||||||
b.y = -1.1F;
|
b.y = -1.1F;
|
||||||
a.transform = SC_SACD_Mat4_Identity();
|
a.transform = SC_SACD_Mat4_Identity();
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Scale_Mat4(1.0F, 2.0F, 1.0F);
|
a.transform = SC_SACD_Scale_Mat4(1.0F, 2.0F, 1.0F);
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Scale_Mat4(1.0F, -2.0F, 1.0F);
|
a.transform = SC_SACD_Scale_Mat4(1.0F, -2.0F, 1.0F);
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.y = 0.0F;
|
a.y = 0.0F;
|
||||||
b.y = 0.0F;
|
b.y = 0.0F;
|
||||||
a.z = 1.1F;
|
a.z = 1.1F;
|
||||||
b.z = -1.1F;
|
b.z = -1.1F;
|
||||||
a.transform = SC_SACD_Mat4_Identity();
|
a.transform = SC_SACD_Mat4_Identity();
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Scale_Mat4(1.0F, 1.0F, 2.0F);
|
a.transform = SC_SACD_Scale_Mat4(1.0F, 1.0F, 2.0F);
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
|
|
||||||
a.transform = SC_SACD_Scale_Mat4(1.0F, 1.0F, -2.0F);
|
a.transform = SC_SACD_Scale_Mat4(1.0F, 1.0F, -2.0F);
|
||||||
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Sphere/GenericBox to AABB.
|
// Test Sphere/GenericBox to AABB.
|
||||||
|
@ -670,7 +670,7 @@ int main() {
|
||||||
CHECK_FLOAT(aabb.depth, box.depth);
|
CHECK_FLOAT(aabb.depth, box.depth);
|
||||||
|
|
||||||
auto translate = SC_SACD_Translate_Mat4(-5.0F, -4.0F, 1.0F);
|
auto translate = SC_SACD_Translate_Mat4(-5.0F, -4.0F, 1.0F);
|
||||||
box.transform = SC_SACD_Mat4_Mult(&translate, &box.transform);
|
box.transform = SC_SACD_Mat4_Mult(translate, box.transform);
|
||||||
|
|
||||||
aabb = SC_SACD_Generic_Box_To_AABB(box);
|
aabb = SC_SACD_Generic_Box_To_AABB(box);
|
||||||
CHECK_FLOAT(aabb.x, box.x - 5.0F);
|
CHECK_FLOAT(aabb.x, box.x - 5.0F);
|
||||||
|
|
Loading…
Reference in a new issue