mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Compare commits
4 Commits
v0.4.8
...
interpolat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
672923cb96 | ||
|
|
06d66fc6cc | ||
|
|
7e7098d498 | ||
|
|
06b2a53113 |
@@ -151,7 +151,7 @@ glm_inv_tr(mat4 mat) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
glm_inv_tr_sse2(mat);
|
||||
#else
|
||||
CGLM_ALIGN_MAT mat3 r;
|
||||
CGLM_ALIGN(16) mat3 r;
|
||||
CGLM_ALIGN(16) vec3 t;
|
||||
|
||||
/* rotate */
|
||||
|
||||
@@ -244,7 +244,7 @@ glm_scale_uni(mat4 m, float s) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_rotate_x(mat4 m, float angle, mat4 dest) {
|
||||
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
float c, s;
|
||||
|
||||
c = cosf(angle);
|
||||
@@ -269,7 +269,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_rotate_y(mat4 m, float angle, mat4 dest) {
|
||||
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
float c, s;
|
||||
|
||||
c = cosf(angle);
|
||||
@@ -294,7 +294,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_rotate_z(mat4 m, float angle, mat4 dest) {
|
||||
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
float c, s;
|
||||
|
||||
c = cosf(angle);
|
||||
@@ -351,7 +351,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_rotate(mat4 m, float angle, vec3 axis) {
|
||||
CGLM_ALIGN_MAT mat4 rot;
|
||||
CGLM_ALIGN(16) mat4 rot;
|
||||
glm_rotate_make(rot, angle, axis);
|
||||
glm_mul_rot(m, rot, m);
|
||||
}
|
||||
|
||||
124
include/cglm/bezier.h
Normal file
124
include/cglm/bezier.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#ifndef cglm_bezier_h
|
||||
#define cglm_bezier_h
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*!
|
||||
* @brief cubic bezier interpolation
|
||||
*
|
||||
* @param[in] t time between 0 and 1
|
||||
* @param[in] p0 begin point
|
||||
* @param[in] c0 control point 1
|
||||
* @param[in] c1 control point 2
|
||||
* @param[in] p1 end point
|
||||
*
|
||||
* @return B(s)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_bezier_cubic(float t, float p0, float c0, float c1, float p1) {
|
||||
float s, ss, tt;
|
||||
|
||||
s = 1.0f - t;
|
||||
ss = s * s;
|
||||
tt = t * t;
|
||||
|
||||
return p0 * ss * s + 3.0f * c0 * t * ss + 3.0f * c1 * tt * s + p1 * tt * t;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief cubic bezier interpolation for vec3
|
||||
*
|
||||
* @param[in] t time between 0 and 1
|
||||
* @param[in] p0 begin point
|
||||
* @param[in] c0 control point 1
|
||||
* @param[in] c1 control point 2
|
||||
* @param[in] p1 end point
|
||||
* @param[in] dest destination
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_bezier_cubicv3(float t, vec3 p0, vec3 c0, vec3 c1, vec3 p1, vec3 dest) {
|
||||
vec3 Bs, tmp0, tmp1, tmp2;
|
||||
float s, ss, tt;
|
||||
|
||||
s = 1.0f - t;
|
||||
ss = s * s;
|
||||
tt = t * t;
|
||||
|
||||
glm_vec_scale(p0, ss * s, Bs);
|
||||
glm_vec_scale(c0, 3.0f * t * ss, tmp0);
|
||||
glm_vec_scale(c1, 3.0f * tt * s, tmp1);
|
||||
glm_vec_scale(p1, tt * t, tmp2);
|
||||
|
||||
glm_vec_add(Bs, tmp0, Bs);
|
||||
glm_vec_add(Bs, tmp1, Bs);
|
||||
glm_vec_add(Bs, tmp2, Bs);
|
||||
|
||||
glm_vec_copy(Bs, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief cubic hermite interpolation
|
||||
*
|
||||
* @param[in] t time between 0 and 1
|
||||
* @param[in] p0 begin point
|
||||
* @param[in] t0 tangent 1
|
||||
* @param[in] t1 tangent 2
|
||||
* @param[in] p1 end point
|
||||
*
|
||||
* @return B(s)
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_hermite_cubic(float t, float p0, float t0, float t1, float p1) {
|
||||
float tt, ttt;
|
||||
|
||||
tt = t * t;
|
||||
ttt = tt * t;
|
||||
|
||||
return p0 * (2.0f * ttt - 3.0f * tt + 1)
|
||||
+ t0 * (ttt - 2.0f * tt + t)
|
||||
+ p1 * (3.0f * tt - 2.0f * ttt)
|
||||
- t1 * (ttt - tt);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief cubic hermite interpolation for vec3
|
||||
*
|
||||
* @param[in] t time between 0 and 1
|
||||
* @param[in] p0 begin point
|
||||
* @param[in] t0 tangent 1
|
||||
* @param[in] t1 tangent 2
|
||||
* @param[in] p1 end point
|
||||
* @param[in] dest destination
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_hermite_cubicv3(float t, vec3 p0, vec3 t0, vec3 t1, vec3 p1, vec3 dest) {
|
||||
vec3 Hs, tmp0, tmp1, tmp2;
|
||||
float tt, ttt;
|
||||
|
||||
tt = t * t;
|
||||
ttt = tt * t;
|
||||
|
||||
glm_vec_scale(p0, 2.0f * ttt - 3.0f * tt + 1, Hs);
|
||||
glm_vec_scale(t0, ttt - 2.0f * tt + t, tmp0);
|
||||
glm_vec_scale(p1, 3.0f * tt - 2.0f * ttt, tmp1);
|
||||
glm_vec_scale(t1, ttt - tt, tmp2);
|
||||
|
||||
glm_vec_add(Hs, tmp0, Hs);
|
||||
glm_vec_add(Hs, tmp1, Hs);
|
||||
glm_vec_add(Hs, tmp2, Hs);
|
||||
|
||||
glm_vec_copy(Hs, dest);
|
||||
}
|
||||
|
||||
#endif /* cglm_bezier_h */
|
||||
@@ -26,5 +26,6 @@
|
||||
#include "project.h"
|
||||
#include "sphere.h"
|
||||
#include "ease.h"
|
||||
#include "bezier.h"
|
||||
|
||||
#endif /* cglm_h */
|
||||
|
||||
@@ -81,7 +81,7 @@ glm_mat3_copy(mat3 mat, mat3 dest) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat3_identity(mat3 mat) {
|
||||
CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT;
|
||||
CGLM_ALIGN(16) mat3 t = GLM_MAT3_IDENTITY_INIT;
|
||||
glm_mat3_copy(t, mat);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ glm_mat3_transpose_to(mat3 m, mat3 dest) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat3_transpose(mat3 m) {
|
||||
CGLM_ALIGN_MAT mat3 tmp;
|
||||
CGLM_ALIGN(16) mat3 tmp;
|
||||
|
||||
tmp[0][1] = m[1][0];
|
||||
tmp[0][2] = m[2][0];
|
||||
|
||||
@@ -139,7 +139,7 @@ glm_mat4_copy(mat4 mat, mat4 dest) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_mat4_identity(mat4 mat) {
|
||||
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT;
|
||||
glm_mat4_copy(t, mat);
|
||||
}
|
||||
|
||||
|
||||
@@ -742,7 +742,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) {
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_quat_rotate(mat4 m, versor q, mat4 dest) {
|
||||
CGLM_ALIGN_MAT mat4 rot;
|
||||
CGLM_ALIGN(16) mat4 rot;
|
||||
glm_quat_mat4(q, rot);
|
||||
glm_mul_rot(m, rot, dest);
|
||||
}
|
||||
|
||||
@@ -26,25 +26,13 @@
|
||||
# define CGLM_ALIGN_IF(X) /* no alignment */
|
||||
#endif
|
||||
|
||||
#ifdef __AVX__
|
||||
# define CGLM_ALIGN_MAT CGLM_ALIGN(32)
|
||||
#else
|
||||
# define CGLM_ALIGN_MAT CGLM_ALIGN(16)
|
||||
#endif
|
||||
|
||||
typedef float vec2[2];
|
||||
typedef CGLM_ALIGN_IF(8) float vec3[3];
|
||||
typedef int ivec3[3];
|
||||
typedef CGLM_ALIGN_IF(16) float vec4[4];
|
||||
|
||||
#ifdef __AVX__
|
||||
typedef CGLM_ALIGN_IF(32) vec3 mat3[3];
|
||||
typedef CGLM_ALIGN_IF(32) vec4 mat4[4];
|
||||
#else
|
||||
typedef vec3 mat3[3];
|
||||
typedef vec3 mat3[3];
|
||||
typedef CGLM_ALIGN_IF(16) vec4 mat4[4];
|
||||
#endif
|
||||
|
||||
|
||||
typedef vec4 versor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user