Add LH & RH_NO perspective functions

This commit adds functions `glm_perspective_lh_no` and
`glm_perspective_rh_no` to the code. Unit tests are added and this
commit follows the new pattern of adding the a new file per
coordinate-system and clip-space tuple.

. Makefile.am updated
. removed test/glm_cmp project stub
. unit tests include naive implementations to as well as magic number
  ref-data generated by the corresponding GLM functions.

No tests run yet on Windows or Mac.
This commit is contained in:
michaelg
2021-04-30 21:53:17 +01:00
committed by Tai Chi Minh Ralph Eastwood
parent b3a18b8a15
commit c013bd462c
21 changed files with 266 additions and 89 deletions

55
include/cglm/cam_lh_no.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glm_perspective_lh_no(float fovy,
float aspect,
float nearVal,
float farVal,
mat4 dest)
*/
#ifndef cglm_cam_lh_no_h
#define cglm_cam_lh_no_h
#include "common.h"
#include "plane.h"
/*!
* @brief set up perspective projection matrix with a left-hand coordinate
* system and a clip-space of [-1, 1]
*
* @param[in] fovy field of view angle
* @param[in] aspect aspect ratio ( width / height )
* @param[in] nearVal near clipping plane
* @param[in] farVal far clipping planes
* @param[out] dest result matrix
*/
CGLM_INLINE
void
glm_perspective_lh_no(float fovy,
float aspect,
float nearVal,
float farVal,
mat4 dest) {
/* Impl follows glm::perspectiveLH_NO in glm/ext/matrix_clip_space.inl */
float fl, fn;
glm_mat4_zero(dest);
fl = 1.0f / tanf(fovy * 0.5f);
fn = 1.0f / (farVal - nearVal);
dest[0][0] = fl / aspect;
dest[1][1] = fl;
dest[2][2] = (farVal + nearVal) * fn;
dest[2][3] = 1.0f;
dest[3][2] = -2.0f * farVal * nearVal * fn;
}
#endif /*cglm_cam_lh_no_h*/

View File

@@ -20,7 +20,6 @@
#include "common.h"
#include "plane.h"
/*!
* @brief set up perspective projection matrix with a left-hand coordinate
* system (suitable, apparently, for DirectX and Metal) and a clip-space with
@@ -47,11 +46,11 @@ glm_perspective_lh_zo(float fovy,
fl = 1.0f / tanf(fovy * 0.5f);
fn = 1.0f / (farVal - nearVal);
dest[0][0] = fl / aspect;
dest[1][1] = fl;
dest[2][2] = farVal * fn;
dest[2][3] = 1.0f;
dest[3][2] = -(farVal * nearVal * fn);
dest[0][0] = fl / aspect;
dest[1][1] = fl;
dest[2][2] = farVal * fn;
dest[2][3] = 1.0f;
dest[3][2] = -farVal * nearVal * fn;
}
#endif /*cglm_cam_lh_zo_h*/

55
include/cglm/cam_rh_no.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glm_perspective_rh_no(float fovy,
float aspect,
float nearVal,
float farVal,
mat4 dest)
*/
#ifndef cglm_cam_rh_no_h
#define cglm_cam_rh_no_h
#include "common.h"
#include "plane.h"
/*!
* @brief set up perspective projection matrix with a right-hand coordinate
* system and a clip space of [-1, 1].
*
* @param[in] fovy field of view angle
* @param[in] aspect aspect ratio ( width / height )
* @param[in] nearVal near clipping plane
* @param[in] farVal far clipping planes
* @param[out] dest result matrix
*/
CGLM_INLINE
void
glm_perspective_rh_no(float fovy,
float aspect,
float nearVal,
float farVal,
mat4 dest) {
/* Impl follows glm::perspectiveRH_NO in glm/ext/matrix_clip_space.inl */
float fl, fn;
glm_mat4_zero(dest);
fl = 1.0f / tanf(fovy * 0.5f);
fn = 1.0f / (farVal - nearVal);
dest[0][0] = fl / aspect;
dest[1][1] = fl;
dest[2][2] = -(farVal + nearVal) * fn;
dest[2][3] = -1.0f;
dest[3][2] = -2.0f * farVal * nearVal * fn;
}
#endif /*cglm_cam_rh_no_h*/

View File

@@ -25,8 +25,6 @@
* system (suitable for Vulkan) and a clip-space with depth values from zero
* to one.
*
* https://github.com/godlikepanos/anki-3d-engine/blob/317cb379ff3a7b09f9034f49c7bdab0f96a1c0b3/AnKi/Math/Mat.h#L1254
*
* @param[in] fovy field of view angle
* @param[in] aspect aspect ratio ( width / height )
* @param[in] nearVal near clipping plane
@@ -48,11 +46,11 @@ glm_perspective_rh_zo(float fovy,
fl = 1.0f / tanf(fovy * 0.5f);
fn = 1.0f / (farVal - nearVal);
dest[0][0] = fl / aspect;
dest[1][1] = fl;
dest[0][0] = fl / aspect;
dest[1][1] = fl;
dest[2][2] = -farVal * fn;
dest[2][3] = -1.0f;
dest[3][2] = -farVal * nearVal * fn;
}
#endif /*cglm_cam_lh_zo_h*/
#endif /*cglm_cam_rh_zo_h*/

View File

@@ -19,6 +19,8 @@
#include "cam.h"
#include "cam_lh_zo.h"
#include "cam_rh_zo.h"
#include "cam_lh_no.h"
#include "cam_rh_no.h"
#include "frustum.h"
#include "quat.h"
#include "euler.h"