Compare commits

...

28 Commits

Author SHA1 Message Date
Recep Aslantas
08479f38ce Merge pull request #63 from recp/avx
avx: replace binary constants (resolve https://github.com/recp/cglm/issues/62) with hex and fix glm_mul_avx
2018-10-19 09:52:32 +03:00
Recep Aslantas
dadae4b773 avx: fix glm_mul_avx
* use glm_mat4_mul_avx here. because it seems there is no big difference for now.
2018-10-19 09:40:40 +03:00
Recep Aslantas
20360f2296 avx: replace binary constants with hex 2018-10-12 09:05:42 +03:00
Recep Aslantas
aa2b0f2631 code style and minor optimization[s] 2018-09-22 00:10:50 +03:00
Recep Aslantas
280ac72fd8 Merge pull request #61 from hartenfels/master
Replace non-standard M_PI* constants
2018-09-21 23:39:10 +03:00
Recep Aslantas
7405d5e1d0 Update types.h 2018-09-21 23:33:42 +03:00
Carsten Hartenfels
eefafefbae Also add a load of other number constants
These are all missing from standard C, so we might as well define em.

See https://github.com/recp/cglm/pull/61#discussion_r219406859
2018-09-21 20:03:28 +02:00
Carsten Hartenfels
b9021978cb Replace the use of deprecated CGLM_PI* constants 2018-09-21 19:59:23 +02:00
Carsten Hartenfels
3fd12032e6 Clean up pi constants, deprecating the old names
GLM_PI* is now used for the double versions, GLM_PI*f for the float
versions. The CGLM_ prefixed versions are now deprecated, since that
prefix is kinda only used for constants.

See https://github.com/recp/cglm/pull/61#issuecomment-423069770
2018-09-21 07:29:54 +02:00
Carsten Hartenfels
59ee8c1fd2 Use even more precise definitions for pi constants
See https://github.com/recp/cglm/pull/61#issuecomment-422955122
2018-09-21 07:26:55 +02:00
Carsten Hartenfels
b00f2b9ccc Replace M_PI_4 in test_affine with CGLM_PI_4
As in the previous commit, because it's non-standard and depending on
your settings it can fail to compile because of it.
2018-09-19 20:46:37 +02:00
Carsten Hartenfels
d3c50147cb Replace non-standard M_PI* constants with literals
M_PI, M_PI_2 and M_PI_4 aren't part of the C standard. If you put your
gcc into strict standards mode, like `-std=c11`, you won't get these
constants and including cglm.h will fail.

This commit replaces those constants with their literal values. The cast
to a float remains, to keep exactly the same behavior as before.
2018-09-19 20:42:05 +02:00
Recep Aslantas
98da3daf82 identiy helper for arrays (matrix/quaternion)
this helpers makes all array elements identity
2018-09-12 12:44:11 +03:00
Recep Aslantas
2e1790ccf9 Merge pull request #59 from jonathanplatzer/avx
Fix alignment issue when using AVX
2018-07-19 11:38:55 +03:00
Jonathan Platzer
cc5f533fc9 Add macro for automatic alignment of matrices 2018-07-19 10:14:30 +02:00
Jonathan Platzer
2d63d7e0cd Fix alignment issue when using AVX 2018-07-18 12:03:38 +02:00
Recep Aslantas
3738499927 update doc for vec4_ucopy 2018-07-14 12:12:15 +03:00
Recep Aslantas
1d527dc2f0 unalignned version for vec4_copy 2018-07-14 12:03:42 +03:00
Recep Aslantas
43c4d05d4a new version for clamp: clamp to zero and one 2018-07-12 11:39:56 +03:00
Recep Aslantas
c5f5032fcc fix function params docs 2018-07-10 11:42:18 +03:00
Recep Aslantas
5d605ce372 avoid zero division for percent
* two value may be same, in this case now returns 1.
* to must be >= from and current <= to && current >= from
2018-07-10 10:54:31 +03:00
Recep Aslantas
c216c0cb7e add MIN and MAX macros
because we could use min/max for intergers too. it may not guarantee that MIN and MAX macros will always be defined by compiler
2018-06-26 15:27:53 +03:00
Recep Aslantas
eb8e0df6df update version 2018-06-21 10:54:53 +03:00
Recep Aslantas
1775bf7458 Merge pull request #57 from recp/anim
Animation Utils
2018-06-21 10:48:19 +03:00
Recep Aslantas
3adeac06f8 update build files 2018-06-21 10:07:51 +03:00
Recep Aslantas
669777eb37 additional utils 2018-06-18 17:55:25 +03:00
Recep Aslantas
02f6c67393 improve easing funcs 2018-06-15 08:55:59 +03:00
Recep Aslantas
564324f5d2 easing functions 2018-06-10 10:29:02 +03:00
40 changed files with 1036 additions and 91 deletions

View File

@@ -7,7 +7,7 @@
#***************************************************************************** #*****************************************************************************
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([cglm], [0.4.7], [info@recp.me]) AC_INIT([cglm], [0.4.9], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])

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.4.7' version = u'0.4.9'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'0.4.7' release = u'0.4.9'
# 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.

View File

@@ -20,6 +20,7 @@ Functions:
1. :c:func:`glm_mat3_copy` 1. :c:func:`glm_mat3_copy`
#. :c:func:`glm_mat3_identity` #. :c:func:`glm_mat3_identity`
#. :c:func:`glm_mat3_identity_array`
#. :c:func:`glm_mat3_mul` #. :c:func:`glm_mat3_mul`
#. :c:func:`glm_mat3_transpose_to` #. :c:func:`glm_mat3_transpose_to`
#. :c:func:`glm_mat3_transpose` #. :c:func:`glm_mat3_transpose`
@@ -49,6 +50,14 @@ Functions documentation
Parameters: Parameters:
| *[out]* **mat** matrix | *[out]* **mat** matrix
.. c:function:: void glm_mat3_identity_array(mat3 * __restrict mat, size_t count)
make given matrix array's each element identity matrix
Parameters:
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
| *[in]* **count** count of matrices
.. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) .. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest)
multiply m1 and m2 to dest multiply m1 and m2 to dest

View File

