Compare commits

...

19 Commits

Author SHA1 Message Date
Recep Aslantas
ef0dd289bb update version 2017-12-17 15:56:16 +03:00
Recep Aslantas
4052943a0d matrix: make accurate inv version default
* now the glm_mat4_inv_precise is deault, because I don't think all people are aware of this func
* the old behavior (fast) replaced with new func: glm_mat4_inv_fast

if fast version is desired then glm_mat4_inv_fast must be used.
2017-12-17 15:49:00 +03:00
Recep Aslantas
33fefb9454 ci, travis: fix coveralls installation 2017-12-07 20:57:53 +03:00
Recep Aslantas
008de93d03 decompose projection matrix into near, far, left, right, top and bottom 2017-11-24 11:07:26 +03:00
Recep Aslantas
171668085d fix decompose near / far values from projection 2017-11-23 17:44:51 +03:00
Recep Aslantas
1907ba1046 decompose perspective near and far values 2017-11-23 17:16:29 +03:00
Recep Aslantas
39e1c35c79 convenient macros for UP vector for lookAt 2017-11-22 10:44:17 +03:00
Recep Aslantas
be605e6100 update ignore file 2017-11-22 10:42:01 +03:00
Recep Aslantas
b8897befa6 test: fix mat4 tests 2017-11-18 11:38:13 +03:00
Recep Aslantas
1b872375ab test: fix generating random matrix 2017-11-17 20:57:36 +03:00
Recep Aslantas
c998ec13d8 test: fix comparing matrix results 2017-11-17 19:05:33 +03:00
Recep Aslantas
b9c135baf2 test: fix generating random matrix
* use affine matrix for testing
2017-11-17 18:50:24 +03:00
Recep Aslantas
efb37ab0f7 vec: helper / special macros for initializing white and black colors 2017-11-11 15:51:17 +03:00
Recep Aslantas
b4cfc2a84a Merge branch 'master' of https://github.com/recp/cglm 2017-10-27 00:21:11 +03:00
Recep Aslantas
9fe48b34a7 inverse (opposite) of vectors 2017-10-27 00:20:41 +03:00
Recep Aslantas
8955a22059 Merge pull request #8 from smx-smx/master
Fixed missing alignment on MinGW + GCC
2017-08-26 23:42:09 +03:00
smx-smx
02ec0a1948 Fixed missing alignment on MinGW + GCC 2017-08-26 21:04:06 +02:00
Recep Aslantas
48977a012b test: add some tests for mat4 2017-07-12 20:46:05 +03:00
Recep Aslantas
208c1d92f2 Update README.md 2017-07-11 18:37:21 +03:00
17 changed files with 359 additions and 39 deletions

3
.gitignore vendored
View File

