mirror of
https://github.com/recp/cglm.git
synced 2025-12-24 20:34:58 +00:00
2d: add translate2d and its friends
This commit is contained in:
@@ -65,7 +65,8 @@ cglm_HEADERS = include/cglm/version.h \
|
||||
include/cglm/curve.h \
|
||||
include/cglm/bezier.h \
|
||||
include/cglm/applesimd.h \
|
||||
include/cglm/ray.h
|
||||
include/cglm/ray.h \
|
||||
include/cglm/affine2d.h
|
||||
|
||||
cglm_calldir=$(includedir)/cglm/call
|
||||
cglm_call_HEADERS = include/cglm/call/mat4.h \
|
||||
@@ -87,7 +88,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \
|
||||
include/cglm/call/ease.h \
|
||||
include/cglm/call/curve.h \
|
||||
include/cglm/call/bezier.h \
|
||||
include/cglm/call/ray.h
|
||||
include/cglm/call/ray.h \
|
||||
include/cglm/call/affine2d.h
|
||||
|
||||
cglm_simddir=$(includedir)/cglm/simd
|
||||
cglm_simd_HEADERS = include/cglm/simd/intrin.h \
|
||||
@@ -151,7 +153,8 @@ libcglm_la_SOURCES=\
|
||||
src/ease.c \
|
||||
src/curve.c \
|
||||
src/bezier.c \
|
||||
src/ray.c
|
||||
src/ray.c \
|
||||
src/affine2d.c
|
||||
|
||||
test_tests_SOURCES=\
|
||||
test/runner.c \
|
||||
|
||||
100
include/cglm/affine2d.h
Normal file
100
include/cglm/affine2d.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
/*
|
||||
Functions:
|
||||
|
||||
*/
|
||||
|
||||
#ifndef cglm_affine2d_h
|
||||
#define cglm_affine2d_h
|
||||
|
||||
#include "common.h"
|
||||
#include "util.h"
|
||||
#include "vec2.h"
|
||||
#include "vec3.h"
|
||||
#include "vec4.h"
|
||||
#include "mat4.h"
|
||||
#include "mat3.h"
|
||||
#include "affine-mat.h"
|
||||
|
||||
/*!
|
||||
* @brief translate existing 2d transform matrix by v vector
|
||||
* and stores result in same matrix
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] v translate vector [x, y, z]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate2d(mat3 m, vec2 v) {
|
||||
m[2][0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0];
|
||||
m[2][1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1];
|
||||
m[2][2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing 2d transform matrix by v vector
|
||||
* and store result in dest
|
||||
*
|
||||
* source matrix will remain same
|
||||
*
|
||||
* @param[in] m affine transfrom
|
||||
* @param[in] v translate vector [x, y, z]
|
||||
* @param[out] dest translated matrix
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate2d_to(mat3 m, vec2 v, mat3 dest) {
|
||||
glm_mat3_copy(m, dest);
|
||||
glm_translate2d(dest, v);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing 2d transform matrix by x factor
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] x x factor
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate2d_x(mat3 m, float x) {
|
||||
m[2][0] = m[0][0] * x + m[2][0];
|
||||
m[2][1] = m[0][1] * x + m[2][1];
|
||||
m[2][2] = m[0][2] * x + m[2][2];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief translate existing 2d transform matrix by y factor
|
||||
*
|
||||
* @param[in, out] m affine transfrom
|
||||
* @param[in] y y factor
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate2d_y(mat3 m, float y) {
|
||||
m[2][0] = m[1][0] * y + m[2][0];
|
||||
m[2][1] = m[1][1] * y + m[2][1];
|
||||
m[2][2] = m[1][2] * y + m[2][2];
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief creates NEW translate 2d transform matrix by v vector
|
||||
*
|
||||
* @param[out] m affine transfrom
|
||||
* @param[in] v translate vector [x, y, z]
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_translate2d_make(mat3 m, vec2 v) {
|
||||
glm_mat3_identity(m);
|
||||
m[2][0] = v[0];
|
||||
m[2][1] = v[1];
|
||||
}
|
||||
|
||||
|
||||
#endif /* cglm_affine2d_h */
|
||||
@@ -32,6 +32,7 @@ extern "C" {
|
||||
#include "call/curve.h"
|
||||
#include "call/bezier.h"
|
||||
#include "call/ray.h"
|
||||
#include "call/affine2d.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
39
include/cglm/call/affine2d.h
Normal file
39
include/cglm/call/affine2d.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#ifndef cglmc_affine2d_h
|
||||
#define cglmc_affine2d_h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../cglm.h"
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_make(mat3 m, vec2 v);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_to(mat3 m, vec2 v, mat3 dest);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d(mat3 m, vec2 v);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_x(mat3 m, float to);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_y(mat3 m, float to);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* cglmc_affine2d_h */
|
||||
@@ -31,5 +31,6 @@
|
||||
#include "curve.h"
|
||||
#include "bezier.h"
|
||||
#include "ray.h"
|
||||
#include "affine2d.h"
|
||||
|
||||
#endif /* cglm_h */
|
||||
|
||||
39
src/affine2d.c
Normal file
39
src/affine2d.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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
|
||||
void
|
||||
glmc_translate2d_make(mat3 m, vec2 v) {
|
||||
glm_translate2d_make(m, v);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_to(mat3 m, vec2 v, mat3 dest) {
|
||||
glm_translate2d_to(m, v, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d(mat3 m, vec2 v) {
|
||||
glm_translate2d(m, v);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_x(mat3 m, float to) {
|
||||
glm_translate2d_x(m, to);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_translate2d_y(mat3 m, float to) {
|
||||
glm_translate2d_y(m, to);
|
||||
}
|
||||
Reference in New Issue
Block a user