@@ -25,6 +25,7 @@ Functions:
1. :c:func:`glm_mat4_ucopy` 1. :c:func:`glm_mat4_ucopy`
#. :c:func:`glm_mat4_copy` #. :c:func:`glm_mat4_copy`
#. :c:func:`glm_mat4_identity` #. :c:func:`glm_mat4_identity`
#. :c:func:`glm_mat4_identity_array`
#. :c:func:`glm_mat4_pick3` #. :c:func:`glm_mat4_pick3`
#. :c:func:`glm_mat4_pick3t` #. :c:func:`glm_mat4_pick3t`
#. :c:func:`glm_mat4_ins3` #. :c:func:`glm_mat4_ins3`
@@ -69,6 +70,14 @@ Functions documentation
Parameters: Parameters:
| *[out]* **mat** matrix | *[out]* **mat** matrix
.. c:function:: void glm_mat4_identity_array(mat4 * __restrict mat, size_t count)
make given matrix array's each element identity matrix
Parameters:
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
| *[in]* **count** count of matrices
.. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest) .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest)
copy upper-left of mat4 to mat3 copy upper-left of mat4 to mat3

View File

@@ -27,6 +27,7 @@ Macros:
Functions: Functions:
1. :c:func:`glm_quat_identity` 1. :c:func:`glm_quat_identity`
#. :c:func:`glm_quat_identity_array`
#. :c:func:`glm_quat_init` #. :c:func:`glm_quat_init`
#. :c:func:`glm_quat` #. :c:func:`glm_quat`
#. :c:func:`glm_quatv` #. :c:func:`glm_quatv`
@@ -70,6 +71,14 @@ Functions documentation
Parameters: Parameters:
| *[in, out]* **q** quaternion | *[in, out]* **q** quaternion
.. c:function:: void glm_quat_identity_array(versor * __restrict q, size_t count)
| make given quaternion array's each element identity quaternion
Parameters:
| *[in, out]* **q** quat array (must be aligned (16) if alignment is not disabled)
| *[in]* **count** count of quaternions
.. c:function:: void glm_quat_init(versor q, float x, float y, float z, float w) .. c:function:: void glm_quat_init(versor q, float x, float y, float z, float w)
| inits quaternion with given values | inits quaternion with given values

View File

@@ -136,3 +136,38 @@ Functions documentation
Returns: Returns:
interpolated value interpolated value
.. c:function:: bool glm_eq(float a, float b)
check if two float equal with using EPSILON
Parameters:
| *[in]* **a** a
| *[in]* **b** b
Returns:
true if a and b equals
.. c:function:: float glm_percent(float from, float to, float current)
percentage of current value between start and end value
Parameters:
| *[in]* **from** from value
| *[in]* **to** to value
| *[in]* **current** value between from and to values
Returns:
clamped normalized percent (0-100 in 0-1)
.. c:function:: float glm_percentc(float from, float to, float current)
clamped percentage of current value between start and end value
Parameters:
| *[in]* **from** from value
| *[in]* **to** to value
| *[in]* **current** value between from and to values
Returns:
clamped normalized percent (0-100 in 0-1)

View File

@@ -24,6 +24,7 @@ Functions:
1. :c:func:`glm_vec4` 1. :c:func:`glm_vec4`
#. :c:func:`glm_vec4_copy3` #. :c:func:`glm_vec4_copy3`
#. :c:func:`glm_vec4_copy` #. :c:func:`glm_vec4_copy`
#. :c:func:`glm_vec4_ucopy`
#. :c:func:`glm_vec4_zero` #. :c:func:`glm_vec4_zero`
#. :c:func:`glm_vec4_one` #. :c:func:`glm_vec4_one`
#. :c:func:`glm_vec4_dot` #. :c:func:`glm_vec4_dot`
@@ -89,6 +90,16 @@ Functions documentation
| *[in]* **v** source | *[in]* **v** source
| *[in]* **dest** destination | *[in]* **dest** destination
.. c:function:: void glm_vec4_ucopy(vec4 v, vec4 dest)
copy all members of [a] to [dest]
| alignment is not required
Parameters:
| *[in]* **v** source
| *[in]* **dest** destination
.. c:function:: void glm_vec4_zero(vec4 v) .. c:function:: void glm_vec4_zero(vec4 v)
makes all members zero makes all members zero

View File

@@ -151,7 +151,7 @@ glm_inv_tr(mat4 mat) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glm_inv_tr_sse2(mat); glm_inv_tr_sse2(mat);
#else #else
CGLM_ALIGN(16) mat3 r; CGLM_ALIGN_MAT mat3 r;
CGLM_ALIGN(16) vec3 t; CGLM_ALIGN(16) vec3 t;
/* rotate */ /* rotate */

View File