@@ -57,3 +57,6 @@ test/tests
cglm_arm/* cglm_arm/*
cglm_test_ios/* cglm_test_ios/*
cglm_test_iosTests/* cglm_test_iosTests/*
docs/build/*
win/cglm_test_*
* copy.*

View File

@@ -36,9 +36,6 @@ branches:
only: only:
- master - master
before_install:
- pip install --user cpp-coveralls
script: script:
- sh ./build-deps.sh - sh ./build-deps.sh
- sh ./autogen.sh - sh ./autogen.sh
@@ -52,6 +49,7 @@ script:
after_success: after_success:
- if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then - if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then
pip install --user cpp-coveralls
coveralls coveralls
--build-root . --build-root .
--exclude lib --exclude lib

View File

@@ -58,8 +58,8 @@ Almost all functions are marked inline (always_inline) so compiler probably will
To call pre-compiled version, just use `glmc_` (c stands for 'call') instead of `glm_`. To call pre-compiled version, just use `glmc_` (c stands for 'call') instead of `glm_`.
```C ```C
#include <cglm.h> /* for inline */ #include <cglm/cglm.h> /* for inline */
#include <cglm-call.h> /* for library call (this also includes cglm.h) */ #include <cglm/call.h> /* for library call (this also includes cglm.h) */
mat4 rot, trans, rt; mat4 rot, trans, rt;
/* ... */ /* ... */
@@ -125,7 +125,7 @@ $ devenv cglm.sln /Build Release
## How to use ## How to use
If you want to use inline versions of funcstions then; include main header If you want to use inline versions of funcstions then; include main header
```C ```C
#include <cglm.h> #include <cglm/cglm.h>
``` ```
the haeder will include all headers. Then call func you want e.g. rotate vector by axis: the haeder will include all headers. Then call func you want e.g. rotate vector by axis:
```C ```C
@@ -144,7 +144,7 @@ like this function you may see `_to` postfix, this functions store results to an
to call pre-compiled versions include header with `c` postfix, c means call. Pre-compiled versions are just wrappers. to call pre-compiled versions include header with `c` postfix, c means call. Pre-compiled versions are just wrappers.
```C ```C
#include <cglm-call.h> #include <cglm/call.h>
``` ```
this header will include all heaers with c postfix. You need to call functions with c posfix: this header will include all heaers with c postfix. You need to call functions with c posfix:
```C ```C
@@ -158,9 +158,9 @@ Function usage and parameters are documented inside related headers.
- If headers are not working properly with your compiler, IDE please open an issue, because I'm using GCC and clang to test it maybe sometimes MSVC - If headers are not working properly with your compiler, IDE please open an issue, because I'm using GCC and clang to test it maybe sometimes MSVC
**TODO:** **TODO:**
- [ ] Unit tests - [ ] Unit tests (In Progress)
- [ ] Unit tests for comparing cglm with glm results - [ ] Unit tests for comparing cglm with glm results
- [x] Add version info - [x] Add version info
- [ ] Unaligned operations (e.g. `glm_umat4_mul`) - [ ] Unaligned operations (e.g. `glm_umat4_mul`)
- [ ] Extra documentation - [ ] Extra documentation
- [ ] ARM Neon Arch - [ ] ARM Neon Arch (In Progress)

View File

