Merge branch 'master' into vec2_mat2

This commit is contained in:
Recep Aslantas
2020-02-23 13:10:36 +03:00
75 changed files with 8194 additions and 1305 deletions

95
include/cglm/applesimd.h Normal file
View File

@@ -0,0 +1,95 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_applesimd_h
#define cglm_applesimd_h
#if defined(__APPLE__) \
&& defined(SIMD_COMPILER_HAS_REQUIRED_FEATURES) \
&& defined(SIMD_BASE) \
&& defined(SIMD_TYPES) \
&& defined(SIMD_VECTOR_TYPES)
#include "common.h"
/*!
* @brief converts mat4 to Apple's simd type simd_float4x4
* @return simd_float4x4
*/
CGLM_INLINE
simd_float4x4
glm_mat4_applesimd(mat4 m) {
simd_float4x4 t;
t.columns[0][0] = m[0][0];
t.columns[0][1] = m[0][1];
t.columns[0][2] = m[0][2];
t.columns[0][3] = m[0][3];
t.columns[1][0] = m[1][0];
t.columns[1][1] = m[1][1];
t.columns[1][2] = m[1][2];
t.columns[1][3] = m[1][3];
t.columns[2][0] = m[2][0];
t.columns[2][1] = m[2][1];
t.columns[2][2] = m[2][2];
t.columns[2][3] = m[2][3];
t.columns[3][0] = m[3][0];
t.columns[3][1] = m[3][1];
t.columns[3][2] = m[3][2];
t.columns[3][3] = m[3][3];
return t;
}
/*!
* @brief converts mat3 to Apple's simd type simd_float3x3
* @return simd_float3x3
*/
CGLM_INLINE
simd_float3x3
glm_mat3_applesimd(mat3 m) {
simd_float3x3 t;
t.columns[0][0] = m[0][0];
t.columns[0][1] = m[0][1];
t.columns[0][2] = m[0][2];
t.columns[1][0] = m[1][0];
t.columns[1][1] = m[1][1];
t.columns[1][2] = m[1][2];
t.columns[2][0] = m[2][0];
t.columns[2][1] = m[2][1];
t.columns[2][2] = m[2][2];
return t;
}
/*!
* @brief converts vec4 to Apple's simd type simd_float4
* @return simd_float4
*/
CGLM_INLINE
simd_float4
glm_vec4_applesimd(vec4 v) {
return (simd_float4){v[0], v[1], v[2], v[3]};
}
/*!
* @brief converts vec3 to Apple's simd type simd_float3
* @return v
*/
CGLM_INLINE
simd_float3
glm_vec3_applesimd(vec3 v) {
return (simd_float3){v[0], v[1], v[2]};
}
#endif
#endif /* cglm_applesimd_h */

View File