@@ -244,7 +244,7 @@ glm_scale_uni(mat4 m, float s) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate_x(mat4 m, float angle, mat4 dest) { glm_rotate_x(mat4 m, float angle, mat4 dest) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
@@ -269,7 +269,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate_y(mat4 m, float angle, mat4 dest) { glm_rotate_y(mat4 m, float angle, mat4 dest) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
@@ -294,7 +294,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate_z(mat4 m, float angle, mat4 dest) { glm_rotate_z(mat4 m, float angle, mat4 dest) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
@@ -351,7 +351,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate(mat4 m, float angle, vec3 axis) { glm_rotate(mat4 m, float angle, vec3 axis) {
CGLM_ALIGN(16) mat4 rot; CGLM_ALIGN_MAT mat4 rot;
glm_rotate_make(rot, angle, axis); glm_rotate_make(rot, angle, axis);
glm_mul_rot(m, rot, m); glm_mul_rot(m, rot, m);
} }

View File

@@ -26,6 +26,7 @@ extern "C" {
#include "call/io.h" #include "call/io.h"
#include "call/project.h" #include "call/project.h"
#include "call/sphere.h" #include "call/sphere.h"
#include "call/ease.h"
#ifdef __cplusplus #ifdef __cplusplus
} }

140
include/cglm/call/ease.h Normal file
View File

@@ -0,0 +1,140 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_ease_h
#define cglmc_ease_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
float
glmc_ease_linear(float t);
CGLM_EXPORT
float
glmc_ease_sine_in(float t);
CGLM_EXPORT
float
glmc_ease_sine_out(float t);
CGLM_EXPORT
float
glmc_ease_sine_inout(float t);
CGLM_EXPORT
float
glmc_ease_quad_in(float t);
CGLM_EXPORT
float
glmc_ease_quad_out(float t);
CGLM_EXPORT
float
glmc_ease_quad_inout(float t);
CGLM_EXPORT
float
glmc_ease_cubic_in(float t);
CGLM_EXPORT
float
glmc_ease_cubic_out(float t);
CGLM_EXPORT
float
glmc_ease_cubic_inout(float t);
CGLM_EXPORT
float
glmc_ease_quart_in(float t);
CGLM_EXPORT
float
glmc_ease_quart_out(float t);
CGLM_EXPORT
float
glmc_ease_quart_inout(float t);
CGLM_EXPORT
float
glmc_ease_quint_in(float t);
CGLM_EXPORT
float
glmc_ease_quint_out(float t);
CGLM_EXPORT
float
glmc_ease_quint_inout(float t);
CGLM_EXPORT
float
glmc_ease_exp_in(float t);
CGLM_EXPORT
float
glmc_ease_exp_out(float t);
CGLM_EXPORT
float
glmc_ease_exp_inout(float t);
CGLM_EXPORT
float
glmc_ease_circ_in(float t);
CGLM_EXPORT
float
glmc_ease_circ_out(float t);
CGLM_EXPORT
float
glmc_ease_circ_inout(float t);
CGLM_EXPORT
float
glmc_ease_back_in(float t);
CGLM_EXPORT
float
glmc_ease_back_out(float t);
CGLM_EXPORT
float
glmc_ease_back_inout(float t);
CGLM_EXPORT
float
glmc_ease_elast_in(float t);
CGLM_EXPORT
float
glmc_ease_elast_out(float t);
CGLM_EXPORT
float
glmc_ease_elast_inout(float t);
CGLM_EXPORT
float
glmc_ease_bounce_out(float t);
CGLM_EXPORT
float
glmc_ease_bounce_in(float t);
CGLM_EXPORT
float
glmc_ease_bounce_inout(float t);
#endif /* cglmc_ease_h */

View File

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

View File

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

View File

@@ -17,6 +17,10 @@ CGLM_EXPORT
void void
glmc_quat_identity(versor q); glmc_quat_identity(versor q);
CGLM_EXPORT
void
glmc_quat_identity_array(versor * __restrict q, size_t count);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_quat_init(versor q, float x, float y, float z, float w); glmc_quat_init(versor q, float x, float y, float z, float w);

View File

@@ -37,6 +37,10 @@ CGLM_EXPORT
void void
glmc_vec4_copy(vec4 v, vec4 dest); glmc_vec4_copy(vec4 v, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_ucopy(vec4 v, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_dot(vec4 a, vec4 b); glmc_vec4_dot(vec4 a, vec4 b);

View File

@@ -198,26 +198,15 @@ glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_ortho_default(float aspect, glm_ortho_default(float aspect, mat4 dest) {
mat4 dest) {
if (aspect >= 1.0f) { if (aspect >= 1.0f) {
glm_ortho(-1.0f * aspect, glm_ortho(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest);
1.0f * aspect, return;
-1.0f,
1.0f,
-100.0f,
100.0f,
dest);
return;
} }
glm_ortho(-1.0f, aspect = 1.0f / aspect;
1.0f,
-1.0f / aspect, glm_ortho(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest);
1.0f / aspect,
-100.0f,
100.0f,
dest);
} }
/*! /*!
@@ -240,7 +229,7 @@ glm_ortho_default_s(float aspect,
-size - 100.0f, -size - 100.0f,
size + 100.0f, size + 100.0f,
dest); dest);
return; return;
} }
glm_ortho(-size, glm_ortho(-size,
@@ -291,13 +280,8 @@ glm_perspective(float fovy,
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_perspective_default(float aspect, glm_perspective_default(float aspect, mat4 dest) {
mat4 dest) { glm_perspective(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
glm_perspective((float)CGLM_PI_4,
aspect,
0.01f,
100.0f,
dest);
} }
/*! /*!
@@ -310,8 +294,7 @@ glm_perspective_default(float aspect,
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_perspective_resize(float aspect, glm_perspective_resize(float aspect, mat4 proj) {
mat4 proj) {
if (proj[0][0] == 0.0f) if (proj[0][0] == 0.0f)
return; return;

View File

@@ -25,5 +25,6 @@
#include "io.h" #include "io.h"
#include "project.h" #include "project.h"
#include "sphere.h" #include "sphere.h"
#include "ease.h"
#endif /* cglm_h */ #endif /* cglm_h */

317
include/cglm/ease.h Normal file
View File

@@ -0,0 +1,317 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_ease_h
#define cglm_ease_h
#include "common.h"
CGLM_INLINE
float
glm_ease_linear(float t) {
return t;
}
CGLM_INLINE
float
glm_ease_sine_in(float t) {
return sinf((t - 1.0f) * GLM_PI_2f) + 1.0f;
}
CGLM_INLINE
float
glm_ease_sine_out(float t) {
return sinf(t * GLM_PI_2f);
}
CGLM_INLINE
float
glm_ease_sine_inout(float t) {
return 0.5f * (1.0f - cosf(t * GLM_PIf));
}
CGLM_INLINE
float
glm_ease_quad_in(float t) {
return t * t;
}
CGLM_INLINE
float
glm_ease_quad_out(float t) {
return -(t * (t - 2.0f));
}
CGLM_INLINE
float
glm_ease_quad_inout(float t) {
float tt;
tt = t * t;
if (t < 0.5f)
return 2.0f * tt;
return (-2.0f * tt) + (4.0f * t) - 1.0f;
}
CGLM_INLINE
float
glm_ease_cubic_in(float t) {
return t * t * t;
}
CGLM_INLINE
float
glm_ease_cubic_out(float t) {
float f;
f = t - 1.0f;
return f * f * f + 1.0f;
}
CGLM_INLINE
float
glm_ease_cubic_inout(float t) {
float f;
if (t < 0.5f)
return 4.0f * t * t * t;
f = 2.0f * t - 2.0f;
return 0.5f * f * f * f + 1.0f;
}
CGLM_INLINE
float
glm_ease_quart_in(float t) {
float f;
f = t * t;
return f * f;
}
CGLM_INLINE
float
glm_ease_quart_out(float t) {
float f;
f = t - 1.0f;
return f * f * f * (1.0f - t) + 1.0f;
}
CGLM_INLINE
float
glm_ease_quart_inout(float t) {
float f, g;
if (t < 0.5f) {
f = t * t;
return 8.0f * f * f;
}
f = t - 1.0f;
g = f * f;
return -8.0f * g * g + 1.0f;
}
CGLM_INLINE
float
glm_ease_quint_in(float t) {
float f;
f = t * t;
return f * f * t;
}
CGLM_INLINE
float
glm_ease_quint_out(float t) {
float f, g;
f = t - 1.0f;
g = f * f;
return g * g * f + 1.0f;
}
CGLM_INLINE
float
glm_ease_quint_inout(float t) {
float f, g;
if (t < 0.5f) {
f = t * t;
return 16.0f * f * f * t;
}
f = 2.0f * t - 2.0f;
g = f * f;
return 0.5f * g * g * f + 1.0f;
}
CGLM_INLINE
float
glm_ease_exp_in(float t) {
if (t == 0.0f)
return t;
return powf(2.0f, 10.0f * (t - 1.0f));
}
CGLM_INLINE
float
glm_ease_exp_out(float t) {
if (t == 1.0f)
return t;
return 1.0f - powf(2.0f, -10.0f * t);
}
CGLM_INLINE
float
glm_ease_exp_inout(float t) {
if (t == 0.0f || t == 1.0f)
return t;
if (t < 0.5f)
return 0.5f * powf(2.0f, (20.0f * t) - 10.0f);
return -0.5f * powf(2.0f, (-20.0f * t) + 10.0f) + 1.0f;
}
CGLM_INLINE
float
glm_ease_circ_in(float t) {
return 1.0f - sqrtf(1.0f - (t * t));
}
CGLM_INLINE
float
glm_ease_circ_out(float t) {
return sqrtf((2.0f - t) * t);
}
CGLM_INLINE
float
glm_ease_circ_inout(float t) {
if (t < 0.5f)
return 0.5f * (1.0f - sqrtf(1.0f - 4.0f * (t * t)));
return 0.5f * (sqrtf(-((2.0f * t) - 3.0f) * ((2.0f * t) - 1.0f)) + 1.0f);
}
CGLM_INLINE
float
glm_ease_back_in(float t) {
float o, z;
o = 1.70158f;
z = ((o + 1.0f) * t) - o;
return t * t * z;
}
CGLM_INLINE
float
glm_ease_back_out(float t) {
float o, z, n;
o = 1.70158f;
n = t - 1.0f;
z = (o + 1.0f) * n + o;
return n * n * z + 1.0f;
}
CGLM_INLINE
float
glm_ease_back_inout(float t) {
float o, z, n, m, s, x;
o = 1.70158f;
s = o * 1.525f;
x = 0.5;
n = t / 0.5f;
if (n < 1.0f) {
z = (s + 1) * n - s;
m = n * n * z;
return x * m;
}
n -= 2.0f;
z = (s + 1.0f) * n + s;
m = (n * n * z) + 2;
return x * m;
}
CGLM_INLINE
float
glm_ease_elast_in(float t) {
return sinf(13.0f * GLM_PI_2f * t) * powf(2.0f, 10.0f * (t - 1.0f));
}
CGLM_INLINE
float
glm_ease_elast_out(float t) {
return sinf(-13.0f * GLM_PI_2f * (t + 1.0f)) * powf(2.0f, -10.0f * t) + 1.0f;
}
CGLM_INLINE
float
glm_ease_elast_inout(float t) {
float a;
a = 2.0f * t;
if (t < 0.5f)
return 0.5f * sinf(13.0f * GLM_PI_2f * a)
* powf(2.0f, 10.0f * (a - 1.0f));
return 0.5f * (sinf(-13.0f * GLM_PI_2f * a)
* powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f);
}
CGLM_INLINE
float
glm_ease_bounce_out(float t) {
float tt;
tt = t * t;
if (t < (4.0f / 11.0f))
return (121.0f * tt) / 16.0f;
if (t < 8.0f / 11.0f)
return ((363.0f / 40.0f) * tt) - ((99.0f / 10.0f) * t) + (17.0f / 5.0f);
if (t < (9.0f / 10.0f))
return (4356.0f / 361.0f) * tt
- (35442.0f / 1805.0f) * t
+ (16061.0f / 1805.0f);
return ((54.0f / 5.0f) * tt) - ((513.0f / 25.0f) * t) + (268.0f / 25.0f);
}
CGLM_INLINE
float
glm_ease_bounce_in(float t) {
return 1.0f - glm_ease_bounce_out(1.0f - t);
}
CGLM_INLINE
float
glm_ease_bounce_inout(float t) {
if (t < 0.5f)
return 0.5f * (1.0f - glm_ease_bounce_out(t * 2.0f));
return 0.5f * glm_ease_bounce_out(t * 2.0f - 1.0f) + 0.5f;
}
#endif /* cglm_ease_h */

View File

@@ -84,12 +84,12 @@ glm_euler_angles(mat4 m, vec3 dest) {
thetaZ = atan2f(-m10, m00); thetaZ = atan2f(-m10, m00);
} else { /* m20 == -1 */ } else { /* m20 == -1 */
/* Not a unique solution */ /* Not a unique solution */
thetaY = -CGLM_PI_2; thetaY = -GLM_PI_2f;
thetaX = -atan2f(m01, m11); thetaX = -atan2f(m01, m11);
thetaZ = 0.0f; thetaZ = 0.0f;
} }
} else { /* m20 == +1 */ } else { /* m20 == +1 */
thetaY = CGLM_PI_2; thetaY = GLM_PI_2f;
thetaX = atan2f(m01, m11); thetaX = atan2f(m01, m11);
thetaZ = 0.0f; thetaZ = 0.0f;
} }

View File

@@ -25,7 +25,7 @@
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_print(mat4 matrix, glm_mat4_print(mat4 matrix,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
int j; int j;
@@ -55,7 +55,7 @@ glm_mat4_print(mat4 matrix,
CGLM_INLINE CGLM_INLINE
void void
glm_mat3_print(mat3 matrix, glm_mat3_print(mat3 matrix,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
int j; int j;
@@ -85,7 +85,7 @@ glm_mat3_print(mat3 matrix,
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_print(vec4 vec, glm_vec4_print(vec4 vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
@@ -107,7 +107,7 @@ glm_vec4_print(vec4 vec,
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_print(vec3 vec, glm_vec3_print(vec3 vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
@@ -129,7 +129,7 @@ glm_vec3_print(vec3 vec,
CGLM_INLINE CGLM_INLINE
void void
glm_ivec3_print(ivec3 vec, glm_ivec3_print(ivec3 vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
@@ -151,7 +151,7 @@ glm_ivec3_print(ivec3 vec,
CGLM_INLINE CGLM_INLINE
void void
glm_versor_print(versor vec, glm_versor_print(versor vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;

View File

@@ -16,6 +16,7 @@
Functions: Functions:
CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest);
CGLM_INLINE void glm_mat3_identity(mat3 mat); CGLM_INLINE void glm_mat3_identity(mat3 mat);
CGLM_INLINE void glm_mat3_identity_array(mat3 * restrict mat, size_t count);
CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest); CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest);
CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest);
CGLM_INLINE void glm_mat3_transpose(mat3 m); CGLM_INLINE void glm_mat3_transpose(mat3 m);
@@ -81,10 +82,29 @@ glm_mat3_copy(mat3 mat, mat3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat3_identity(mat3 mat) { glm_mat3_identity(mat3 mat) {
CGLM_ALIGN(16) mat3 t = GLM_MAT3_IDENTITY_INIT; CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT;
glm_mat3_copy(t, mat); glm_mat3_copy(t, mat);
} }
/*!
* @brief make given matrix array's each element identity matrix
*
* @param[in, out] mat matrix array (must be aligned (16/32)
* if alignment is not disabled)
*
* @param[in] count count of matrices
*/
CGLM_INLINE
void
glm_mat3_identity_array(mat3 * __restrict mat, size_t count) {
CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_mat3_copy(t, mat[i]);
}
}
/*! /*!
* @brief multiply m1 and m2 to dest * @brief multiply m1 and m2 to dest
* *
@@ -155,7 +175,7 @@ glm_mat3_transpose_to(mat3 m, mat3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat3_transpose(mat3 m) { glm_mat3_transpose(mat3 m) {
CGLM_ALIGN(16) mat3 tmp; CGLM_ALIGN_MAT mat3 tmp;
tmp[0][1] = m[1][0]; tmp[0][1] = m[1][0];
tmp[0][2] = m[2][0]; tmp[0][2] = m[2][0];

View File

@@ -23,6 +23,7 @@
CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest);
CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest);
CGLM_INLINE void glm_mat4_identity(mat4 mat); CGLM_INLINE void glm_mat4_identity(mat4 mat);
CGLM_INLINE void glm_mat4_identity_array(mat4 * restrict mat, size_t count);
CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest);
CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest);
CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest); CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest);
@@ -139,10 +140,29 @@ glm_mat4_copy(mat4 mat, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_identity(mat4 mat) { glm_mat4_identity(mat4 mat) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
glm_mat4_copy(t, mat); glm_mat4_copy(t, mat);
} }
/*!
* @brief make given matrix array's each element identity matrix
*
* @param[in, out] mat matrix array (must be aligned (16/32)
* if alignment is not disabled)
*
* @param[in] count count of matrices
*/
CGLM_INLINE
void
glm_mat4_identity_array(mat4 * __restrict mat, size_t count) {
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_mat4_copy(t, mat[i]);
}
}
/*! /*!
* @brief copy upper-left of mat4 to mat3 * @brief copy upper-left of mat4 to mat3
* *

View File

@@ -103,6 +103,25 @@ glm_quat_identity(versor q) {
glm_vec4_copy(v, q); glm_vec4_copy(v, q);
} }
/*!
* @brief make given quaternion array's each element identity quaternion
*
* @param[in, out] q quat array (must be aligned (16)
* if alignment is not disabled)
*
* @param[in] count count of quaternions
*/
CGLM_INLINE
void
glm_quat_identity_array(versor * __restrict q, size_t count) {
CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_vec4_copy(v, q[i]);
}
}
/*! /*!
* @brief inits quaterion with raw values * @brief inits quaterion with raw values
* *
@@ -670,7 +689,7 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) {
dot = glm_vec_dot(dir, fwd); dot = glm_vec_dot(dir, fwd);
if (fabsf(dot + 1.0f) < 0.000001f) { if (fabsf(dot + 1.0f) < 0.000001f) {
glm_quat_init(dest, up[0], up[1], up[2], CGLM_PI); glm_quat_init(dest, up[0], up[1], up[2], GLM_PIf);
return; return;
} }
@@ -742,7 +761,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_rotate(mat4 m, versor q, mat4 dest) { glm_quat_rotate(mat4 m, versor q, mat4 dest) {
CGLM_ALIGN(16) mat4 rot; CGLM_ALIGN_MAT mat4 rot;
glm_quat_mat4(q, rot); glm_quat_mat4(q, rot);
glm_mul_rot(m, rot, dest); glm_mul_rot(m, rot, dest);
} }

View File

@@ -27,21 +27,24 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) {
y2 = glmm_load256(m1[0]); /* h g f e d c b a */ y2 = glmm_load256(m1[0]); /* h g f e d c b a */
y3 = glmm_load256(m1[2]); /* p o n m l k j i */ y3 = glmm_load256(m1[2]); /* p o n m l k j i */
y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ /* 0x03: 0b00000011 */
y5 = _mm256_permute2f128_ps(y3, y3, 0b00000000); /* l k j i l k j i */ y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */
y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */
/* f f f f a a a a */ /* f f f f a a a a */
/* g g g g c c c c */ /* h h h h c c c c */
/* e e e e b b b b */ /* e e e e b b b b */
y7 = _mm256_permute_ps(y0, 0b10101010); /* g g g g d d d d */
y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0));
y7 = _mm256_permutevar_ps(y0, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2));
y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1));
y9 = _mm256_permutevar_ps(y0, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3));
glmm_store256(dest[0], glmm_store256(dest[0],
_mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6),
_mm256_mul_ps(y4, y8)), _mm256_mul_ps(y3, y7)),
_mm256_mul_ps(y5, y7))); _mm256_add_ps(_mm256_mul_ps(y4, y8),
_mm256_mul_ps(y5, y9))));
/* n n n n i i i i */ /* n n n n i i i i */
/* p p p p k k k k */ /* p p p p k k k k */

View File

@@ -27,8 +27,9 @@ glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) {
y2 = glmm_load256(m1[0]); /* h g f e d c b a */ y2 = glmm_load256(m1[0]); /* h g f e d c b a */
y3 = glmm_load256(m1[2]); /* p o n m l k j i */ y3 = glmm_load256(m1[2]); /* p o n m l k j i */
y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ /* 0x03: 0b00000011 */
y5 = _mm256_permute2f128_ps(y3, y3, 0b00000011); /* l k j i p o n m */ y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */
y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */
/* f f f f a a a a */ /* f f f f a a a a */
/* h h h h c c c c */ /* h h h h c c c c */

View File

@@ -16,7 +16,7 @@
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_scale_sse2(mat4 m, float s){ glm_mat4_scale_sse2(mat4 m, float s) {
__m128 x0; __m128 x0;
x0 = _mm_set1_ps(s); x0 = _mm_set1_ps(s);
@@ -28,7 +28,7 @@ glm_mat4_scale_sse2(mat4 m, float s){
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_transp_sse2(mat4 m, mat4 dest){ glm_mat4_transp_sse2(mat4 m, mat4 dest) {
__m128 r0, r1, r2, r3; __m128 r0, r1, r2, r3;
r0 = glmm_load(m[0]); r0 = glmm_load(m[0]);

View File

@@ -26,18 +26,58 @@
# define CGLM_ALIGN_IF(X) /* no alignment */ # define CGLM_ALIGN_IF(X) /* no alignment */
#endif #endif
#ifdef __AVX__
# define CGLM_ALIGN_MAT CGLM_ALIGN(32)
#else
# define CGLM_ALIGN_MAT CGLM_ALIGN(16)
#endif
typedef float vec2[2]; typedef float vec2[2];
typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef CGLM_ALIGN_IF(8) float vec3[3];
typedef int ivec3[3]; typedef int ivec3[3];
typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef CGLM_ALIGN_IF(16) float vec4[4];
typedef vec3 mat3[3]; #ifdef __AVX__
typedef CGLM_ALIGN_IF(32) vec3 mat3[3];
typedef CGLM_ALIGN_IF(32) vec4 mat4[4];
#else
typedef vec3 mat3[3];
typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4];
#endif
typedef vec4 versor; typedef vec4 versor;
#define CGLM_PI ((float)M_PI) #define GLM_E 2.71828182845904523536028747135266250 /* e */
#define CGLM_PI_2 ((float)M_PI_2) #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */
#define CGLM_PI_4 ((float)M_PI_4) #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */
#define GLM_LN2 0.693147180559945309417232121458176568 /* loge(2) */
#define GLM_LN10 2.30258509299404568401799145468436421 /* loge(10) */
#define GLM_PI 3.14159265358979323846264338327950288 /* pi */
#define GLM_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
#define GLM_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
#define GLM_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
#define GLM_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
#define GLM_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */
#define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */
#define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
#define GLM_Ef ((float)GLM_E)
#define GLM_LOG2Ef ((float)GLM_LOG2E)
#define GLM_LOG10Ef ((float)GLM_LOG10E)
#define GLM_LN2f ((float)GLM_LN2)
#define GLM_LN10f ((float)GLM_LN10)
#define GLM_PIf ((float)GLM_PI)
#define GLM_PI_2f ((float)GLM_PI_2)
#define GLM_PI_4f ((float)GLM_PI_4)
#define GLM_1_PIf ((float)GLM_1_PI)
#define GLM_2_PIf ((float)GLM_2_PI)
#define GLM_2_SQRTPIf ((float)GLM_2_SQRTPI)
#define GLM_SQRT2f ((float)GLM_SQRT2)
#define GLM_SQRT1_2f ((float)GLM_SQRT1_2)
/* DEPRECATED! use GLM_PI and friends */
#define CGLM_PI GLM_PIf
#define CGLM_PI_2 GLM_PI_2f
#define CGLM_PI_4 GLM_PI_4f
#endif /* cglm_types_h */ #endif /* cglm_types_h */

View File

@@ -19,6 +19,10 @@
#define cglm_util_h #define cglm_util_h
#include "common.h" #include "common.h"
#include <stdbool.h>
#define GLM_MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define GLM_MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
/*! /*!
* @brief get sign of 32 bit integer as +1, -1, 0 * @brief get sign of 32 bit integer as +1, -1, 0
@@ -54,7 +58,7 @@ glm_signf(float val) {
CGLM_INLINE CGLM_INLINE
float float
glm_rad(float deg) { glm_rad(float deg) {
return deg * CGLM_PI / 180.0f; return deg * GLM_PIf / 180.0f;
} }
/*! /*!
@@ -65,7 +69,7 @@ glm_rad(float deg) {
CGLM_INLINE CGLM_INLINE
float float
glm_deg(float rad) { glm_deg(float rad) {
return rad * 180.0f / CGLM_PI; return rad * 180.0f / GLM_PIf;
} }
/*! /*!
@@ -76,7 +80,7 @@ glm_deg(float rad) {
CGLM_INLINE CGLM_INLINE
void void
glm_make_rad(float *deg) { glm_make_rad(float *deg) {
*deg = *deg * CGLM_PI / 180.0f; *deg = *deg * GLM_PIf / 180.0f;
} }
/*! /*!
@@ -87,7 +91,7 @@ glm_make_rad(float *deg) {
CGLM_INLINE CGLM_INLINE
void void
glm_make_deg(float *rad) { glm_make_deg(float *rad) {
*rad = *rad * 180.0f / CGLM_PI; *rad = *rad * 180.0f / GLM_PIf;
} }
/*! /*!
@@ -142,6 +146,17 @@ glm_clamp(float val, float minVal, float maxVal) {
return glm_min(glm_max(val, minVal), maxVal); return glm_min(glm_max(val, minVal), maxVal);
} }
/*!
* @brief clamp a number to zero and one
*
* @param[in] val value to clamp
*/
CGLM_INLINE
float
glm_clamp_zo(float val) {
return glm_clamp(val, 0.0f, 1.0f);
}
/*! /*!
* @brief linear interpolation between two number * @brief linear interpolation between two number
* *
@@ -154,7 +169,52 @@ glm_clamp(float val, float minVal, float maxVal) {
CGLM_INLINE CGLM_INLINE
float float
glm_lerp(float from, float to, float t) { glm_lerp(float from, float to, float t) {
return from + glm_clamp(t, 0.0f, 1.0f) * (to - from); return from + glm_clamp_zo(t) * (to - from);
}
/*!
* @brief check if two float equal with using EPSILON
*
* @param[in] a a
* @param[in] b b
*/
CGLM_INLINE
bool
glm_eq(float a, float b) {
return fabsf(a - b) <= FLT_EPSILON;
}
/*!
* @brief percentage of current value between start and end value
*
* maybe fraction could be alternative name.
*
* @param[in] from from value
* @param[in] to to value
* @param[in] current current value
*/
CGLM_INLINE
float
glm_percent(float from, float to, float current) {
float t;
if ((t = to - from) == 0.0f)
return 1.0f;
return (current - from) / t;
}
/*!
* @brief clamped percentage of current value between start and end value
*
* @param[in] from from value
* @param[in] to to value
* @param[in] current current value
*/
CGLM_INLINE
float
glm_percentc(float from, float to, float current) {
return glm_clamp(glm_percent(from, to, current), 0.0f, 1.0f);
} }
#endif /* cglm_util_h */ #endif /* cglm_util_h */

View File

@@ -736,7 +736,7 @@ glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) {
vec3 s, v; vec3 s, v;
/* from + s * (to - from) */ /* from + s * (to - from) */
glm_vec_broadcast(glm_clamp(t, 0.0f, 1.0f), s); glm_vec_broadcast(glm_clamp_zo(t), s);
glm_vec_sub(to, from, v); glm_vec_sub(to, from, v);
glm_vec_mulv(s, v, v); glm_vec_mulv(s, v, v);
glm_vec_add(from, v, dest); glm_vec_add(from, v, dest);

View File

@@ -25,6 +25,7 @@
CGLM_INLINE void glm_vec4(vec3 v3, float last, vec4 dest); CGLM_INLINE void glm_vec4(vec3 v3, float last, vec4 dest);
CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest);
CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest);
CGLM_INLINE void glm_vec4_ucopy(vec4 v, vec4 dest);
CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b);
CGLM_INLINE float glm_vec4_norm2(vec4 v); CGLM_INLINE float glm_vec4_norm2(vec4 v);
CGLM_INLINE float glm_vec4_norm(vec4 vec); CGLM_INLINE float glm_vec4_norm(vec4 vec);
@@ -120,6 +121,23 @@ glm_vec4_copy(vec4 v, vec4 dest) {
#endif #endif
} }
/*!
* @brief copy all members of [a] to [dest]
*
* alignment is not required
*
* @param[in] v source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_ucopy(vec4 v, vec4 dest) {
dest[0] = v[0];
dest[1] = v[1];
dest[2] = v[2];
dest[3] = v[3];
}
/*! /*!
* @brief make vector zero * @brief make vector zero
* *
@@ -698,7 +716,7 @@ glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) {
vec4 s, v; vec4 s, v;
/* from + s * (to - from) */ /* from + s * (to - from) */
glm_vec4_broadcast(glm_clamp(t, 0.0f, 1.0f), s); glm_vec4_broadcast(glm_clamp_zo(t), s);
glm_vec4_sub(to, from, v); glm_vec4_sub(to, from, v);
glm_vec4_mulv(s, v, v); glm_vec4_mulv(s, v, v);
glm_vec4_add(from, v, dest); glm_vec4_add(from, v, dest);