@@ -64,6 +64,14 @@ CGLM_EXPORT
void void
glmc_vec_flipsign(vec3 v); glmc_vec_flipsign(vec3 v);
CGLM_EXPORT
void
glmc_vec_inv(vec3 v);
CGLM_EXPORT
void
glmc_vec_inv_to(vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_angle(vec3 v1, vec3 v2); glmc_vec_angle(vec3 v1, vec3 v2);

View File

@@ -65,6 +65,14 @@ CGLM_EXPORT
void void
glmc_vec4_flipsign(vec4 v); glmc_vec4_flipsign(vec4 v);
CGLM_EXPORT
void
glmc_vec4_inv(vec4 v);
CGLM_EXPORT
void
glmc_vec4_inv_to(vec4 v, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_distance(vec4 v1, vec4 v2); glmc_vec4_distance(vec4 v1, vec4 v2);

View File

@@ -31,6 +31,25 @@
CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest); CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest);
CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj); 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_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest);
CGLM_INLINE void glm_persp_decomp(mat4 proj,
float * __restrict near,
float * __restrict far,
float * __restrict top,
float * __restrict bottom,
float * __restrict left,
float * __restrict right);
CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6]);
CGLM_INLINE void glm_persp_decomp_x(mat4 proj,
float * __restrict left,
float * __restrict right);
CGLM_INLINE void glm_persp_decomp_y(mat4 proj,
float * __restrict top,
float * __restrict bottom);
CGLM_INLINE void glm_persp_decomp_z(mat4 proj,
float * __restrict near,
float * __restrict far);
CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float * __restrict far);
CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float * __restrict near);
*/ */
#ifndef cglm_vcam_h #ifndef cglm_vcam_h
@@ -281,4 +300,126 @@ glm_lookat(vec3 eye,
dest[3][3] = 1.0f; dest[3][3] = 1.0f;
} }
/*!
* @brief decomposes frustum values of perspective projection.
*
* @param[in] proj perspective projection matrix
* @param[out] near near
* @param[out] far far
* @param[out] top top
* @param[out] bottom bottom
* @param[out] left left
* @param[out] right right
*/
CGLM_INLINE
void
glm_persp_decomp(mat4 proj,
float * __restrict near,
float * __restrict far,
float * __restrict top,
float * __restrict bottom,
float * __restrict left,
float * __restrict right) {
*near = proj[3][2] / (proj[2][2] - 1);
*far = proj[3][2] / (proj[2][2] + 1);
*bottom = *near * (proj[2][1] - 1) / proj[1][1];
*top = *near * (proj[2][1] + 1) / proj[1][1];
*left = *near * (proj[2][0] - 1) / proj[0][0];
*right = *near * (proj[2][0] + 1) / proj[0][0];
}
/*!
* @brief decomposes frustum values of perspective projection.
* this makes easy to get all values at once
*
* @param[in] proj perspective projection matrix
* @param[out] dest array
*/
CGLM_INLINE
void
glm_persp_decompv(mat4 proj, float dest[6]) {
glm_persp_decomp(proj, &dest[0], &dest[1], &dest[2],
&dest[3], &dest[4], &dest[5]);
}
/*!
* @brief decomposes left and right values of perspective projection.
* x stands for x axis (left / right axis)
*
* @param[in] proj perspective projection matrix
* @param[out] left left
* @param[out] right right
*/
CGLM_INLINE
void
glm_persp_decomp_x(mat4 proj,
float * __restrict left,
float * __restrict right) {
float near;
near = proj[3][2] / (proj[3][3] - 1);
*left = near * (proj[2][0] - 1) / proj[0][0];
*right = near * (proj[2][0] + 1) / proj[0][0];
}
/*!
* @brief decomposes top and bottom values of perspective projection.
* y stands for y axis (top / botom axis)
*
* @param[in] proj perspective projection matrix
* @param[out] top top
* @param[out] bottom bottom
*/
CGLM_INLINE
void
glm_persp_decomp_y(mat4 proj,
float * __restrict top,
float * __restrict bottom) {
float near;
near = proj[3][2] / (proj[3][3] - 1);
*bottom = near * (proj[2][1] - 1) / proj[1][1];
*top = near * (proj[2][1] + 1) / proj[1][1];
}
/*!
* @brief decomposes near and far values of perspective projection.
* z stands for z axis (near / far axis)
*
* @param[in] proj perspective projection matrix
* @param[out] near near
* @param[out] far far
*/
CGLM_INLINE
void
glm_persp_decomp_z(mat4 proj,
float * __restrict near,
float * __restrict far) {
*near = proj[3][2] / (proj[2][2] - 1);
*far = proj[3][2] / (proj[2][2] + 1);
}
/*!
* @brief decomposes far value of perspective projection.
*
* @param[in] proj perspective projection matrix
* @param[out] far far
*/
CGLM_INLINE
void
glm_persp_decomp_far(mat4 proj, float * __restrict far) {
*far = proj[3][2] / (proj[2][2] + 1);
}
/*!
* @brief decomposes near value of perspective projection.
*
* @param[in] proj perspective projection matrix
* @param[out] near near
*/
CGLM_INLINE
void
glm_persp_decomp_near(mat4 proj, float * __restrict near) {
*near = proj[3][2] / (proj[2][2] - 1);
}
#endif /* cglm_vcam_h */ #endif /* cglm_vcam_h */

View File

