| 1 | #include "../HandmadeTest.h" |
| 2 | |
| 3 | TEST(Projection, Orthographic) |
| 4 | { |
| 5 | #define ORTHO_BOUNDS -8.0f, 12.0f, 5.0f, 10.0f, 1.0f, 100.0f |
| 6 | |
| 7 | // Right-handed |
| 8 | { |
| 9 | // Near and far distances correspond to negative Z, hence the Z coordinates here are negative. |
| 10 | HMM_Vec4 minCorner = HMM_V4(-8.0f, 5.0f, -1.0f, 1.0); |
| 11 | HMM_Vec4 maxCorner = HMM_V4(12.0f, 10.0f, -100.0f, 1.0); |
| 12 | |
| 13 | // Z from -1 to 1 (GL convention) |
| 14 | { |
| 15 | HMM_Mat4 projection = HMM_Orthographic_RH_NO(ORTHO_BOUNDS); |
| 16 | EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, -1.0f, 1.0f)); |
| 17 | EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f)); |
| 18 | } |
| 19 | |
| 20 | // Z from 0 to 1 (DX convention) |
| 21 | { |
| 22 | HMM_Mat4 projection = HMM_Orthographic_RH_ZO(ORTHO_BOUNDS); |
| 23 | EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, 0.0f, 1.0f)); |
| 24 | EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f)); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // Left-handed |
| 29 | { |
| 30 | // Near and far distances correspond to positive Z, hence the Z coordinates here are positive. |
| 31 | HMM_Vec4 minCorner = HMM_V4(-8.0f, 5.0f, 1.0f, 1.0); |
| 32 | HMM_Vec4 maxCorner = HMM_V4(12.0f, 10.0f, 100.0f, 1.0); |
| 33 | |
| 34 | // Z from -1 to 1 (GL convention) |
| 35 | { |
| 36 | HMM_Mat4 projection = HMM_Orthographic_LH_NO(ORTHO_BOUNDS); |
| 37 | EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, -1.0f, 1.0f)); |
| 38 | EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f)); |
| 39 | } |
| 40 | |
| 41 | // Z from 0 to 1 (DX convention) |
| 42 | { |
| 43 | HMM_Mat4 projection = HMM_Orthographic_LH_ZO(ORTHO_BOUNDS); |
| 44 | EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, 0.0f, 1.0f)); |
| 45 | EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f)); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | TEST(Projection, Perspective) |
| 51 | { |
nothing calls this directly
no test coverage detected