View File

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

View File

@@ -56,7 +56,8 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/box.h \ include/cglm/box.h \
include/cglm/color.h \ include/cglm/color.h \
include/cglm/project.h \ include/cglm/project.h \
include/cglm/sphere.h include/cglm/sphere.h \
include/cglm/ease.h
cglm_calldir=$(includedir)/cglm/call cglm_calldir=$(includedir)/cglm/call
cglm_call_HEADERS = include/cglm/call/mat4.h \ cglm_call_HEADERS = include/cglm/call/mat4.h \
@@ -72,7 +73,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \
include/cglm/call/frustum.h \ include/cglm/call/frustum.h \
include/cglm/call/box.h \ include/cglm/call/box.h \
include/cglm/call/project.h \ include/cglm/call/project.h \
include/cglm/call/sphere.h include/cglm/call/sphere.h \
include/cglm/call/ease.h
cglm_simddir=$(includedir)/cglm/simd cglm_simddir=$(includedir)/cglm/simd
cglm_simd_HEADERS = include/cglm/simd/intrin.h cglm_simd_HEADERS = include/cglm/simd/intrin.h
@@ -104,7 +106,8 @@ libcglm_la_SOURCES=\
src/frustum.c \ src/frustum.c \
src/box.c \ src/box.c \
src/project.c \ src/project.c \
src/sphere.c src/sphere.c \
src/ease.c
test_tests_SOURCES=\ test_tests_SOURCES=\
test/src/test_common.c \ test/src/test_common.c \

195
src/ease.c Normal file
View File

@@ -0,0 +1,195 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#include "../include/cglm/cglm.h"
#include "../include/cglm/call.h"
CGLM_EXPORT
float
glmc_ease_linear(float t) {
return glm_ease_linear(t);
}
CGLM_EXPORT
float
glmc_ease_sine_in(float t) {
return glm_ease_sine_in(t);
}
CGLM_EXPORT
float
glmc_ease_sine_out(float t) {
return glm_ease_sine_out(t);
}
CGLM_EXPORT
float
glmc_ease_sine_inout(float t) {
return glm_ease_sine_inout(t);
}
CGLM_EXPORT
float
glmc_ease_quad_in(float t) {
return glm_ease_quad_in(t);
}
CGLM_EXPORT
float
glmc_ease_quad_out(float t) {
return glm_ease_quad_out(t);
}
CGLM_EXPORT
float
glmc_ease_quad_inout(float t) {
return glm_ease_quad_inout(t);
}
CGLM_EXPORT
float
glmc_ease_cubic_in(float t) {
return glm_ease_cubic_in(t);
}
CGLM_EXPORT
float
glmc_ease_cubic_out(float t) {
return glm_ease_cubic_out(t);
}
CGLM_EXPORT
float
glmc_ease_cubic_inout(float t) {
return glm_ease_cubic_inout(t);
}
CGLM_EXPORT
float
glmc_ease_quart_in(float t) {
return glm_ease_quart_in(t);
}
CGLM_EXPORT
float
glmc_ease_quart_out(float t) {
return glm_ease_quart_out(t);
}
CGLM_EXPORT
float
glmc_ease_quart_inout(float t) {
return glm_ease_quart_inout(t);
}
CGLM_EXPORT
float
glmc_ease_quint_in(float t) {
return glm_ease_quint_in(t);
}
CGLM_EXPORT
float
glmc_ease_quint_out(float t) {
return glm_ease_quint_out(t);
}
CGLM_EXPORT
float
glmc_ease_quint_inout(float t) {
return glm_ease_quint_inout(t);
}
CGLM_EXPORT
float
glmc_ease_exp_in(float t) {
return glm_ease_exp_in(t);
}
CGLM_EXPORT
float
glmc_ease_exp_out(float t) {
return glm_ease_exp_out(t);
}
CGLM_EXPORT
float
glmc_ease_exp_inout(float t) {
return glm_ease_exp_inout(t);
}
CGLM_EXPORT
float
glmc_ease_circ_in(float t) {
return glm_ease_circ_in(t);
}
CGLM_EXPORT
float
glmc_ease_circ_out(float t) {
return glm_ease_circ_out(t);
}
CGLM_EXPORT
float
glmc_ease_circ_inout(float t) {
return glm_ease_circ_inout(t);
}
CGLM_EXPORT
float
glmc_ease_back_in(float t) {
return glm_ease_back_in(t);
}
CGLM_EXPORT
float
glmc_ease_back_out(float t) {
return glm_ease_back_out(t);
}
CGLM_EXPORT
float
glmc_ease_back_inout(float t) {
return glm_ease_back_inout(t);
}
CGLM_EXPORT
float
glmc_ease_elast_in(float t) {
return glm_ease_elast_in(t);
}
CGLM_EXPORT
float
glmc_ease_elast_out(float t) {
return glm_ease_elast_out(t);
}
CGLM_EXPORT
float
glmc_ease_elast_inout(float t) {
return glm_ease_elast_inout(t);
}
CGLM_EXPORT
float
glmc_ease_bounce_out(float t) {
return glm_ease_bounce_out(t);
}
CGLM_EXPORT
float
glmc_ease_bounce_in(float t) {
return glm_ease_bounce_in(t);
}
CGLM_EXPORT
float
glmc_ease_bounce_inout(float t) {
return glm_ease_bounce_inout(t);
}