@@ -22,9 +22,9 @@
#define GLM_BEZIER_MAT ((mat4)GLM_BEZIER_MAT_INIT)
#define GLM_HERMITE_MAT ((mat4)GLM_HERMITE_MAT_INIT)
#define CGLM_DECASTEL_EPS 1e-9
#define CGLM_DECASTEL_MAX 1000
#define CGLM_DECASTEL_SMALL 1e-20
#define CGLM_DECASTEL_EPS 1e-9f
#define CGLM_DECASTEL_MAX 1000.0f
#define CGLM_DECASTEL_SMALL 1e-20f
/*!
* @brief cubic bezier interpolation

View File

@@ -24,6 +24,10 @@ CGLM_EXPORT
void
glmc_mat3_identity(mat3 mat);
CGLM_EXPORT
void
glmc_mat3_zero(mat3 mat);
CGLM_EXPORT
void
glmc_mat3_identity_array(mat3 * __restrict mat, size_t count);

View File

@@ -33,6 +33,10 @@ CGLM_EXPORT
void
glmc_mat4_identity_array(mat4 * __restrict mat, size_t count);
CGLM_EXPORT
void
glmc_mat4_zero(mat4 mat);
CGLM_EXPORT
void
glmc_mat4_pick3(mat4 mat, mat3 dest);

View File

@@ -131,11 +131,11 @@ glmc_quat_look(vec3 eye, versor ori, mat4 dest);
CGLM_EXPORT
void
glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest);
glmc_quat_for(vec3 dir, vec3 up, versor dest);
CGLM_EXPORT
void
glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest);
glmc_quat_forp(vec3 from, vec3 to, vec3 up, versor dest);
CGLM_EXPORT
void

View File

@@ -319,10 +319,7 @@ glm_perspective_resize(float aspect, mat4 proj) {
*/
CGLM_INLINE
void
glm_lookat(vec3 eye,
vec3 center,
vec3 up,
mat4 dest) {
glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) {
CGLM_ALIGN(8) vec3 f, u, s;
glm_vec3_sub(center, eye, f);

View File

@@ -446,6 +446,9 @@ glm_mat4_quat(mat4 m, versor dest) {
/*!
* @brief multiply vector with mat4
*
* actually the result is vec4, after multiplication the last component
* is trimmed. if you need it don't use this func.
*
* @param[in] m mat4(affine transform)
* @param[in] v vec3
* @param[in] last 4th item to make it vec4

View File

@@ -30,7 +30,14 @@
CGLM_INLINE
void
glm_plane_normalize(vec4 plane) {
glm_vec4_scale(plane, 1.0f / glm_vec3_norm(plane), plane);
float norm;
if ((norm = glm_vec3_norm(plane)) == 0.0f) {
glm_vec4_zero(plane);
return;
}
glm_vec4_scale(plane, 1.0f / norm, plane);
}
#endif /* cglm_plane_h */

View File

@@ -693,32 +693,23 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) {
* @brief creates look rotation quaternion
*
* @param[in] dir direction to look
* @param[in] fwd forward vector
* @param[in] up up vector
* @param[out] dest destination quaternion
*/
CGLM_INLINE
void
glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) {
CGLM_ALIGN(8) vec3 axis;
float dot, angle;
glm_quat_for(vec3 dir, vec3 up, versor dest) {
CGLM_ALIGN_MAT mat3 m;
dot = glm_vec3_dot(dir, fwd);
if (fabsf(dot + 1.0f) < 0.000001f) {
glm_quat_init(dest, up[0], up[1], up[2], GLM_PIf);
return;
}
glm_vec3_normalize_to(dir, m[2]);
if (fabsf(dot - 1.0f) < 0.000001f) {
glm_quat_identity(dest);
return;
}
/* No need to negate in LH, but we use RH here */
glm_vec3_negate(m[2]);
glm_vec3_crossn(up, m[2], m[0]);
glm_vec3_cross(m[2], m[0], m[1]);
angle = acosf(dot);
glm_cross(fwd, dir, axis);
glm_normalize(axis);
glm_quatv(dest, angle, axis);
glm_mat3_quat(m, dest);
}
/*!
@@ -727,16 +718,15 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) {
*
* @param[in] from source point
* @param[in] to destination point
* @param[in] fwd forward vector
* @param[in] up up vector
* @param[out] dest destination quaternion
*/
CGLM_INLINE
void
glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) {
glm_quat_forp(vec3 from, vec3 to, vec3 up, versor dest) {
CGLM_ALIGN(8) vec3 dir;
glm_vec3_sub(to, from, dir);
glm_quat_for(dir, fwd, up, dest);
glm_quat_for(dir, up, dest);
}
/*!

View File

@@ -34,17 +34,19 @@ glmm_hadd(float32x4_t v) {
static inline
float
glmm_hmin(float32x4_t v) {
v = vpmin_f32(vget_low_f32(v), vget_high_f32(v));
v = vpmin_f32(v, v);
return vget_lane_f32(v, 0);
float32x2_t t;
t = vpmin_f32(vget_low_f32(v), vget_high_f32(v));
t = vpmin_f32(t, t);
return vget_lane_f32(t, 0);
}
static inline
float
glmm_hmax(float32x4_t v) {
v = vpmax_f32(vget_low_f32(v), vget_high_f32(v));
v = vpmax_f32(v, v);
return vget_lane_f32(v, 0);
float32x2_t t;
t = vpmax_f32(vget_low_f32(v), vget_high_f32(v));
t = vpmax_f32(t, t);
return vget_lane_f32(t, 0);
}
static inline

View File

@@ -16,7 +16,7 @@
CGLM_INLINE mat4s glms_scale_make(vec3s v);
CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v);
CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s);
CGLM_INLINE mat4s glmx_rotate_x(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_x(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle);
CGLM_INLINE mat4s glms_rotate_make(float angle, vec3s axis);
@@ -169,7 +169,7 @@ glms_scale_uni(mat4s m, float s) {
*/
CGLM_INLINE
mat4s
glmx_rotate_x(mat4s m, float angle) {
glms_rotate_x(mat4s m, float angle) {
mat4s r;
glm_rotate_x(m.raw, angle, r.raw);
return r;

View File

@@ -14,9 +14,9 @@
Functions:
CGLM_INLINE mat3s glms_mat3_copy(mat3s mat);
CGLM_INLINE mat3s glms_mat3_identity();
CGLM_INLINE mat3s glms_mat3_identity(void);
CGLM_INLINE void glms_mat3_identity_array(mat3s * __restrict mat, size_t count);
CGLM_INLINE mat3s glms_mat3_zero();
CGLM_INLINE mat3s glms_mat3_zero(void);
CGLM_INLINE mat3s glms_mat3_mul(mat3s m1, mat3s m2);
CGLM_INLINE ma3s glms_mat3_transpose(mat3s m);
CGLM_INLINE vec3s glms_mat3_mulv(mat3s m, vec3s v);
@@ -38,12 +38,8 @@
#include "../mat3.h"
#include "vec3.h"
#define GLMS_MAT3_IDENTITY_INIT {1.0f, 0.0f, 0.0f, \
0.0f, 1.0f, 0.0f, \
0.0f, 0.0f, 1.0f}
#define GLMS_MAT3_ZERO_INIT {0.0f, 0.0f, 0.0f, \
0.0f, 0.0f, 0.0f, \
0.0f, 0.0f, 0.0f}
#define GLMS_MAT3_IDENTITY_INIT {GLM_MAT3_IDENTITY_INIT}
#define GLMS_MAT3_ZERO_INIT {GLM_MAT3_ZERO_INIT}
/* for C only */
#define GLMS_MAT3_IDENTITY ((mat3s)GLMS_MAT3_IDENTITY_INIT)
@@ -79,7 +75,7 @@ glms_mat3_copy(mat3s mat) {
*/
CGLM_INLINE
mat3s
glms_mat3_identity() {
glms_mat3_identity(void) {
mat3s r;
glm_mat3_identity(r.raw);
return r;
@@ -111,7 +107,7 @@ glms_mat3_identity_array(mat3s * __restrict mat, size_t count) {
*/
CGLM_INLINE
mat3s
glms_mat3_zero() {
glms_mat3_zero(void) {
mat3s r;
glm_mat3_zero(r.raw);
return r;

View File

@@ -20,9 +20,9 @@
Functions:
CGLM_INLINE mat4s glms_mat4_ucopy(mat4s mat);
CGLM_INLINE mat4s glms_mat4_copy(mat4s mat);
CGLM_INLINE mat4s glms_mat4_identity();
CGLM_INLINE mat4s glms_mat4_identity(void);
CGLM_INLINE void glms_mat4_identity_array(mat4s * __restrict mat, size_t count);
CGLM_INLINE mat4s glms_mat4_zero();
CGLM_INLINE mat4s glms_mat4_zero(void);
CGLM_INLINE mat3s glms_mat4_pick3(mat4s mat);
CGLM_INLINE mat3s glms_mat4_pick3t(mat4s mat);
CGLM_INLINE mat4s glms_mat4_ins3(mat3s mat);
@@ -53,15 +53,8 @@
#include "vec4.h"
#include "vec3.h"
#define GLMS_MAT4_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f, \
0.0f, 1.0f, 0.0f, 0.0f, \
0.0f, 0.0f, 1.0f, 0.0f, \
0.0f, 0.0f, 0.0f, 1.0f}
#define GLMS_MAT4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f, \
0.0f, 0.0f, 0.0f, 0.0f, \
0.0f, 0.0f, 0.0f, 0.0f, \
0.0f, 0.0f, 0.0f, 0.0f}
#define GLMS_MAT4_IDENTITY_INIT {GLM_MAT4_IDENTITY_INIT}
#define GLMS_MAT4_ZERO_INIT {GLM_MAT4_ZERO_INIT}
/* for C only */
#define GLMS_MAT4_IDENTITY ((mat4s)GLMS_MAT4_IDENTITY_INIT)
@@ -114,7 +107,7 @@ glms_mat4_copy(mat4s mat) {
*/
CGLM_INLINE
mat4s
glms_mat4_identity() {
glms_mat4_identity(void) {
mat4s r;
glm_mat4_identity(r.raw);
return r;
@@ -146,7 +139,7 @@ glms_mat4_identity_array(mat4s * __restrict mat, size_t count) {
*/
CGLM_INLINE
mat4s
glms_mat4_zero() {
glms_mat4_zero(void) {
mat4s r;
glm_mat4_zero(r.raw);
return r;

View File

@@ -11,7 +11,7 @@
GLMS_QUAT_IDENTITY
Functions:
CGLM_INLINE versors glms_quat_identity()
CGLM_INLINE versors glms_quat_identity(void)
CGLM_INLINE void glms_quat_identity_array(versor *q, size_t count)
CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w)
CGLM_INLINE versors glms_quatv(float angle, vec3s axis)
@@ -62,7 +62,7 @@
* ----------------------------------------------------------------------------
*/
#define GLMS_QUAT_IDENTITY_INIT GLM_QUAT_IDENTITY_INIT
#define GLMS_QUAT_IDENTITY_INIT {GLM_QUAT_IDENTITY_INIT}
#define GLMS_QUAT_IDENTITY ((versors)GLMS_QUAT_IDENTITY_INIT)
/*!
@@ -72,7 +72,7 @@
*/
CGLM_INLINE
versors
glms_quat_identity() {
glms_quat_identity(void) {
versors dest;
glm_quat_identity(dest.raw);
return dest;
@@ -251,7 +251,7 @@ CGLM_INLINE
vec3s
glms_quat_imagn(versors q) {
vec3s dest;
glm_normalize_to(q.imag.raw, dest.raw);
glm_normalize_to(q.raw, dest.raw);
return dest;
}
@@ -437,15 +437,14 @@ glms_quat_look(vec3s eye, versors ori) {
* @brief creates look rotation quaternion
*
* @param[in] dir direction to look
* @param[in] fwd forward vector
* @param[in] up up vector
* @returns destination quaternion
*/
CGLM_INLINE
versors
glms_quat_for(vec3s dir, vec3s fwd, vec3s up) {
glms_quat_for(vec3s dir, vec3s up) {
versors dest;
glm_quat_for(dir.raw, fwd.raw, up.raw, dest.raw);
glm_quat_for(dir.raw, up.raw, dest.raw);
return dest;
}
@@ -455,15 +454,14 @@ glms_quat_for(vec3s dir, vec3s fwd, vec3s up) {
*
* @param[in] from source point
* @param[in] to destination point
* @param[in] fwd forward vector
* @param[in] up up vector
* @returns destination quaternion
*/
CGLM_INLINE
versors
glms_quat_forp(vec3s from, vec3s to, vec3s fwd, vec3s up) {
glms_quat_forp(vec3s from, vec3s to, vec3s up) {
versors dest;
glm_quat_forp(from.raw, to.raw, fwd.raw, up.raw, dest.raw);
glm_quat_forp(from.raw, to.raw, up.raw, dest.raw);
return dest;
}

View File

@@ -19,8 +19,8 @@
CGLM_INLINE vec3s glms_vec3(vec4s v4);
CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len);
CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len);
CGLM_INLINE vec3s glms_vec3_zero();
CGLM_INLINE vec3s glms_vec3_one();
CGLM_INLINE vec3s glms_vec3_zero(void);
CGLM_INLINE vec3s glms_vec3_one(void);
CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b);
CGLM_INLINE float glms_vec3_norm2(vec3s v);
CGLM_INLINE float glms_vec3_norm(vec3s v);
@@ -86,15 +86,15 @@
#include "../vec3.h"
#include "vec3-ext.h"
#define GLMS_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f}
#define GLMS_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f}
#define GLMS_VEC3_ONE_INIT {GLM_VEC3_ONE_INIT}
#define GLMS_VEC3_ZERO_INIT {GLM_VEC3_ZERO_INIT}
#define GLMS_VEC3_ONE ((vec3s)GLMS_VEC3_ONE_INIT)
#define GLMS_VEC3_ZERO ((vec3s)GLMS_VEC3_ZERO_INIT)
#define GLMS_YUP ((vec3s){0.0f, 1.0f, 0.0f})
#define GLMS_ZUP ((vec3s){0.0f, 0.0f, 1.0f})
#define GLMS_XUP ((vec3s){1.0f, 0.0f, 0.0f})
#define GLMS_YUP ((vec3s){{0.0f, 1.0f, 0.0f}})
#define GLMS_ZUP ((vec3s){{0.0f, 0.0f, 1.0f}})
#define GLMS_XUP ((vec3s){{1.0f, 0.0f, 0.0f}})
/*!
* @brief init vec3 using vec4
@@ -151,7 +151,7 @@ glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) {
*/
CGLM_INLINE
vec3s
glms_vec3_zero() {
glms_vec3_zero(void) {
vec3s r;
glm_vec3_zero(r.raw);
return r;
@@ -164,7 +164,7 @@ glms_vec3_zero() {
*/
CGLM_INLINE
vec3s
glms_vec3_one() {
glms_vec3_one(void) {
vec3s r;
glm_vec3_one(r.raw);
return r;

View File

@@ -7,12 +7,12 @@
/*
Macros:
GLM_VEC4_ONE_INIT
GLM_VEC4_BLACK_INIT
GLM_VEC4_ZERO_INIT
GLM_VEC4_ONE
GLM_VEC4_BLACK
GLM_VEC4_ZERO
GLMS_VEC4_ONE_INIT
GLMS_VEC4_BLACK_INIT
GLMS_VEC4_ZERO_INIT
GLMS_VEC4_ONE
GLMS_VEC4_BLACK
GLMS_VEC4_ZERO
Functions:
CGLM_INLINE vec4s glms_vec4(vec3s v3, float last);
@@ -72,9 +72,9 @@
#include "../vec4.h"
#include "vec4-ext.h"
#define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f}
#define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f}
#define GLMS_VEC4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f}
#define GLMS_VEC4_ONE_INIT {GLM_VEC4_ONE_INIT}
#define GLMS_VEC4_BLACK_INIT {GLM_VEC4_BLACK_INIT}
#define GLMS_VEC4_ZERO_INIT {GLM_VEC4_ZERO_INIT}
#define GLMS_VEC4_ONE ((vec4s)GLM_VEC4_ONE_INIT)
#define GLMS_VEC4_BLACK ((vec4s)GLM_VEC4_BLACK_INIT)
@@ -180,7 +180,7 @@ glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) {
*/
CGLM_INLINE
vec4s
glms_vec4_zero() {
glms_vec4_zero(void) {
vec4s r;
glm_vec4_zero(r.raw);
return r;
@@ -193,7 +193,7 @@ glms_vec4_zero() {
*/
CGLM_INLINE
vec4s
glms_vec4_one() {
glms_vec4_one(void) {
vec4s r;
glm_vec4_one(r.raw);
return r;

View File

@@ -10,40 +10,71 @@
#include "types.h"
/*
* Anonymous structs are available since C11, but we'd like to be compatible
* with C99 and C89 too. So let's figure out if we should be using them or not.
* It's simply a convenience feature, you can e.g. build the library with
* anonymous structs and your application without them and they'll still be
* compatible, cglm doesn't use the anonymous structs internally.
*/
#ifndef CGLM_USE_ANONYMOUS_STRUCT
/* If the user doesn't explicitly specify if they want anonymous structs or
* not, then we'll try to intuit an appropriate choice. */
# if defined(CGLM_NO_ANONYMOUS_STRUCT)
/* The user has defined CGLM_NO_ANONYMOUS_STRUCT. This used to be the
* only #define governing the use of anonymous structs, so for backward
* compatibility, we still honor that choice and disable them. */
# define CGLM_USE_ANONYMOUS_STRUCT 0
# elif __STDC_VERSION__ >= 20112L || defined(_MSVC_VER)
/* We're compiling for C11 or this is the MSVC compiler. In either
* case, anonymous structs are available, so use them. */
# define CGLM_USE_ANONYMOUS_STRUCT 1
# elif defined(_MSC_VER) && (_MSC_VER >= 1900) /* Visual Studio 2015 */
/* We can support anonymous structs
* since Visual Studio 2015 or 2017 (1910) maybe? */
# define CGLM_USE_ANONYMOUS_STRUCT 1
# else
/* Otherwise, we're presumably building for C99 or C89 and can't rely
* on anonymous structs being available. Turn them off. */
# define CGLM_USE_ANONYMOUS_STRUCT 0
# endif
#endif
typedef union vec2s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
vec2 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
};
#endif
vec2 raw;
} vec2s;
typedef union vec3s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
vec3 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
float z;
};
#endif
vec3 raw;
} vec3s;
typedef union ivec3s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
ivec3 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
int z;
};
#endif
ivec3 raw;
} ivec3s;
typedef union CGLM_ALIGN_IF(16) vec4s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
vec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
@@ -51,11 +82,11 @@ typedef union CGLM_ALIGN_IF(16) vec4s {
float w;
};
#endif
vec4 raw;
} vec4s;
typedef union CGLM_ALIGN_IF(16) versors {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
vec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float x;
float y;
@@ -68,34 +99,35 @@ typedef union CGLM_ALIGN_IF(16) versors {
float real;
};
#endif
vec4 raw;
} versors;
typedef union mat2s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
mat2 raw;
vec2s col[2];
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01;
float m10, m11;
};
#endif
vec2s col[2];
mat2 raw;
} mat2s;
typedef union mat3s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
mat3 raw;
vec3s col[3];
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02;
float m10, m11, m12;
float m20, m21, m22;
};
#endif
vec3s col[3];
mat3 raw;
} mat3s;
typedef union CGLM_ALIGN_MAT mat4s {
#ifndef CGLM_NO_ANONYMOUS_STRUCT
mat4 raw;
vec4s col[4];
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
@@ -103,8 +135,6 @@ typedef union CGLM_ALIGN_MAT mat4s {
float m30, m31, m32, m33;
};
#endif
vec4s col[4];
mat4 raw;
} mat4s;
#endif /* cglm_types_struct_h */

View File

@@ -36,11 +36,16 @@ typedef float vec2[2];
typedef float vec3[3];
typedef int ivec3[3];
typedef CGLM_ALIGN_IF(16) float vec4[4];
typedef vec4 versor;
typedef vec4 versor; /* |x, y, z, w| -> w is the last */
typedef vec3 mat3[3];
typedef CGLM_ALIGN_IF(16) vec2 mat2[2];
typedef CGLM_ALIGN_MAT vec4 mat4[4];
/*
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.
*/
#define GLM_E 2.71828182845904523536028747135266250 /* e */
#define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */
#define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */

View File

@@ -111,9 +111,10 @@
#define GLM_VEC3_ONE ((vec3)GLM_VEC3_ONE_INIT)
#define GLM_VEC3_ZERO ((vec3)GLM_VEC3_ZERO_INIT)
#define GLM_YUP ((vec3){0.0f, 1.0f, 0.0f})
#define GLM_ZUP ((vec3){0.0f, 0.0f, 1.0f})
#define GLM_XUP ((vec3){1.0f, 0.0f, 0.0f})
#define GLM_YUP ((vec3){0.0f, 1.0f, 0.0f})
#define GLM_ZUP ((vec3){0.0f, 0.0f, 1.0f})
#define GLM_XUP ((vec3){1.0f, 0.0f, 0.0f})
#define GLM_FORWARD ((vec3){0.0f, 0.0f, -1.0f})
#define GLM_XXX GLM_SHUFFLE3(0, 0, 0)
#define GLM_YYY GLM_SHUFFLE3(1, 1, 1)
@@ -996,6 +997,27 @@ glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_smoothinterp(from, to, glm_clamp_zo(t), dest);
}
/*!
* @brief swizzle vector components
*
* you can use existin masks e.g. GLM_XXX, GLM_ZYX
*
* @param[in] v source
* @param[in] mask mask
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_swizzle(vec3 v, int mask, vec3 dest) {
vec3 t;
t[0] = v[(mask & (3 << 0))];
t[1] = v[(mask & (3 << 2)) >> 2];
t[2] = v[(mask & (3 << 4)) >> 4];
glm_vec3_copy(t, dest);
}
/*!
* @brief vec3 cross product
*
@@ -1054,25 +1076,4 @@ glm_normalize_to(vec3 v, vec3 dest) {
glm_vec3_normalize_to(v, dest);
}
/*!
* @brief swizzle vector components
*
* you can use existin masks e.g. GLM_XXX, GLM_ZYX
*
* @param[in] v source
* @param[in] mask mask
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_swizzle(vec3 v, int mask, vec3 dest) {
vec3 t;
t[0] = v[(mask & (3 << 0))];
t[1] = v[(mask & (3 << 2)) >> 2];
t[2] = v[(mask & (3 << 4)) >> 4];
glm_vec3_copy(t, dest);
}
#endif /* cglm_vec3_h */

View File

@@ -252,7 +252,7 @@ glm_vec4_abs(vec4 v, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(dest, glmm_abs(glmm_load(v)));
#elif defined(CGLM_NEON_FP)
vst1q_f32(dest, vabsq_f32(vld1q_f32(a)));
vst1q_f32(dest, vabsq_f32(vld1q_f32(v)));
#else
dest[0] = fabsf(v[0]);
dest[1] = fabsf(v[1]);

View File

@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 6
#define CGLM_VERSION_PATCH 0
#define CGLM_VERSION_PATCH 3
#endif /* cglm_version_h */