Compare commits

...
21 Commits
Author SHA1 Message Date
Recep Aslantas 888aca08d5 v0.9.7 2026-10-25 21:12:10 +03:00
Recep Aslantas 5390138d7f merge pull request #501 from tooold2rock-n-roll/tooold2rock-n-roll/500_glms_aabb2d_radius_bug
Tooold2rock n roll/500 glms aabb2d radius bug
2026-10-25 00:10:08 +03:00
Recep Aslantas 11d34be968 merge pull request #504 from fhgffy/fix/glm-spin-translation-502
affine: preserve translation in glm_spin
2026-10-25 00:02:24 +03:00
Recep Aslantas 1e65d6b52e merge pull request #505 from snowyukitty/fix/non-unit-quaternion-matrices
Fix non-unit quaternion rotation matrices
2026-10-24 23:48:26 +03:00
snowyukitty 8ff4f978c3 Fix non-unit quaternion rotation matrices 2026-10-10 03:59:20 +09:00
fhgffy d7b1e02778 affine: preserve translation in glm_spin 2026-10-04 20:31:02 +08:00
TooOld2Rock'nRoll 38a60f4f85 Adding vim files to gitignore. 2026-09-23 10:05:22 -03:00
TooOld2Rock'nRoll 81ec84493f Changing (size) for (diag) at aabb2d radius function. 2026-09-23 10:02:08 -03:00
Recep Aslantas 58d8c15a12 Merge pull request #499 from tooold2rock-n-roll/tooold2rock-n-roll/issue_n498_int2float_conversion_warnings
Fixing warning messages.
2026-07-29 18:21:01 +03:00
TooOld2Rock'nRoll bbd81a24d3 Fixing warning messages. 2026-07-29 10:37:03 -03:00
Recep Aslantas b7813d0edb Merge pull request #496 from 94xhn/fix/aabb-sphere-below-min-face-selection
box/aabb2d: fix wrong face selected below AABB min bound in sphere/circle test
2026-07-18 18:32:22 +03:00
94xhn 1c260ceb7d box/aabb2d: fix wrong face selected below AABB min bound in sphere/circle test
glm_aabb_sphere() and glm_aabb2d_circle() pick which box face to
measure axis distance to via `!(a - 1)`, where
`a = (s[i] < box[0][i]) + (s[i] > box[1][i])` is 1 for either
out-of-range direction. `!(a - 1)` always resolves to index 1
(the max face) whenever a == 1, so when the query point is below
the box's min bound on an axis, distance is measured to the wrong
(max) face instead of the min face, inflating dmin and producing
false-negative intersection results.

The above-max direction happens to pick the correct face already,
which is why this went unnoticed since the index-selection logic
was introduced in #180 (fix for #179).

Fix: index directly with the "above max" boolean
(s[i] > box[1][i]) instead of the derived !(a - 1) expression --
it's 0 for below-min (selects box[0], correct) and 1 for
above-max (selects box[1], correct), and is already computed as
part of `a`/`b`/`c` so no extra branching is introduced. Same fix
applied to both the 3D (box.h) and 2D (aabb2d.h) variants since
they share the identical pattern.

Verified against a hand-written Ericson/Graphics-Gems reference
point-AABB distance test: 200k randomized box/sphere fuzz cases
show 3418/200000 false negatives before this fix and 0/200000
after, with no change to the already-correct above-max and
fully-enclosed cases.
2026-07-18 18:06:58 +08:00
Recep Aslantas 49e4284773 build: add missing files 2026-07-16 16:56:37 +03:00
Recep Aslantas 46f46e5dcb Merge pull request #492 from FunkyAss/fix/call_api_pulls_inline
Fix "Call API pulls inline API"
2026-05-31 21:43:15 +03:00
Davide Del Zompo a97af506ce address review comments
- use relative includes for cglm/call/ headers
 - explicitly include stdio in cglm/call/io.h
 - update call documentation
2026-04-18 10:11:03 +03:00
Davide Del Zompo 454f032310 call API: don't include inline functions in header 2026-03-22 11:24:45 +02:00
Davide Del Zompo f0f05dadc5 Move glm_euler_seq to types.h 2026-03-22 11:11:46 +02:00
Recep Aslantas 83d5b2c973 docs: add infinite perspective 2026-02-10 22:59:46 +03:00
Recep Aslantas 7e1bdd0676 Merge pull request #489 from Lephar/master
Implement infinite perspective projection matrix creation functions
2026-02-10 22:45:21 +03:00
Ali Emre Gülcü 0dc17e5d47 Implement default infinite perspective projection matrix creation functions 2026-02-10 16:35:50 +03:00
Ali Emre Gülcü d6c6b4c542 Implement infinite perspective projection matrix creation functions 2026-02-10 12:30:11 +03:00
87 changed files with 745 additions and 164 deletions

No files matched your search

+3
View File
@@ -83,3 +83,6 @@ xcode/*
.vscode
.build
*.swp
.lastsession.vim
.vimrc
compile_commands.json
+1 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.13)
project(cglm
VERSION 0.9.6
VERSION 0.9.7
HOMEPAGE_URL https://github.com/recp/cglm
DESCRIPTION "OpenGL Mathematics (glm) for C"
LANGUAGES C
+2 -1
View File
@@ -79,7 +79,8 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/bezier.h \
include/cglm/applesimd.h \
include/cglm/ray.h \
include/cglm/affine2d.h
include/cglm/affine2d.h \
include/cglm/affine2d-post.h
cglm_clipspacedir=$(includedir)/cglm/clipspace
cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \
+1 -1
View File
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
# Description
s.name = "cglm"
s.version = "0.9.5"
s.version = "0.9.7"
s.summary = "📽 Highly Optimized Graphics Math (glm) for C"
s.description = <<-DESC
cglm is math library for graphics programming for C. See the documentation or README for all features.
+1 -1
View File
@@ -7,7 +7,7 @@
#*****************************************************************************
AC_PREREQ([2.69])
AC_INIT([cglm], [0.9.6], [[email protected]])
AC_INIT([cglm], [0.9.7], [[email protected]])
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects serial-tests])
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.
+3 -2
View File
@@ -15,5 +15,6 @@ It would be duplicate documentation also it
would be hard to sync documentation between inline and call version for me.
By including **clgm/cglm.h** you include all inline versions. To get precompiled
versions you need to include **cglm/call.h** header it also includes all
call versions plus *clgm/cglm.h* (inline versions)
versions you need to include **cglm/call.h** header. When using the
precompiled versions, explicitly including **cglm/cglm.h** is still necessary
for the inline versions to be included.
+31
View File
@@ -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 )
+2 -2
View File
@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
# built documents.
#
# The short X.Y version.
version = u'0.9.6'
version = u'0.9.7'
# The full version, including alpha/beta/rc tags.
release = u'0.9.6'
release = u'0.9.7'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
+2 -2
View File
@@ -235,8 +235,8 @@ glm_aabb2d_circle(vec2 aabb[2], vec3 c) {
a = (c[0] < aabb[0][0]) + (c[0] > aabb[1][0]);
b = (c[1] < aabb[0][1]) + (c[1] > aabb[1][1]);
dmin = glm_pow2((c[0] - aabb[!(a - 1)][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[!(b - 1)][1]) * (b != 0));
dmin = glm_pow2((c[0] - aabb[c[0] > aabb[1][0]][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[c[1] > aabb[1][1]][1]) * (b != 0));
return dmin <= glm_pow2(c[2]);
}
+1 -1
View File
@@ -297,7 +297,7 @@ CGLM_INLINE
void
glm_spin(mat4 m, float angle, vec3 axis) {
CGLM_ALIGN_MAT mat4 rot;
glm_rotate_atm(rot, m[3], angle, axis);
glm_rotate_make(rot, angle, axis);
glm_mat4_mul(m, rot, m);
}
+3 -3
View File
@@ -243,9 +243,9 @@ glm_aabb_sphere(vec3 box[2], vec4 s) {
b = (s[1] < box[0][1]) + (s[1] > box[1][1]);
c = (s[2] < box[0][2]) + (s[2] > box[1][2]);
dmin = glm_pow2((s[0] - box[!(a - 1)][0]) * (a != 0))
+ glm_pow2((s[1] - box[!(b - 1)][1]) * (b != 0))
+ glm_pow2((s[2] - box[!(c - 1)][2]) * (c != 0));
dmin = glm_pow2((s[0] - box[s[0] > box[1][0]][0]) * (a != 0))
+ glm_pow2((s[1] - box[s[1] > box[1][1]][1]) * (b != 0))
+ glm_pow2((s[2] - box[s[2] > box[1][2]][2]) * (c != 0));
return dmin <= glm_pow2(s[3]);
}
-1
View File
@@ -11,7 +11,6 @@
extern "C" {
#endif
#include "cglm.h"
#include "call/vec2.h"
#include "call/vec3.h"
#include "call/vec4.h"
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
/* DEPRECATED! use _diag */
#define glmc_aabb2d_size(aabb) glmc_aabb2d_diag(aabb)
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
float
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+9 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
@@ -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);
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../../cglm.h"
#include "../../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
float
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
float
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+2 -1
View File
@@ -12,7 +12,8 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
#include <stdio.h>
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
/* DEPRECATED! use _copy, _ucopy versions */
#define glmc_mat3_dup(mat, dest) glmc_mat3_copy(mat, dest)
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
/* DEPRECATED! use _copy, _ucopy versions */
#define glmc_mat4_udup(mat, dest) glmc_mat4_ucopy(mat, dest)
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
float
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+2 -1
View File
@@ -10,7 +10,8 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
bool
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
float
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
CGLM_EXPORT
void
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
/* DEPRECATED! use _copy, _ucopy versions */
#define glmc_vec_dup(v, dest) glmc_vec3_copy(v, dest)
+1 -1
View File
@@ -11,7 +11,7 @@
extern "C" {
#endif
#include "../cglm.h"
#include "../common.h"
/* DEPRECATED! use _copy, _ucopy versions */
#define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest)
+49 -1
View File
@@ -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
+47
View File
@@ -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
+49 -1
View File
@@ -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
+47
View File
@@ -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
+48
View File
@@ -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
-19
View File
@@ -83,25 +83,6 @@
# include "clipspace/view_rh_no.h"
#endif
/*!
* if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]...
* vector then you can convert it to this enum by doing this:
* @code
* glm_euler_seq order;
* order = orderVec[0] | orderVec[1] << 2 | orderVec[2] << 4;
* @endcode
* you may need to explicit cast if required
*/
typedef enum glm_euler_seq {
GLM_EULER_XYZ = 0 << 0 | 1 << 2 | 2 << 4,
GLM_EULER_XZY = 0 << 0 | 2 << 2 | 1 << 4,
GLM_EULER_YZX = 1 << 0 | 2 << 2 | 0 << 4,
GLM_EULER_YXZ = 1 << 0 | 0 << 2 | 2 << 4,
GLM_EULER_ZXY = 2 << 0 | 0 << 2 | 1 << 4,
GLM_EULER_ZYX = 2 << 0 | 1 << 2 | 0 << 4
} glm_euler_seq;
CGLM_INLINE
glm_euler_seq
glm_euler_order(int ord[3]) {
+40 -40
View File
@@ -482,22 +482,22 @@ glm_quat_mul(versor p, versor q, versor dest) {
CGLM_INLINE
void
glm_quat_mat4(versor q, mat4 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z,
xx, yy, zz,
xy, yz, xz,
wx, wy, wz, norm, s;
wx, wy, wz;
norm = glm_quat_norm(q);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
glm_quat_normalize_to(q, p);
x = q[0];
y = q[1];
z = q[2];
w = q[3];
x = p[0];
y = p[1];
z = p[2];
w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z;
xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz;
@@ -529,22 +529,22 @@ glm_quat_mat4(versor q, mat4 dest) {
CGLM_INLINE
void
glm_quat_mat4t(versor q, mat4 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z,
xx, yy, zz,
xy, yz, xz,
wx, wy, wz, norm, s;
wx, wy, wz;
norm = glm_quat_norm(q);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
glm_quat_normalize_to(q, p);
x = q[0];
y = q[1];
z = q[2];
w = q[3];
x = p[0];
y = p[1];
z = p[2];
w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z;
xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz;
@@ -576,22 +576,22 @@ glm_quat_mat4t(versor q, mat4 dest) {
CGLM_INLINE
void
glm_quat_mat3(versor q, mat3 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z,
xx, yy, zz,
xy, yz, xz,
wx, wy, wz, norm, s;
wx, wy, wz;
norm = glm_quat_norm(q);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
glm_quat_normalize_to(q, p);
x = q[0];
y = q[1];
z = q[2];
w = q[3];
x = p[0];
y = p[1];
z = p[2];
w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z;
xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz;
@@ -615,22 +615,22 @@ glm_quat_mat3(versor q, mat3 dest) {
CGLM_INLINE
void
glm_quat_mat3t(versor q, mat3 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z,
xx, yy, zz,
xy, yz, xz,
wx, wy, wz, norm, s;
wx, wy, wz;
norm = glm_quat_norm(q);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
glm_quat_normalize_to(q, p);
x = q[0];
y = q[1];
z = q[2];
w = q[3];
x = p[0];
y = p[1];
z = p[2];
w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z;
xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz;
+1 -1
View File
@@ -168,7 +168,7 @@ glms_aabb2d_(sizev)(vec2s aabb[2]) {
CGLM_INLINE
float
glms_aabb2d_(radius)(vec2s aabb[2]) {
return glms_aabb2d_(size)(aabb) * 0.5f;
return glms_aabb2d_(diag)(aabb) * 0.5f;
}
/*!
+19
View File
@@ -91,6 +91,25 @@ typedef CGLM_ALIGN_MAT vec4 mat4[4];
typedef vec2 mat4x2[4]; /* [col (4), row (2)] */
typedef vec3 mat4x3[4]; /* [col (4), row (3)] */
/*!
* if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]...
* vector then you can convert it to this enum by doing this:
* @code
* glm_euler_seq order;
* order = orderVec[0] | orderVec[1] << 2 | orderVec[2] << 4;
* @endcode
* you may need to explicit cast if required
*/
typedef enum glm_euler_seq {
GLM_EULER_XYZ = 0 << 0 | 1 << 2 | 2 << 4,
GLM_EULER_XZY = 0 << 0 | 2 << 2 | 1 << 4,
GLM_EULER_YZX = 1 << 0 | 2 << 2 | 0 << 4,
GLM_EULER_YXZ = 1 << 0 | 0 << 2 | 2 << 4,
GLM_EULER_ZXY = 2 << 0 | 0 << 2 | 1 << 4,
GLM_EULER_ZYX = 2 << 0 | 1 << 2 | 0 << 4
} glm_euler_seq;
/*
Important: cglm stores quaternion as [x, y, z, w] in memory since v0.4.0
it was [w, x, y, z] before v0.4.0 ( v0.3.5 and earlier ). w is real part.
+1 -1
View File
@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 9
#define CGLM_VERSION_PATCH 6
#define CGLM_VERSION_PATCH 7
#endif /* cglm_version_h */
+1 -1
View File
@@ -1,5 +1,5 @@
project('cglm', 'c',
version : '0.9.6',
version : '0.9.7',
license : 'mit',
default_options : [
'c_std=c11',
+12
View File
@@ -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) {
+44
View File
@@ -492,6 +492,50 @@ TEST_IMPL(GLM_PREFIX, rotate_atm) {
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, spin) {
mat4 m;
mat4 expected = {{ 0.0f, 1.0f, 0.0f, 0.0f},
{-1.0f, 0.0f, 0.0f, 0.0f},
{ 0.0f, 0.0f, 1.0f, 0.0f},
{ 5.0f, 0.0f, 0.0f, 1.0f}};
glm_translate_make(m, (vec3){5.0f, 0.0f, 0.0f});
GLM(spin)(m, GLM_PI_2f, GLM_ZUP);
ASSERTIFY(test_assert_mat4_eq(m, expected));
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, spin_affine) {
mat4 m, original = {{0.0f, 2.0f, 0.0f, 0.0f},
{-3.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 4.0f, 0.0f},
{5.0f, -2.0f, 7.0f, 1.0f}};
mat4 expected = {{-3.0f, 0.0f, 0.0f, 0.0f},
{0.0f, -2.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 4.0f, 0.0f},
{5.0f, -2.0f, 7.0f, 1.0f}};
vec3 axis = {0.0f, 0.0f, 2.0f};
glm_mat4_copy(original, m);
GLM(spin)(m, GLM_PI_2f, axis);
ASSERTIFY(test_assert_mat4_eq(m, expected));
ASSERT(test_eq(axis[2], 2.0f))
GLM(spin)(m, -GLM_PI_2f, axis);
ASSERTIFY(test_assert_mat4_eq(m, original));
GLM(spin)(m, 0.0f, GLM_XUP);
ASSERTIFY(test_assert_mat4_eq(m, original));
glm_vec3_zero(m[3]);
glm_vec3_zero(expected[3]);
GLM(spin)(m, GLM_PI_2f, axis);
ASSERTIFY(test_assert_mat4_eq(m, expected));
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, decompose_scalev) {
mat4 m1;
vec3 s1;
+5 -5
View File
@@ -15,7 +15,7 @@
TEST_IMPL(MACRO_GLM_MAT2_IDENTITY_INIT) {
mat2 m = GLM_MAT2_IDENTITY_INIT;
ASSERT(test_eq(m[0][0], 1.0f))
ASSERT(test_eq(m[0][1], 0.0f))
ASSERT(test_eq(m[1][0], 0.0f))
@@ -24,9 +24,9 @@ TEST_IMPL(MACRO_GLM_MAT2_IDENTITY_INIT) {
TEST_SUCCESS
}
TEST_IMPL(MACRO_GLM_MAT2_ZERO_INIT) {
TEST_IMPL(MACRO_GLM_MAT2_ZERO_INIT) {
mat2 m = GLM_MAT2_ZERO_INIT;
ASSERT(test_eq(m[0][0], 0.0f))
ASSERT(test_eq(m[0][1], 0.0f))
ASSERT(test_eq(m[1][0], 0.0f))
@@ -199,7 +199,7 @@ TEST_IMPL(GLM_PREFIX, mat2_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat2_scale)(m1, scale);
@@ -231,7 +231,7 @@ TEST_IMPL(GLM_PREFIX, mat2_inv) {
/* test inverse precise */
GLM(mat2_inv)(m1, m2);
GLM(mat2_inv)(m2, m3);
ASSERTIFY(test_assert_mat2_eq(m1, m3))
}
+1 -1
View File
@@ -143,7 +143,7 @@ TEST_IMPL(GLM_PREFIX, mat2x3_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat2x3_scale)(m1, scale);
+1 -1
View File
@@ -146,7 +146,7 @@ TEST_IMPL(GLM_PREFIX, mat2x4_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat2x4_scale)(m1, scale);
+1 -1
View File
@@ -187,7 +187,7 @@ TEST_IMPL(GLM_PREFIX, mat3_scale) {
int i, j, k;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat3_scale)(m1, scale);
+1 -1
View File
@@ -142,7 +142,7 @@ TEST_IMPL(GLM_PREFIX, mat3x2_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat3x2_scale)(m1, scale);
+1 -1
View File
@@ -148,7 +148,7 @@ TEST_IMPL(GLM_PREFIX, mat3x4_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat3x4_scale)(m1, scale);
+22 -22
View File
@@ -244,19 +244,19 @@ TEST_IMPL(GLM_PREFIX, mat4_quat) {
versor q1, q2, q3;
vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f};
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
GLM(quat_mat4)(q1, m1);
GLM(mat4_quat)(m1, q2);
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
GLM(mat4_quat)(m1, q3);
GLM(quat_axis)(q3, axis1);
GLM(vec3_normalize)(axis1);
GLM(vec3_normalize)(axis2);
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
ASSERTIFY(test_assert_vec4_eq(q1, q2))
@@ -271,7 +271,7 @@ TEST_IMPL(GLM_PREFIX, mat4_transpose_to) {
mat4 m1;
GLM(mat4_transpose_to)(mat, m1);
ASSERTIFY(test_assert_mat4_eqt(mat, m1))
TEST_SUCCESS
@@ -283,7 +283,7 @@ TEST_IMPL(GLM_PREFIX, mat4_transpose) {
GLM(mat4_copy)(mat, m1);
GLM(mat4_transpose)(m1);
ASSERTIFY(test_assert_mat4_eqt(mat, m1))
TEST_SUCCESS
@@ -295,8 +295,8 @@ TEST_IMPL(GLM_PREFIX, mat4_scale_p) {
int i, j, k;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4_scale_p)(m1, scale);
for (i = 0; i < 4; i++) {
@@ -315,8 +315,8 @@ TEST_IMPL(GLM_PREFIX, mat4_scale) {
int i, j, k;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4_scale)(m1, scale);
for (i = 0; i < 4; i++) {
@@ -389,14 +389,14 @@ TEST_IMPL(GLM_PREFIX, mat4_inv_precise) {
for (i = 0; i < 100000; i++) {
test_rand_mat4(m1);
test_rand_mat4(m2);
glm_mat4_inv_precise(m1, m2);
glm_mat4_inv_precise(m2, m3);
ASSERTIFY(test_assert_mat4_eq(m1, m3))
test_rand_mat4(m4);
test_rand_mat4(m5);
glmc_mat4_inv_precise(m4, m5);
glmc_mat4_inv_precise(m5, m6);
ASSERTIFY(test_assert_mat4_eq(m4, m6))
@@ -408,24 +408,24 @@ TEST_IMPL(GLM_PREFIX, mat4_inv_precise) {
TEST_IMPL(GLM_PREFIX, mat4_inv_fast) {
mat4 m1, m2, m3;
int i;
for (i = 0; i < 100000; i++) {
test_rand_mat4(m1);
test_rand_mat4(m2);
/* test inverse precise */
GLM(mat4_inv_fast)(m1, m2);
GLM(mat4_inv_fast)(m2, m3);
ASSERTIFY(test_assert_mat4_eq2(m1, m3, 0.0009f))
}
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, mat4_swap_col) {
mat4 m1 = A_MATRIX;
mat4 m2 = A_MATRIX;
GLM(mat4_swap_col)(m1, 0, 1);
GLM(mat4_swap_col)(m1, 2, 3);
@@ -433,17 +433,17 @@ TEST_IMPL(GLM_PREFIX, mat4_swap_col) {
ASSERTIFY(test_assert_vec4_eq(m1[1], m2[0]))
ASSERTIFY(test_assert_vec4_eq(m1[2], m2[3]))
ASSERTIFY(test_assert_vec4_eq(m1[3], m2[2]))
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, mat4_swap_row) {
mat4 m1 = A_MATRIX;
mat4 m2 = A_MATRIX;
GLM(mat4_swap_row)(m1, 0, 1);
GLM(mat4_swap_row)(m1, 2, 3);
ASSERT(test_eq(m1[0][0], m2[0][1]))
ASSERT(test_eq(m1[0][1], m2[0][0]))
ASSERT(test_eq(m1[0][2], m2[0][3]))
@@ -479,7 +479,7 @@ TEST_IMPL(GLM_PREFIX, mat4_rmc) {
+ v[2] * mat[i][2]
+ v[3] * mat[i][3];
}
r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2] + v[3] * v1[3];
ASSERT(test_eq(r1, r2))
+2 -2
View File
@@ -98,7 +98,7 @@ TEST_IMPL(GLM_PREFIX, mat4x2_mul) {
for (r = 0; r < 2; r++) {
for (c = 0; c < 2; c++) {
for (k = 0; k < 4; k++) {
m4[c][r] += m1[k][r] * m2[c][k];
m4[c][r] += m1[k][r] * m2[c][k];
}
}
}
@@ -145,7 +145,7 @@ TEST_IMPL(GLM_PREFIX, mat4x2_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4x2_scale)(m1, scale);
+1 -1
View File
@@ -149,7 +149,7 @@ TEST_IMPL(GLM_PREFIX, mat4x3_scale) {
int i, j;
float scale;
scale = rand() % 100;
scale = (float)(rand() % 100);
GLM(mat4x3_scale)(m1, scale);
+176 -4
View File
@@ -504,9 +504,10 @@ TEST_IMPL(GLM_PREFIX, quat_mul) {
TEST_IMPL(GLM_PREFIX, quat_mat4) {
mat4 m1, m2;
versor q1, q2, q3;
versor q1, q2, q3, scaled, original;
vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
@@ -543,14 +544,47 @@ TEST_IMPL(GLM_PREFIX, quat_mat4) {
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
}
/* Scaling a quaternion must not change its rotation or mutate it. */
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
for (i = 0; i < (int)(sizeof(scales) / sizeof(scales[0])); i++) {
glm_vec4_scale(q1, scales[i], scaled);
glm_vec4_copy(scaled, original);
GLM(quat_mat4)(scaled, m1);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
ASSERT(scaled[0] == original[0] && scaled[1] == original[1]);
ASSERT(scaled[2] == original[2] && scaled[3] == original[3]);
}
/* Issue #503: a non-unit half-turn about Z. */
glm_vec4_zero(scaled);
scaled[2] = 2.0f;
GLM(quat_mat4)(scaled, m1);
glm_mat4_identity(m2);
m2[0][0] = m2[1][1] = -1.0f;
ASSERTIFY(test_assert_mat4_eq(m1, m2));
/* Normalizing first avoids overflowing 2 / dot for tiny inputs. */
scaled[2] = 1e-20f;
GLM(quat_mat4)(scaled, m1);
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00002f));
/* Keep the existing identity fallback for a zero quaternion. */
glm_vec4_zero(scaled);
GLM(quat_mat4)(scaled, m1);
glm_mat4_identity(m2);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, quat_mat4t) {
mat4 m1, m2;
versor q1, q2, q3;
versor q1, q2, q3, scaled, original;
vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
@@ -594,15 +628,52 @@ TEST_IMPL(GLM_PREFIX, quat_mat4t) {
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
}
/* Scaling a quaternion must not change its rotation or mutate it. */
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
for (i = 0; i < (int)(sizeof(scales) / sizeof(scales[0])); i++) {
glm_vec4_scale(q1, scales[i], scaled);
glm_vec4_copy(scaled, original);
GLM(quat_mat4t)(scaled, m1);
glm_mat4_transpose(m1);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
ASSERT(scaled[0] == original[0] && scaled[1] == original[1]);
ASSERT(scaled[2] == original[2] && scaled[3] == original[3]);
}
/* Issue #503: a non-unit half-turn about Z. */
glm_vec4_zero(scaled);
scaled[2] = 2.0f;
GLM(quat_mat4t)(scaled, m1);
glm_mat4_transpose(m1);
glm_mat4_identity(m2);
m2[0][0] = m2[1][1] = -1.0f;
ASSERTIFY(test_assert_mat4_eq(m1, m2));
/* Normalizing first avoids overflowing 2 / dot for tiny inputs. */
scaled[2] = 1e-20f;
GLM(quat_mat4t)(scaled, m1);
glm_mat4_transpose(m1);
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00002f));
/* Keep the existing identity fallback for a zero quaternion. */
glm_vec4_zero(scaled);
GLM(quat_mat4t)(scaled, m1);
glm_mat4_transpose(m1);
glm_mat4_identity(m2);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, quat_mat3) {
mat4 m1, m2;
mat3 m3;
versor q1, q2, q3;
versor q1, q2, q3, scaled, original;
vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
@@ -648,15 +719,56 @@ TEST_IMPL(GLM_PREFIX, quat_mat3) {
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
}
/* Scaling a quaternion must not change its rotation or mutate it. */
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
for (i = 0; i < (int)(sizeof(scales) / sizeof(scales[0])); i++) {
glm_vec4_scale(q1, scales[i], scaled);
glm_vec4_copy(scaled, original);
GLM(quat_mat3)(scaled, m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
ASSERT(scaled[0] == original[0] && scaled[1] == original[1]);
ASSERT(scaled[2] == original[2] && scaled[3] == original[3]);
}
/* Issue #503: a non-unit half-turn about Z. */
glm_vec4_zero(scaled);
scaled[2] = 2.0f;
GLM(quat_mat3)(scaled, m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
glm_mat4_identity(m2);
m2[0][0] = m2[1][1] = -1.0f;
ASSERTIFY(test_assert_mat4_eq(m1, m2));
/* Normalizing first avoids overflowing 2 / dot for tiny inputs. */
scaled[2] = 1e-20f;
GLM(quat_mat3)(scaled, m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00002f));
/* Keep the existing identity fallback for a zero quaternion. */
glm_vec4_zero(scaled);
GLM(quat_mat3)(scaled, m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
glm_mat4_identity(m2);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, quat_mat3t) {
mat4 m1, m2;
mat3 m3;
versor q1, q2, q3;
versor q1, q2, q3, scaled, original;
vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
@@ -706,6 +818,50 @@ TEST_IMPL(GLM_PREFIX, quat_mat3t) {
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
}
/* Scaling a quaternion must not change its rotation or mutate it. */
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
for (i = 0; i < (int)(sizeof(scales) / sizeof(scales[0])); i++) {
glm_vec4_scale(q1, scales[i], scaled);
glm_vec4_copy(scaled, original);
GLM(quat_mat3t)(scaled, m3);
glm_mat3_transpose(m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
ASSERT(scaled[0] == original[0] && scaled[1] == original[1]);
ASSERT(scaled[2] == original[2] && scaled[3] == original[3]);
}
/* Issue #503: a non-unit half-turn about Z. */
glm_vec4_zero(scaled);
scaled[2] = 2.0f;
GLM(quat_mat3t)(scaled, m3);
glm_mat3_transpose(m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
glm_mat4_identity(m2);
m2[0][0] = m2[1][1] = -1.0f;
ASSERTIFY(test_assert_mat4_eq(m1, m2));
/* Normalizing first avoids overflowing 2 / dot for tiny inputs. */
scaled[2] = 1e-20f;
GLM(quat_mat3t)(scaled, m3);
glm_mat3_transpose(m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00002f));
/* Keep the existing identity fallback for a zero quaternion. */
glm_vec4_zero(scaled);
GLM(quat_mat3t)(scaled, m3);
glm_mat3_transpose(m3);
glm_mat4_identity(m1);
glm_mat4_ins3(m3, m1);
glm_mat4_identity(m2);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
TEST_SUCCESS
}
@@ -843,6 +999,12 @@ TEST_IMPL(GLM_PREFIX, quat_look) {
ASSERTIFY(test_assert_mat4_eq(m1, m2));
/* A scaled orientation must yield the same camera view. */
glm_vec4_scale(q1, -2.0f, q1);
GLM(quat_look)(v1, q1, m1);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
TEST_SUCCESS
}
@@ -1006,6 +1168,16 @@ TEST_IMPL(GLM_PREFIX, quat_rotate) {
ASSERT(test_eq(v1[1], 0.0f))
ASSERT(test_eq(v1[2], 1.0f))
/* Non-unit orientation must not add scaling to the transform. */
glm_mat4_identity(m1);
glm_mat4_identity(m2);
glm_quatv(q1, GLM_PI_2f, GLM_YUP);
glm_vec4_scale(q1, 2.0f, q1);
GLM(quat_rotate)(m1, q1, m1);
glm_rotate(m2, GLM_PI_2f, GLM_YUP);
ASSERTIFY(test_assert_mat4_eq(m1, m2));
TEST_SUCCESS
}
+39
View File
@@ -114,6 +114,27 @@ TEST_IMPL(quats_zero_init) {
TEST_SUCCESS
}
TEST_IMPL(quats_mat_nonunit) {
versors q = {{0.0f, 0.0f, 2.0f, 0.0f}};
mat4s m4;
mat3s m3;
mat4 expected4 = GLM_MAT4_IDENTITY_INIT;
mat3 expected3 = GLM_MAT3_IDENTITY_INIT;
expected4[0][0] = expected4[1][1] = -1.0f;
expected3[0][0] = expected3[1][1] = -1.0f;
m4 = glms_quat_mat4(q);
ASSERTIFY(test_assert_mat4_eq(m4.raw, expected4));
m4 = glms_quat_mat4t(q);
ASSERTIFY(test_assert_mat4_eq(m4.raw, expected4));
m3 = glms_quat_mat3(q);
ASSERTIFY(test_assert_mat3_eq(m3.raw, expected3));
m3 = glms_quat_mat3t(q);
ASSERTIFY(test_assert_mat3_eq(m3.raw, expected3));
TEST_SUCCESS
}
TEST_IMPL(vec3s_one_init) {
vec3s vec3_one = GLMS_VEC3_ONE_INIT;
vec3 vec3_one_a = GLM_VEC3_ONE_INIT;
@@ -148,3 +169,21 @@ TEST_IMPL(vec4s_zero_init) {
test_assert_vec4_eq(vec4_zero.raw, vec4_zero_a);
TEST_SUCCESS
}
TEST_IMPL(mat4s_spin) {
mat4s m, result;
mat4 expected = {{ 0.0f, 1.0f, 0.0f, 0.0f},
{-1.0f, 0.0f, 0.0f, 0.0f},
{ 0.0f, 0.0f, 1.0f, 0.0f},
{ 5.0f, 0.0f, 0.0f, 1.0f}};
glm_translate_make(m.raw, (vec3){5.0f, 0.0f, 0.0f});
result = glms_spin(m, GLM_PI_2f, (vec3s){{0.0f, 0.0f, 1.0f}});
ASSERTIFY(test_assert_mat4_eq(result.raw, expected));
ASSERTIFY(test_assert_mat4_eq(m.raw, (mat4){{1.0f, 0.0f, 0.0f, 0.0f},
{0.0f, 1.0f, 0.0f, 0.0f},
{0.0f, 0.0f, 1.0f, 0.0f},
{5.0f, 0.0f, 0.0f, 1.0f}}));
TEST_SUCCESS
}
+12
View File
@@ -43,6 +43,8 @@ TEST_DECLARE(glm_rotate_make)
TEST_DECLARE(glm_rotate)
TEST_DECLARE(glm_rotate_at)
TEST_DECLARE(glm_rotate_atm)
TEST_DECLARE(glm_spin)
TEST_DECLARE(glm_spin_affine)
TEST_DECLARE(glm_decompose_scalev)
TEST_DECLARE(glm_uniscaled)
TEST_DECLARE(glm_decompose_rs)
@@ -65,6 +67,8 @@ TEST_DECLARE(glmc_rotate_make)
TEST_DECLARE(glmc_rotate)
TEST_DECLARE(glmc_rotate_at)
TEST_DECLARE(glmc_rotate_atm)
TEST_DECLARE(glmc_spin)
TEST_DECLARE(glmc_spin_affine)
TEST_DECLARE(glmc_decompose_scalev)
TEST_DECLARE(glmc_uniscaled)
TEST_DECLARE(glmc_decompose_rs)
@@ -1221,6 +1225,7 @@ TEST_DECLARE(mat3x2s_zero_init)
TEST_DECLARE(mat3x2s_zero)
TEST_DECLARE(mat3x4s_zero_init)
TEST_DECLARE(mat3x4s_zero)
TEST_DECLARE(mat4s_spin)
TEST_DECLARE(mat4s_identity_init)
TEST_DECLARE(mat4s_zero_init)
TEST_DECLARE(mat4x2s_zero_init)
@@ -1228,6 +1233,7 @@ TEST_DECLARE(mat4x2s_zero)
TEST_DECLARE(mat4x3s_zero_init)
TEST_DECLARE(mat4x3s_zero)
TEST_DECLARE(quats_zero_init)
TEST_DECLARE(quats_mat_nonunit)
TEST_DECLARE(vec3s_one_init)
TEST_DECLARE(vec3s_zero_init)
TEST_DECLARE(vec4s_black_init)
@@ -1264,6 +1270,8 @@ TEST_LIST {
TEST_ENTRY(glm_rotate)
TEST_ENTRY(glm_rotate_at)
TEST_ENTRY(glm_rotate_atm)
TEST_ENTRY(glm_spin)
TEST_ENTRY(glm_spin_affine)
TEST_ENTRY(glm_decompose_scalev)
TEST_ENTRY(glm_uniscaled)
TEST_ENTRY(glm_decompose_rs)
@@ -1286,6 +1294,8 @@ TEST_LIST {
TEST_ENTRY(glmc_rotate)
TEST_ENTRY(glmc_rotate_at)
TEST_ENTRY(glmc_rotate_atm)
TEST_ENTRY(glmc_spin)
TEST_ENTRY(glmc_spin_affine)
TEST_ENTRY(glmc_decompose_scalev)
TEST_ENTRY(glmc_uniscaled)
TEST_ENTRY(glmc_decompose_rs)
@@ -2440,6 +2450,7 @@ TEST_LIST {
TEST_ENTRY(mat3x2s_zero)
TEST_ENTRY(mat3x4s_zero_init)
TEST_ENTRY(mat3x4s_zero)
TEST_ENTRY(mat4s_spin)
TEST_ENTRY(mat4s_identity_init)
TEST_ENTRY(mat4s_zero_init)
TEST_ENTRY(mat4x2s_zero_init)
@@ -2447,6 +2458,7 @@ TEST_LIST {
TEST_ENTRY(mat4x3s_zero_init)
TEST_ENTRY(mat4x3s_zero)
TEST_ENTRY(quats_zero_init)
TEST_ENTRY(quats_mat_nonunit)
TEST_ENTRY(vec3s_one_init)
TEST_ENTRY(vec3s_zero_init)
TEST_ENTRY(vec4s_black_init)
+1
View File
@@ -56,6 +56,7 @@
<ClInclude Include="..\test\src\test_aabb2d.h" />
<ClInclude Include="..\test\src\test_affine.h" />
<ClInclude Include="..\test\src\test_affine2d.h" />
<ClInclude Include="..\test\src\test_affine2d_post.h" />
<ClInclude Include="..\test\src\test_affine_mat.h" />
<ClInclude Include="..\test\src\test_cam.h" />
<ClInclude Include="..\test\src\test_cam_lh_no.h" />
+3
View File
@@ -52,6 +52,9 @@
<ClInclude Include="..\test\src\test_affine2d.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\test\src\test_affine2d_post.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\test\src\test_cam.h">
<Filter>src</Filter>
</ClInclude>
+3
View File
@@ -97,6 +97,7 @@
<ClInclude Include="..\include\cglm\affine-pre.h" />
<ClInclude Include="..\include\cglm\affine.h" />
<ClInclude Include="..\include\cglm\affine2d.h" />
<ClInclude Include="..\include\cglm\affine2d-post.h" />
<ClInclude Include="..\include\cglm\applesimd.h" />
<ClInclude Include="..\include\cglm\bezier.h" />
<ClInclude Include="..\include\cglm\box.h" />
@@ -172,6 +173,8 @@
<ClInclude Include="..\include\cglm\ease.h" />
<ClInclude Include="..\include\cglm\euler.h" />
<ClInclude Include="..\include\cglm\frustum.h" />
<ClInclude Include="..\include\cglm\handed\euler_to_quat_lh.h" />
<ClInclude Include="..\include\cglm\handed\euler_to_quat_rh.h" />
<ClInclude Include="..\include\cglm\io.h" />
<ClInclude Include="..\include\cglm\ivec2.h" />
<ClInclude Include="..\include\cglm\ivec3.h" />
+12
View File
@@ -47,6 +47,9 @@
<Filter Include="include\cglm\struct\handed">
<UniqueIdentifier>{e6a410e7-83db-41a5-b9fc-34bbfcf46ae5}</UniqueIdentifier>
</Filter>
<Filter Include="include\cglm\handed">
<UniqueIdentifier>{BA6FE2A0-1E8D-4FBA-A272-8C0989F28E0D}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\affine.c">
@@ -744,5 +747,14 @@
<ClInclude Include="..\include\cglm\struct\noise.h">
<Filter>include\cglm\struct</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\affine2d-post.h">
<Filter>include\cglm</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\handed\euler_to_quat_lh.h">
<Filter>include\cglm\handed</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\handed\euler_to_quat_rh.h">
<Filter>include\cglm\handed</Filter>
</ClInclude>
</ItemGroup>
</Project>