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
@@ -248,39 +248,6 @@ glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) {
|
||||
dest[3][2] = 2.0f * nearZ * farZ * fn;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up perspective projection matrix with a left-hand coordinate
|
||||
* system (suitable for DirectX, Metal and Vulkan) and a clip-space with
|
||||
* depth values from zero to one.
|
||||
*
|
||||
* @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_zo(float fovy,
|
||||
float aspect,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest) {
|
||||
/* Impl follows glm::perspectiveLH_ZO in glm/ext/matrix_clip_space.inl */
|
||||
float f, fn;
|
||||
|
||||
glm_mat4_zero(dest);
|
||||
|
||||
f = 1.0f / tanf(fovy * 0.5f);
|
||||
fn = 1.0f / (farVal - nearVal);
|
||||
|
||||
dest[0][0] = f / aspect;
|
||||
dest[1][1] = f;
|
||||
dest[2][2] = farVal * fn;
|
||||
dest[2][3] = 1.0f;
|
||||
dest[3][2] = -(farVal * nearVal * fn);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief extend perspective projection matrix's far distance
|
||||
*
|
||||
|
||||
57
include/cglm/cam_lh_zo.h
Normal file
57
include/cglm/cam_lh_zo.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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_zo(float fovy,
|
||||
float aspect,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest)
|
||||
*/
|
||||
|
||||
#ifndef cglm_cam_lh_zo_h
|
||||
#define cglm_cam_lh_zo_h
|
||||
|
||||
#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
|
||||
* depth values from zero to one.
|
||||
*
|
||||
* @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_zo(float fovy,
|
||||
float aspect,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest) {
|
||||
/* Impl follows glm::perspectiveLH_ZO 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 * fn;
|
||||
dest[2][3] = 1.0f;
|
||||
dest[3][2] = -(farVal * nearVal * fn);
|
||||
}
|
||||
|
||||
#endif /*cglm_cam_lh_zo_h*/
|
||||
58
include/cglm/cam_rh_zo.h
Normal file
58
include/cglm/cam_rh_zo.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_zo(float fovy,
|
||||
float aspect,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest)
|
||||
*/
|
||||
|
||||
#ifndef cglm_cam_rh_zo_h
|
||||
#define cglm_cam_rh_zo_h
|
||||
|
||||
#include "common.h"
|
||||
#include "plane.h"
|
||||
|
||||
/*!
|
||||
* @brief set up perspective projection matrix with a right-hand coordinate
|
||||
* 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
|
||||
* @param[in] farVal far clipping planes
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_rh_zo(float fovy,
|
||||
float aspect,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest) {
|
||||
/* Impl follows glm::perspectiveRH_ZO 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 * fn;
|
||||
dest[2][3] = -1.0f;
|
||||
dest[3][2] = -farVal * nearVal * fn;
|
||||
}
|
||||
|
||||
#endif /*cglm_cam_lh_zo_h*/
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "mat2.h"
|
||||
#include "affine.h"
|
||||
#include "cam.h"
|
||||
#include "cam_lh_zo.h"
|
||||
#include "cam_rh_zo.h"
|
||||
#include "frustum.h"
|
||||
#include "quat.h"
|
||||
#include "euler.h"
|
||||
|
||||
Reference in New Issue
Block a user