mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
cam: extend frustum's far distance helper (#71)
* this will help to implement zoom easily
This commit is contained in:
@@ -36,6 +36,7 @@ Functions:
|
|||||||
#. :c:func:`glm_ortho_default`
|
#. :c:func:`glm_ortho_default`
|
||||||
#. :c:func:`glm_ortho_default_s`
|
#. :c:func:`glm_ortho_default_s`
|
||||||
#. :c:func:`glm_perspective`
|
#. :c:func:`glm_perspective`
|
||||||
|
#. :c:func:`glm_persp_move_far`
|
||||||
#. :c:func:`glm_perspective_default`
|
#. :c:func:`glm_perspective_default`
|
||||||
#. :c:func:`glm_perspective_resize`
|
#. :c:func:`glm_perspective_resize`
|
||||||
#. :c:func:`glm_lookat`
|
#. :c:func:`glm_lookat`
|
||||||
@@ -145,6 +146,16 @@ Functions documentation
|
|||||||
| *[in]* **farVal** far clipping planes
|
| *[in]* **farVal** far clipping planes
|
||||||
| *[out]* **dest** result matrix
|
| *[out]* **dest** result matrix
|
||||||
|
|
||||||
|
.. c:function:: void glm_persp_move_far(mat4 proj, float deltaFar)
|
||||||
|
|
||||||
|
| extend perspective projection matrix's far distance
|
||||||
|
|
||||||
|
| this function does not guarantee far >= near, be aware of that!
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
| *[in, out]* **proj** projection matrix to extend
|
||||||
|
| *[in]* **deltaFar** distance from existing far (negative to shink)
|
||||||
|
|
||||||
.. c:function:: void glm_perspective_default(float aspect, mat4 dest)
|
.. c:function:: void glm_perspective_default(float aspect, mat4 dest)
|
||||||
|
|
||||||
| set up perspective projection matrix with default near/far
|
| set up perspective projection matrix with default near/far
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ glmc_perspective(float fovy,
|
|||||||
float farVal,
|
float farVal,
|
||||||
mat4 dest);
|
mat4 dest);
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_persp_move_far(mat4 proj, float deltaFar);
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
glmc_perspective_default(float aspect, mat4 dest);
|
glmc_perspective_default(float aspect, mat4 dest);
|
||||||
|
|||||||
@@ -271,6 +271,30 @@ glm_perspective(float fovy,
|
|||||||
dest[3][2] = 2.0f * nearVal * farVal * fn;
|
dest[3][2] = 2.0f * nearVal * farVal * fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief extend perspective projection matrix's far distance
|
||||||
|
*
|
||||||
|
* this function does not guarantee far >= near, be aware of that!
|
||||||
|
*
|
||||||
|
* @param[in, out] proj projection matrix to extend
|
||||||
|
* @param[in] deltaFar distance from existing far (negative to shink)
|
||||||
|
*/
|
||||||
|
CGLM_INLINE
|
||||||
|
void
|
||||||
|
glm_persp_move_far(mat4 proj, float deltaFar) {
|
||||||
|
float fn, farVal, nearVal, p22, p32;
|
||||||
|
|
||||||
|
p22 = proj[2][2];
|
||||||
|
p32 = proj[3][2];
|
||||||
|
|
||||||
|
nearVal = p32 / (p22 - 1.0f);
|
||||||
|
farVal = p32 / (p22 + 1.0f) + deltaFar;
|
||||||
|
fn = 1.0f / (nearVal - farVal);
|
||||||
|
|
||||||
|
proj[2][2] = (nearVal + farVal) * fn;
|
||||||
|
proj[3][2] = 2.0f * nearVal * farVal * fn;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief set up perspective projection matrix with default near/far
|
* @brief set up perspective projection matrix with default near/far
|
||||||
* and angle values
|
* and angle values
|
||||||
|
|||||||
@@ -88,6 +88,12 @@ glmc_perspective(float fovy,
|
|||||||
dest);
|
dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGLM_EXPORT
|
||||||
|
void
|
||||||
|
glmc_persp_move_far(mat4 proj, float deltaFar) {
|
||||||
|
glm_persp_move_far(proj, deltaFar);
|
||||||
|
}
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
glmc_perspective_default(float aspect, mat4 dest) {
|
glmc_perspective_default(float aspect, mat4 dest) {
|
||||||
|
|||||||
Reference in New Issue
Block a user