View File

@@ -20,6 +20,12 @@ glmc_mat3_identity(mat3 mat) {
glm_mat3_identity(mat); glm_mat3_identity(mat);
} }
CGLM_EXPORT
void
glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) {
glm_mat3_identity_array(mat, count);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) {

View File

@@ -26,6 +26,12 @@ glmc_mat4_identity(mat4 mat) {
glm_mat4_identity(mat); glm_mat4_identity(mat);
} }
CGLM_EXPORT
void
glmc_mat4_identity_array(mat4 * __restrict mat, size_t count) {
glm_mat4_identity_array(mat, count);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_pick3(mat4 mat, mat3 dest) { glmc_mat4_pick3(mat4 mat, mat3 dest) {

View File

@@ -8,13 +8,18 @@
#include "../include/cglm/cglm.h" #include "../include/cglm/cglm.h"
#include "../include/cglm/call.h" #include "../include/cglm/call.h"
CGLM_EXPORT CGLM_EXPORT
void void
glmc_quat_identity(versor q) { glmc_quat_identity(versor q) {
glm_quat_identity(q); glm_quat_identity(q);
} }
CGLM_EXPORT
void
glmc_quat_identity_array(versor * __restrict q, size_t count) {
glm_quat_identity_array(q, count);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_quat_init(versor q, float x, float y, float z, float w) { glmc_quat_init(versor q, float x, float y, float z, float w) {

View File

@@ -38,6 +38,12 @@ glmc_vec4_copy(vec4 v, vec4 dest) {
glm_vec4_copy(v, dest); glm_vec4_copy(v, dest);
} }
CGLM_EXPORT
void
glmc_vec4_ucopy(vec4 v, vec4 dest) {
glm_vec4_ucopy(v, dest);
}
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_dot(vec4 a, vec4 b) { glmc_vec4_dot(vec4 a, vec4 b) {

View File

@@ -12,7 +12,7 @@ test_affine(void **state) {
mat4 t1, t2, t3, t4, t5; mat4 t1, t2, t3, t4, t5;
/* test translate is postmultiplied */ /* test translate is postmultiplied */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -21,16 +21,16 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test rotate is postmultiplied */ /* test rotate is postmultiplied */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate(t2, M_PI_4, GLM_YUP); glm_rotate(t2, GLM_PI_4f, GLM_YUP);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test scale is postmultiplied */ /* test scale is postmultiplied */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glm_scale_make(t4, (vec3){3, 5, 6}); glm_scale_make(t4, (vec3){3, 5, 6});
@@ -41,7 +41,7 @@ test_affine(void **state) {
test_assert_mat4_eq(t3, t5); test_assert_mat4_eq(t3, t5);
/* test translate_x */ /* test translate_x */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 0, 0}); glm_translate_make(t2, (vec3){34, 0, 0});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -49,7 +49,7 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test translate_y */ /* test translate_y */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){0, 57, 0}); glm_translate_make(t2, (vec3){0, 57, 0});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -57,7 +57,7 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test translate_z */ /* test translate_z */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){0, 0, 36}); glm_translate_make(t2, (vec3){0, 0, 36});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -65,43 +65,43 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test rotate_x */ /* test rotate_x */
glmc_rotate_make(t1, M_PI_4, (vec3){1, 0, 0}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){1, 0, 0});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate_x(t2, M_PI_4, t2); glm_rotate_x(t2, GLM_PI_4f, t2);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test rotate_y */ /* test rotate_y */
glmc_rotate_make(t1, M_PI_4, (vec3){0, 1, 0}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 1, 0});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate_y(t2, M_PI_4, t2); glm_rotate_y(t2, GLM_PI_4f, t2);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test rotate_z */ /* test rotate_z */
glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate_z(t2, M_PI_4, t2); glm_rotate_z(t2, GLM_PI_4f, t2);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test rotate */ /* test rotate */
glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glmc_rotate(t2, M_PI_4, (vec3){0, 0, 1}); glmc_rotate(t2, GLM_PI_4f, (vec3){0, 0, 1});
test_assert_mat4_eq(t3, t2); test_assert_mat4_eq(t3, t2);
/* test scale_uni */ /* test scale_uni */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glm_scale_make(t4, (vec3){3, 3, 3}); glm_scale_make(t4, (vec3){3, 3, 3});

View File

@@ -23,6 +23,7 @@
<ClCompile Include="..\src\box.c" /> <ClCompile Include="..\src\box.c" />
<ClCompile Include="..\src\cam.c" /> <ClCompile Include="..\src\cam.c" />
<ClCompile Include="..\src\dllmain.c" /> <ClCompile Include="..\src\dllmain.c" />
<ClCompile Include="..\src\ease.c" />
<ClCompile Include="..\src\euler.c" /> <ClCompile Include="..\src\euler.c" />
<ClCompile Include="..\src\frustum.c" /> <ClCompile Include="..\src\frustum.c" />
<ClCompile Include="..\src\io.c" /> <ClCompile Include="..\src\io.c" />
@@ -43,6 +44,7 @@
<ClInclude Include="..\include\cglm\call\affine.h" /> <ClInclude Include="..\include\cglm\call\affine.h" />
<ClInclude Include="..\include\cglm\call\box.h" /> <ClInclude Include="..\include\cglm\call\box.h" />
<ClInclude Include="..\include\cglm\call\cam.h" /> <ClInclude Include="..\include\cglm\call\cam.h" />
<ClInclude Include="..\include\cglm\call\ease.h" />
<ClInclude Include="..\include\cglm\call\euler.h" /> <ClInclude Include="..\include\cglm\call\euler.h" />
<ClInclude Include="..\include\cglm\call\frustum.h" /> <ClInclude Include="..\include\cglm\call\frustum.h" />
<ClInclude Include="..\include\cglm\call\io.h" /> <ClInclude Include="..\include\cglm\call\io.h" />
@@ -58,6 +60,7 @@
<ClInclude Include="..\include\cglm\cglm.h" /> <ClInclude Include="..\include\cglm\cglm.h" />
<ClInclude Include="..\include\cglm\color.h" /> <ClInclude Include="..\include\cglm\color.h" />
<ClInclude Include="..\include\cglm\common.h" /> <ClInclude Include="..\include\cglm\common.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\io.h" /> <ClInclude Include="..\include\cglm\io.h" />

View File

@@ -81,6 +81,9 @@
<ClCompile Include="..\src\sphere.c"> <ClCompile Include="..\src\sphere.c">
<Filter>src</Filter> <Filter>src</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\ease.c">
<Filter>src</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\src\config.h"> <ClInclude Include="..\src\config.h">
@@ -224,5 +227,11 @@
<ClInclude Include="..\include\cglm\sphere.h"> <ClInclude Include="..\include\cglm\sphere.h">
<Filter>include\cglm</Filter> <Filter>include\cglm</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\include\cglm\call\ease.h">
<Filter>include\cglm\call</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\ease.h">
<Filter>include\cglm</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>