mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Compare commits
26 Commits
integratio
...
83d5b2c973
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83d5b2c973 | ||
|
|
7e1bdd0676 | ||
|
|
0dc17e5d47 | ||
|
|
d6c6b4c542 | ||
|
|
0356534c0c | ||
|
|
5ff0d80c85 | ||
|
|
1952042f2c | ||
|
|
3aad5823ca | ||
|
|
da957fa421 | ||
|
|
47e5d48749 | ||
|
|
a4602f2d5f | ||
|
|
6af4e0d565 | ||
|
|
a311dbfe4c | ||
|
|
a761088e15 | ||
|
|
a886d6e170 | ||
|
|
1a8b105ce6 | ||
|
|
ec5f8074c4 | ||
|
|
6f5fde8b52 | ||
|
|
9da4e78c2e | ||
|
|
27a3ddc928 | ||
|
|
5d530cd8e0 | ||
|
|
dde053a295 | ||
|
|
2128235d42 | ||
|
|
9fb418bcac | ||
|
|
5fde20d65c | ||
|
|
ebc65782f8 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -82,3 +82,4 @@ cmake-build-debug
|
||||
xcode/*
|
||||
.vscode
|
||||
.build
|
||||
*.swp
|
||||
|
||||
@@ -23,7 +23,7 @@ checkCFLAGS = $(AM_CFLAGS) \
|
||||
-std=gnu11 \
|
||||
-O3 \
|
||||
-DCGLM_DEFINE_PRINTS \
|
||||
-I./include
|
||||
-I$(srcdir)/include
|
||||
|
||||
check_PROGRAMS = test/tests
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
||||
@@ -36,8 +36,10 @@ Functions:
|
||||
#. :c:func:`glm_ortho_default`
|
||||
#. :c:func:`glm_ortho_default_s`
|
||||
#. :c:func:`glm_perspective`
|
||||
#. :c:func:`glm_perspective_infinite`
|
||||
#. :c:func:`glm_persp_move_far`
|
||||
#. :c:func:`glm_perspective_default`
|
||||
#. :c:func:`glm_perspective_default_infinite`
|
||||
#. :c:func:`glm_perspective_resize`
|
||||
#. :c:func:`glm_lookat`
|
||||
#. :c:func:`glm_look`
|
||||
@@ -146,6 +148,21 @@ Functions documentation
|
||||
| *[in]* **farVal** far clipping planes
|
||||
| *[out]* **dest** result matrix
|
||||
|
||||
.. c:function:: void glm_perspective_infinite(float fovy, float aspect, float nearZ, mat4 dest)
|
||||
|
||||
| set up perspective projection matrix with infinite far plane
|
||||
|
||||
The far clipping plane is pushed to infinity. This can improve depth
|
||||
precision for distant objects and is required by some rendering techniques
|
||||
such as shadow volumes. Dispatches to the appropriate clipspace variant
|
||||
based on compile-time configuration (LH/RH, NO/ZO).
|
||||
|
||||
Parameters:
|
||||
| *[in]* **fovy** field of view angle (in radians)
|
||||
| *[in]* **aspect** aspect ratio ( width / height )
|
||||
| *[in]* **nearZ** near clipping plane
|
||||
| *[out]* **dest** result matrix
|
||||
|
||||
.. c:function:: void glm_persp_move_far(mat4 proj, float deltaFar)
|
||||
|
||||
| extend perspective projection matrix's far distance
|
||||
@@ -165,6 +182,20 @@ Functions documentation
|
||||
| *[in]* **aspect** aspect aspect ratio ( width / height )
|
||||
| *[out]* **dest** result matrix
|
||||
|
||||
.. c:function:: void glm_perspective_default_infinite(float aspect, mat4 dest)
|
||||
|
||||
| set up infinite perspective projection matrix with default near
|
||||
and angle values
|
||||
|
||||
Equivalent to calling :c:func:`glm_perspective_infinite` with
|
||||
``fovy = GLM_PI_4`` (45°) and ``nearZ = 0.01``. Useful as a
|
||||
quick drop-in when you need an infinite projection without tuning
|
||||
the individual parameters.
|
||||
|
||||
Parameters:
|
||||
| *[in]* **aspect** aspect ratio ( width / height )
|
||||
| *[out]* **dest** result matrix
|
||||
|
||||
.. c:function:: void glm_perspective_resize(float aspect, mat4 proj)
|
||||
|
||||
| resize perspective matrix by aspect ratio ( width / height )
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -63,7 +63,7 @@ Functions documentation
|
||||
Zero out the mat2x3 (m).
|
||||
|
||||
Parameters:
|
||||
| *[in, out]* **mat** mat2x3 (src, dest)
|
||||
| *[in, out]* **m** mat2x3 (src, dest)
|
||||
|
||||
.. csv-table:: mat2x3 **(m)**
|
||||
:header: "", "column 1", "column 2"
|
||||
|
||||
1154
docs/source/mat3.rst
1154
docs/source/mat3.rst
File diff suppressed because it is too large
Load Diff
@@ -48,6 +48,7 @@ Functions:
|
||||
#. :c:func:`glm_mat4_swap_row`
|
||||
#. :c:func:`glm_mat4_rmc`
|
||||
#. :c:func:`glm_mat4_make`
|
||||
#. :c:func:`glm_mat4_textrans`
|
||||
|
||||
Functions documentation
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -313,3 +314,15 @@ Functions documentation
|
||||
Parameters:
|
||||
| *[in]* **src** pointer to an array of floats
|
||||
| *[out]* **dest** destination matrix4x4
|
||||
|
||||
.. c:function:: void glm_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest)
|
||||
|
||||
Create texture transformation matrix, rotation is in radians CCW/RH
|
||||
|
||||
Parameters:
|
||||
| *[in]* **sx** scale x
|
||||
| *[in]* **sy** scale y
|
||||
| *[in]* **rot** rotation in radians CCW/RH
|
||||
| *[in]* **tx** translation x
|
||||
| *[in]* **ty** translation y
|
||||
| *[out]* **dest** destination matrix3x3
|
||||
|
||||
@@ -51,6 +51,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_infinite(float fovy, float aspect, float nearZ, mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_persp_move_far(mat4 proj, float deltaFar);
|
||||
@@ -59,6 +63,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_default(float aspect, mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_default_infinite(float aspect, mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize(float aspect, mat4 proj);
|
||||
|
||||
@@ -27,6 +27,10 @@ glmc_perspective_lh_no(float fovy,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_lh_no(float aspect, mat4 proj);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -27,6 +27,10 @@ glmc_perspective_lh_zo(float fovy,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_lh_zo(float aspect, mat4 proj);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -27,6 +27,10 @@ glmc_perspective_rh_no(float fovy,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_rh_no(float aspect, mat4 proj);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -27,6 +27,10 @@ glmc_perspective_rh_zo(float fovy,
|
||||
float nearVal,
|
||||
float farVal,
|
||||
mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_rh_zo(float aspect, mat4 proj);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -13,21 +13,25 @@ extern "C" {
|
||||
|
||||
#include "../cglm.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_make(const float * __restrict src, mat2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_copy(mat2 mat, mat2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_identity(mat2 mat);
|
||||
glmc_mat2_identity(mat2 m);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_identity_array(mat2 * __restrict mat, size_t count);
|
||||
glmc_mat2_identity_array(mat2 * __restrict mats, size_t count);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_zero(mat2 mat);
|
||||
glmc_mat2_zero(mat2 m);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
@@ -35,28 +39,20 @@ glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_transpose_to(mat2 m, mat2 dest);
|
||||
glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_transpose_to(mat2 mat, mat2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_transpose(mat2 m);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_trace(mat2 m);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_scale(mat2 m, float s);
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_det(mat2 mat);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_inv(mat2 mat, mat2 dest);
|
||||
@@ -71,11 +67,15 @@ glmc_mat2_swap_row(mat2 mat, int row1, int row2);
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c);
|
||||
glmc_mat2_trace(mat2 m);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_make(const float * __restrict src, mat2 dest);
|
||||
float
|
||||
glmc_mat2_det(mat2 m);
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -84,6 +84,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_make(const float * __restrict src, mat3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -125,6 +125,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_make(const float * __restrict src, mat4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -245,6 +245,10 @@ CGLM_EXPORT
|
||||
bool
|
||||
glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec2_swap(vec2 a, vec2 b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -363,6 +363,10 @@ CGLM_EXPORT
|
||||
bool
|
||||
glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_swap(vec3 a, vec3 b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -336,6 +336,10 @@ CGLM_EXPORT
|
||||
bool
|
||||
glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_swap(vec4 a, vec4 b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,7 +25,12 @@
|
||||
float nearZ,
|
||||
float farZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_infinite(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_infinite(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj)
|
||||
CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest)
|
||||
CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest)
|
||||
@@ -87,7 +92,7 @@
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief set up perspective peprojection matrix
|
||||
* @brief set up perspective projection matrix
|
||||
*
|
||||
* @param[in] left viewport.left
|
||||
* @param[in] right viewport.right
|
||||
@@ -274,6 +279,28 @@ glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up perspective projection matrix with infinite far plane
|
||||
*
|
||||
* @param[in] fovy field of view angle
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[in] nearZ near clipping plane
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_infinite(float fovy, float aspect, float nearZ, mat4 dest) {
|
||||
#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
|
||||
glm_perspective_infinite_lh_zo(fovy, aspect, nearZ, dest);
|
||||
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
|
||||
glm_perspective_infinite_lh_no(fovy, aspect, nearZ, dest);
|
||||
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
|
||||
glm_perspective_infinite_rh_zo(fovy, aspect, nearZ, dest);
|
||||
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
|
||||
glm_perspective_infinite_rh_no(fovy, aspect, nearZ, dest);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief extend perspective projection matrix's far distance
|
||||
*
|
||||
@@ -317,6 +344,27 @@ glm_perspective_default(float aspect, mat4 dest) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix with default near
|
||||
* and angle values
|
||||
*
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_default_infinite(float aspect, mat4 dest) {
|
||||
#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
|
||||
glm_perspective_default_infinite_lh_zo(aspect, dest);
|
||||
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
|
||||
glm_perspective_default_infinite_lh_no(aspect, dest);
|
||||
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
|
||||
glm_perspective_default_infinite_rh_zo(aspect, dest);
|
||||
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
|
||||
glm_perspective_default_infinite_rh_no(aspect, dest);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief resize perspective matrix by aspect ratio ( width / height )
|
||||
* this makes very easy to resize proj matrix when window /viewport
|
||||
|
||||
@@ -16,7 +16,12 @@
|
||||
float nearZ,
|
||||
float farZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_infinite_lh_no(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_lh_no(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_infinite_lh_no(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_resize_lh_no(float aspect, mat4 proj)
|
||||
CGLM_INLINE void glm_persp_move_far_lh_no(mat4 proj,
|
||||
float deltaFar)
|
||||
@@ -116,7 +121,35 @@ glm_perspective_lh_no(float fovy,
|
||||
dest[2][2] =-(nearZ + farZ) * fn;
|
||||
dest[2][3] = 1.0f;
|
||||
dest[3][2] = 2.0f * nearZ * farZ * fn;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite 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] nearZ near clipping plane
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_infinite_lh_no(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest) {
|
||||
float f;
|
||||
|
||||
glm_mat4_zero(dest);
|
||||
|
||||
f = 1.0f / tanf(fovy * 0.5f);
|
||||
|
||||
dest[0][0] = f / aspect;
|
||||
dest[1][1] = f;
|
||||
dest[2][2] = 1.0f;
|
||||
dest[2][3] = 1.0f;
|
||||
dest[3][2] =-2.0f * nearZ;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -133,6 +166,20 @@ glm_perspective_default_lh_no(float aspect, mat4 dest) {
|
||||
glm_perspective_lh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix with default near
|
||||
* and angle values with a left-hand coordinate system and a
|
||||
* clip-space of [-1, 1].
|
||||
*
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_default_infinite_lh_no(float aspect, mat4 dest) {
|
||||
glm_perspective_infinite_lh_no(GLM_PI_4f, aspect, 0.01f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief resize perspective matrix by aspect ratio ( width / height )
|
||||
* this makes very easy to resize proj matrix when window /viewport
|
||||
|
||||
@@ -16,7 +16,12 @@
|
||||
float nearZ,
|
||||
float farZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_infinite_lh_zo(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_lh_zo(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_infinite_lh_zo(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_resize_lh_zo(float aspect, mat4 proj)
|
||||
CGLM_INLINE void glm_persp_move_far_lh_zo(mat4 proj,
|
||||
float deltaFar)
|
||||
@@ -116,6 +121,35 @@ glm_perspective_lh_zo(float fovy,
|
||||
dest[3][2] = nearZ * farZ * fn;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix
|
||||
* with a left-hand coordinate system and a
|
||||
* clip-space of [0, 1].
|
||||
*
|
||||
* @param[in] fovy field of view angle
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[in] nearZ near clipping plane
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_infinite_lh_zo(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest) {
|
||||
float f;
|
||||
|
||||
glm_mat4_zero(dest);
|
||||
|
||||
f = 1.0f / tanf(fovy * 0.5f);
|
||||
|
||||
dest[0][0] = f / aspect;
|
||||
dest[1][1] = f;
|
||||
dest[2][2] = 1.0f;
|
||||
dest[2][3] = 1.0f;
|
||||
dest[3][2] =-nearZ;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief extend perspective projection matrix's far distance with a
|
||||
* left-hand coordinate system and a clip-space with depth values
|
||||
@@ -144,7 +178,7 @@ glm_persp_move_far_lh_zo(mat4 proj, float deltaFar) {
|
||||
|
||||
/*!
|
||||
* @brief set up perspective projection matrix with default near/far
|
||||
* and angle values with a left-hand coordinate system and a
|
||||
* and angle values with a left-hand coordinate system and a
|
||||
* clip-space of [0, 1].
|
||||
*
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
@@ -156,6 +190,20 @@ glm_perspective_default_lh_zo(float aspect, mat4 dest) {
|
||||
glm_perspective_lh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix with default near
|
||||
* and angle values with a left-hand coordinate system and a
|
||||
* clip-space of [0, 1].
|
||||
*
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_default_infinite_lh_zo(float aspect, mat4 dest) {
|
||||
glm_perspective_infinite_lh_zo(GLM_PI_4f, aspect, 0.01f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief resize perspective matrix by aspect ratio ( width / height )
|
||||
* this makes very easy to resize proj matrix when window /viewport
|
||||
|
||||
@@ -16,7 +16,12 @@
|
||||
float nearZ,
|
||||
float farZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_infinite_rh_no(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_rh_no(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_infinite_rh_no(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_resize_rh_no(float aspect, mat4 proj)
|
||||
CGLM_INLINE void glm_persp_move_far_rh_no(mat4 proj,
|
||||
float deltaFar)
|
||||
@@ -116,7 +121,35 @@ glm_perspective_rh_no(float fovy,
|
||||
dest[2][2] = (nearZ + farZ) * fn;
|
||||
dest[2][3] =-1.0f;
|
||||
dest[3][2] = 2.0f * nearZ * farZ * fn;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite 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] nearZ near clipping plane
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_infinite_rh_no(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest) {
|
||||
float f;
|
||||
|
||||
glm_mat4_zero(dest);
|
||||
|
||||
f = 1.0f / tanf(fovy * 0.5f);
|
||||
|
||||
dest[0][0] = f / aspect;
|
||||
dest[1][1] = f;
|
||||
dest[2][2] =-1.0f;
|
||||
dest[2][3] =-1.0f;
|
||||
dest[3][2] =-2.0f * nearZ;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -133,6 +166,20 @@ glm_perspective_default_rh_no(float aspect, mat4 dest) {
|
||||
glm_perspective_rh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix with default near
|
||||
* and angle values with a right-hand coordinate system and a
|
||||
* clip-space of [-1, 1].
|
||||
*
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_default_infinite_rh_no(float aspect, mat4 dest) {
|
||||
glm_perspective_infinite_rh_no(GLM_PI_4f, aspect, 0.01f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief resize perspective matrix by aspect ratio ( width / height )
|
||||
* this makes very easy to resize proj matrix when window /viewport
|
||||
|
||||
@@ -16,7 +16,12 @@
|
||||
float nearZ,
|
||||
float farZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_infinite_rh_zo(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_rh_zo(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_default_infinite_rh_zo(float aspect, mat4 dest)
|
||||
CGLM_INLINE void glm_perspective_resize_rh_zo(float aspect, mat4 proj)
|
||||
CGLM_INLINE void glm_persp_move_far_rh_zo(mat4 proj,
|
||||
float deltaFar)
|
||||
@@ -116,6 +121,35 @@ glm_perspective_rh_zo(float fovy,
|
||||
dest[3][2] = nearZ * farZ * fn;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix
|
||||
* with a right-hand coordinate system and a
|
||||
* clip-space of [0, 1].
|
||||
*
|
||||
* @param[in] fovy field of view angle
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[in] nearZ near clipping plane
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_infinite_rh_zo(float fovy,
|
||||
float aspect,
|
||||
float nearZ,
|
||||
mat4 dest) {
|
||||
float f;
|
||||
|
||||
glm_mat4_zero(dest);
|
||||
|
||||
f = 1.0f / tanf(fovy * 0.5f);
|
||||
|
||||
dest[0][0] = f / aspect;
|
||||
dest[1][1] = f;
|
||||
dest[2][2] =-1.0f;
|
||||
dest[2][3] =-1.0f;
|
||||
dest[3][2] =-nearZ;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up perspective projection matrix with default near/far
|
||||
* and angle values with a right-hand coordinate system and a
|
||||
@@ -130,6 +164,20 @@ glm_perspective_default_rh_zo(float aspect, mat4 dest) {
|
||||
glm_perspective_rh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief set up infinite perspective projection matrix with default near
|
||||
* and angle values with a right-hand coordinate system and a
|
||||
* clip-space of [0, 1].
|
||||
*
|
||||
* @param[in] aspect aspect ratio ( width / height )
|
||||
* @param[out] dest result matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_perspective_default_infinite_rh_zo(float aspect, mat4 dest) {
|
||||
glm_perspective_infinite_rh_zo(GLM_PI_4f, aspect, 0.01f, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief resize perspective matrix by aspect ratio ( width / height )
|
||||
* this makes very easy to resize proj matrix when window /viewport
|
||||
|
||||
@@ -13,22 +13,22 @@
|
||||
GLM_MAT2_ZERO
|
||||
|
||||
Functions:
|
||||
CGLM_INLINE void glm_mat2_make(float * restrict src, mat2 dest)
|
||||
CGLM_INLINE void glm_mat2_copy(mat2 mat, mat2 dest)
|
||||
CGLM_INLINE void glm_mat2_identity(mat2 mat)
|
||||
CGLM_INLINE void glm_mat2_identity_array(mat2 * restrict mat, size_t count)
|
||||
CGLM_INLINE void glm_mat2_zero(mat2 mat)
|
||||
CGLM_INLINE void glm_mat2_identity(mat2 m)
|
||||
CGLM_INLINE void glm_mat2_identity_array(mat2 * restrict mats, size_t count)
|
||||
CGLM_INLINE void glm_mat2_zero(mat2 m)
|
||||
CGLM_INLINE void glm_mat2_mul(mat2 m1, mat2 m2, mat2 dest)
|
||||
CGLM_INLINE void glm_mat2_transpose_to(mat2 m, mat2 dest)
|
||||
CGLM_INLINE void glm_mat2_transpose(mat2 m)
|
||||
CGLM_INLINE void glm_mat2_mulv(mat2 m, vec2 v, vec2 dest)
|
||||
CGLM_INLINE float glm_mat2_trace(mat2 m)
|
||||
CGLM_INLINE void glm_mat2_transpose_to(mat2 mat, mat2 dest)
|
||||
CGLM_INLINE void glm_mat2_transpose(mat2 m)
|
||||
CGLM_INLINE void glm_mat2_scale(mat2 m, float s)
|
||||
CGLM_INLINE float glm_mat2_det(mat2 mat)
|
||||
CGLM_INLINE void glm_mat2_inv(mat2 mat, mat2 dest)
|
||||
CGLM_INLINE void glm_mat2_swap_col(mat2 mat, int col1, int col2)
|
||||
CGLM_INLINE void glm_mat2_swap_row(mat2 mat, int row1, int row2)
|
||||
CGLM_INLINE float glm_mat2_det(mat2 m)
|
||||
CGLM_INLINE float glm_mat2_trace(mat2 m)
|
||||
CGLM_INLINE float glm_mat2_rmc(vec2 r, mat2 m, vec2 c)
|
||||
CGLM_INLINE void glm_mat2_make(float * restrict src, mat2 dest)
|
||||
*/
|
||||
|
||||
#ifndef cglm_mat2_h
|
||||
@@ -57,10 +57,25 @@
|
||||
#define GLM_MAT2_ZERO ((mat2)GLM_MAT2_ZERO_INIT)
|
||||
|
||||
/*!
|
||||
* @brief copy all members of [mat] to [dest]
|
||||
* @brief Create mat2 (dest) from pointer (src).
|
||||
*
|
||||
* @param[in] mat source
|
||||
* @param[out] dest destination
|
||||
* @param[in] src pointer to an array of floats (left)
|
||||
* @param[out] dest destination (result, mat2)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_make(const float * __restrict src, mat2 dest) {
|
||||
dest[0][0] = src[0];
|
||||
dest[0][1] = src[1];
|
||||
dest[1][0] = src[2];
|
||||
dest[1][1] = src[3];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Copy mat2 (mat) to mat2 (dest).
|
||||
*
|
||||
* @param[in] mat mat2 (left, src)
|
||||
* @param[out] dest destination (result, mat2)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -69,7 +84,9 @@ glm_mat2_copy(mat2 mat, mat2 dest) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief make given matrix identity. It is identical with below,
|
||||
* @brief Copy a mat2 identity to mat2 (m), or makes mat2 (m) an identity.
|
||||
*
|
||||
* The same thing may be achieved with either of bellow methods,
|
||||
* but it is more easy to do that with this func especially for members
|
||||
* e.g. glm_mat2_identity(aStruct->aMatrix);
|
||||
*
|
||||
@@ -80,59 +97,57 @@ glm_mat2_copy(mat2 mat, mat2 dest) {
|
||||
* mat2 mat = GLM_MAT2_IDENTITY_INIT;
|
||||
* @endcode
|
||||
*
|
||||
* @param[in, out] mat destination
|
||||
* @param[in, out] m mat2 (src, dest)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_identity(mat2 mat) {
|
||||
glm_mat2_identity(mat2 m) {
|
||||
CGLM_ALIGN_MAT mat2 t = GLM_MAT2_IDENTITY_INIT;
|
||||
glm_mat2_copy(t, mat);
|
||||
glm_mat2_copy(t, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief make given matrix array's each element identity matrix
|
||||
* @brief Given an array of mat2’s (mats) make each matrix an identity matrix.
|
||||
*
|
||||
* @param[in, out] mat matrix array (must be aligned (16)
|
||||
* if alignment is not disabled)
|
||||
*
|
||||
* @param[in] count count of matrices
|
||||
* @param[in, out] mats Array of mat2’s (must be aligned (16/32) if alignment is not disabled)
|
||||
* @param[in] count Array size of mats or number of matrices
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_identity_array(mat2 * __restrict mat, size_t count) {
|
||||
glm_mat2_identity_array(mat2 * __restrict mats, size_t count) {
|
||||
CGLM_ALIGN_MAT mat2 t = GLM_MAT2_IDENTITY_INIT;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
glm_mat2_copy(t, mat[i]);
|
||||
glm_mat2_copy(t, mats[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief make given matrix zero.
|
||||
* @brief Zero out the mat2 (m).
|
||||
*
|
||||
* @param[in, out] mat matrix
|
||||
* @param[in, out] m mat2 (src, dest)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_zero(mat2 mat) {
|
||||
glm_mat2_zero(mat2 m) {
|
||||
CGLM_ALIGN_MAT mat2 t = GLM_MAT2_ZERO_INIT;
|
||||
glm_mat2_copy(t, mat);
|
||||
glm_mat2_copy(t, m);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief multiply m1 and m2 to dest
|
||||
* @brief Multiply mat2 (m1) by mat2 (m2) and store in mat2 (dest).
|
||||
*
|
||||
* m1, m2 and dest matrices can be same matrix, it is possible to write this:
|
||||
* m1, m2 and dest matrices can be same matrix, it is possible to write this:
|
||||
*
|
||||
* @code
|
||||
* mat2 m = GLM_MAT2_IDENTITY_INIT;
|
||||
* glm_mat2_mul(m, m, m);
|
||||
* @endcode
|
||||
*
|
||||
* @param[in] m1 left matrix
|
||||
* @param[in] m2 right matrix
|
||||
* @param[out] dest destination matrix
|
||||
* @param[in] m1 mat2 (left)
|
||||
* @param[in] m2 mat2 (right)
|
||||
* @param[out] dest destination (result, mat2)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -157,32 +172,44 @@ glm_mat2_mul(mat2 m1, mat2 m2, mat2 dest) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief transpose mat2 and store in dest
|
||||
* @brief Multiply mat2 (m) by vec2 (v) and store in vec2 (dest).
|
||||
*
|
||||
* source matrix will not be transposed unless dest is m
|
||||
*
|
||||
* @param[in] m matrix
|
||||
* @param[out] dest result
|
||||
* @param[in] m mat2 (left)
|
||||
* @param[in] v vec2 (right, column vector)
|
||||
* @param[out] dest destination (result, column vector)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_transpose_to(mat2 m, mat2 dest) {
|
||||
glm_mat2_mulv(mat2 m, vec2 v, vec2 dest) {
|
||||
dest[0] = m[0][0] * v[0] + m[1][0] * v[1];
|
||||
dest[1] = m[0][1] * v[0] + m[1][1] * v[1];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Transpose mat2 (mat) and store in mat2 (dest).
|
||||
*
|
||||
* @param[in] mat mat2 (left, src)
|
||||
* @param[out] dest destination (result, mat2)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_transpose_to(mat2 mat, mat2 dest) {
|
||||
#if defined(__wasm__) && defined(__wasm_simd128__)
|
||||
glm_mat2_transp_wasm(m, dest);
|
||||
glm_mat2_transp_wasm(mat, dest);
|
||||
#elif defined( __SSE__ ) || defined( __SSE2__ )
|
||||
glm_mat2_transp_sse2(m, dest);
|
||||
glm_mat2_transp_sse2(mat, dest);
|
||||
#else
|
||||
dest[0][0] = m[0][0];
|
||||
dest[0][1] = m[1][0];
|
||||
dest[1][0] = m[0][1];
|
||||
dest[1][1] = m[1][1];
|
||||
dest[0][0] = mat[0][0];
|
||||
dest[0][1] = mat[1][0];
|
||||
dest[1][0] = mat[0][1];
|
||||
dest[1][1] = mat[1][1];
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief transpose mat2 and store result in same matrix
|
||||
* @brief Transpose mat2 (m) and store result in the same matrix.
|
||||
*
|
||||
* @param[in, out] m source and dest
|
||||
* @param[in, out] m mat2 (src, dest)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -194,39 +221,10 @@ glm_mat2_transpose(mat2 m) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief multiply mat2 with vec2 (column vector) and store in dest vector
|
||||
* @brief Multiply mat2 (m) by scalar constant (s).
|
||||
*
|
||||
* @param[in] m mat2 (left)
|
||||
* @param[in] v vec2 (right, column vector)
|
||||
* @param[out] dest vec2 (result, column vector)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_mulv(mat2 m, vec2 v, vec2 dest) {
|
||||
dest[0] = m[0][0] * v[0] + m[1][0] * v[1];
|
||||
dest[1] = m[0][1] * v[0] + m[1][1] * v[1];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief trace of matrix
|
||||
*
|
||||
* sum of the elements on the main diagonal from upper left to the lower right
|
||||
*
|
||||
* @param[in] m matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_mat2_trace(mat2 m) {
|
||||
return m[0][0] + m[1][1];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief scale (multiply with scalar) matrix
|
||||
*
|
||||
* multiply matrix with scalar
|
||||
*
|
||||
* @param[in, out] m matrix
|
||||
* @param[in] s scalar
|
||||
* @param[in, out] m mat2 (src, dest)
|
||||
* @param[in] s float (scalar)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -247,23 +245,10 @@ glm_mat2_scale(mat2 m, float s) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief mat2 determinant
|
||||
* @brief Inverse mat2 (mat) and store in mat2 (dest).
|
||||
*
|
||||
* @param[in] mat matrix
|
||||
*
|
||||
* @return determinant
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_mat2_det(mat2 mat) {
|
||||
return mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief inverse mat2 and store in dest
|
||||
*
|
||||
* @param[in] mat matrix
|
||||
* @param[out] dest inverse matrix
|
||||
* @param[in] mat mat2 (left, src)
|
||||
* @param[out] dest destination (result, inverse mat2)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -281,11 +266,11 @@ glm_mat2_inv(mat2 mat, mat2 dest) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two matrix columns
|
||||
* @brief Swap two columns in mat2 (mat) and store in same matrix.
|
||||
*
|
||||
* @param[in,out] mat matrix
|
||||
* @param[in] col1 col1
|
||||
* @param[in] col2 col2
|
||||
* @param[in, out] mat mat2 (src, dest)
|
||||
* @param[in] col1 Column 1 array index
|
||||
* @param[in] col2 Column 2 array index
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -303,11 +288,11 @@ glm_mat2_swap_col(mat2 mat, int col1, int col2) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two matrix rows
|
||||
* @brief Swap two rows in mat2 (mat) and store in same matrix.
|
||||
*
|
||||
* @param[in,out] mat matrix
|
||||
* @param[in] row1 row1
|
||||
* @param[in] row2 row2
|
||||
* @param[in, out] mat mat2 (src, dest)
|
||||
* @param[in] row1 Row 1 array index
|
||||
* @param[in] row2 Row 2 array index
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
@@ -325,18 +310,47 @@ glm_mat2_swap_row(mat2 mat, int row1, int row2) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief helper for R (row vector) * M (matrix) * C (column vector)
|
||||
* @brief Returns mat2 determinant.
|
||||
*
|
||||
* rmc stands for Row * Matrix * Column
|
||||
* @param[in] m mat2 (src)
|
||||
*
|
||||
* the result is scalar because R * M = Matrix1x2 (row vector),
|
||||
* then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar)
|
||||
* @return[out] mat2 determinant (float)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_mat2_det(mat2 m) {
|
||||
return m[0][0] * m[1][1] - m[1][0] * m[0][1];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns trace of matrix. Which is:
|
||||
*
|
||||
* @param[in] r row vector or matrix1x2
|
||||
* @param[in] m matrix2x2
|
||||
* @param[in] c column vector or matrix2x1
|
||||
* The sum of the elements on the main diagonal from
|
||||
* upper left corner to the bottom right corner.
|
||||
*
|
||||
* @return scalar value e.g. Matrix1x1
|
||||
* @param[in] m mat2 (src)
|
||||
*
|
||||
* @return[out] mat2 trace (float)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_mat2_trace(mat2 m) {
|
||||
return m[0][0] + m[1][1];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Helper for R (row vector) * M (matrix) * C (column vector)
|
||||
*
|
||||
* rmc stands for Row * Matrix * Column
|
||||
*
|
||||
* the result is scalar because M * C = ResC (1x2, column vector),
|
||||
* then if you take the dot_product(R (2x1), ResC (1x2)) = scalar value.
|
||||
*
|
||||
* @param[in] r vec2 (2x1, row vector)
|
||||
* @param[in] m mat2 (2x2, matrix)
|
||||
* @param[in] c vec2 (1x2, column vector)
|
||||
*
|
||||
* @return[out] Scalar value (float, 1x1)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
@@ -346,19 +360,4 @@ glm_mat2_rmc(vec2 r, mat2 m, vec2 c) {
|
||||
return glm_vec2_dot(r, tmp);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create mat2 matrix from pointer
|
||||
*
|
||||
* @param[in] src pointer to an array of floats
|
||||
* @param[out] dest matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat2_make(const float * __restrict src, mat2 dest) {
|
||||
dest[0][0] = src[0];
|
||||
dest[0][1] = src[1];
|
||||
dest[1][0] = src[2];
|
||||
dest[1][1] = src[3];
|
||||
}
|
||||
|
||||
#endif /* cglm_mat2_h */
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
CGLM_INLINE void glm_mat3_swap_row(mat3 mat, int row1, int row2);
|
||||
CGLM_INLINE float glm_mat3_rmc(vec3 r, mat3 m, vec3 c);
|
||||
CGLM_INLINE void glm_mat3_make(float * restrict src, mat3 dest);
|
||||
CGLM_INLINE void glm_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest);
|
||||
*/
|
||||
|
||||
#ifndef cglm_mat3_h
|
||||
@@ -448,4 +449,32 @@ glm_mat3_make(const float * __restrict src, mat3 dest) {
|
||||
dest[2][2] = src[8];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create mat3 matrix from texture transform parameters
|
||||
*
|
||||
* @param[in] sx scale x
|
||||
* @param[in] sy scale y
|
||||
* @param[in] rot rotation in radians CCW/RH
|
||||
* @param[in] tx translate x
|
||||
* @param[in] ty translate y
|
||||
* @param[out] dest texture transform matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest) {
|
||||
float c, s;
|
||||
|
||||
c = cosf(rot);
|
||||
s = sinf(rot);
|
||||
|
||||
glm_mat3_identity(dest);
|
||||
|
||||
dest[0][0] = c * sx;
|
||||
dest[0][1] = -s * sy;
|
||||
dest[1][0] = s * sx;
|
||||
dest[1][1] = c * sy;
|
||||
dest[2][0] = tx;
|
||||
dest[2][1] = ty;
|
||||
}
|
||||
|
||||
#endif /* cglm_mat3_h */
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2);
|
||||
CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c);
|
||||
CGLM_INLINE void glm_mat4_make(float * restrict src, mat4 dest);
|
||||
CGLM_INLINE void glm_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest);
|
||||
*/
|
||||
|
||||
#ifndef cglm_mat_h
|
||||
@@ -799,4 +800,32 @@ glm_mat4_make(const float * __restrict src, mat4 dest) {
|
||||
dest[2][3] = src[11]; dest[3][3] = src[15];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create mat4 matrix from texture transform parameters
|
||||
*
|
||||
* @param[in] sx scale x
|
||||
* @param[in] sy scale y
|
||||
* @param[in] rot rotation in radians CCW/RH
|
||||
* @param[in] tx translate x
|
||||
* @param[in] ty translate y
|
||||
* @param[out] dest texture transform matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest) {
|
||||
float c, s;
|
||||
|
||||
c = cosf(rot);
|
||||
s = sinf(rot);
|
||||
|
||||
glm_mat4_identity(dest);
|
||||
|
||||
dest[0][0] = c * sx;
|
||||
dest[0][1] = -s * sy;
|
||||
dest[1][0] = s * sx;
|
||||
dest[1][1] = c * sy;
|
||||
dest[3][0] = tx;
|
||||
dest[3][1] = ty;
|
||||
}
|
||||
|
||||
#endif /* cglm_mat_h */
|
||||
|
||||
@@ -13,21 +13,20 @@
|
||||
GLM_MAT2_ZERO
|
||||
|
||||
Functions:
|
||||
CGLM_INLINE void glms_mat2_identity(mat2 mat)
|
||||
CGLM_INLINE void glms_mat2_identity_array(mat2 * restrict mat, size_t count)
|
||||
CGLM_INLINE void glms_mat2_zero(mat2 mat)
|
||||
CGLM_INLINE void glms_mat2_mul(mat2 m1, mat2 m2, mat2 dest)
|
||||
CGLM_INLINE void glms_mat2_transpose_to(mat2 m, mat2 dest)
|
||||
CGLM_INLINE void glms_mat2_transpose(mat2 m)
|
||||
CGLM_INLINE void glms_mat2_mulv(mat2 m, vec2 v, vec2 dest)
|
||||
CGLM_INLINE float glms_mat2_trace(mat2 m)
|
||||
CGLM_INLINE void glms_mat2_scale(mat2 m, float s)
|
||||
CGLM_INLINE float glms_mat2_det(mat2 mat)
|
||||
CGLM_INLINE void glms_mat2_inv(mat2 mat, mat2 dest)
|
||||
CGLM_INLINE void glms_mat2_swap_col(mat2 mat, int col1, int col2)
|
||||
CGLM_INLINE void glms_mat2_swap_row(mat2 mat, int row1, int row2)
|
||||
CGLM_INLINE float glms_mat2_rmc(vec2 r, mat2 m, vec2 c)
|
||||
CGLM_INLINE mat2s glms_mat2_make(const float * __restrict src);
|
||||
CGLM_INLINE mat2s glms_mat2_identity(void)
|
||||
CGLM_INLINE void glms_mat2_identity_array(mat2 * restrict mats, size_t count)
|
||||
CGLM_INLINE mat2s glms_mat2_zero(void)
|
||||
CGLM_INLINE mat2s glms_mat2_mul(mat2 m1, mat2 m2)
|
||||
CGLM_INLINE vec2s glms_mat2_mulv(mat2 m, vec2 v)
|
||||
CGLM_INLINE mat2s glms_mat2_transpose(mat2 m)
|
||||
CGLM_INLINE mat2s glms_mat2_scale(mat2 m, float s)
|
||||
CGLM_INLINE mat2s glms_mat2_inv(mat2 m)
|
||||
CGLM_INLINE mat2s glms_mat2_swap_col(mat2 mat, int col1, int col2)
|
||||
CGLM_INLINE mat2s glms_mat2_swap_row(mat2 mat, int row1, int row2)
|
||||
CGLM_INLINE float glms_mat2_det(mat2 m)
|
||||
CGLM_INLINE float glms_mat2_trace(mat2 m)
|
||||
CGLM_INLINE float glms_mat2_rmc(vec2 r, mat2 m, vec2 c)
|
||||
*/
|
||||
|
||||
#ifndef cglms_mat2_h
|
||||
@@ -48,7 +47,23 @@
|
||||
#define GLMS_MAT2_ZERO ((mat2s)GLMS_MAT2_ZERO_INIT)
|
||||
|
||||
/*!
|
||||
* @brief make given matrix identity. It is identical with below,
|
||||
* @brief Returns mat2s (r) from pointer (src).
|
||||
*
|
||||
* @param[in] src pointer to an array of floats
|
||||
* @return[out] r constructed mat2s from raw pointer
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
glms_mat2_(make)(const float * __restrict src) {
|
||||
mat2s r;
|
||||
glm_mat2_make(src, r.raw);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Return a identity mat2s (r).
|
||||
*
|
||||
* The same thing may be achieved with either of bellow methods,
|
||||
* but it is more easy to do that with this func especially for members
|
||||
* e.g. glm_mat2_identity(aStruct->aMatrix);
|
||||
*
|
||||
@@ -59,7 +74,7 @@
|
||||
* mat2 mat = GLM_MAT2_IDENTITY_INIT;
|
||||
* @endcode
|
||||
*
|
||||
* @returns identity matrix
|
||||
* @return[out] r constructed mat2s from raw pointer
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
@@ -70,28 +85,26 @@ glms_mat2_(identity)(void) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief make given matrix array's each element identity matrix
|
||||
* @brief Given an array of mat2s’s (mats) make each matrix an identity matrix.
|
||||
*
|
||||
* @param[in, out] mat matrix array (must be aligned (16)
|
||||
* if alignment is not disabled)
|
||||
*
|
||||
* @param[in] count count of matrices
|
||||
* @param[in, out] mats Array of mat2s’s (must be aligned (16/32) if alignment is not disabled)
|
||||
* @param[in] count Array size of mats or number of matrices
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glms_mat2_(identity_array)(mat2s * __restrict mat, size_t count) {
|
||||
glms_mat2_(identity_array)(mat2s * __restrict mats, size_t count) {
|
||||
CGLM_ALIGN_MAT mat2s t = GLMS_MAT2_IDENTITY_INIT;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
glm_mat2_copy(t.raw, mat[i].raw);
|
||||
glm_mat2_copy(t.raw, mats[i].raw);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief make given matrix zero.
|
||||
* @brief Return zero'd out mat2 (r).
|
||||
*
|
||||
* @returns matrix
|
||||
* @return[out] r constructed mat2s from raw pointer
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
@@ -102,19 +115,18 @@ glms_mat2_(zero)(void) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief multiply m1 and m2 to dest
|
||||
* @brief Multiply mat2 (m1) by mat2 (m2) and return in mat2s (r)
|
||||
*
|
||||
* m1, m2 and dest matrices can be same matrix, it is possible to write this:
|
||||
* m1 and m2 matrices can be the same matrix, it is possible to write this:
|
||||
*
|
||||
* @code
|
||||
* mat2 m = GLM_MAT2_IDENTITY_INIT;
|
||||
* r = glms_mat2_mul(m, m);
|
||||
* mat2s r = glms_mat2_mul(m, m);
|
||||
* @endcode
|
||||
*
|
||||
* @param[in] m1 left matrix
|
||||
* @param[in] m2 right matrix
|
||||
*
|
||||
* @returns destination matrix
|
||||
* @param[in] m1 mat2s (left)
|
||||
* @param[in] m2 mat2s (right)
|
||||
* @return[out] r constructed mat2s from raw pointers
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
@@ -124,26 +136,12 @@ glms_mat2_(mul)(mat2s m1, mat2s m2) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief transpose mat2
|
||||
/*
|
||||
* @brief Multiply mat2s (m) by vec2s (v) and return in vec2s (r).
|
||||
*
|
||||
* @param[in] m matrix to transpose
|
||||
*
|
||||
* @returns transposed matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
glms_mat2_(transpose)(mat2s m) {
|
||||
glm_mat2_transpose(m.raw);
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief multiply mat2 with vec2 (column vector) and store in dest vector
|
||||
*
|
||||
* @param[in] m mat2 (left)
|
||||
* @param[in] v vec2 (right, column vector)
|
||||
* @returns vec2 (result, column vector)
|
||||
* @param[in] m mat2s (left)
|
||||
* @param[in] v vec2s (right, column vector)
|
||||
* @return[out] r constructed vec2s from raw pointers
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec2s
|
||||
@@ -154,26 +152,24 @@ glms_mat2_(mulv)(mat2s m, vec2s v) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief trace of matrix
|
||||
* @brief Transpose mat2s (m) and store result in the same matrix.
|
||||
*
|
||||
* sum of the elements on the main diagonal from upper left to the lower right
|
||||
*
|
||||
* @param[in] m matrix
|
||||
* @param[in] m mat2s (src)
|
||||
* @return[out] m constructed mat2s from raw pointers
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glms_mat2_(trace)(mat2s m) {
|
||||
return glm_mat2_trace(m.raw);
|
||||
mat2s
|
||||
glms_mat2_(transpose)(mat2s m) {
|
||||
glm_mat2_transpose(m.raw);
|
||||
return m;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief scale (multiply with scalar) matrix
|
||||
* @brief Multiply mat2s (m) by scalar constant (s)
|
||||
*
|
||||
* multiply matrix with scalar
|
||||
*
|
||||
* @param[in, out] m matrix
|
||||
* @param[in] s scalar
|
||||
* @returns matrix
|
||||
* @param[in] m mat2s (src)
|
||||
* @param[in] s scalar value
|
||||
* @return[out] m constructed mat2s from raw pointers
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
@@ -183,39 +179,26 @@ glms_mat2_(scale)(mat2s m, float s) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief mat2 determinant
|
||||
* @brief Inverse mat2s (m) and return in mat2s (r).
|
||||
*
|
||||
* @param[in] mat matrix
|
||||
*
|
||||
* @return determinant
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glms_mat2_(det)(mat2s mat) {
|
||||
return glm_mat2_det(mat.raw);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief inverse mat2 and store in dest
|
||||
*
|
||||
* @param[in] mat matrix
|
||||
* @returns matrix
|
||||
* @param[in] m mat2s (left, src)
|
||||
* @return[out] r constructed mat2s from raw pointers
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
glms_mat2_(inv)(mat2s mat) {
|
||||
glms_mat2_(inv)(mat2s m) {
|
||||
mat2s r;
|
||||
glm_mat2_inv(mat.raw, r.raw);
|
||||
glm_mat2_inv(m.raw, r.raw);
|
||||
return r;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two matrix columns
|
||||
* @brief Swap two columns in mat2s (mat) and store in same matrix.
|
||||
*
|
||||
* @param[in] mat matrix
|
||||
* @param[in] col1 col1
|
||||
* @param[in] col2 col2
|
||||
* @returns matrix
|
||||
* @param[in] mat mat2s
|
||||
* @param[in] col1 column 1 array index
|
||||
* @param[in] col2 column 2 array index
|
||||
* @return[out] mat constructed mat2s from raw pointers columns swapped
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
@@ -225,12 +208,12 @@ glms_mat2_(swap_col)(mat2s mat, int col1, int col2) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two matrix rows
|
||||
* @brief Swap two rows in mat2s (mat) and store in same matrix.
|
||||
*
|
||||
* @param[in] mat matrix
|
||||
* @param[in] row1 row1
|
||||
* @param[in] row2 row2
|
||||
* @returns matrix
|
||||
* @param[in] mat mat2s
|
||||
* @param[in] row1 row 1 array index
|
||||
* @param[in] row2 row 2 array index
|
||||
* @return[out] mat constructed mat2s from raw pointers rows swapped
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
@@ -240,18 +223,47 @@ glms_mat2_(swap_row)(mat2s mat, int row1, int row2) {
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief helper for R (row vector) * M (matrix) * C (column vector)
|
||||
* @brief Returns mat2 determinant.
|
||||
*
|
||||
* rmc stands for Row * Matrix * Column
|
||||
* @param[in] m mat2 (src)
|
||||
*
|
||||
* the result is scalar because R * M = Matrix1x2 (row vector),
|
||||
* then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar)
|
||||
* @return[out] mat2s raw pointers determinant (float)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glms_mat2_(det)(mat2s m) {
|
||||
return glm_mat2_det(m.raw);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns trace of matrix. Which is:
|
||||
*
|
||||
* @param[in] r row vector or matrix1x2
|
||||
* @param[in] m matrix2x2
|
||||
* @param[in] c column vector or matrix2x1
|
||||
* The sum of the elements on the main diagonal from
|
||||
* upper left corner to the bottom right corner.
|
||||
*
|
||||
* @return scalar value e.g. Matrix1x1
|
||||
* @param[in] m mat2 (m)
|
||||
*
|
||||
* @return[out] mat2s raw pointers trace (float)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glms_mat2_(trace)(mat2s m) {
|
||||
return glm_mat2_trace(m.raw);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Helper for R (row vector) * M (matrix) * C (column vector)
|
||||
*
|
||||
* rmc stands for Row * Matrix * Column
|
||||
*
|
||||
* the result is scalar because M * C = ResC (1x2, column vector),
|
||||
* then if you take the dot_product(R (2x1), ResC (1x2)) = scalar value.
|
||||
*
|
||||
* @param[in] r vec2s (2x1, row vector)
|
||||
* @param[in] m mat2s (2x2, matrix)
|
||||
* @param[in] c vec2s (1x2, column vector)
|
||||
*
|
||||
* @return[out] Scalar value (float, 1x1)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
@@ -259,18 +271,4 @@ glms_mat2_(rmc)(vec2s r, mat2s m, vec2s c) {
|
||||
return glm_mat2_rmc(r.raw, m.raw, c.raw);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create mat2 matrix from pointer
|
||||
*
|
||||
* @param[in] src pointer to an array of floats
|
||||
* @return constructed matrix from raw pointer
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat2s
|
||||
glms_mat2_(make)(const float * __restrict src) {
|
||||
mat2s r;
|
||||
glm_mat2_make(src, r.raw);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* cglms_mat2_h */
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
CGLM_INLINE mat3s glms_mat3_swap_row(mat3s mat, int row1, int row2);
|
||||
CGLM_INLINE float glms_mat3_rmc(vec3s r, mat3s m, vec3s c);
|
||||
CGLM_INLINE mat3s glms_mat3_make(const float * __restrict src);
|
||||
CGLM_INLINE mat3s glms_mat3_textrans(float sx, float sy, float rot, float tx, float ty);
|
||||
*/
|
||||
|
||||
#ifndef cglms_mat3s_h
|
||||
@@ -300,4 +301,22 @@ glms_mat3_(make)(const float * __restrict src) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create mat3 matrix from texture transform parameters
|
||||
*
|
||||
* @param[in] sx scale x
|
||||
* @param[in] sy scale y
|
||||
* @param[in] rot rotation in radians CCW/RH
|
||||
* @param[in] tx translate x
|
||||
* @param[in] ty translate y
|
||||
* @return texture transform matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat3s
|
||||
glms_mat3_(textrans)(float sx, float sy, float rot, float tx, float ty) {
|
||||
mat3s r;
|
||||
glm_mat3_textrans(sx, sy, rot, tx, ty, r.raw);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* cglms_mat3s_h */
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
CGLM_INLINE mat4s glms_mat4_swap_row(mat4s mat, int row1, int row2);
|
||||
CGLM_INLINE float glms_mat4_rmc(vec4s r, mat4s m, vec4s c);
|
||||
CGLM_INLINE mat4s glms_mat4_make(const float * __restrict src);
|
||||
CGLM_INLINE mat4s glms_mat4_textrans(float sx, float sy, float rot, float tx, float ty);
|
||||
*/
|
||||
|
||||
#ifndef cglms_mat4s_h
|
||||
@@ -474,4 +475,22 @@ glms_mat4_(make)(const float * __restrict src) {
|
||||
return r;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Create mat4 matrix from texture transform parameters
|
||||
*
|
||||
* @param[in] sx scale x
|
||||
* @param[in] sy scale y
|
||||
* @param[in] rot rotation in radians CCW/RH
|
||||
* @param[in] tx translate x
|
||||
* @param[in] ty translate y
|
||||
* @return texture transform matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat4s
|
||||
glms_mat4_(textrans)(float sx, float sy, float rot, float tx, float ty) {
|
||||
mat4s r;
|
||||
glm_mat4_textrans(sx, sy, rot, tx, ty, r.raw);
|
||||
return r;
|
||||
}
|
||||
|
||||
#endif /* cglms_mat4s_h */
|
||||
|
||||
@@ -144,6 +144,7 @@ glm_vec2_isnan(vec2 v) {
|
||||
#ifndef CGLM_FAST_MATH
|
||||
return isnan(v[0]) || isnan(v[1]);
|
||||
#else
|
||||
(void)v;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -160,6 +161,7 @@ glm_vec2_isinf(vec2 v) {
|
||||
#ifndef CGLM_FAST_MATH
|
||||
return isinf(v[0]) || isinf(v[1]);
|
||||
#else
|
||||
(void)v;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
CGLM_INLINE void glm_vec2_make(float * restrict src, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_reflect(vec2 v, vec2 n, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest)
|
||||
CGLM_INLINE void glm_vec2_swap(vec2 a, vec2 b)
|
||||
*/
|
||||
|
||||
#ifndef cglm_vec2_h
|
||||
@@ -795,4 +796,16 @@ glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two vectors
|
||||
* @param a the first vector to swap
|
||||
* @param b the second vector to swap
|
||||
*/
|
||||
CGLM_INLINE void glm_vec2_swap(vec2 a, vec2 b) {
|
||||
vec2 tmp;
|
||||
glm_vec2_copy(a, tmp);
|
||||
glm_vec2_copy(b, a);
|
||||
glm_vec2_copy(tmp, b);
|
||||
}
|
||||
|
||||
#endif /* cglm_vec2_h */
|
||||
|
||||
@@ -179,6 +179,7 @@ glm_vec3_isnan(vec3 v) {
|
||||
#ifndef CGLM_FAST_MATH
|
||||
return isnan(v[0]) || isnan(v[1]) || isnan(v[2]);
|
||||
#else
|
||||
(void)v;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -195,6 +196,7 @@ glm_vec3_isinf(vec3 v) {
|
||||
#ifndef CGLM_FAST_MATH
|
||||
return isinf(v[0]) || isinf(v[1]) || isinf(v[2]);
|
||||
#else
|
||||
(void)v;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@
|
||||
CGLM_INLINE void glm_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_reflect(vec3 v, vec3 n, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
|
||||
CGLM_INLINE void glm_vec3_swap(vec3 a, vec3 b)
|
||||
|
||||
Convenient:
|
||||
CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d);
|
||||
@@ -1261,4 +1262,16 @@ glm_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two vectors
|
||||
* @param a the first vector to swap
|
||||
* @param b the second vector to swap
|
||||
*/
|
||||
CGLM_INLINE void glm_vec3_swap(vec3 a, vec3 b) {
|
||||
vec3 tmp;
|
||||
glm_vec3_copy(a, tmp);
|
||||
glm_vec3_copy(b, a);
|
||||
glm_vec3_copy(tmp, b);
|
||||
}
|
||||
|
||||
#endif /* cglm_vec3_h */
|
||||
|
||||
@@ -193,6 +193,7 @@ glm_vec4_isnan(vec4 v) {
|
||||
#ifndef CGLM_FAST_MATH
|
||||
return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]);
|
||||
#else
|
||||
(void)v;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
@@ -209,6 +210,7 @@ glm_vec4_isinf(vec4 v) {
|
||||
#ifndef CGLM_FAST_MATH
|
||||
return isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3]);
|
||||
#else
|
||||
(void)v;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
CGLM_INLINE void glm_vec4_make(float * restrict src, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_reflect(vec4 v, vec4 n, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
|
||||
CGLM_INLINE void glm_vec4_swap(vec4 a, vec4 b)
|
||||
|
||||
DEPRECATED:
|
||||
glm_vec4_dup
|
||||
@@ -1345,4 +1346,16 @@ glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swap two vectors
|
||||
* @param a the first vector to swap
|
||||
* @param b the second vector to swap
|
||||
*/
|
||||
CGLM_INLINE void glm_vec4_swap(vec4 a, vec4 b) {
|
||||
vec4 tmp;
|
||||
glm_vec4_copy(a, tmp);
|
||||
glm_vec4_copy(b, a);
|
||||
glm_vec4_copy(tmp, b);
|
||||
}
|
||||
|
||||
#endif /* cglm_vec4_h */
|
||||
|
||||
12
src/cam.c
12
src/cam.c
@@ -62,6 +62,12 @@ glmc_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) {
|
||||
glm_perspective(fovy, aspect, nearZ, farZ, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_infinite(float fovy, float aspect, float nearZ, mat4 dest) {
|
||||
glm_perspective_infinite(fovy, aspect, nearZ, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_persp_move_far(mat4 proj, float deltaFar) {
|
||||
@@ -74,6 +80,12 @@ glmc_perspective_default(float aspect, mat4 dest) {
|
||||
glm_perspective_default(aspect, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_default_infinite(float aspect, mat4 dest) {
|
||||
glm_perspective_default_infinite(aspect, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize(float aspect, mat4 proj) {
|
||||
|
||||
@@ -34,6 +34,12 @@ glmc_perspective_lh_no(float fovy,
|
||||
dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_lh_no(float aspect, mat4 proj) {
|
||||
glm_perspective_resize_lh_no(aspect, proj);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_persp_move_far_lh_no(mat4 proj, float deltaFar) {
|
||||
|
||||
@@ -34,6 +34,12 @@ glmc_perspective_lh_zo(float fovy,
|
||||
dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_lh_zo(float aspect, mat4 proj) {
|
||||
glm_perspective_resize_lh_zo(aspect, proj);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar) {
|
||||
|
||||
@@ -34,6 +34,12 @@ glmc_perspective_rh_no(float fovy,
|
||||
dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_rh_no(float aspect, mat4 proj) {
|
||||
glm_perspective_resize_rh_no(aspect, proj);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_persp_move_far_rh_no(mat4 proj, float deltaFar) {
|
||||
|
||||
@@ -34,6 +34,12 @@ glmc_perspective_rh_zo(float fovy,
|
||||
dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_perspective_resize_rh_zo(float aspect, mat4 proj) {
|
||||
glm_perspective_resize_rh_zo(aspect, proj);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar) {
|
||||
|
||||
62
src/mat2.c
62
src/mat2.c
@@ -8,6 +8,12 @@
|
||||
#include "../include/cglm/cglm.h"
|
||||
#include "../include/cglm/call.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_make(const float * __restrict src, mat2 dest) {
|
||||
glm_mat2_make(src, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_copy(mat2 mat, mat2 dest) {
|
||||
@@ -16,20 +22,20 @@ glmc_mat2_copy(mat2 mat, mat2 dest) {
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_identity(mat2 mat) {
|
||||
glm_mat2_identity(mat);
|
||||
glmc_mat2_identity(mat2 m) {
|
||||
glm_mat2_identity(m);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_identity_array(mat2 * __restrict mat, size_t count) {
|
||||
glm_mat2_identity_array(mat, count);
|
||||
glmc_mat2_identity_array(mat2 * __restrict mats, size_t count) {
|
||||
glm_mat2_identity_array(mats, count);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_zero(mat2 mat) {
|
||||
glm_mat2_zero(mat);
|
||||
glmc_mat2_zero(mat2 m) {
|
||||
glm_mat2_zero(m);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
@@ -40,8 +46,14 @@ glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest) {
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_transpose_to(mat2 m, mat2 dest) {
|
||||
glm_mat2_transpose_to(m, dest);
|
||||
glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest) {
|
||||
glm_mat2_mulv(m, v, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_transpose_to(mat2 mat, mat2 dest) {
|
||||
glm_mat2_transpose_to(mat, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
@@ -50,30 +62,12 @@ glmc_mat2_transpose(mat2 m) {
|
||||
glm_mat2_transpose(m);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest) {
|
||||
glm_mat2_mulv(m, v, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_trace(mat2 m) {
|
||||
return glm_mat2_trace(m);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_scale(mat2 m, float s) {
|
||||
glm_mat2_scale(m, s);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_det(mat2 mat) {
|
||||
return glm_mat2_det(mat);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_inv(mat2 mat, mat2 dest) {
|
||||
@@ -94,12 +88,18 @@ glmc_mat2_swap_row(mat2 mat, int row1, int row2) {
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) {
|
||||
return glm_mat2_rmc(r, m, c);
|
||||
glmc_mat2_det(mat2 m) {
|
||||
return glm_mat2_det(m);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat2_make(const float * __restrict src, mat2 dest) {
|
||||
glm_mat2_make(src, dest);
|
||||
float
|
||||
glmc_mat2_trace(mat2 m) {
|
||||
return glm_mat2_trace(m);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) {
|
||||
return glm_mat2_rmc(r, m, c);
|
||||
}
|
||||
|
||||
@@ -109,3 +109,9 @@ void
|
||||
glmc_mat3_make(const float * __restrict src, mat3 dest) {
|
||||
glm_mat3_make(src, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest) {
|
||||
glm_mat3_textrans(sx, sy, rot, tx, ty, dest);
|
||||
}
|
||||
|
||||
@@ -169,3 +169,9 @@ void
|
||||
glmc_mat4_make(const float * __restrict src, mat4 dest) {
|
||||
glm_mat4_make(src, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest) {
|
||||
glm_mat4_textrans(sx, sy, rot, tx, ty, dest);
|
||||
}
|
||||
|
||||
@@ -356,3 +356,9 @@ bool
|
||||
glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
|
||||
return glm_vec2_refract(v, n, eta, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec2_swap(vec2 a, vec2 b) {
|
||||
glm_vec2_swap(a, b);
|
||||
}
|
||||
|
||||
@@ -501,3 +501,9 @@ bool
|
||||
glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
|
||||
return glm_vec3_refract(v, n, eta, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_swap(vec3 a, vec3 b) {
|
||||
glm_vec3_swap(a, b);
|
||||
}
|
||||
|
||||
@@ -459,3 +459,9 @@ bool
|
||||
glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
|
||||
return glm_vec4_refract(v, n, eta, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_swap(vec4 a, vec4 b) {
|
||||
glm_vec4_swap(a, b);
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ test_assert_mat4_eq(mat4 m1, mat4 m2) {
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ test_assert_mat4_eqt(mat4 m1, mat4 m2) {
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ test_assert_mat2_eqt(mat2 m1, mat2 m2) {
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009);
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ test_assert_mat2_eq(mat2 m1, mat2 m2) {
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009);
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ test_assert_mat2x3_eq(mat2x3 m1, mat2x3 m2) {
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ test_assert_mat2x4_eq(mat2x4 m1, mat2x4 m2) {
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ test_assert_mat3_eq(mat3 m1, mat3 m2) {
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009);
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ test_assert_mat3_eqt(mat3 m1, mat3 m2) {
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009);
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ test_assert_mat3x2_eq(mat3x2 m1, mat3x2 m2) {
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ test_assert_mat3x4_eq(mat3x4 m1, mat3x4 m2) {
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ test_assert_mat4x2_eq(mat4x2 m1, mat4x2 m2) {
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ test_assert_mat4x3_eq(mat4x3 m1, mat4x3 m2) {
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,24 +509,24 @@ test_assert_mat4x3_eq(mat4x3 m1, mat4x3 m2) {
|
||||
|
||||
test_status_t
|
||||
test_assert_eqf(float a, float b) {
|
||||
ASSERT(fabsf(a - b) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(a - b) <= 0.000009f); /* rounding errors */
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_vec2_eq(vec2 v1, vec2 v2) {
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_vec3_eq(vec3 v1, vec3 v2) {
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009f);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -540,10 +540,10 @@ test_assert_vec3s_eq(vec3s v1, vec3s v2) {
|
||||
|
||||
test_status_t
|
||||
test_assert_vec4_eq(vec4 v1, vec4 v2) {
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009f);
|
||||
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009f);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -557,20 +557,20 @@ test_assert_vec4s_eq(vec4s v1, vec4s v2) {
|
||||
|
||||
test_status_t
|
||||
test_assert_quat_eq_abs(versor v1, versor v2) {
|
||||
ASSERT(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */
|
||||
ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009);
|
||||
ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009);
|
||||
ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009);
|
||||
ASSERT(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009f); /* rounding errors */
|
||||
ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009f);
|
||||
ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009f);
|
||||
ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009f);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_quat_eq(versor v1, versor v2) {
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009f);
|
||||
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009f);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -579,10 +579,10 @@ test_status_t
|
||||
test_assert_quat_eq_identity(versor q) {
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
ASSERT(fabsf(q[0] - p[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(q[1] - p[1]) <= 0.000009);
|
||||
ASSERT(fabsf(q[2] - p[2]) <= 0.000009);
|
||||
ASSERT(fabsf(q[3] - p[3]) <= 0.000009);
|
||||
ASSERT(fabsf(q[0] - p[0]) <= 0.000009f); /* rounding errors */
|
||||
ASSERT(fabsf(q[1] - p[1]) <= 0.000009f);
|
||||
ASSERT(fabsf(q[2] - p[2]) <= 0.000009f);
|
||||
ASSERT(fabsf(q[3] - p[3]) <= 0.000009f);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -327,4 +327,26 @@ TEST_IMPL(GLM_PREFIX, mat3_make) {
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_textrans) {
|
||||
mat3 m, expected;
|
||||
float sx = 2.0f, sy = 3.0f, rot = GLM_PI_4f;
|
||||
float tx = 10.0f, ty = 20.0f;
|
||||
|
||||
GLM(mat3_textrans)(sx, sy, rot, tx, ty, m);
|
||||
|
||||
ASSERT(test_eq(m[0][0], cosf(rot) * sx))
|
||||
ASSERT(test_eq(m[0][1],-sinf(rot) * sy))
|
||||
ASSERT(test_eq(m[1][0], sinf(rot) * sx))
|
||||
ASSERT(test_eq(m[1][1], cosf(rot) * sy))
|
||||
ASSERT(test_eq(m[2][0], tx))
|
||||
ASSERT(test_eq(m[2][1], ty))
|
||||
|
||||
GLM(mat3_textrans)(1.0f, 1.0f, 0.0f, 0.0f, 0.0f, m);
|
||||
GLM(mat3_identity)(expected);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eq(m, expected))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
#undef A_MATRIX
|
||||
|
||||
@@ -504,5 +504,27 @@ TEST_IMPL(GLM_PREFIX, mat4_make) {
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_textrans) {
|
||||
mat4 m, expected;
|
||||
float sx = 2.0f, sy = 3.0f, rot = GLM_PI_4f;
|
||||
float tx = 10.0f, ty = 20.0f;
|
||||
|
||||
GLM(mat4_textrans)(sx, sy, rot, tx, ty, m);
|
||||
|
||||
ASSERT(test_eq(m[0][0], cosf(rot) * sx))
|
||||
ASSERT(test_eq(m[0][1],-sinf(rot) * sy))
|
||||
ASSERT(test_eq(m[1][0], sinf(rot) * sx))
|
||||
ASSERT(test_eq(m[1][1], cosf(rot) * sy))
|
||||
ASSERT(test_eq(m[3][0], tx))
|
||||
ASSERT(test_eq(m[3][1], ty))
|
||||
|
||||
GLM(mat4_textrans)(1.0f, 1.0f, 0.0f, 0.0f, 0.0f, m);
|
||||
GLM(mat4_identity)(expected);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq(m, expected))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
#undef A_MATRIX
|
||||
#undef A_MATRIX3
|
||||
|
||||
@@ -27,13 +27,13 @@ TEST_IMPL(GLM_PREFIX, unprojecti) {
|
||||
/* unprojected of projected vector must be same as original one */
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
#ifndef CGLM_FAST_MATH
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01)
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01f)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01f)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01f)
|
||||
#else
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1)
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1f)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1f)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1f)
|
||||
#endif
|
||||
|
||||
TEST_SUCCESS
|
||||
@@ -58,13 +58,13 @@ TEST_IMPL(GLM_PREFIX, unproject) {
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
|
||||
#ifndef CGLM_FAST_MATH
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01)
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01f)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01f)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01f)
|
||||
#else
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1)
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1f)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1f)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1f)
|
||||
#endif
|
||||
|
||||
TEST_SUCCESS
|
||||
@@ -89,13 +89,13 @@ TEST_IMPL(GLM_PREFIX, project) {
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
|
||||
#ifndef CGLM_FAST_MATH
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01)
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01f)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01f)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01f)
|
||||
#else
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1)
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1f)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1f)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1f)
|
||||
#endif
|
||||
|
||||
/* test with no projection */
|
||||
|
||||
@@ -20,7 +20,7 @@ TEST_IMPL(GLM_PREFIX, ray_triangle) {
|
||||
|
||||
hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d);
|
||||
ASSERT(hit);
|
||||
ASSERT(fabsf(d - 5.0f) <= 0.0000009);
|
||||
ASSERT(fabsf(d - 5.0f) <= 0.0000009f);
|
||||
|
||||
/* Check whether a simple miss works */
|
||||
hit = GLM(ray_triangle)(origin, opposite, v0, v1, v2, &d);
|
||||
@@ -65,9 +65,9 @@ TEST_IMPL(GLM_PREFIX, ray_at) {
|
||||
glm_vec3_normalize(direction);
|
||||
|
||||
GLM(ray_at)(origin, direction, distance, result);
|
||||
ASSERT(fabsf(result[0] - 1.0f) <= 0.0000009); /* Expecting to be 1 unit along the x-axis */
|
||||
ASSERT(fabsf(result[1] - 1.0f) <= 0.0000009); /* Expecting to be 1 unit along the y-axis */
|
||||
ASSERT(fabsf(result[2] - 1.0f) <= 0.0000009); /* Expecting to be 1 unit along the z-axis */
|
||||
ASSERT(fabsf(result[0] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the x-axis */
|
||||
ASSERT(fabsf(result[1] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the y-axis */
|
||||
ASSERT(fabsf(result[2] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the z-axis */
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ TEST_DECLARE(glm_mat4_swap_col)
|
||||
TEST_DECLARE(glm_mat4_swap_row)
|
||||
TEST_DECLARE(glm_mat4_rmc)
|
||||
TEST_DECLARE(glm_mat4_make)
|
||||
TEST_DECLARE(glm_mat4_textrans)
|
||||
|
||||
TEST_DECLARE(glmc_mat4_ucopy)
|
||||
TEST_DECLARE(glmc_mat4_copy)
|
||||
@@ -218,6 +219,7 @@ TEST_DECLARE(glm_mat3_swap_col)
|
||||
TEST_DECLARE(glm_mat3_swap_row)
|
||||
TEST_DECLARE(glm_mat3_rmc)
|
||||
TEST_DECLARE(glm_mat3_make)
|
||||
TEST_DECLARE(glm_mat3_textrans)
|
||||
|
||||
TEST_DECLARE(glmc_mat3_copy)
|
||||
TEST_DECLARE(glmc_mat3_identity)
|
||||
@@ -1355,7 +1357,8 @@ TEST_LIST {
|
||||
TEST_ENTRY(glm_mat4_swap_row)
|
||||
TEST_ENTRY(glm_mat4_rmc)
|
||||
TEST_ENTRY(glm_mat4_make)
|
||||
|
||||
TEST_ENTRY(glm_mat4_textrans)
|
||||
|
||||
TEST_ENTRY(glmc_mat4_ucopy)
|
||||
TEST_ENTRY(glmc_mat4_copy)
|
||||
TEST_ENTRY(glmc_mat4_identity)
|
||||
@@ -1437,6 +1440,7 @@ TEST_LIST {
|
||||
TEST_ENTRY(glm_mat3_swap_row)
|
||||
TEST_ENTRY(glm_mat3_rmc)
|
||||
TEST_ENTRY(glm_mat3_make)
|
||||
TEST_ENTRY(glm_mat3_textrans)
|
||||
|
||||
TEST_ENTRY(glmc_mat3_copy)
|
||||
TEST_ENTRY(glmc_mat3_identity)
|
||||
|
||||
Reference in New Issue
Block a user