Add Mat4 translation function
Implemented creating a Mat4 that does translation.
This commit is contained in:
parent
954c48f6f9
commit
ecf5ce1745
3 changed files with 25 additions and 0 deletions
|
@ -457,6 +457,11 @@ SC_SACD_Mat4 SC_SACD_Rotation_Mat4_ZAxis(float z_radians) {
|
||||||
return mat;
|
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,
|
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) {
|
||||||
|
|
|
@ -111,6 +111,8 @@ 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);
|
||||||
SC_SACD_EXPORT SC_SACD_Mat4 SC_SACD_Rotation_Mat4_ZAxis(float z_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(
|
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,
|
||||||
const SC_SACD_Vec3 *point);
|
const SC_SACD_Vec3 *point);
|
||||||
|
|
18
src/test.cpp
18
src/test.cpp
|
@ -543,6 +543,24 @@ int main() {
|
||||||
CHECK_FLOAT(result.z, 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'
|
std::cout << "Checks checked: " << checks_checked << '\n'
|
||||||
<< "Checks passed: " << checks_passed << '\n';
|
<< "Checks passed: " << checks_passed << '\n';
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue