Compare commits

...

19 Commits

Author SHA1 Message Date
Recep Aslantas
0356534c0c Merge pull request #488 from lesleyrs/wextra
fix -ffast-math with -Wextra warnings
2026-01-31 14:44:49 +03:00
lesleyrs
5ff0d80c85 fix -ffast-math with -Wextra warnings 2026-01-22 16:09:11 +01:00
Recep Aslantas
1952042f2c Merge pull request #487 from tayoky/master
add glm_vecx_swap functions
2025-11-19 23:44:21 +03:00
tayoky
3aad5823ca add glm_vecx_swap functions 2025-11-15 10:39:14 +01:00
Recep Aslantas
da957fa421 Merge pull request #483 from Lephar/master
Add missing glmc_perspective_resize_**_**() call/clipspace functions
2025-11-08 17:41:00 +03:00
Ali Emre Gülcü
47e5d48749 Add missing glmc_perspective_resize_**_**() call/clipspace functions 2025-11-05 09:56:28 +03:00
Recep Aslantas
a4602f2d5f Merge pull request #478 from fd00/fix-make
Fix `make` on `srcdir != builddir`
2025-06-18 17:44:56 +03:00
Daisuke Fujimura (fd0)
6af4e0d565 Fix make on srcdir != builddir 2025-06-18 20:55:40 +09:00
Recep Aslantas
a311dbfe4c Merge pull request #476 from aganm/double-promotion
Fix double-promotion warnings in tests
2025-05-13 12:33:55 +03:00
Michael Aganier
a761088e15 Fix double-promotion warnings in tests 2025-05-12 17:38:21 -04:00
Recep Aslantas
a886d6e170 Merge pull request #471 from under-view/feature/mat3-tables
mat3: add tables to docs & fix comments
2025-04-24 16:07:51 +03:00
Recep Aslantas
1a8b105ce6 Merge pull request #472 from under-view/mat2-docs-cleanup
mat2: docs cleanup
2025-04-24 16:07:31 +03:00
Vincent Davis Jr
ec5f8074c4 mat2: docs cleanup
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2025-04-17 18:08:50 -04:00
Vincent Davis Jr
6f5fde8b52 mat3: add tables to docs & fix comments
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2025-04-17 14:22:00 -04:00
Recep Aslantas
9da4e78c2e Merge pull request #469 from under-view/feature/mat2-tables
mat2: add tables to docs & fix comments
2025-04-11 17:14:17 +03:00
Vincent Davis Jr
27a3ddc928 gitignore: ignore vim swp files
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2025-04-11 00:13:55 -04:00
Vincent Davis Jr
5d530cd8e0 mat2: add tables to docs & fix comments
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2025-04-11 00:13:54 -04:00
Vincent Davis Jr
dde053a295 mat2x3[docs]: fix glm_mat2x3_zero parameters
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2025-04-05 09:58:49 -04:00
Recep Aslantas
2128235d42 Merge pull request #467 from recp/textrans
build texture transform matrix helper
2025-04-05 13:52:15 +03:00
32 changed files with 2387 additions and 623 deletions

1
.gitignore vendored
View File

@@ -82,3 +82,4 @@ cmake-build-debug
xcode/* xcode/*
.vscode .vscode
.build .build
*.swp

View File

@@ -23,7 +23,7 @@ checkCFLAGS = $(AM_CFLAGS) \
-std=gnu11 \ -std=gnu11 \
-O3 \ -O3 \
-DCGLM_DEFINE_PRINTS \ -DCGLM_DEFINE_PRINTS \
-I./include -I$(srcdir)/include
check_PROGRAMS = test/tests check_PROGRAMS = test/tests
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)

File diff suppressed because it is too large Load Diff

View File

@@ -63,7 +63,7 @@ Functions documentation
Zero out the mat2x3 (m). Zero out the mat2x3 (m).
Parameters: Parameters:
| *[in, out]* **mat** mat2x3 (src, dest) | *[in, out]* **m** mat2x3 (src, dest)
.. csv-table:: mat2x3 **(m)** .. csv-table:: mat2x3 **(m)**
:header: "", "column 1", "column 2" :header: "", "column 1", "column 2"

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,10 @@ glmc_perspective_lh_no(float fovy,
float farVal, float farVal,
mat4 dest); mat4 dest);
CGLM_EXPORT
void
glmc_perspective_resize_lh_no(float aspect, mat4 proj);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_lh_no(mat4 proj, float deltaFar); glmc_persp_move_far_lh_no(mat4 proj, float deltaFar);

View File

@@ -28,6 +28,10 @@ glmc_perspective_lh_zo(float fovy,
float farVal, float farVal,
mat4 dest); mat4 dest);
CGLM_EXPORT
void
glmc_perspective_resize_lh_zo(float aspect, mat4 proj);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar); glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar);

View File

@@ -28,6 +28,10 @@ glmc_perspective_rh_no(float fovy,
float farVal, float farVal,
mat4 dest); mat4 dest);
CGLM_EXPORT
void
glmc_perspective_resize_rh_no(float aspect, mat4 proj);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_rh_no(mat4 proj, float deltaFar); glmc_persp_move_far_rh_no(mat4 proj, float deltaFar);

View File

@@ -28,6 +28,10 @@ glmc_perspective_rh_zo(float fovy,
float farVal, float farVal,
mat4 dest); mat4 dest);
CGLM_EXPORT
void
glmc_perspective_resize_rh_zo(float aspect, mat4 proj);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar); glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar);

View File

@@ -13,21 +13,25 @@ extern "C" {
#include "../cglm.h" #include "../cglm.h"
CGLM_EXPORT
void
glmc_mat2_make(const float * __restrict src, mat2 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_copy(mat2 mat, mat2 dest); glmc_mat2_copy(mat2 mat, mat2 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_identity(mat2 mat); glmc_mat2_identity(mat2 m);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_identity_array(mat2 * __restrict mat, size_t count); glmc_mat2_identity_array(mat2 * __restrict mats, size_t count);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_zero(mat2 mat); glmc_mat2_zero(mat2 m);
CGLM_EXPORT CGLM_EXPORT
void void
@@ -35,28 +39,20 @@ glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest);
CGLM_EXPORT CGLM_EXPORT
void 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 CGLM_EXPORT
void void
glmc_mat2_transpose(mat2 m); 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 CGLM_EXPORT
void void
glmc_mat2_scale(mat2 m, float s); glmc_mat2_scale(mat2 m, float s);
CGLM_EXPORT
float
glmc_mat2_det(mat2 mat);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_inv(mat2 mat, mat2 dest); glmc_mat2_inv(mat2 mat, mat2 dest);
@@ -71,11 +67,15 @@ glmc_mat2_swap_row(mat2 mat, int row1, int row2);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c); glmc_mat2_trace(mat2 m);
CGLM_EXPORT CGLM_EXPORT
void float
glmc_mat2_make(const float * __restrict src, mat2 dest); glmc_mat2_det(mat2 m);
CGLM_EXPORT
float
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -245,6 +245,10 @@ CGLM_EXPORT
bool bool
glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest); glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_swap(vec2 a, vec2 b);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -363,6 +363,10 @@ CGLM_EXPORT
bool bool
glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest); glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_swap(vec3 a, vec3 b);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -336,6 +336,10 @@ CGLM_EXPORT
bool bool
glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest); glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_swap(vec4 a, vec4 b);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -13,22 +13,22 @@
GLM_MAT2_ZERO GLM_MAT2_ZERO
Functions: 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_copy(mat2 mat, mat2 dest)
CGLM_INLINE void glm_mat2_identity(mat2 mat) CGLM_INLINE void glm_mat2_identity(mat2 m)
CGLM_INLINE void glm_mat2_identity_array(mat2 * restrict mat, size_t count) CGLM_INLINE void glm_mat2_identity_array(mat2 * restrict mats, size_t count)
CGLM_INLINE void glm_mat2_zero(mat2 mat) 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_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 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 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_inv(mat2 mat, mat2 dest)
CGLM_INLINE void glm_mat2_swap_col(mat2 mat, int col1, int col2) 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 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 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 #ifndef cglm_mat2_h
@@ -57,10 +57,25 @@
#define GLM_MAT2_ZERO ((mat2)GLM_MAT2_ZERO_INIT) #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[in] src pointer to an array of floats (left)
* @param[out] dest destination * @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 CGLM_INLINE
void 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 * but it is more easy to do that with this func especially for members
* e.g. glm_mat2_identity(aStruct->aMatrix); * e.g. glm_mat2_identity(aStruct->aMatrix);
* *
@@ -80,59 +97,57 @@ glm_mat2_copy(mat2 mat, mat2 dest) {
* mat2 mat = GLM_MAT2_IDENTITY_INIT; * mat2 mat = GLM_MAT2_IDENTITY_INIT;
* @endcode * @endcode
* *
* @param[in, out] mat destination * @param[in, out] m mat2 (src, dest)
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_mat2_identity(mat2 mat) { glm_mat2_identity(mat2 m) {
CGLM_ALIGN_MAT mat2 t = GLM_MAT2_IDENTITY_INIT; 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 mat2s (mats) make each matrix an identity matrix.
* *
* @param[in, out] mat matrix array (must be aligned (16) * @param[in, out] mats Array of mat2s (must be aligned (16/32) if alignment is not disabled)
* if alignment is not disabled) * @param[in] count Array size of mats or number of matrices
*
* @param[in] count count of matrices
*/ */
CGLM_INLINE CGLM_INLINE
void 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; CGLM_ALIGN_MAT mat2 t = GLM_MAT2_IDENTITY_INIT;
size_t i; size_t i;
for (i = 0; i < count; 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 CGLM_INLINE
void void
glm_mat2_zero(mat2 mat) { glm_mat2_zero(mat2 m) {
CGLM_ALIGN_MAT mat2 t = GLM_MAT2_ZERO_INIT; 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 * @code
* mat2 m = GLM_MAT2_IDENTITY_INIT; * mat2 m = GLM_MAT2_IDENTITY_INIT;
* glm_mat2_mul(m, m, m); * glm_mat2_mul(m, m, m);
* @endcode * @endcode
* *
* @param[in] m1 left matrix * @param[in] m1 mat2 (left)
* @param[in] m2 right matrix * @param[in] m2 mat2 (right)
* @param[out] dest destination matrix * @param[out] dest destination (result, mat2)
*/ */
CGLM_INLINE CGLM_INLINE
void 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 mat2 (left)
* * @param[in] v vec2 (right, column vector)
* @param[in] m matrix * @param[out] dest destination (result, column vector)
* @param[out] dest result
*/ */
CGLM_INLINE CGLM_INLINE
void 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__) #if defined(__wasm__) && defined(__wasm_simd128__)
glm_mat2_transp_wasm(m, dest); glm_mat2_transp_wasm(mat, dest);
#elif defined( __SSE__ ) || defined( __SSE2__ ) #elif defined( __SSE__ ) || defined( __SSE2__ )
glm_mat2_transp_sse2(m, dest); glm_mat2_transp_sse2(mat, dest);
#else #else
dest[0][0] = m[0][0]; dest[0][0] = mat[0][0];
dest[0][1] = m[1][0]; dest[0][1] = mat[1][0];
dest[1][0] = m[0][1]; dest[1][0] = mat[0][1];
dest[1][1] = m[1][1]; dest[1][1] = mat[1][1];
#endif #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 CGLM_INLINE
void 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, out] m mat2 (src, dest)
* @param[in] v vec2 (right, column vector) * @param[in] s float (scalar)
* @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
*/ */
CGLM_INLINE CGLM_INLINE
void 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 * @param[in] mat mat2 (left, src)
* * @param[out] dest destination (result, inverse mat2)
* @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
*/ */
CGLM_INLINE CGLM_INLINE
void 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, out] mat mat2 (src, dest)
* @param[in] col1 col1 * @param[in] col1 Column 1 array index
* @param[in] col2 col2 * @param[in] col2 Column 2 array index
*/ */
CGLM_INLINE CGLM_INLINE
void 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, out] mat mat2 (src, dest)
* @param[in] row1 row1 * @param[in] row1 Row 1 array index
* @param[in] row2 row2 * @param[in] row2 Row 2 array index
*/ */
CGLM_INLINE CGLM_INLINE
void 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), * @return[out] mat2 determinant (float)
* then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar) */
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 * The sum of the elements on the main diagonal from
* @param[in] m matrix2x2 * upper left corner to the bottom right corner.
* @param[in] c column vector or matrix2x1
* *
* @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 CGLM_INLINE
float float
@@ -346,19 +360,4 @@ glm_mat2_rmc(vec2 r, mat2 m, vec2 c) {
return glm_vec2_dot(r, tmp); 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 */ #endif /* cglm_mat2_h */

View File

@@ -13,21 +13,20 @@
GLM_MAT2_ZERO GLM_MAT2_ZERO
Functions: 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_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 #ifndef cglms_mat2_h
@@ -48,7 +47,23 @@
#define GLMS_MAT2_ZERO ((mat2s)GLMS_MAT2_ZERO_INIT) #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 * but it is more easy to do that with this func especially for members
* e.g. glm_mat2_identity(aStruct->aMatrix); * e.g. glm_mat2_identity(aStruct->aMatrix);
* *
@@ -59,7 +74,7 @@
* mat2 mat = GLM_MAT2_IDENTITY_INIT; * mat2 mat = GLM_MAT2_IDENTITY_INIT;
* @endcode * @endcode
* *
* @returns identity matrix * @return[out] r constructed mat2s from raw pointer
*/ */
CGLM_INLINE CGLM_INLINE
mat2s mat2s
@@ -70,28 +85,26 @@ glms_mat2_(identity)(void) {
} }
/*! /*!
* @brief make given matrix array's each element identity matrix * @brief Given an array of mat2ss (mats) make each matrix an identity matrix.
* *
* @param[in, out] mat matrix array (must be aligned (16) * @param[in, out] mats Array of mat2ss (must be aligned (16/32) if alignment is not disabled)
* if alignment is not disabled) * @param[in] count Array size of mats or number of matrices
*
* @param[in] count count of matrices
*/ */
CGLM_INLINE CGLM_INLINE
void 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; CGLM_ALIGN_MAT mat2s t = GLMS_MAT2_IDENTITY_INIT;
size_t i; size_t i;
for (i = 0; i < count; 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 CGLM_INLINE
mat2s 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 * @code
* mat2 m = GLM_MAT2_IDENTITY_INIT; * mat2 m = GLM_MAT2_IDENTITY_INIT;
* r = glms_mat2_mul(m, m); * mat2s r = glms_mat2_mul(m, m);
* @endcode * @endcode
* *
* @param[in] m1 left matrix * @param[in] m1 mat2s (left)
* @param[in] m2 right matrix * @param[in] m2 mat2s (right)
* * @return[out] r constructed mat2s from raw pointers
* @returns destination matrix
*/ */
CGLM_INLINE CGLM_INLINE
mat2s mat2s
@@ -124,26 +136,12 @@ glms_mat2_(mul)(mat2s m1, mat2s m2) {
return r; return r;
} }
/*! /*
* @brief transpose mat2 * @brief Multiply mat2s (m) by vec2s (v) and return in vec2s (r).
* *
* @param[in] m matrix to transpose * @param[in] m mat2s (left)
* * @param[in] v vec2s (right, column vector)
* @returns transposed matrix * @return[out] r constructed vec2s from raw pointers
*/
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)
*/ */
CGLM_INLINE CGLM_INLINE
vec2s 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 mat2s (src)
* * @return[out] m constructed mat2s from raw pointers
* @param[in] m matrix
*/ */
CGLM_INLINE CGLM_INLINE
float mat2s
glms_mat2_(trace)(mat2s m) { glms_mat2_(transpose)(mat2s m) {
return glm_mat2_trace(m.raw); 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] m mat2s (src)
* * @param[in] s scalar value
* @param[in, out] m matrix * @return[out] m constructed mat2s from raw pointers
* @param[in] s scalar
* @returns matrix
*/ */
CGLM_INLINE CGLM_INLINE
mat2s 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 * @param[in] m mat2s (left, src)
* * @return[out] r constructed mat2s from raw pointers
* @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
*/ */
CGLM_INLINE CGLM_INLINE
mat2s mat2s
glms_mat2_(inv)(mat2s mat) { glms_mat2_(inv)(mat2s m) {
mat2s r; mat2s r;
glm_mat2_inv(mat.raw, r.raw); glm_mat2_inv(m.raw, r.raw);
return r; 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] mat mat2s
* @param[in] col1 col1 * @param[in] col1 column 1 array index
* @param[in] col2 col2 * @param[in] col2 column 2 array index
* @returns matrix * @return[out] mat constructed mat2s from raw pointers columns swapped
*/ */
CGLM_INLINE CGLM_INLINE
mat2s 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] mat mat2s
* @param[in] row1 row1 * @param[in] row1 row 1 array index
* @param[in] row2 row2 * @param[in] row2 row 2 array index
* @returns matrix * @return[out] mat constructed mat2s from raw pointers rows swapped
*/ */
CGLM_INLINE CGLM_INLINE
mat2s 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), * @return[out] mat2s raw pointers determinant (float)
* then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar) */
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 * The sum of the elements on the main diagonal from
* @param[in] m matrix2x2 * upper left corner to the bottom right corner.
* @param[in] c column vector or matrix2x1
* *
* @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 CGLM_INLINE
float float
@@ -259,18 +271,4 @@ glms_mat2_(rmc)(vec2s r, mat2s m, vec2s c) {
return glm_mat2_rmc(r.raw, m.raw, c.raw); 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 */ #endif /* cglms_mat2_h */

View File

@@ -144,6 +144,7 @@ glm_vec2_isnan(vec2 v) {
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
return isnan(v[0]) || isnan(v[1]); return isnan(v[0]) || isnan(v[1]);
#else #else
(void)v;
return false; return false;
#endif #endif
} }
@@ -160,6 +161,7 @@ glm_vec2_isinf(vec2 v) {
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
return isinf(v[0]) || isinf(v[1]); return isinf(v[0]) || isinf(v[1]);
#else #else
(void)v;
return false; return false;
#endif #endif
} }

