Compare commits

...

2 commits

Author SHA1 Message Date
ecf5ce1745 Add Mat4 translation function
Implemented creating a Mat4 that does translation.
2024-04-29 14:09:49 +09:00
954c48f6f9 Change Mat3 to Mat4 2024-04-29 13:39:59 +09:00
3 changed files with 161 additions and 80 deletions

View file

@ -27,28 +27,37 @@ SC_SACD_Vec3 operator/(const SC_SACD_Vec3 &a, float scalar) {
return SC_SACD_Vec3{a.x / scalar, a.y / scalar, a.z / scalar};
}
SC_SACD_Mat3 operator*(const SC_SACD_Mat3 &a, const SC_SACD_Mat3 &b) {
SC_SACD_Mat3 mat;
SC_SACD_Mat4 operator*(const SC_SACD_Mat4 &a, const SC_SACD_Mat4 &b) {
SC_SACD_Mat4 mat;
mat.x0 = b.x0 * a.x0 + b.y0 * a.x1 + b.z0 * a.x2;
mat.y0 = b.x0 * a.y0 + b.y0 * a.y1 + b.z0 * a.y2;
mat.z0 = b.x0 * a.z0 + b.y0 * a.z1 + b.z0 * a.z2;
mat.x0 = b.x0 * a.x0 + b.y0 * a.x1 + b.z0 * a.x2 + b.w0 * a.x3;
mat.y0 = b.x0 * a.y0 + b.y0 * a.y1 + b.z0 * a.y2 + b.w0 * a.y3;
mat.z0 = b.x0 * a.z0 + b.y0 * a.z1 + b.z0 * a.z2 + b.w0 * a.z3;
mat.w0 = b.x0 * a.w0 + b.y0 * a.w1 + b.z0 * a.w2 + b.w0 * a.w3;
mat.x1 = b.x1 * a.x0 + b.y1 * a.x1 + b.z1 * a.x2;
mat.y1 = b.x1 * a.y0 + b.y1 * a.y1 + b.z1 * a.y2;
mat.z1 = b.x1 * a.z0 + b.y1 * a.z1 + b.z1 * a.z2;
mat.x1 = b.x1 * a.x0 + b.y1 * a.x1 + b.z1 * a.x2 + b.w1 * a.x3;
mat.y1 = b.x1 * a.y0 + b.y1 * a.y1 + b.z1 * a.y2 + b.w1 * a.y3;
mat.z1 = b.x1 * a.z0 + b.y1 * a.z1 + b.z1 * a.z2 + b.w1 * a.z3;
mat.w1 = b.x1 * a.w0 + b.y1 * a.w1 + b.z1 * a.w2 + b.w1 * a.w3;
mat.x2 = b.x2 * a.x0 + b.y2 * a.x1 + b.z2 * a.x2;
mat.y2 = b.x2 * a.y0 + b.y2 * a.y1 + b.z2 * a.y2;
mat.z2 = b.x2 * a.z0 + b.y2 * a.z1 + b.z2 * a.z2;
mat.x2 = b.x2 * a.x0 + b.y2 * a.x1 + b.z2 * a.x2 + b.w2 * a.x3;
mat.y2 = b.x2 * a.y0 + b.y2 * a.y1 + b.z2 * a.y2 + b.w2 * a.y3;
mat.z2 = b.x2 * a.z0 + b.y2 * a.z1 + b.z2 * a.z2 + b.w2 * a.z3;
mat.w2 = b.x2 * a.w0 + b.y2 * a.w1 + b.z2 * a.w2 + b.w2 * a.w3;
mat.x3 = b.x3 * a.x0 + b.y3 * a.x1 + b.z3 * a.x2 + b.w3 * a.x3;
mat.y3 = b.x3 * a.y0 + b.y3 * a.y1 + b.z3 * a.y2 + b.w3 * a.y3;
mat.z3 = b.x3 * a.z0 + b.y3 * a.z1 + b.z3 * a.z2 + b.w3 * a.z3;
mat.w3 = b.x3 * a.w0 + b.y3 * a.w1 + b.z3 * a.w2 + b.w3 * a.w3;
return mat;
}
SC_SACD_Vec3 operator*(const SC_SACD_Mat3 &mat, const SC_SACD_Vec3 &vec) {
return SC_SACD_Vec3{vec.x * mat.x0 + vec.y * mat.x1 + vec.z * mat.x2,
vec.x * mat.y0 + vec.y * mat.y1 + vec.z * mat.y2,
vec.x * mat.z0 + vec.y * mat.z1 + vec.z * mat.z2};
SC_SACD_Vec3 operator*(const SC_SACD_Mat4 &mat, const SC_SACD_Vec3 &vec) {
return SC_SACD_Vec3{
vec.x * mat.x0 + vec.y * mat.x1 + vec.z * mat.x2 + mat.x3,
vec.x * mat.y0 + vec.y * mat.y1 + vec.z * mat.y2 + mat.y3,
vec.x * mat.z0 + vec.y * mat.z1 + vec.z * mat.z2 + mat.z3};
}
std::vector<SC_SACD_Vec3> SC_SACD_Get_Box_Normals(
@ -318,15 +327,16 @@ SC_SACD_Vec3 SC_SACD_Cross_Product(const SC_SACD_Vec3 a, const SC_SACD_Vec3 b) {
a.x * b.y - a.y * b.x};
}
SC_SACD_Mat3 SC_SACD_Mat3_Identity(void) {
return SC_SACD_Mat3{1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F};
SC_SACD_Mat4 SC_SACD_Mat4_Identity(void) {
return SC_SACD_Mat4{1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F,
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
}
SC_SACD_Mat3 SC_SACD_Mat3_Mult(const SC_SACD_Mat3 *a, const SC_SACD_Mat3 *b) {
SC_SACD_Mat4 SC_SACD_Mat4_Mult(const SC_SACD_Mat4 *a, const SC_SACD_Mat4 *b) {
return (*a) * (*b);
}
SC_SACD_Vec3 SC_SACD_Mat3_Vec3_Mult(const SC_SACD_Mat3 *mat,
SC_SACD_Vec3 SC_SACD_Mat4_Vec3_Mult(const SC_SACD_Mat4 *mat,
const SC_SACD_Vec3 vec) {
return (*mat) * vec;
}
@ -350,73 +360,108 @@ SC_SACD_Vec3 SC_SACD_Vec3_Rotate(const SC_SACD_Vec3 vec, float x_axis,
* [ -sin, 0, cos ]
*/
SC_SACD_Mat3 mat;
SC_SACD_Mat4 mat;
SC_SACD_Vec3 result;
// About x_axis.
mat = SC_SACD_Rotation_Mat3_XAxis(x_axis);
mat = SC_SACD_Rotation_Mat4_XAxis(x_axis);
result = SC_SACD_Mat3_Vec3_Mult(&mat, vec);
result = SC_SACD_Mat4_Vec3_Mult(&mat, vec);
// About y_axis.
mat = SC_SACD_Rotation_Mat3_YAxis(y_axis);
mat = SC_SACD_Rotation_Mat4_YAxis(y_axis);
result = SC_SACD_Mat3_Vec3_Mult(&mat, result);
result = SC_SACD_Mat4_Vec3_Mult(&mat, result);
// About z_axis.
mat = SC_SACD_Rotation_Mat3_ZAxis(z_axis);
mat = SC_SACD_Rotation_Mat4_ZAxis(z_axis);
return SC_SACD_Mat3_Vec3_Mult(&mat, result);
return SC_SACD_Mat4_Vec3_Mult(&mat, result);
}
SC_SACD_Mat3 SC_SACD_Rotation_Mat3_XAxis(float x_radians) {
SC_SACD_Mat3 mat;
SC_SACD_Mat4 SC_SACD_Rotation_Mat4_XAxis(float x_radians) {
SC_SACD_Mat4 mat;
mat.x0 = 1.0F;
mat.x1 = 0.0F;
mat.x2 = 0.0F;
mat.x3 = 0.0F;
mat.y0 = 0.0F;
mat.y1 = std::cos(x_radians);
mat.y2 = -std::sin(x_radians);
mat.y3 = 0.0F;
mat.z0 = 0.0F;
mat.z1 = -mat.y2;
mat.z2 = mat.y1;
mat.z3 = 0.0F;
mat.w0 = 0.0F;
mat.w1 = 0.0F;
mat.w2 = 0.0F;
mat.w3 = 1.0F;
return mat;
}
SC_SACD_Mat3 SC_SACD_Rotation_Mat3_YAxis(float y_radians) {
SC_SACD_Mat3 mat;
SC_SACD_Mat4 SC_SACD_Rotation_Mat4_YAxis(float y_radians) {
SC_SACD_Mat4 mat;
mat.x0 = std::cos(y_radians);
mat.x1 = 0.0F;
mat.x2 = std::sin(y_radians);
mat.x3 = 0.0F;
mat.y0 = 0.0F;
mat.y1 = 1.0F;
mat.y2 = 0.0F;
mat.y3 = 0.0F;
mat.z0 = -mat.x2;
mat.z1 = 0.0F;
mat.z2 = mat.x0;
mat.z3 = 0.0F;
mat.w0 = 0.0F;
mat.w1 = 0.0F;
mat.w2 = 0.0F;
mat.w3 = 1.0F;
return mat;
}
SC_SACD_Mat3 SC_SACD_Rotation_Mat3_ZAxis(float z_radians) {
SC_SACD_Mat3 mat;
SC_SACD_Mat4 SC_SACD_Rotation_Mat4_ZAxis(float z_radians) {
SC_SACD_Mat4 mat;
mat.x0 = std::cos(z_radians);
mat.x1 = -std::sin(z_radians);
mat.x2 = 0.0F;
mat.x3 = 0.0F;
mat.y0 = -mat.x1;
mat.y1 = mat.x0;
mat.y2 = 0.0F;
mat.y3 = 0.0F;
mat.z0 = 0.0F;
mat.z1 = 0.0F;
mat.z2 = 1.0F;
mat.z3 = 0.0F;
mat.w0 = 0.0F;
mat.w1 = 0.0F;
mat.w2 = 0.0F;
mat.w3 = 1.0F;
return mat;
}
SC_SACD_Mat4 SC_SACD_Translate_Mat4(float x, float y, float z) {
return SC_SACD_Mat4{0.0F, 0.0F, 0.0F, x, 0.0F, 1.0F, 0.0F, y,
0.0F, 0.0F, 1.0F, z, 0.0F, 0.0F, 0.0F, 1.0F};
}
SC_SACD_Vec3 SC_SACD_Closest_Point_Dir_Normalized(const SC_SACD_Vec3 *pos,
const SC_SACD_Vec3 *dir,
const SC_SACD_Vec3 *point) {

View file

@ -24,11 +24,12 @@ typedef struct SC_SACD_EXPORT SC_SACD_Vec3 {
float x, y, z;
} SC_SACD_Vec3;
typedef struct SC_SACD_EXPORT SC_SACD_Mat3 {
float x0, x1, x2;
float y0, y1, y2;
float z0, z1, z2;
} SC_SACD_Mat3;
typedef struct SC_SACD_EXPORT SC_SACD_Mat4 {
float x0, x1, x2, x3;
float y0, y1, y2, y3;
float z0, z1, z2, z3;
float w0, w1, w2, w3;
} SC_SACD_Mat4;
typedef struct SC_SACD_EXPORT SC_SACD_AABB_Box {
/// Coordinates are to center of box.
@ -94,21 +95,23 @@ SC_SACD_EXPORT float SC_SACD_Dot_Product(const SC_SACD_Vec3 a,
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Cross_Product(const SC_SACD_Vec3 a,
const SC_SACD_Vec3 b);
SC_SACD_EXPORT SC_SACD_Mat3 SC_SACD_Mat3_Identity(void);
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Mat4_Identity(void);
SC_SACD_EXPORT SC_SACD_Mat3 SC_SACD_Mat3_Mult(const SC_SACD_Mat3 *a,
const SC_SACD_Mat3 *b);
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Mat4_Mult(const SC_SACD_Mat4 *a,
const SC_SACD_Mat4 *b);
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Mat3_Vec3_Mult(const SC_SACD_Mat3 *mat,
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Mat4_Vec3_Mult(const SC_SACD_Mat4 *mat,
const SC_SACD_Vec3 vec);
SC_SACD_EXPORT SC_SACD_Vec3 SC_SACD_Vec3_Rotate(const SC_SACD_Vec3 vec,
float x_axis, float y_axis,
float z_axis);
SC_SACD_EXPORT SC_SACD_Mat3 SC_SACD_Rotation_Mat3_XAxis(float x_radians);
SC_SACD_EXPORT SC_SACD_Mat3 SC_SACD_Rotation_Mat3_YAxis(float y_radians);
SC_SACD_EXPORT SC_SACD_Mat3 SC_SACD_Rotation_Mat3_ZAxis(float z_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_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_Vec3 SC_SACD_Closest_Point_Dir_Normalized(
const SC_SACD_Vec3 *pos, const SC_SACD_Vec3 *dir,

View file

@ -371,125 +371,140 @@ int main() {
// Test matrix/vector multiplication.
{
SC_SACD_Mat3 mat_a{1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F, 9.0F};
SC_SACD_Mat4 mat_a{1.0F, 2.0F, 3.0F, 4.0F, 5.0F, 6.0F, 7.0F, 8.0F,
9.0F, 10.0F, 11.0F, 12.0F, 13.0F, 14.0F, 15.0F, 16.0F};
SC_SACD_Mat3 mat_b{1.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 1.0F};
SC_SACD_Mat4 mat_b = SC_SACD_Mat4_Identity();
{
auto result = SC_SACD_Mat3_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.x1 == result.x1);
CHECK_TRUE(mat_a.x2 == result.x2);
CHECK_TRUE(mat_a.x3 == result.x3);
CHECK_TRUE(mat_a.y0 == result.y0);
CHECK_TRUE(mat_a.y1 == result.y1);
CHECK_TRUE(mat_a.y2 == result.y2);
CHECK_TRUE(mat_a.y3 == result.y3);
CHECK_TRUE(mat_a.z0 == result.z0);
CHECK_TRUE(mat_a.z1 == result.z1);
CHECK_TRUE(mat_a.z2 == result.z2);
CHECK_TRUE(mat_a.z3 == result.z3);
CHECK_TRUE(mat_a.w0 == result.w0);
CHECK_TRUE(mat_a.w1 == result.w1);
CHECK_TRUE(mat_a.w2 == result.w2);
CHECK_TRUE(mat_a.w3 == result.w3);
}
mat_b.x0 = 2.0F;
mat_b.y1 = 0.0F;
mat_b.z2 = 0.0F;
{
auto result = SC_SACD_Mat3_Mult(&mat_a, &mat_b);
auto result = SC_SACD_Mat4_Mult(&mat_a, &mat_b);
CHECK_FLOAT(result.x0, 2.0F);
CHECK_FLOAT(result.y0, 8.0F);
CHECK_FLOAT(result.z0, 14.0F);
CHECK_FLOAT(result.y0, 10.0F);
CHECK_FLOAT(result.z0, 18.0F);
CHECK_FLOAT(result.w0, 26.0F);
CHECK_FLOAT(result.x1, 0.0F);
CHECK_FLOAT(result.y1, 0.0F);
CHECK_FLOAT(result.z1, 0.0F);
CHECK_FLOAT(result.w1, 0.0F);
CHECK_FLOAT(result.x2, 0.0F);
CHECK_FLOAT(result.y2, 0.0F);
CHECK_FLOAT(result.z2, 0.0F);
CHECK_FLOAT(result.w2, 0.0F);
CHECK_FLOAT(result.x3, 4.0F);
CHECK_FLOAT(result.y3, 8.0F);
CHECK_FLOAT(result.z3, 12.0F);
CHECK_FLOAT(result.w3, 16.0F);
}
mat_b = SC_SACD_Mat3_Identity();
mat_b = SC_SACD_Mat4_Identity();
SC_SACD_Vec3 vec_a{1.0F, 0.0F, 0.0F};
{
auto result = SC_SACD_Mat3_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.y == vec_a.y);
CHECK_TRUE(result.z == vec_a.z);
}
// Rotations about each axis.
mat_a = SC_SACD_Rotation_Mat3_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_Mat3_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.y < 1.0001F && result.y > 0.9999F);
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
}
mat_a = SC_SACD_Rotation_Mat3_ZAxis(std::numbers::pi_v<float>);
mat_a = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float>);
{
auto result = SC_SACD_Mat3_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.y < 0.0001F && result.y > -0.0001F);
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
}
mat_a =
SC_SACD_Rotation_Mat3_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_Mat3_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.y < -0.9999F && result.y > -1.0001F);
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
}
mat_a = SC_SACD_Rotation_Mat3_XAxis(std::numbers::pi_v<float> / 2.0F);
mat_a = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float> / 2.0F);
vec_a.x = 0.0F;
vec_a.y = 1.0F;
vec_a.z = 0.0F;
{
auto result = SC_SACD_Mat3_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.y < 0.0001F && result.y > -0.0001F);
CHECK_TRUE(result.z < 1.0001F && result.z > 0.9999F);
}
mat_a = SC_SACD_Rotation_Mat3_XAxis(std::numbers::pi_v<float>);
mat_a = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float>);
{
auto result = SC_SACD_Mat3_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.y < -0.9999F && result.y > -1.0001F);
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
}
mat_a =
SC_SACD_Rotation_Mat3_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_Mat3_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.y < 0.0001F && result.y > -0.0001F);
CHECK_TRUE(result.z < -0.9999F && result.z > -1.0001F);
}
mat_a = SC_SACD_Rotation_Mat3_YAxis(std::numbers::pi_v<float> / 2.0F);
mat_a = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float> / 2.0F);
vec_a.x = 0.0F;
vec_a.y = 0.0F;
vec_a.z = 1.0F;
{
auto result = SC_SACD_Mat3_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.y < 0.0001F && result.y > -0.0001F);
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
}
mat_a = SC_SACD_Rotation_Mat3_YAxis(std::numbers::pi_v<float>);
mat_a = SC_SACD_Rotation_Mat4_YAxis(std::numbers::pi_v<float>);
{
auto result = SC_SACD_Mat3_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.y < 0.0001F && result.y > -0.0001F);
CHECK_TRUE(result.z < -0.9999F && result.z > -1.0001F);
}
mat_a =
SC_SACD_Rotation_Mat3_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_Mat3_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.y < 0.0001F && result.y > -0.0001F);
CHECK_TRUE(result.z < 0.0001F && result.z > -0.0001F);
@ -499,35 +514,53 @@ int main() {
vec_a.x = 1.0F;
vec_a.y = 0.0F;
vec_a.z = 0.0F;
mat_a = SC_SACD_Rotation_Mat3_YAxis(std::numbers::pi_v<float> / 4.0F);
mat_b = SC_SACD_Rotation_Mat3_ZAxis(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);
// Apply mat_a, then mat_b.
mat_a = SC_SACD_Mat3_Mult(&mat_b, &mat_a);
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
{
auto result = SC_SACD_Mat3_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.y, 0.5F);
CHECK_FLOAT(result.z, -std::sqrt(2.0F) / 2.0F);
}
// Apply another rotation on combined mat_a.
mat_b = SC_SACD_Rotation_Mat3_ZAxis(std::numbers::pi_v<float> / 4.0F);
mat_a = SC_SACD_Mat3_Mult(&mat_b, &mat_a);
mat_b = SC_SACD_Rotation_Mat4_ZAxis(std::numbers::pi_v<float> / 4.0F);
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
{
auto result = SC_SACD_Mat3_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.y, std::sqrt(2.0F) / 2.0F);
CHECK_FLOAT(result.z, -std::sqrt(2.0F) / 2.0F);
}
// Apply another rotation on combined mat_a.
mat_b = SC_SACD_Rotation_Mat3_XAxis(std::numbers::pi_v<float> / 2.0F);
mat_a = SC_SACD_Mat3_Mult(&mat_b, &mat_a);
mat_b = SC_SACD_Rotation_Mat4_XAxis(std::numbers::pi_v<float> / 2.0F);
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
{
auto result = SC_SACD_Mat3_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.y, std::sqrt(2.0F) / 2.0F);
CHECK_FLOAT(result.z, std::sqrt(2.0F) / 2.0F);
}
}
// Mat4 rotation and translation.
{
SC_SACD_Mat4 mat_a = SC_SACD_Translate_Mat4(1.0F, 1.0F, 1.0F);
SC_SACD_Mat4 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_b = SC_SACD_Translate_Mat4(0.0F, 0.0F, -1.0F);
mat_a = SC_SACD_Mat4_Mult(&mat_b, &mat_a);
{
auto result =
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.z, 0.0F);
CHECK_FLOAT(result.y, std::sqrt(2.0F));
}
}
std::cout << "Checks checked: " << checks_checked << '\n'
<< "Checks passed: " << checks_passed << '\n';