@@ -36,7 +36,7 @@
CGLM_INLINE void glm_mat4_scale(mat4 m, float s); CGLM_INLINE void glm_mat4_scale(mat4 m, float s);
CGLM_INLINE float glm_mat4_det(mat4 mat); CGLM_INLINE float glm_mat4_det(mat4 mat);
CGLM_INLINE void glm_mat4_inv(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_inv(mat4 mat, mat4 dest);
CGLM_INLINE void glm_mat4_inv_precise(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_inv_fast(mat4 mat, mat4 dest);
CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2); CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2);
CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2); CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2);
*/ */
@@ -78,6 +78,9 @@
#define glm_mat4_udup(mat, dest) glm_mat4_ucopy(mat, dest) #define glm_mat4_udup(mat, dest) glm_mat4_ucopy(mat, dest)
#define glm_mat4_dup(mat, dest) glm_mat4_copy(mat, dest) #define glm_mat4_dup(mat, dest) glm_mat4_copy(mat, dest)
/* DEPRECATED! default is precise now. */
#define glm_mat4_inv_precise(mat, dest) glm_mat4_inv(mat, dest)
/*! /*!
* @brief copy all members of [mat] to [dest] * @brief copy all members of [mat] to [dest]
* *
@@ -448,10 +451,6 @@ glm_mat4_det(mat4 mat) {
/*! /*!
* @brief inverse mat4 and store in dest * @brief inverse mat4 and store in dest
* *
* this func uses reciprocal approximation without extra corrections
* e.g Newton-Raphson. this should work faster than _precise,
* to get precise value use _precise version
*
* @param[in] mat matrix * @param[in] mat matrix
* @param[out] dest inverse matrix * @param[out] dest inverse matrix
*/ */
@@ -504,22 +503,23 @@ glm_mat4_inv(mat4 mat, mat4 dest) {
#endif #endif
} }
/*! /*!
* @brief inverse mat4 precisely and store in dest * @brief inverse mat4 and store in dest
* *
* this do same thing as glm_mat4_inv did. the only diff is this func uses * this func uses reciprocal approximation without extra corrections
* division instead of reciprocal approximation. Due to division this might * e.g Newton-Raphson. this should work faster than normal,
* work slower than glm_mat4_inv * to get more precise use glm_mat4_inv version.
*
* NOTE: You will lose precision, glm_mat4_inv is more accurate
* *
* @param[in] mat matrix * @param[in] mat matrix
* @param[out] dest inverse matrix * @param[out] dest inverse matrix
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_inv_precise(mat4 mat, mat4 dest) { glm_mat4_inv_fast(mat4 mat, mat4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glm_mat4_inv_precise_sse2(mat, dest); glm_mat4_inv_fast_sse2(mat, dest);
#else #else
glm_mat4_inv(mat, dest); glm_mat4_inv(mat, dest);
#endif #endif

View File

@@ -12,6 +12,8 @@
#include "../../common.h" #include "../../common.h"
#include "../intrin.h" #include "../intrin.h"
#define glm_mat4_inv_precise_sse2(mat, dest) glm_mat4_inv_sse2(mat, dest)
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_scale_sse2(mat4 m, float s){ glm_mat4_scale_sse2(mat4 m, float s){
@@ -157,7 +159,7 @@ glm_mat4_det_sse2(mat4 mat) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_inv_sse2(mat4 mat, mat4 dest) { glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) {
__m128 r0, r1, r2, r3, __m128 r0, r1, r2, r3,
v0, v1, v2, v3, v0, v1, v2, v3,
t0, t1, t2, t3, t4, t5, t0, t1, t2, t3, t4, t5,
@@ -281,7 +283,7 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_inv_precise_sse2(mat4 mat, mat4 dest) { glm_mat4_inv_sse2(mat4 mat, mat4 dest) {
__m128 r0, r1, r2, r3, __m128 r0, r1, r2, r3,
v0, v1, v2, v3, v0, v1, v2, v3,
t0, t1, t2, t3, t4, t5, t0, t1, t2, t3, t4, t5,

View File

@@ -8,7 +8,7 @@
#ifndef cglm_types_h #ifndef cglm_types_h
#define cglm_types_h #define cglm_types_h
#if defined(_WIN32) #if defined(_MSC_VER)
# define CGLM_ALIGN(X) /* __declspec(align(X)) */ # define CGLM_ALIGN(X) /* __declspec(align(X)) */
#else #else
# define CGLM_ALIGN(X) __attribute((aligned(X))) # define CGLM_ALIGN(X) __attribute((aligned(X)))

View File

