Add Scale Mat4 creation function
Also added some relevant UnitTests.
This commit is contained in:
parent
a0b41ba274
commit
e0bd54742d
3 changed files with 49 additions and 0 deletions
|
@ -546,6 +546,11 @@ SC_SACD_Mat4 SC_SACD_Translate_Mat4(float x, float y, float z) {
|
||||||
0.0F, 0.0F, 1.0F, z, 0.0F, 0.0F, 0.0F, 1.0F};
|
0.0F, 0.0F, 1.0F, z, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SC_SACD_Mat4 SC_SACD_Scale_Mat4(float x, float y, float z) {
|
||||||
|
return SC_SACD_Mat4{x, 0.0F, 0.0F, 0.0F, 0.0F, y, 0.0F, 0.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(const SC_SACD_Vec3 *pos,
|
||||||
const SC_SACD_Vec3 *dir,
|
const SC_SACD_Vec3 *dir,
|
||||||
const SC_SACD_Vec3 *point) {
|
const SC_SACD_Vec3 *point) {
|
||||||
|
|
|
@ -119,6 +119,8 @@ SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Rotation_Mat4_ZAxis(float z_radians);
|
||||||
|
|
||||||
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Translate_Mat4(float x, float y, float z);
|
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Translate_Mat4(float x, float y, float z);
|
||||||
|
|
||||||
|
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,
|
const SC_SACD_Vec3 *pos, const SC_SACD_Vec3 *dir,
|
||||||
|
|
42
src/test.cpp
42
src/test.cpp
|
@ -591,6 +591,48 @@ int main() {
|
||||||
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Box with Scale Mat4.
|
||||||
|
{
|
||||||
|
SC_SACD_Generic_Box a = SC_SACD_Generic_Box_Default();
|
||||||
|
SC_SACD_Generic_Box b = SC_SACD_Generic_Box_Default();
|
||||||
|
|
||||||
|
a.x = 1.1F;
|
||||||
|
b.x = -1.1F;
|
||||||
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.transform = SC_SACD_Scale_Mat4(2.0F, 1.0F, 1.0F);
|
||||||
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.transform = SC_SACD_Scale_Mat4(-2.0F, 1.0F, 1.0F);
|
||||||
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.x = 0.0F;
|
||||||
|
b.x = 0.0F;
|
||||||
|
a.y = 1.1F;
|
||||||
|
b.y = -1.1F;
|
||||||
|
a.transform = SC_SACD_Mat4_Identity();
|
||||||
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.transform = SC_SACD_Scale_Mat4(1.0F, 2.0F, 1.0F);
|
||||||
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.transform = SC_SACD_Scale_Mat4(1.0F, -2.0F, 1.0F);
|
||||||
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.y = 0.0F;
|
||||||
|
b.y = 0.0F;
|
||||||
|
a.z = 1.1F;
|
||||||
|
b.z = -1.1F;
|
||||||
|
a.transform = SC_SACD_Mat4_Identity();
|
||||||
|
CHECK_FALSE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.transform = SC_SACD_Scale_Mat4(1.0F, 1.0F, 2.0F);
|
||||||
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
|
||||||
|
a.transform = SC_SACD_Scale_Mat4(1.0F, 1.0F, -2.0F);
|
||||||
|
CHECK_TRUE(SC_SACD_Generic_Box_Collision(&a, &b));
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Checks checked: " << checks_checked << '\n'
|
std::cout << "Checks checked: " << checks_checked << '\n'
|
||||||
<< "Checks passed: " << checks_passed << '\n';
|
<< "Checks passed: " << checks_passed << '\n';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue