Compare commits

..
10 Commits
23 changed files with 358 additions and 88 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
+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.
+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.
+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);
}
+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;
}
/*!
+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',
+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)