mirror of
https://github.com/recp/cglm.git
synced 2026-11-20 10:43:09 -06:00
Compare commits
17
Commits
83d5b2c973
..
v0.9.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
888aca08d5 | ||
|
|
5390138d7f | ||
|
|
11d34be968 | ||
|
|
1e65d6b52e | ||
|
|
8ff4f978c3 | ||
|
|
d7b1e02778 | ||
|
|
38a60f4f85 | ||
|
|
81ec84493f | ||
|
|
58d8c15a12 | ||
|
|
bbd81a24d3 | ||
|
|
b7813d0edb | ||
|
|
1c260ceb7d | ||
|
|
49e4284773 | ||
|
|
46f46e5dcb | ||
|
|
a97af506ce | ||
|
|
454f032310 | ||
|
|
f0f05dadc5 |
No files matched your search
@@ -83,3 +83,6 @@ xcode/*
|
||||
.vscode
|
||||
.build
|
||||
*.swp
|
||||
.lastsession.vim
|
||||
.vimrc
|
||||
compile_commands.json
|
||||
+1
-1
@@ -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
@@ -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
@@ -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
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
+2
-2
@@ -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.
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "cglm.h"
|
||||
#include "call/vec2.h"
|
||||
#include "call/vec3.h"
|
||||
#include "call/vec4.h"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../cglm.h"
|
||||
#include "../../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
#include <stdio.h>
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "../cglm.h"
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
bool
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
float
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
#include "../common.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
@@ -1,5 +1,5 @@
|
||||
project('cglm', 'c',
|
||||
version : '0.9.6',
|
||||
version : '0.9.7',
|
||||
license : 'mit',
|
||||
default_options : [
|
||||
'c_std=c11',
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user