translate and move

This commit is contained in:
Recep Aslantas
2016-09-11 16:48:12 +03:00
parent 111908b9e0
commit 7f4d4868eb
2 changed files with 101 additions and 0 deletions

73
include/cglm-affine.h Normal file
View File

@@ -0,0 +1,73 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_affine_h
#define cglm_affine_h
#include "cglm.h"
CGLM_INLINE
void
glm_translate(mat4 m, vec3 v, mat4 dest) {
dest[3][0] = m[3][0] + v[0];
dest[3][1] = m[3][1] + v[1];
dest[3][2] = m[3][2] + v[2];
}
CGLM_INLINE
void
glm_translate_self(mat4 m, vec3 v) {
m[3][0] += v[0];
m[3][1] += v[1];
m[3][2] += v[2];
}
CGLM_INLINE
void
glm_translate_x(mat4 m, float to) {
m[3][0] += to;
}
CGLM_INLINE
void
glm_translate_y(mat4 m, float to) {
m[3][1] += to;
}
CGLM_INLINE
void
glm_translate_z(mat4 m, float to) {
m[3][2] += to;
}
CGLM_INLINE
void
glm_move(mat4 m, vec3 v) {
m[3][0] = v[0];
m[3][1] = v[1];
m[3][2] = v[2];
}
CGLM_INLINE
void
glm_move_x(mat4 m, float to) {
m[3][0] = to;
}
CGLM_INLINE
void
glm_move_y(mat4 m, float to) {
m[3][1] = to;
}
CGLM_INLINE
void
glm_tmove_z(mat4 m, float to) {
m[3][2] = to;
}
#endif /* cglm_affine_h */

View File

@@ -8,10 +8,38 @@
#ifndef glm_common_h
#define glm_common_h
#include <stdint.h>
#if defined(_WIN32)
# define CGLM_INLINE __forceinline
#else
# define CGLM_INLINE static inline __attribute((always_inline))
#endif
#define glm__memcpy(dest, src, size) \
do { \
int32_t *srci; \
int32_t *srci_end; \
int32_t *desti; \
\
srci = (int32_t *)src; \
srci_end = (int32_t *)((char *)srci + size); \
desti = (int32_t *)dest; \
\
while (srci != srci_end) \
*desti++ = *srci++; \
} while (0)
#define glm__memzero(dest, size) \
do { \
int32_t *desti; \
int32_t *desti_end; \
\
desti = (int32_t *)dest; \
desti_end = (int32_t *)((char *)desti + size); \
\
while (desti != desti_end) \
*desti++ = 0; \
} while (0)
#endif /* glm_common_h */