diff --git a/include/cglm-affine.h b/include/cglm-affine.h new file mode 100644 index 0000000..5869c44 --- /dev/null +++ b/include/cglm-affine.h @@ -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 */ diff --git a/include/cglm-common.h b/include/cglm-common.h index 3ce2390..71882c5 100644 --- a/include/cglm-common.h +++ b/include/cglm-common.h @@ -8,10 +8,38 @@ #ifndef glm_common_h #define glm_common_h +#include + #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 */