View File

@@ -59,6 +59,7 @@
CGLM_INLINE void glm_vec2_make(float * restrict src, vec2 dest) 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_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_refract(vec2 v, vec2 n, float eta, vec2 dest)
CGLM_INLINE void glm_vec2_swap(vec2 a, vec2 b)
*/ */
#ifndef cglm_vec2_h #ifndef cglm_vec2_h
@@ -795,4 +796,16 @@ glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
return true; 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 */ #endif /* cglm_vec2_h */

View File

@@ -179,6 +179,7 @@ glm_vec3_isnan(vec3 v) {
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
return isnan(v[0]) || isnan(v[1]) || isnan(v[2]); return isnan(v[0]) || isnan(v[1]) || isnan(v[2]);
#else #else
(void)v;
return false; return false;
#endif #endif
} }
@@ -195,6 +196,7 @@ glm_vec3_isinf(vec3 v) {
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
return isinf(v[0]) || isinf(v[1]) || isinf(v[2]); return isinf(v[0]) || isinf(v[1]) || isinf(v[2]);
#else #else
(void)v;
return false; return false;
#endif #endif
} }

View File

@@ -82,6 +82,7 @@
CGLM_INLINE void glm_vec3_faceforward(vec3 n, vec3 v, vec3 nref, vec3 dest); 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_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_refract(vec3 v, vec3 n, float eta, vec3 dest);
CGLM_INLINE void glm_vec3_swap(vec3 a, vec3 b)
Convenient: Convenient:
CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); 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; 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 */ #endif /* cglm_vec3_h */

View File

@@ -193,6 +193,7 @@ glm_vec4_isnan(vec4 v) {
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]); return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]);
#else #else
(void)v;
return false; return false;
#endif #endif
} }
@@ -209,6 +210,7 @@ glm_vec4_isinf(vec4 v) {
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
return isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3]); return isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3]);
#else #else
(void)v;
return false; return false;
#endif #endif
} }

View File

@@ -66,6 +66,7 @@
CGLM_INLINE void glm_vec4_make(float * restrict src, vec4 dest); 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_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_refract(vec4 v, vec4 n, float eta, vec4 dest);
CGLM_INLINE void glm_vec4_swap(vec4 a, vec4 b)
DEPRECATED: DEPRECATED:
glm_vec4_dup glm_vec4_dup
@@ -1345,4 +1346,16 @@ glm_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
return true; 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 */ #endif /* cglm_vec4_h */

View File

@@ -34,6 +34,12 @@ glmc_perspective_lh_no(float fovy,
dest); dest);
} }
CGLM_EXPORT
void
glmc_perspective_resize_lh_no(float aspect, mat4 proj) {
glm_perspective_resize_lh_no(aspect, proj);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_lh_no(mat4 proj, float deltaFar) { glmc_persp_move_far_lh_no(mat4 proj, float deltaFar) {

View File

@@ -34,6 +34,12 @@ glmc_perspective_lh_zo(float fovy,
dest); dest);
} }
CGLM_EXPORT
void
glmc_perspective_resize_lh_zo(float aspect, mat4 proj) {
glm_perspective_resize_lh_zo(aspect, proj);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar) { glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar) {

View File

@@ -34,6 +34,12 @@ glmc_perspective_rh_no(float fovy,
dest); dest);
} }
CGLM_EXPORT
void
glmc_perspective_resize_rh_no(float aspect, mat4 proj) {
glm_perspective_resize_rh_no(aspect, proj);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_rh_no(mat4 proj, float deltaFar) { glmc_persp_move_far_rh_no(mat4 proj, float deltaFar) {

View File

@@ -34,6 +34,12 @@ glmc_perspective_rh_zo(float fovy,
dest); dest);
} }
CGLM_EXPORT
void
glmc_perspective_resize_rh_zo(float aspect, mat4 proj) {
glm_perspective_resize_rh_zo(aspect, proj);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar) { glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar) {

View File

@@ -8,6 +8,12 @@
#include "../include/cglm/cglm.h" #include "../include/cglm/cglm.h"
#include "../include/cglm/call.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 CGLM_EXPORT
void void
glmc_mat2_copy(mat2 mat, mat2 dest) { glmc_mat2_copy(mat2 mat, mat2 dest) {
@@ -16,20 +22,20 @@ glmc_mat2_copy(mat2 mat, mat2 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_identity(mat2 mat) { glmc_mat2_identity(mat2 m) {
glm_mat2_identity(mat); glm_mat2_identity(m);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_identity_array(mat2 * __restrict mat, size_t count) { glmc_mat2_identity_array(mat2 * __restrict mats, size_t count) {
glm_mat2_identity_array(mat, count); glm_mat2_identity_array(mats, count);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_zero(mat2 mat) { glmc_mat2_zero(mat2 m) {
glm_mat2_zero(mat); glm_mat2_zero(m);
} }
CGLM_EXPORT CGLM_EXPORT
@@ -40,8 +46,14 @@ glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_transpose_to(mat2 m, mat2 dest) { glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest) {
glm_mat2_transpose_to(m, 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 CGLM_EXPORT
@@ -50,30 +62,12 @@ glmc_mat2_transpose(mat2 m) {
glm_mat2_transpose(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 CGLM_EXPORT
void void
glmc_mat2_scale(mat2 m, float s) { glmc_mat2_scale(mat2 m, float s) {
glm_mat2_scale(m, s); glm_mat2_scale(m, s);
} }
CGLM_EXPORT
float
glmc_mat2_det(mat2 mat) {
return glm_mat2_det(mat);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat2_inv(mat2 mat, mat2 dest) { glmc_mat2_inv(mat2 mat, mat2 dest) {
@@ -94,12 +88,18 @@ glmc_mat2_swap_row(mat2 mat, int row1, int row2) {
CGLM_EXPORT CGLM_EXPORT
float float
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) { glmc_mat2_det(mat2 m) {
return glm_mat2_rmc(r, m, c); return glm_mat2_det(m);
} }
CGLM_EXPORT CGLM_EXPORT
void float
glmc_mat2_make(const float * __restrict src, mat2 dest) { glmc_mat2_trace(mat2 m) {
glm_mat2_make(src, dest); return glm_mat2_trace(m);
}
CGLM_EXPORT
float
glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) {
return glm_mat2_rmc(r, m, c);
} }

View File

@@ -356,3 +356,9 @@ bool
glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) { glmc_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) {
return glm_vec2_refract(v, n, eta, dest); return glm_vec2_refract(v, n, eta, dest);
} }
CGLM_EXPORT
void
glmc_vec2_swap(vec2 a, vec2 b) {
glm_vec2_swap(a, b);
}

View File

@@ -501,3 +501,9 @@ bool
glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) { glmc_vec3_refract(vec3 v, vec3 n, float eta, vec3 dest) {
return glm_vec3_refract(v, n, eta, dest); return glm_vec3_refract(v, n, eta, dest);
} }
CGLM_EXPORT
void
glmc_vec3_swap(vec3 a, vec3 b) {
glm_vec3_swap(a, b);
}

View File

@@ -459,3 +459,9 @@ bool
glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) { glmc_vec4_refract(vec4 v, vec4 n, float eta, vec4 dest) {
return glm_vec4_refract(v, n, eta, dest); return glm_vec4_refract(v, n, eta, dest);
} }
CGLM_EXPORT
void
glmc_vec4_swap(vec4 a, vec4 b) {
glm_vec4_swap(a, b);
}

View File

@@ -176,7 +176,7 @@ test_assert_mat4_eq(mat4 m1, mat4 m2) {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) { 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 (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) { 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 (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) { 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 (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) { 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 (i = 0; i < 2; i++) {
for (j = 0; j < 3; j++) { 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 (i = 0; i < 2; i++) {
for (j = 0; j < 4; j++) { 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 (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) { 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 (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) { 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 (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) { 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 (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) { 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 (i = 0; i < 4; i++) {
for (j = 0; j < 2; j++) { 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 (i = 0; i < 4; i++) {
for (j = 0; j < 3; j++) { 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_status_t
test_assert_eqf(float a, float b) { 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_SUCCESS
} }
test_status_t test_status_t
test_assert_vec2_eq(vec2 v1, vec2 v2) { test_assert_vec2_eq(vec2 v1, vec2 v2) {
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
TEST_SUCCESS TEST_SUCCESS
} }
test_status_t test_status_t
test_assert_vec3_eq(vec3 v1, vec3 v2) { test_assert_vec3_eq(vec3 v1, vec3 v2) {
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009f);
TEST_SUCCESS TEST_SUCCESS
} }
@@ -540,10 +540,10 @@ test_assert_vec3s_eq(vec3s v1, vec3s v2) {
test_status_t test_status_t
test_assert_vec4_eq(vec4 v1, vec4 v2) { test_assert_vec4_eq(vec4 v1, vec4 v2) {
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009f);
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009); ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009f);
TEST_SUCCESS TEST_SUCCESS
} }
@@ -557,20 +557,20 @@ test_assert_vec4s_eq(vec4s v1, vec4s v2) {
test_status_t test_status_t
test_assert_quat_eq_abs(versor v1, versor v2) { 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[0]) - fabsf(v2[0])) <= 0.0009f); /* rounding errors */
ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009); ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009f);
ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009); ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009f);
ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009); ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009f);
TEST_SUCCESS TEST_SUCCESS
} }
test_status_t test_status_t
test_assert_quat_eq(versor v1, versor v2) { test_assert_quat_eq(versor v1, versor v2) {
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009f); /* rounding errors */
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009f);
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009f);
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009); ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009f);
TEST_SUCCESS TEST_SUCCESS
} }
@@ -579,10 +579,10 @@ test_status_t
test_assert_quat_eq_identity(versor q) { test_assert_quat_eq_identity(versor q) {
versor p = GLM_QUAT_IDENTITY_INIT; versor p = GLM_QUAT_IDENTITY_INIT;
ASSERT(fabsf(q[0] - p[0]) <= 0.000009); /* rounding errors */ ASSERT(fabsf(q[0] - p[0]) <= 0.000009f); /* rounding errors */
ASSERT(fabsf(q[1] - p[1]) <= 0.000009); ASSERT(fabsf(q[1] - p[1]) <= 0.000009f);
ASSERT(fabsf(q[2] - p[2]) <= 0.000009); ASSERT(fabsf(q[2] - p[2]) <= 0.000009f);
ASSERT(fabsf(q[3] - p[3]) <= 0.000009); ASSERT(fabsf(q[3] - p[3]) <= 0.000009f);
TEST_SUCCESS TEST_SUCCESS
} }

View File

@@ -27,13 +27,13 @@ TEST_IMPL(GLM_PREFIX, unprojecti) {
/* unprojected of projected vector must be same as original one */ /* unprojected of projected vector must be same as original one */
/* we used 0.01 because of projection floating point errors */ /* we used 0.01 because of projection floating point errors */
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01) ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01f)
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01f)
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01f)
#else #else
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1) ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1f)
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1) ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1f)
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1) ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1f)
#endif #endif
TEST_SUCCESS TEST_SUCCESS
@@ -58,13 +58,13 @@ TEST_IMPL(GLM_PREFIX, unproject) {
/* we used 0.01 because of projection floating point errors */ /* we used 0.01 because of projection floating point errors */
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01) ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01f)
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01f)
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01f)
#else #else
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1) ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1f)
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1) ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1f)
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1) ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1f)
#endif #endif
TEST_SUCCESS TEST_SUCCESS
@@ -89,13 +89,13 @@ TEST_IMPL(GLM_PREFIX, project) {
/* we used 0.01 because of projection floating point errors */ /* we used 0.01 because of projection floating point errors */
#ifndef CGLM_FAST_MATH #ifndef CGLM_FAST_MATH
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01) ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01f)
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01f)
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01f)
#else #else
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1) ASSERT(fabsf(pos[0] - unprojected[0]) < 0.1f)
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1) ASSERT(fabsf(pos[1] - unprojected[1]) < 0.1f)
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1) ASSERT(fabsf(pos[2] - unprojected[2]) < 0.1f)
#endif #endif
/* test with no projection */ /* test with no projection */

View File

@@ -20,7 +20,7 @@ TEST_IMPL(GLM_PREFIX, ray_triangle) {
hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d); hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d);
ASSERT(hit); ASSERT(hit);
ASSERT(fabsf(d - 5.0f) <= 0.0000009); ASSERT(fabsf(d - 5.0f) <= 0.0000009f);
/* Check whether a simple miss works */ /* Check whether a simple miss works */
hit = GLM(ray_triangle)(origin, opposite, v0, v1, v2, &d); 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_vec3_normalize(direction);
GLM(ray_at)(origin, direction, distance, result); 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[0] - 1.0f) <= 0.0000009f); /* 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[1] - 1.0f) <= 0.0000009f); /* 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[2] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the z-axis */
TEST_SUCCESS TEST_SUCCESS
} }