Fixes
Rotation Matrices should now match the "right-handled rule". Fixes related to weirdness using the column-major ordered Matrix struct.
This commit is contained in:
parent
c99407a474
commit
f0ce6520f4
9 changed files with 2223 additions and 299 deletions
5
Makefile
5
Makefile
|
@ -15,7 +15,8 @@ SOURCES = \
|
|||
src/screen.cc \
|
||||
src/screen_test.cc \
|
||||
src/screen_trunner.cc \
|
||||
src/3d_helpers.cc
|
||||
src/3d_helpers.cc \
|
||||
src/raymath.cc
|
||||
|
||||
HEADERS = \
|
||||
src/game.h \
|
||||
|
@ -47,7 +48,7 @@ clean:
|
|||
rm -f test
|
||||
|
||||
format:
|
||||
clang-format -i --style=google ${HEADERS} ${SOURCES}
|
||||
clang-format -i --style=google ${HEADERS} ${SOURCES} ${TEST_SOURCES}
|
||||
|
||||
.SECONDEXPANSION:
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
// standard library includes
|
||||
#include <cmath>
|
||||
|
||||
// third party includes
|
||||
#include <raymath.h>
|
||||
|
||||
Matrix get_identity_matrix() {
|
||||
return Matrix{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};
|
||||
|
@ -20,12 +23,12 @@ Matrix get_identity_matrix() {
|
|||
// 0, 0, 0, 1
|
||||
|
||||
Matrix get_rotation_matrix_about_z(float radians) {
|
||||
// OpenGL is column-major.
|
||||
// OpenGL is column-major but testing shows that not transposing works.
|
||||
return Matrix{std::cos(radians),
|
||||
std::sin(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
-std::sin(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
std::sin(radians),
|
||||
std::cos(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
|
@ -46,16 +49,16 @@ Matrix get_rotation_matrix_about_z(float radians) {
|
|||
// 0, 0, 0, 1
|
||||
|
||||
Matrix get_rotation_matrix_about_y(float radians) {
|
||||
// OpenGL is column-major.
|
||||
// OpenGL is column-major but testing shows that not transposing works.
|
||||
return Matrix{std::cos(radians),
|
||||
0.0F,
|
||||
-std::sin(radians),
|
||||
std::sin(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
1.0F,
|
||||
0.0F,
|
||||
0.0F,
|
||||
std::sin(radians),
|
||||
-std::sin(radians),
|
||||
0.0F,
|
||||
std::cos(radians),
|
||||
0.0F,
|
||||
|
@ -72,17 +75,17 @@ Matrix get_rotation_matrix_about_y(float radians) {
|
|||
// 0, 0, 0, 1
|
||||
|
||||
Matrix get_rotation_matrix_about_x(float radians) {
|
||||
// OpenGL is column-major.
|
||||
// OpenGL is column-major but testing shows that not transposing works.
|
||||
return Matrix{1.0F,
|
||||
0.0F,
|
||||
0.0F,
|
||||
0.0F,
|
||||
0.0F,
|
||||
std::cos(radians),
|
||||
std::sin(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
-std::sin(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
std::sin(radians),
|
||||
std::cos(radians),
|
||||
0.0F,
|
||||
0.0F,
|
||||
|
@ -91,38 +94,29 @@ Matrix get_rotation_matrix_about_x(float radians) {
|
|||
1.0F};
|
||||
}
|
||||
|
||||
Matrix translate_matrix_x(float distance) {
|
||||
// OpenGL is column-major but testing shows that not transposing works.
|
||||
return Matrix{1.0F, 0.0F, 0.0F, distance, 0.0F, 1.0F, 0.0F, 0.0F,
|
||||
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||
}
|
||||
|
||||
Matrix translate_matrix_y(float distance) {
|
||||
// OpenGL is column-major but testing shows that not transposing works.
|
||||
return Matrix{1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, distance,
|
||||
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||
}
|
||||
|
||||
Matrix translate_matrix_z(float distance) {
|
||||
// OpenGL is column-major but testing shows that not transposing works.
|
||||
return Matrix{1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F,
|
||||
0.0F, 0.0F, 1.0F, distance, 0.0F, 0.0F, 0.0F, 1.0F};
|
||||
}
|
||||
|
||||
Matrix translate_matrix_xyz(float x, float y, float z) {
|
||||
return Matrix{1.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};
|
||||
}
|
||||
|
||||
Matrix operator*(const Matrix &a, const Matrix &b) {
|
||||
return Matrix{a.m0 * b.m0 + a.m1 * b.m4 + a.m2 * b.m8 + a.m3 * b.m12,
|
||||
a.m4 * b.m0 + a.m5 * b.m4 + a.m6 * b.m8 + a.m7 * b.m12,
|
||||
a.m8 * b.m0 + a.m9 * b.m4 + a.m10 * b.m8 + a.m11 * b.m12,
|
||||
a.m12 * b.m0 + a.m13 * b.m4 + a.m14 * b.m8 + a.m15 * b.m12,
|
||||
|
||||
a.m0 * b.m1 + a.m1 * b.m5 + a.m2 * b.m9 + a.m3 * b.m13,
|
||||
a.m4 * b.m1 + a.m5 * b.m5 + a.m6 * b.m9 + a.m7 * b.m13,
|
||||
a.m8 * b.m1 + a.m9 * b.m5 + a.m10 * b.m9 + a.m11 * b.m13,
|
||||
a.m12 * b.m1 + a.m13 * b.m5 + a.m14 * b.m9 + a.m15 * b.m13,
|
||||
|
||||
a.m0 * b.m2 + a.m1 * b.m6 + a.m2 * b.m10 + a.m3 * b.m14,
|
||||
a.m4 * b.m2 + a.m5 * b.m6 + a.m6 * b.m10 + a.m7 * b.m14,
|
||||
a.m8 * b.m2 + a.m9 * b.m6 + a.m10 * b.m10 + a.m11 * b.m14,
|
||||
a.m12 * b.m2 + a.m13 * b.m6 + a.m14 * b.m10 + a.m15 * b.m14,
|
||||
|
||||
a.m0 * b.m3 + a.m1 * b.m7 + a.m2 * b.m11 + a.m3 * b.m15,
|
||||
a.m4 * b.m3 + a.m5 * b.m7 + a.m6 * b.m11 + a.m7 * b.m15,
|
||||
a.m8 * b.m3 + a.m9 * b.m7 + a.m10 * b.m11 + a.m11 * b.m15,
|
||||
a.m12 * b.m3 + a.m13 * b.m7 + a.m14 * b.m11 + a.m15 * b.m15};
|
||||
}
|
||||
|
||||
Vector4 operator*(const Matrix &m, const Vector4 &v) {
|
||||
return Vector4{
|
||||
m.m0 * v.x + m.m1 * v.y + m.m2 * v.z + m.m3 * v.w,
|
||||
m.m4 * v.x + m.m5 * v.y + m.m6 * v.z + m.m7 * v.w,
|
||||
m.m8 * v.x + m.m9 * v.y + m.m10 * v.z + m.m11 * v.w,
|
||||
m.m12 * v.x + m.m13 * v.y + m.m14 * v.z + m.m15 * v.w,
|
||||
};
|
||||
return MatrixMultiply(a, b);
|
||||
}
|
||||
|
|
|
@ -9,9 +9,15 @@ extern Matrix get_rotation_matrix_about_z(float radians);
|
|||
extern Matrix get_rotation_matrix_about_y(float radians);
|
||||
extern Matrix get_rotation_matrix_about_x(float radians);
|
||||
|
||||
extern Matrix translate_matrix_x(float distance);
|
||||
extern Matrix translate_matrix_y(float distance);
|
||||
extern Matrix translate_matrix_z(float distance);
|
||||
extern Matrix translate_matrix_xyz(float x, float y, float z);
|
||||
|
||||
extern Matrix operator*(const Matrix &a, const Matrix &b);
|
||||
extern Vector4 operator*(const Matrix &m, const Vector4 &v);
|
||||
|
||||
// Unimplemented as this function isn't really needed and it exposes some
|
||||
// weirdness regarding column-major matrices.
|
||||
// extern Vector4 operator*(const Matrix &m, const Vector4 &v);
|
||||
|
||||
#endif
|
||||
|
|
2
src/raymath.cc
Normal file
2
src/raymath.cc
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define RAYMATH_IMPLEMENTATION
|
||||
#include <raymath.h>
|
|
@ -18,8 +18,7 @@ TRunnerScreen::TRunnerScreen(std::weak_ptr<ScreenStack> stack)
|
|||
TEMP_default_material(LoadMaterialDefault()),
|
||||
TEMP_matrix(get_identity_matrix()),
|
||||
TEMP_offset_matrix(translate_matrix_z(-4.0F)),
|
||||
grid_spacing(1.0F),
|
||||
grid_spacing_modifier(0.0F) {}
|
||||
TEMP_value(0.0F) {}
|
||||
|
||||
TRunnerScreen::~TRunnerScreen() {
|
||||
UnloadMesh(TEMP_cube);
|
||||
|
@ -27,14 +26,17 @@ TRunnerScreen::~TRunnerScreen() {
|
|||
}
|
||||
|
||||
bool TRunnerScreen::update(float dt) {
|
||||
// grid_spacing_modifier += dt * GRID_SPACING_RATE;
|
||||
// if (grid_spacing_modifier > 2.0F * PI) {
|
||||
// grid_spacing_modifier -= 2.0F * PI;
|
||||
// }
|
||||
// grid_spacing = std::sin(grid_spacing_modifier) + GRID_SPACING_OFFSET;
|
||||
TEMP_matrix = get_rotation_matrix_about_z(dt) *
|
||||
get_rotation_matrix_about_y(dt * 1.2F) *
|
||||
get_rotation_matrix_about_x(dt * 1.4F) * TEMP_matrix;
|
||||
TEMP_value += TEMP_VALUE_INC_RATE * dt;
|
||||
if (TEMP_value < PI / 2.0F) {
|
||||
TEMP_matrix = get_rotation_matrix_about_z(TEMP_value);
|
||||
} else if (TEMP_value < PI) {
|
||||
TEMP_matrix = get_rotation_matrix_about_y(TEMP_value - PI / 2.0F);
|
||||
} else if (TEMP_value < PI * 3.0F / 2.0F) {
|
||||
TEMP_matrix = get_rotation_matrix_about_x(TEMP_value - PI);
|
||||
} else {
|
||||
TEMP_value -= PI * 3.0F / 2.0F;
|
||||
TEMP_matrix = get_rotation_matrix_about_z(TEMP_value);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -45,39 +47,6 @@ bool TRunnerScreen::draw() {
|
|||
|
||||
DrawMesh(TEMP_cube, TEMP_default_material, TEMP_matrix * TEMP_offset_matrix);
|
||||
|
||||
// for (unsigned int i = 11; i-- > 1;) {
|
||||
// // upper
|
||||
// DrawRay(Ray{Vector3{0.0F, 2.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{1.0F, 0.0F, 0.0F}},
|
||||
// BLACK);
|
||||
// DrawRay(Ray{Vector3{0.0F, 2.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{-1.0F, 0.0F, 0.0F}},
|
||||
// BLACK);
|
||||
//
|
||||
// // lower
|
||||
// DrawRay(Ray{Vector3{0.0F, -2.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{1.0F, 0.0F, 0.0F}},
|
||||
// BLACK);
|
||||
// DrawRay(Ray{Vector3{0.0F, -2.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{-1.0F, 0.0F, 0.0F}},
|
||||
// BLACK);
|
||||
//
|
||||
// // left
|
||||
// DrawRay(Ray{Vector3{-2.0F, 0.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{0.0F, 1.0F, 0.0F}},
|
||||
// BLACK);
|
||||
// DrawRay(Ray{Vector3{-2.0F, 0.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{0.0F, -1.0F, 0.0F}},
|
||||
// BLACK);
|
||||
//
|
||||
// // right
|
||||
// DrawRay(Ray{Vector3{2.0F, 0.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{0.0F, 1.0F, 0.0F}},
|
||||
// BLACK);
|
||||
// DrawRay(Ray{Vector3{2.0F, 0.0F, -(0.5F + grid_spacing * (float)i)},
|
||||
// Vector3{0.0F, -1.0F, 0.0F}},
|
||||
// BLACK);
|
||||
// }
|
||||
EndMode3D();
|
||||
EndDrawing();
|
||||
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
// third party includes
|
||||
#include <raylib.h>
|
||||
|
||||
constexpr float GRID_SPACING_RATE = 1.0F;
|
||||
constexpr float GRID_SPACING_OFFSET = 1.5F;
|
||||
constexpr float TEMP_VALUE_INC_RATE = 1.0F;
|
||||
|
||||
class TRunnerScreen : public Screen {
|
||||
public:
|
||||
|
@ -46,8 +45,7 @@ class TRunnerScreen : public Screen {
|
|||
Material TEMP_default_material;
|
||||
Matrix TEMP_matrix;
|
||||
Matrix TEMP_offset_matrix;
|
||||
float grid_spacing;
|
||||
float grid_spacing_modifier;
|
||||
float TEMP_value;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
215
src/test/test.cc
215
src/test/test.cc
|
@ -16,12 +16,15 @@
|
|||
|
||||
#define ASSERT_FLOAT_EQUALS(f, v) \
|
||||
if ((f) < (v)-0.1F || (f) > (v) + 0.1F) { \
|
||||
std::cerr << "ASSERT_FLOAT_EQUALS: " << (f) << " is not (roughly) equal to " << (v) << " at line " << __LINE__ << "!\n"; \
|
||||
std::cerr << "ASSERT_FLOAT_EQUALS: " << (f) \
|
||||
<< " is not (roughly) equal to " << (v) << " at line " \
|
||||
<< __LINE__ << "!\n"; \
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
std::cout << "Testing 3d_helpers...\n";
|
||||
// Note that there is some weirdness regarding column-major ordering of matrix
|
||||
// values.
|
||||
{
|
||||
auto identity = get_identity_matrix();
|
||||
ASSERT_TRUE(identity.m0 == 1.0F);
|
||||
|
@ -64,42 +67,17 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(identity.m13, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(identity.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(identity.m15, 1.0F);
|
||||
|
||||
{
|
||||
auto v = Vector4{1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = identity * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 1.0F, 0.0F, 1.0F};
|
||||
auto v_result = identity * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, 1.0F, 1.0F};
|
||||
auto v_result = identity * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// 90 degree rotation and identity matrix.
|
||||
auto m = get_rotation_matrix_about_z(PI / 2.0F) * get_identity_matrix();
|
||||
ASSERT_FLOAT_EQUALS(m.m0, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m1, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m1, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m2, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m3, 0.0F);
|
||||
|
||||
ASSERT_FLOAT_EQUALS(m.m4, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m4, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m5, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m6, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m7, 0.0F);
|
||||
|
@ -113,43 +91,11 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m13, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m15, 1.0F);
|
||||
|
||||
{
|
||||
auto v = Vector4{1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{-1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, -1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
}
|
||||
{
|
||||
// Double 90 degree rotation about z.
|
||||
auto m = get_rotation_matrix_about_z(PI/2.0F) * get_rotation_matrix_about_z(PI/2.0F);
|
||||
auto m = get_rotation_matrix_about_z(PI / 2.0F) *
|
||||
get_rotation_matrix_about_z(PI / 2.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m0, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m1, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m2, 0.0F);
|
||||
|
@ -169,46 +115,15 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m13, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m15, 1.0F);
|
||||
{
|
||||
auto v = Vector4{1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{-1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, -1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
|
||||
// Rotate back 90 degrees.
|
||||
m = get_rotation_matrix_about_z(-PI / 2.0F) * m;
|
||||
ASSERT_FLOAT_EQUALS(m.m0, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m1, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m1, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m2, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m3, 0.0F);
|
||||
|
||||
ASSERT_FLOAT_EQUALS(m.m4, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m4, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m5, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m6, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m7, 0.0F);
|
||||
|
@ -228,7 +143,7 @@ int main() {
|
|||
auto m = get_rotation_matrix_about_y(PI / 2.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m0, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m1, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m2, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m2, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m3, 0.0F);
|
||||
|
||||
ASSERT_FLOAT_EQUALS(m.m4, 0.0F);
|
||||
|
@ -236,7 +151,7 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m6, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m7, 0.0F);
|
||||
|
||||
ASSERT_FLOAT_EQUALS(m.m8, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m8, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m9, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m10, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m11, 0.0F);
|
||||
|
@ -246,39 +161,6 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m15, 1.0F);
|
||||
|
||||
{
|
||||
auto v = Vector4{1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, -1.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{-1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, 1.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
|
||||
// additional 90 degrees.
|
||||
m = get_rotation_matrix_about_y(PI / 2.0F) * m;
|
||||
ASSERT_FLOAT_EQUALS(m.m0, -1.0F);
|
||||
|
@ -300,22 +182,6 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m13, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m15, 1.0F);
|
||||
{
|
||||
auto v = Vector4{1.0F, 0.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, -1.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -328,11 +194,11 @@ int main() {
|
|||
|
||||
ASSERT_FLOAT_EQUALS(m.m4, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m5, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m6, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m6, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m7, 0.0F);
|
||||
|
||||
ASSERT_FLOAT_EQUALS(m.m8, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m9, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m9, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m10, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m11, 0.0F);
|
||||
|
||||
|
@ -340,38 +206,7 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m13, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m15, 1.0F);
|
||||
{
|
||||
auto v = Vector4{0.0F, 1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, 1.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, -1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, -1.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
|
||||
// Additional 90 degrees.
|
||||
m = get_rotation_matrix_about_x(PI / 2.0F) * m;
|
||||
ASSERT_FLOAT_EQUALS(m.m0, 1.0F);
|
||||
|
@ -393,22 +228,6 @@ int main() {
|
|||
ASSERT_FLOAT_EQUALS(m.m13, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m14, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(m.m15, 1.0F);
|
||||
{
|
||||
auto v = Vector4{0.0F, 1.0F, 0.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
{
|
||||
auto v = Vector4{0.0F, 0.0F, 1.0F, 1.0F};
|
||||
auto v_result = m * v;
|
||||
ASSERT_FLOAT_EQUALS(v_result.x, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.y, 0.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.z, -1.0F);
|
||||
ASSERT_FLOAT_EQUALS(v_result.w, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Finished tests.\n";
|
||||
|
|
|
@ -11,7 +11,8 @@ SOURCES = \
|
|||
../src/screen.cc \
|
||||
../src/screen_test.cc \
|
||||
../src/screen_trunner.cc \
|
||||
../src/3d_helpers.cc
|
||||
../src/3d_helpers.cc \
|
||||
../src/raymath.cc
|
||||
|
||||
HEADERS = \
|
||||
../src/ems.h \
|
||||
|
|
2134
wasm_include/raymath.h
Normal file
2134
wasm_include/raymath.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue