Compare commits

...
13 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
30 changed files with 359 additions and 69 deletions

No files matched your search

+3
View File
@@ -83,3 +83,6 @@ xcode/*
.vscode .vscode
.build .build
*.swp *.swp
.lastsession.vim
.vimrc
compile_commands.json
+1 -1
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(cglm project(cglm
VERSION 0.9.6 VERSION 0.9.7
HOMEPAGE_URL https://github.com/recp/cglm HOMEPAGE_URL https://github.com/recp/cglm
DESCRIPTION "OpenGL Mathematics (glm) for C" DESCRIPTION "OpenGL Mathematics (glm) for C"
LANGUAGES C LANGUAGES C
+2 -1
View File
@@ -79,7 +79,8 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/bezier.h \ include/cglm/bezier.h \
include/cglm/applesimd.h \ include/cglm/applesimd.h \
include/cglm/ray.h \ include/cglm/ray.h \
include/cglm/affine2d.h include/cglm/affine2d.h \
include/cglm/affine2d-post.h
cglm_clipspacedir=$(includedir)/cglm/clipspace cglm_clipspacedir=$(includedir)/cglm/clipspace
cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \ cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \
+1 -1
View File
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
# Description # Description
s.name = "cglm" s.name = "cglm"
s.version = "0.9.5" s.version = "0.9.7"
s.summary = "📽 Highly Optimized Graphics Math (glm) for C" s.summary = "📽 Highly Optimized Graphics Math (glm) for C"
s.description = <<-DESC s.description = <<-DESC
cglm is math library for graphics programming for C. See the documentation or README for all features. 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_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]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects serial-tests])
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am. # Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.
+2 -2
View File
@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'0.9.6' version = u'0.9.7'
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # 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]); a = (c[0] < aabb[0][0]) + (c[0] > aabb[1][0]);
b = (c[1] < aabb[0][1]) + (c[1] > aabb[1][1]); b = (c[1] < aabb[0][1]) + (c[1] > aabb[1][1]);
dmin = glm_pow2((c[0] - aabb[!(a - 1)][0]) * (a != 0)) dmin = glm_pow2((c[0] - aabb[c[0] > aabb[1][0]][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[!(b - 1)][1]) * (b != 0)); + glm_pow2((c[1] - aabb[c[1] > aabb[1][1]][1]) * (b != 0));
return dmin <= glm_pow2(c[2]); return dmin <= glm_pow2(c[2]);
} }
+1 -1
View File
@@ -297,7 +297,7 @@ CGLM_INLINE
void void
glm_spin(mat4 m, float angle, vec3 axis) { glm_spin(mat4 m, float angle, vec3 axis) {
CGLM_ALIGN_MAT mat4 rot; 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); 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]); b = (s[1] < box[0][1]) + (s[1] > box[1][1]);
c = (s[2] < box[0][2]) + (s[2] > box[1][2]); c = (s[2] < box[0][2]) + (s[2] > box[1][2]);
dmin = glm_pow2((s[0] - box[!(a - 1)][0]) * (a != 0)) dmin = glm_pow2((s[0] - box[s[0] > box[1][0]][0]) * (a != 0))
+ glm_pow2((s[1] - box[!(b - 1)][1]) * (b != 0)) + glm_pow2((s[1] - box[s[1] > box[1][1]][1]) * (b != 0))
+ glm_pow2((s[2] - box[!(c - 1)][2]) * (c != 0)); + glm_pow2((s[2] - box[s[2] > box[1][2]][2]) * (c != 0));
return dmin <= glm_pow2(s[3]); return dmin <= glm_pow2(s[3]);
} }
+40 -40
View File
@@ -482,22 +482,22 @@ glm_quat_mul(versor p, versor q, versor dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_mat4(versor q, mat4 dest) { glm_quat_mat4(versor q, mat4 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z, float w, x, y, z,
xx, yy, zz, xx, yy, zz,
xy, yz, xz, xy, yz, xz,
wx, wy, wz, norm, s; wx, wy, wz;
norm = glm_quat_norm(q); glm_quat_normalize_to(q, p);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
x = q[0]; x = p[0];
y = q[1]; y = p[1];
z = q[2]; z = p[2];
w = q[3]; w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x; xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y; yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z; zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz; dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz; dest[1][1] = 1.0f - xx - zz;
@@ -529,22 +529,22 @@ glm_quat_mat4(versor q, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_mat4t(versor q, mat4 dest) { glm_quat_mat4t(versor q, mat4 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z, float w, x, y, z,
xx, yy, zz, xx, yy, zz,
xy, yz, xz, xy, yz, xz,
wx, wy, wz, norm, s; wx, wy, wz;
norm = glm_quat_norm(q); glm_quat_normalize_to(q, p);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
x = q[0]; x = p[0];
y = q[1]; y = p[1];
z = q[2]; z = p[2];
w = q[3]; w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x; xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y; yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z; zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz; dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz; dest[1][1] = 1.0f - xx - zz;
@@ -576,22 +576,22 @@ glm_quat_mat4t(versor q, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_mat3(versor q, mat3 dest) { glm_quat_mat3(versor q, mat3 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z, float w, x, y, z,
xx, yy, zz, xx, yy, zz,
xy, yz, xz, xy, yz, xz,
wx, wy, wz, norm, s; wx, wy, wz;
norm = glm_quat_norm(q); glm_quat_normalize_to(q, p);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
x = q[0]; x = p[0];
y = q[1]; y = p[1];
z = q[2]; z = p[2];
w = q[3]; w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x; xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y; yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z; zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz; dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz; dest[1][1] = 1.0f - xx - zz;
@@ -615,22 +615,22 @@ glm_quat_mat3(versor q, mat3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_mat3t(versor q, mat3 dest) { glm_quat_mat3t(versor q, mat3 dest) {
CGLM_ALIGN(16) versor p;
float w, x, y, z, float w, x, y, z,
xx, yy, zz, xx, yy, zz,
xy, yz, xz, xy, yz, xz,
wx, wy, wz, norm, s; wx, wy, wz;
norm = glm_quat_norm(q); glm_quat_normalize_to(q, p);
s = norm > 0.0f ? 2.0f / norm : 0.0f;
x = q[0]; x = p[0];
y = q[1]; y = p[1];
z = q[2]; z = p[2];
w = q[3]; w = p[3];
xx = s * x * x; xy = s * x * y; wx = s * w * x; xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x;
yy = s * y * y; yz = s * y * z; wy = s * w * y; yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y;
zz = s * z * z; xz = s * x * z; wz = s * w * z; zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z;
dest[0][0] = 1.0f - yy - zz; dest[0][0] = 1.0f - yy - zz;
dest[1][1] = 1.0f - xx - zz; dest[1][1] = 1.0f - xx - zz;
+1 -1
View File
@@ -168,7 +168,7 @@ glms_aabb2d_(sizev)(vec2s aabb[2]) {
CGLM_INLINE CGLM_INLINE
float float
glms_aabb2d_(radius)(vec2s aabb[2]) { glms_aabb2d_(radius)(vec2s aabb[2]) {
return glms_aabb2d_(size)(aabb) * 0.5f; return glms_aabb2d_(diag)(aabb) * 0.5f;
} }
/*! /*!
+1 -1
View File
@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 9 #define CGLM_VERSION_MINOR 9
#define CGLM_VERSION_PATCH 6 #define CGLM_VERSION_PATCH 7
#endif /* cglm_version_h */ #endif /* cglm_version_h */
+1 -1
View File
@@ -1,5 +1,5 @@
project('cglm', 'c', project('cglm', 'c',
version : '0.9.6', version : '0.9.7',
license : 'mit', license : 'mit',
default_options : [ default_options : [
'c_std=c11', 'c_std=c11',
+44
View File
@@ -492,6 +492,50 @@ TEST_IMPL(GLM_PREFIX, rotate_atm) {
TEST_SUCCESS 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) { TEST_IMPL(GLM_PREFIX, decompose_scalev) {
mat4 m1; mat4 m1;
vec3 s1; vec3 s1;
+1 -1
View File
@@ -199,7 +199,7 @@ TEST_IMPL(GLM_PREFIX, mat2_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat2_scale)(m1, scale); GLM(mat2_scale)(m1, scale);
+1 -1
View File
@@ -143,7 +143,7 @@ TEST_IMPL(GLM_PREFIX, mat2x3_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat2x3_scale)(m1, scale); GLM(mat2x3_scale)(m1, scale);
+1 -1
View File
@@ -146,7 +146,7 @@ TEST_IMPL(GLM_PREFIX, mat2x4_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat2x4_scale)(m1, scale); GLM(mat2x4_scale)(m1, scale);
+1 -1
View File
@@ -187,7 +187,7 @@ TEST_IMPL(GLM_PREFIX, mat3_scale) {
int i, j, k; int i, j, k;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat3_scale)(m1, scale); GLM(mat3_scale)(m1, scale);
+1 -1
View File
@@ -142,7 +142,7 @@ TEST_IMPL(GLM_PREFIX, mat3x2_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat3x2_scale)(m1, scale); GLM(mat3x2_scale)(m1, scale);
+1 -1
View File
@@ -148,7 +148,7 @@ TEST_IMPL(GLM_PREFIX, mat3x4_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat3x4_scale)(m1, scale); GLM(mat3x4_scale)(m1, scale);
+2 -2
View File
@@ -295,7 +295,7 @@ TEST_IMPL(GLM_PREFIX, mat4_scale_p) {
int i, j, k; int i, j, k;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat4_scale_p)(m1, scale); GLM(mat4_scale_p)(m1, scale);
@@ -315,7 +315,7 @@ TEST_IMPL(GLM_PREFIX, mat4_scale) {
int i, j, k; int i, j, k;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat4_scale)(m1, scale); GLM(mat4_scale)(m1, scale);
+1 -1
View File
@@ -145,7 +145,7 @@ TEST_IMPL(GLM_PREFIX, mat4x2_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat4x2_scale)(m1, scale); GLM(mat4x2_scale)(m1, scale);
+1 -1
View File
@@ -149,7 +149,7 @@ TEST_IMPL(GLM_PREFIX, mat4x3_scale) {
int i, j; int i, j;
float scale; float scale;
scale = rand() % 100; scale = (float)(rand() % 100);
GLM(mat4x3_scale)(m1, scale); 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) { TEST_IMPL(GLM_PREFIX, quat_mat4) {
mat4 m1, m2; mat4 m1, m2;
versor q1, q2, q3; versor q1, q2, q3, scaled, original;
vec3 axis1; vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f}; vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i; int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); 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)); 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_SUCCESS
} }
TEST_IMPL(GLM_PREFIX, quat_mat4t) { TEST_IMPL(GLM_PREFIX, quat_mat4t) {
mat4 m1, m2; mat4 m1, m2;
versor q1, q2, q3; versor q1, q2, q3, scaled, original;
vec3 axis1; vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f}; vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i; int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); 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)); 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_SUCCESS
} }
TEST_IMPL(GLM_PREFIX, quat_mat3) { TEST_IMPL(GLM_PREFIX, quat_mat3) {
mat4 m1, m2; mat4 m1, m2;
mat3 m3; mat3 m3;
versor q1, q2, q3; versor q1, q2, q3, scaled, original;
vec3 axis1; vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f}; vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i; int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); 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)); 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_SUCCESS
} }
TEST_IMPL(GLM_PREFIX, quat_mat3t) { TEST_IMPL(GLM_PREFIX, quat_mat3t) {
mat4 m1, m2; mat4 m1, m2;
mat3 m3; mat3 m3;
versor q1, q2, q3; versor q1, q2, q3, scaled, original;
vec3 axis1; vec3 axis1;
vec3 axis2 = {1.9f, 2.3f, 4.5f}; vec3 axis2 = {1.9f, 2.3f, 4.5f};
float scales[] = {2.0f, 0.5f, -2.0f, -0.5f, 1e-10f, 1e10f};
int i; int i;
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); 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)); 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 TEST_SUCCESS
} }
@@ -843,6 +999,12 @@ TEST_IMPL(GLM_PREFIX, quat_look) {
ASSERTIFY(test_assert_mat4_eq(m1, m2)); 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 TEST_SUCCESS
} }
@@ -1006,6 +1168,16 @@ TEST_IMPL(GLM_PREFIX, quat_rotate) {
ASSERT(test_eq(v1[1], 0.0f)) ASSERT(test_eq(v1[1], 0.0f))
ASSERT(test_eq(v1[2], 1.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 TEST_SUCCESS
} }
+39
View File
@@ -114,6 +114,27 @@ TEST_IMPL(quats_zero_init) {
TEST_SUCCESS 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) { TEST_IMPL(vec3s_one_init) {
vec3s vec3_one = GLMS_VEC3_ONE_INIT; vec3s vec3_one = GLMS_VEC3_ONE_INIT;
vec3 vec3_one_a = GLM_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_assert_vec4_eq(vec4_zero.raw, vec4_zero_a);
TEST_SUCCESS 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)
TEST_DECLARE(glm_rotate_at) TEST_DECLARE(glm_rotate_at)
TEST_DECLARE(glm_rotate_atm) TEST_DECLARE(glm_rotate_atm)
TEST_DECLARE(glm_spin)
TEST_DECLARE(glm_spin_affine)
TEST_DECLARE(glm_decompose_scalev) TEST_DECLARE(glm_decompose_scalev)
TEST_DECLARE(glm_uniscaled) TEST_DECLARE(glm_uniscaled)
TEST_DECLARE(glm_decompose_rs) TEST_DECLARE(glm_decompose_rs)
@@ -65,6 +67,8 @@ TEST_DECLARE(glmc_rotate_make)
TEST_DECLARE(glmc_rotate) TEST_DECLARE(glmc_rotate)
TEST_DECLARE(glmc_rotate_at) TEST_DECLARE(glmc_rotate_at)
TEST_DECLARE(glmc_rotate_atm) TEST_DECLARE(glmc_rotate_atm)
TEST_DECLARE(glmc_spin)
TEST_DECLARE(glmc_spin_affine)
TEST_DECLARE(glmc_decompose_scalev) TEST_DECLARE(glmc_decompose_scalev)
TEST_DECLARE(glmc_uniscaled) TEST_DECLARE(glmc_uniscaled)
TEST_DECLARE(glmc_decompose_rs) TEST_DECLARE(glmc_decompose_rs)
@@ -1221,6 +1225,7 @@ TEST_DECLARE(mat3x2s_zero_init)
TEST_DECLARE(mat3x2s_zero) TEST_DECLARE(mat3x2s_zero)
TEST_DECLARE(mat3x4s_zero_init) TEST_DECLARE(mat3x4s_zero_init)
TEST_DECLARE(mat3x4s_zero) TEST_DECLARE(mat3x4s_zero)
TEST_DECLARE(mat4s_spin)
TEST_DECLARE(mat4s_identity_init) TEST_DECLARE(mat4s_identity_init)
TEST_DECLARE(mat4s_zero_init) TEST_DECLARE(mat4s_zero_init)
TEST_DECLARE(mat4x2s_zero_init) TEST_DECLARE(mat4x2s_zero_init)
@@ -1228,6 +1233,7 @@ TEST_DECLARE(mat4x2s_zero)
TEST_DECLARE(mat4x3s_zero_init) TEST_DECLARE(mat4x3s_zero_init)
TEST_DECLARE(mat4x3s_zero) TEST_DECLARE(mat4x3s_zero)
TEST_DECLARE(quats_zero_init) TEST_DECLARE(quats_zero_init)
TEST_DECLARE(quats_mat_nonunit)
TEST_DECLARE(vec3s_one_init) TEST_DECLARE(vec3s_one_init)
TEST_DECLARE(vec3s_zero_init) TEST_DECLARE(vec3s_zero_init)
TEST_DECLARE(vec4s_black_init) TEST_DECLARE(vec4s_black_init)
@@ -1264,6 +1270,8 @@ TEST_LIST {
TEST_ENTRY(glm_rotate) TEST_ENTRY(glm_rotate)
TEST_ENTRY(glm_rotate_at) TEST_ENTRY(glm_rotate_at)
TEST_ENTRY(glm_rotate_atm) TEST_ENTRY(glm_rotate_atm)
TEST_ENTRY(glm_spin)
TEST_ENTRY(glm_spin_affine)
TEST_ENTRY(glm_decompose_scalev) TEST_ENTRY(glm_decompose_scalev)
TEST_ENTRY(glm_uniscaled) TEST_ENTRY(glm_uniscaled)
TEST_ENTRY(glm_decompose_rs) TEST_ENTRY(glm_decompose_rs)
@@ -1286,6 +1294,8 @@ TEST_LIST {
TEST_ENTRY(glmc_rotate) TEST_ENTRY(glmc_rotate)
TEST_ENTRY(glmc_rotate_at) TEST_ENTRY(glmc_rotate_at)
TEST_ENTRY(glmc_rotate_atm) TEST_ENTRY(glmc_rotate_atm)
TEST_ENTRY(glmc_spin)
TEST_ENTRY(glmc_spin_affine)
TEST_ENTRY(glmc_decompose_scalev) TEST_ENTRY(glmc_decompose_scalev)
TEST_ENTRY(glmc_uniscaled) TEST_ENTRY(glmc_uniscaled)
TEST_ENTRY(glmc_decompose_rs) TEST_ENTRY(glmc_decompose_rs)
@@ -2440,6 +2450,7 @@ TEST_LIST {
TEST_ENTRY(mat3x2s_zero) TEST_ENTRY(mat3x2s_zero)
TEST_ENTRY(mat3x4s_zero_init) TEST_ENTRY(mat3x4s_zero_init)
TEST_ENTRY(mat3x4s_zero) TEST_ENTRY(mat3x4s_zero)
TEST_ENTRY(mat4s_spin)
TEST_ENTRY(mat4s_identity_init) TEST_ENTRY(mat4s_identity_init)
TEST_ENTRY(mat4s_zero_init) TEST_ENTRY(mat4s_zero_init)
TEST_ENTRY(mat4x2s_zero_init) TEST_ENTRY(mat4x2s_zero_init)
@@ -2447,6 +2458,7 @@ TEST_LIST {
TEST_ENTRY(mat4x3s_zero_init) TEST_ENTRY(mat4x3s_zero_init)
TEST_ENTRY(mat4x3s_zero) TEST_ENTRY(mat4x3s_zero)
TEST_ENTRY(quats_zero_init) TEST_ENTRY(quats_zero_init)
TEST_ENTRY(quats_mat_nonunit)
TEST_ENTRY(vec3s_one_init) TEST_ENTRY(vec3s_one_init)
TEST_ENTRY(vec3s_zero_init) TEST_ENTRY(vec3s_zero_init)
TEST_ENTRY(vec4s_black_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_aabb2d.h" />
<ClInclude Include="..\test\src\test_affine.h" /> <ClInclude Include="..\test\src\test_affine.h" />
<ClInclude Include="..\test\src\test_affine2d.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_affine_mat.h" />
<ClInclude Include="..\test\src\test_cam.h" /> <ClInclude Include="..\test\src\test_cam.h" />
<ClInclude Include="..\test\src\test_cam_lh_no.h" /> <ClInclude Include="..\test\src\test_cam_lh_no.h" />
+3
View File
@@ -52,6 +52,9 @@
<ClInclude Include="..\test\src\test_affine2d.h"> <ClInclude Include="..\test\src\test_affine2d.h">
<Filter>src</Filter> <Filter>src</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\test\src\test_affine2d_post.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\test\src\test_cam.h"> <ClInclude Include="..\test\src\test_cam.h">
<Filter>src</Filter> <Filter>src</Filter>
</ClInclude> </ClInclude>
+3
View File
@@ -97,6 +97,7 @@
<ClInclude Include="..\include\cglm\affine-pre.h" /> <ClInclude Include="..\include\cglm\affine-pre.h" />
<ClInclude Include="..\include\cglm\affine.h" /> <ClInclude Include="..\include\cglm\affine.h" />
<ClInclude Include="..\include\cglm\affine2d.h" /> <ClInclude Include="..\include\cglm\affine2d.h" />
<ClInclude Include="..\include\cglm\affine2d-post.h" />
<ClInclude Include="..\include\cglm\applesimd.h" /> <ClInclude Include="..\include\cglm\applesimd.h" />
<ClInclude Include="..\include\cglm\bezier.h" /> <ClInclude Include="..\include\cglm\bezier.h" />
<ClInclude Include="..\include\cglm\box.h" /> <ClInclude Include="..\include\cglm\box.h" />
@@ -172,6 +173,8 @@
<ClInclude Include="..\include\cglm\ease.h" /> <ClInclude Include="..\include\cglm\ease.h" />
<ClInclude Include="..\include\cglm\euler.h" /> <ClInclude Include="..\include\cglm\euler.h" />
<ClInclude Include="..\include\cglm\frustum.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\io.h" />
<ClInclude Include="..\include\cglm\ivec2.h" /> <ClInclude Include="..\include\cglm\ivec2.h" />
<ClInclude Include="..\include\cglm\ivec3.h" /> <ClInclude Include="..\include\cglm\ivec3.h" />
+12
View File
@@ -47,6 +47,9 @@
<Filter Include="include\cglm\struct\handed"> <Filter Include="include\cglm\struct\handed">
<UniqueIdentifier>{e6a410e7-83db-41a5-b9fc-34bbfcf46ae5}</UniqueIdentifier> <UniqueIdentifier>{e6a410e7-83db-41a5-b9fc-34bbfcf46ae5}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="include\cglm\handed">
<UniqueIdentifier>{BA6FE2A0-1E8D-4FBA-A272-8C0989F28E0D}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\affine.c"> <ClCompile Include="..\src\affine.c">
@@ -744,5 +747,14 @@
<ClInclude Include="..\include\cglm\struct\noise.h"> <ClInclude Include="..\include\cglm\struct\noise.h">
<Filter>include\cglm\struct</Filter> <Filter>include\cglm\struct</Filter>
</ClInclude> </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> </ItemGroup>
</Project> </Project>