@@ -13,6 +13,11 @@
/* /*
Macros: Macros:
glm_vec_dup(v, dest) glm_vec_dup(v, dest)
GLM_VEC3_ONE_INIT
GLM_VEC3_ONE
GLM_YUP
GLM_ZUP
GLM_XUP
Functions: Functions:
CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest); CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest);
@@ -25,6 +30,8 @@
CGLM_INLINE void glm_vec_scale(vec3 v, float s, vec3 dest); CGLM_INLINE void glm_vec_scale(vec3 v, float s, vec3 dest);
CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest); CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest);
CGLM_INLINE void glm_vec_flipsign(vec3 v); CGLM_INLINE void glm_vec_flipsign(vec3 v);
CGLM_INLINE void glm_vec_inv(vec3 v);
CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec_normalize(vec3 v); CGLM_INLINE void glm_vec_normalize(vec3 v);
CGLM_INLINE void glm_vec_normalize_to(vec3 vec, vec3 dest); CGLM_INLINE void glm_vec_normalize_to(vec3 vec, vec3 dest);
CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2); CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2);
@@ -45,6 +52,13 @@
/* DEPRECATED! use _copy, _ucopy versions */ /* DEPRECATED! use _copy, _ucopy versions */
#define glm_vec_dup(v, dest) glm_vec_copy(v, dest) #define glm_vec_dup(v, dest) glm_vec_copy(v, dest)
#define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f}
#define GLM_VEC3_ONE (vec3)GLM_VEC3_ONE_INIT
#define GLM_YUP (vec3){0.0f, 1.0f, 0.0f}
#define GLM_ZUP (vec3){0.0f, 0.0f, 1.0f}
#define GLM_XUP (vec3){1.0f, 0.0f, 0.0f}
/*! /*!
* @brief copy all members of [a] to [dest] * @brief copy all members of [a] to [dest]
* *
@@ -198,6 +212,30 @@ glm_vec_flipsign(vec3 v) {
v[2] = -v[2]; v[2] = -v[2];
} }
/*!
* @brief make vector as inverse/opposite of itself
*
* @param[in, out] v vector
*/
CGLM_INLINE
void
glm_vec_inv(vec3 v) {
glm_vec_flipsign(v);
}
/*!
* @brief inverse/opposite vector
*
* @param[in] v source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec_inv_to(vec3 v, vec3 dest) {
glm_vec_copy(v, dest);
glm_vec_flipsign(dest);
}
/*! /*!
* @brief normalize vec3 and store result in same vec * @brief normalize vec3 and store result in same vec
* *

View File

@@ -14,6 +14,10 @@
Macros: Macros:
glm_vec4_dup3(v, dest) glm_vec4_dup3(v, dest)
glm_vec4_dup(v, dest) glm_vec4_dup(v, dest)
GLM_VEC4_ONE_INIT
GLM_VEC4_BLACK_INIT
GLM_VEC4_ONE
GLM_VEC4_BLACK
Functions: Functions:
CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest);
@@ -26,6 +30,8 @@
CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest);
CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest);
CGLM_INLINE void glm_vec4_flipsign(vec4 v); CGLM_INLINE void glm_vec4_flipsign(vec4 v);
CGLM_INLINE void glm_vec4_inv(vec4 v);
CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest);
CGLM_INLINE void glm_vec4_normalize(vec4 v); CGLM_INLINE void glm_vec4_normalize(vec4 v);
CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest); CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest);
CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2);
@@ -42,6 +48,12 @@
#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) #define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest)
#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) #define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest)
#define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f}
#define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f}
#define GLM_VEC4_ONE (vec4)GLM_VEC4_ONE_INIT
#define GLM_VEC4_BLACK (vec4)GLM_VEC4_BLACK_INIT
/*! /*!
* @brief copy first 3 members of [a] to [dest] * @brief copy first 3 members of [a] to [dest]
* *
@@ -225,6 +237,30 @@ glm_vec4_flipsign(vec4 v) {
#endif #endif
} }
/*!
* @brief make vector as inverse/opposite of itself
*
* @param[in, out] v vector
*/
CGLM_INLINE
void
glm_vec4_inv(vec4 v) {
glm_vec4_flipsign(v);
}
/*!
* @brief inverse/opposite vector
*
* @param[in] v source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_inv_to(vec4 v, vec4 dest) {
glm_vec4_copy(v, dest);
glm_vec4_flipsign(dest);
}
/*! /*!
* @brief normalize vec4 and store result in same vec * @brief normalize vec4 and store result in same vec
* *

View File

@@ -9,7 +9,7 @@
#define cglm_version_h #define cglm_version_h
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 2 #define CGLM_VERSION_MINOR 3
#define CGLM_VERSION_PATCH 1 #define CGLM_VERSION_PATCH 1
#endif /* cglm_version_h */ #endif /* cglm_version_h */

View File

