mirror of
https://github.com/recp/cglm.git
synced 2026-01-06 07:04:07 +00:00
Add function glm_perspective_lh_zo
This commit adds the function `glm_perspective_lh_zo`, modelled on the implementation of glm_perspective, but amended to provide a left-hand coordinate system expected by DirectX, Metal and Vulkan (per the GLM project's `glm/detail/setup.hpp`). It uses a clip-space of zero-to-one. The function is tested against a longhand version of the algorithm it seeks to implement as well as against the output of the GLM project's `glm::perspectiveLH_ZO` function. This commit adds a new subdirectory `test/glm_cmp` which contains a basic CMake file and `main.cpp`. An interested user should link or copy or clone the GLM project into this directory. The `main` function can be used to print the reference data used so others can verify behaviour in the future, or add new literal reference values.
This commit is contained in:
committed by
Tai Chi Minh Ralph Eastwood
parent
a242d83805
commit
1bce62c371
@@ -248,6 +248,39 @@ 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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user