mirror of
https://github.com/recp/cglm.git
synced 2025-12-26 02:25:02 +00:00
Add glm_perspective_rh_zo function + tests
This commit adds the RH/ZO perspective function. It does so in the new file `cam_rh_zo.h` and further refactors the LH variant into new file `cam_lh_zo.h`. This creates some churn in the tests and configuration files as new test files were added as well, and all these changes found their way into the build files. Tests passing on Linux.
This commit is contained in:
committed by
Tai Chi Minh Ralph Eastwood
parent
1bce62c371
commit
b3a18b8a15
@@ -6,6 +6,8 @@ set(TESTFILES
|
||||
src/test_euler.c
|
||||
src/test_bezier.c
|
||||
src/test_cam.c
|
||||
src/test_cam_lh_zo.c
|
||||
src/test_cam_rh_zo.c
|
||||
src/test_struct.c
|
||||
src/test_clamp.c
|
||||
src/test_common.c
|
||||
|
||||
@@ -10,6 +10,21 @@ static void outputForPerspectiveLH_ZO() {
|
||||
const float near = 0.1f;
|
||||
const float far = 100.0f;
|
||||
glm::mat4 cmp = glm::perspectiveLH_ZO(fovy, aspect, near, far);
|
||||
puts("/*reference test data for glm_perspective_lh_zo*/");
|
||||
puts("mat4 cmp = {0};");
|
||||
printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]);
|
||||
printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]);
|
||||
printf("cmp[2][2] = %0.7ff;\n", cmp[2][2]);
|
||||
printf("cmp[2][3] = %0.7ff;\n", cmp[2][3]);
|
||||
printf("cmp[3][2] = %0.7ff;\n", cmp[3][2]);
|
||||
}
|
||||
static void outputForPerspectiveRH_ZO() {
|
||||
const float fovy = glm::radians(45.0f);
|
||||
const float aspect = 640/480.0f;
|
||||
const float near = 0.1f;
|
||||
const float far = 100.0f;
|
||||
glm::mat4 cmp = glm::perspectiveRH_ZO(fovy, aspect, near, far);
|
||||
puts("/*reference test data for glm_perspective_rh_zo*/");
|
||||
puts("mat4 cmp = {0};");
|
||||
printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]);
|
||||
printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]);
|
||||
@@ -19,6 +34,6 @@ static void outputForPerspectiveLH_ZO() {
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
outputForPerspectiveLH_ZO();
|
||||
outputForPerspectiveRH_ZO();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7,40 +7,6 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
TEST_IMPL(perspective_lh_zo) {
|
||||
mat4 dst;
|
||||
const float fovy = glm_rad(45.0f);
|
||||
const float aspect = 640/480.0f;
|
||||
const float near = 0.1f;
|
||||
const float far = 100.0f;
|
||||
|
||||
glm_perspective_lh_zo(fovy, aspect, near, far, dst);
|
||||
|
||||
/* Sanity mk. I */
|
||||
/* Longhand version of what the above function _should_ be doing */
|
||||
ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect)))
|
||||
ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2)))
|
||||
ASSERT(test_eq(dst[2][2], far / (far - near)))
|
||||
ASSERT(test_eq(dst[2][3], 1.0f))
|
||||
ASSERT(test_eq(dst[3][2], -1 * far * near / (far - near)))
|
||||
|
||||
/* Sanity mk. II */
|
||||
/* "Reference values" generated by GLM's glm::perspectiveLH_ZO */
|
||||
mat4 cmp = {0};
|
||||
cmp[0][0] = 1.8106601f;
|
||||
cmp[1][1] = 2.4142134f;
|
||||
cmp[2][2] = 1.0010010f;
|
||||
cmp[2][3] = 1.0000000f;
|
||||
cmp[3][2] = -0.1001001f;
|
||||
|
||||
for (uint32_t i = 0 ; i < 16 ; i++) {
|
||||
uint32_t r = i%4, c = i/4;
|
||||
ASSERT(fabsf(dst[r][c] - cmp[r][c]) < GLM_FLT_EPSILON)
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(camera_lookat) {
|
||||
mat4 view1, view2;
|
||||
vec3 center,
|
||||
|
||||
37
test/src/test_cam_lh_zo.c
Normal file
37
test/src/test_cam_lh_zo.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
TEST_IMPL(perspective_lh_zo) {
|
||||
mat4 dst;
|
||||
const float fovy = glm_rad(45.0f);
|
||||
const float aspect = 640/480.0f;
|
||||
const float zNearVal = 0.1f;
|
||||
const float zFarVal = 100.0f;
|
||||
|
||||
glm_perspective_lh_zo(fovy, aspect, zNearVal, zFarVal, dst);
|
||||
|
||||
/* Sanity mk. I */
|
||||
/* Longhand version of what the above function _should_ be doing */
|
||||
ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect)))
|
||||
ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2)))
|
||||
ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal)))
|
||||
ASSERT(test_eq(dst[2][3], 1.0f))
|
||||
ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal)))
|
||||
|
||||
/* Sanity mk. II */
|
||||
/* "Reference values" generated by GLM's glm::perspectiveLH_ZO */
|
||||
mat4 cmp = {0};
|
||||
cmp[0][0] = 1.8106601f;
|
||||
cmp[1][1] = 2.4142134f;
|
||||
cmp[2][2] = 1.0010010f;
|
||||
cmp[2][3] = 1.0000000f;
|
||||
cmp[3][2] = -0.1001001f;
|
||||
|
||||
return (test_assert_mat4_eq(dst, cmp));
|
||||
}
|
||||
37
test/src/test_cam_rh_zo.c
Normal file
37
test/src/test_cam_rh_zo.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
TEST_IMPL(perspective_rh_zo) {
|
||||
mat4 dst;
|
||||
const float fovy = glm_rad(45.0f);
|
||||
const float aspect = 640/480.0f;
|
||||
const float zNearVal = 0.1f;
|
||||
const float zFarVal = 100.0f;
|
||||
|
||||
glm_perspective_rh_zo(fovy, aspect, zNearVal, zFarVal, dst);
|
||||
|
||||
/* Sanity mk. I: longhand version */
|
||||
float focal_len = 1 / tanf(fovy / 2);
|
||||
ASSERT(test_eq(dst[0][0], focal_len / aspect))
|
||||
ASSERT(test_eq(dst[1][1], focal_len))
|
||||
ASSERT(test_eq(dst[2][2], zFarVal / (zNearVal - zFarVal)))
|
||||
ASSERT(test_eq(dst[2][3], -1.0f))
|
||||
ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal)))
|
||||
|
||||
/* Sanity mk. II */
|
||||
/*reference test data for glm_perspective_rh_zo*/
|
||||
mat4 cmp = {0};
|
||||
cmp[0][0] = 1.8106601f;
|
||||
cmp[1][1] = 2.4142134f;
|
||||
cmp[2][2] = -1.0010010f;
|
||||
cmp[2][3] = -1.0000000f;
|
||||
cmp[3][2] = -0.1001001f;
|
||||
|
||||
return test_assert_mat4_eq(dst, cmp);
|
||||
}
|
||||
@@ -222,8 +222,9 @@ TEST_DECLARE(glmc_mat2_swap_col)
|
||||
TEST_DECLARE(glmc_mat2_swap_row)
|
||||
TEST_DECLARE(glmc_mat2_rmc)
|
||||
|
||||
/* camera */
|
||||
/* camera (incl [LR]H cross [NZ]O) */
|
||||
TEST_DECLARE(perspective_lh_zo)
|
||||
TEST_DECLARE(perspective_rh_zo)
|
||||
TEST_DECLARE(camera_lookat)
|
||||
TEST_DECLARE(camera_decomp)
|
||||
|
||||
@@ -947,8 +948,9 @@ TEST_LIST {
|
||||
TEST_ENTRY(glmc_mat2_swap_row)
|
||||
TEST_ENTRY(glmc_mat2_rmc)
|
||||
|
||||
/* camera */
|
||||
/* camera (incl [LR]H cross [NZ]O) */
|
||||
TEST_ENTRY(perspective_lh_zo)
|
||||
TEST_ENTRY(perspective_rh_zo)
|
||||
TEST_ENTRY(camera_lookat)
|
||||
TEST_ENTRY(camera_decomp)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user