@@ -80,6 +80,18 @@ glmc_vec_flipsign(vec3 v) {
glm_vec_flipsign(v); glm_vec_flipsign(v);
} }
CGLM_EXPORT
void
glmc_vec_inv(vec3 v) {
glm_vec_inv(v);
}
CGLM_EXPORT
void
glmc_vec_inv_to(vec3 v, vec3 dest) {
glm_vec_inv_to(v, dest);
}
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_angle(vec3 v1, vec3 v2) { glmc_vec_angle(vec3 v1, vec3 v2) {

View File

@@ -80,6 +80,18 @@ glmc_vec4_flipsign(vec4 v) {
glm_vec4_flipsign(v); glm_vec4_flipsign(v);
} }
CGLM_EXPORT
void
glmc_vec4_inv(vec4 v) {
glm_vec4_inv(v);
}
CGLM_EXPORT
void
glmc_vec4_inv_to(vec4 v, vec4 dest) {
glm_vec4_inv_to(v, dest);
}
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_distance(vec4 v1, vec4 v2) { glmc_vec4_distance(vec4 v1, vec4 v2) {

View File

@@ -6,31 +6,47 @@
#include "test_common.h" #include "test_common.h"
#include <stdlib.h> #include <stdlib.h>
#define m 4
#define n 4
void void
test_rand_mat4(mat4 dest) { test_rand_mat4(mat4 dest) {
int i, j; glm_mat4_copy(GLM_MAT4_IDENTITY, dest);
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) { /* random position */
dest[i][j] = drand48(); dest[3][0] = drand48();
} dest[3][1] = drand48();
} dest[3][2] = drand48();
/* random rotatation around random axis with random angle */
glm_rotate(dest, drand48(), (vec3){drand48(), drand48(), drand48()});
/* random scale */
/* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */
} }
void void
test_assert_mat4_eq(mat4 m1, mat4 m2) { test_assert_mat4_eq(mat4 m1, mat4 m2) {
int i, j, k; int i, j, k;
#define m 4
#define n 4
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) { for (j = 0; j < n; j++) {
for (k = 0; k < m; k++) for (k = 0; k < m; k++)
assert_true(fabsf(m1[i][j] - m2[i][j]) <= FLT_EPSILON); assert_true(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009);
} }
} }
#undef m
#undef n
} }
void
test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) {
int i, j, k;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
for (k = 0; k < m; k++)
assert_true(fabsf(m1[i][j] - m2[i][j]) <= eps);
}
}
}

View File

@@ -28,4 +28,7 @@ test_rand_mat4(mat4 dest);
void void
test_assert_mat4_eq(mat4 m1, mat4 m2); test_assert_mat4_eq(mat4 m1, mat4 m2);
void
test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps);
#endif /* test_common_h */ #endif /* test_common_h */

View File

@@ -16,6 +16,7 @@ test_mat4(void **state) {
mat4 m2 = GLM_MAT4_IDENTITY_INIT; mat4 m2 = GLM_MAT4_IDENTITY_INIT;
mat4 m3; mat4 m3;
mat4 m4 = GLM_MAT4_ZERO_INIT; mat4 m4 = GLM_MAT4_ZERO_INIT;
mat4 m5;
int i, j, k; int i, j, k;
/* test identity matrix multiplication */ /* test identity matrix multiplication */
@@ -48,4 +49,46 @@ test_mat4(void **state) {
/* test pre compiled */ /* test pre compiled */
glmc_mat4_mul(m1, m2, m3); glmc_mat4_mul(m1, m2, m3);
test_assert_mat4_eq(m3, m4); test_assert_mat4_eq(m3, m4);
for (i = 0; i < 100000; i++) {
test_rand_mat4(m3);
test_rand_mat4(m4);
/* test inverse precise */
glm_mat4_inv_precise(m3, m4);
glm_mat4_inv_precise(m4, m5);
test_assert_mat4_eq(m3, m5);
test_rand_mat4(m3);
test_rand_mat4(m4);
glmc_mat4_inv_precise(m3, m4);
glmc_mat4_inv_precise(m4, m5);
test_assert_mat4_eq(m3, m5);
/* test inverse rcp */
test_rand_mat4(m3);
test_rand_mat4(m4);
glm_mat4_inv_fast(m3, m4);
glm_mat4_inv_fast(m4, m5);
test_assert_mat4_eq2(m3, m5, 0.0009f);
test_rand_mat4(m3);
test_rand_mat4(m4);
glmc_mat4_inv(m3, m4);
glmc_mat4_inv(m4, m5);
test_assert_mat4_eq2(m3, m5, 0.0009f);
}
/* print */
glm_mat4_print(m3, stderr);
glm_mat4_print(m4, stderr);
/* test determinant */
assert_int_equal(glm_mat4_det(m1), glmc_mat4_det(m1));
#if defined( __SSE2__ )
assert_int_equal(glmc_mat4_det(m1), glm_mat4_det_sse2(m1));
#endif
} }