summaryrefslogtreecommitdiff
path: root/include/cglm/struct/affine2d.h
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2026-01-25 15:10:37 -0600
committerAaditya Dhruv <[email protected]>2026-01-25 15:10:37 -0600
commit118980e02e59ff31871df59dce257075394f3533 (patch)
tree26fba4492bb4b561d21bf49b35d892a821d54fab /include/cglm/struct/affine2d.h
parent0e6e1245b70df4dfcba135d50e1b53d1a8ef7eb8 (diff)
wip
Diffstat (limited to 'include/cglm/struct/affine2d.h')
-rw-r--r--include/cglm/struct/affine2d.h177
1 files changed, 177 insertions, 0 deletions
diff --git a/include/cglm/struct/affine2d.h b/include/cglm/struct/affine2d.h
new file mode 100644
index 0000000..ade7c32
--- /dev/null
+++ b/include/cglm/struct/affine2d.h
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c), Recep Aslantas.
+ *
+ * MIT License (MIT), http://opensource.org/licenses/MIT
+ * Full license can be found in the LICENSE file
+ */
+
+/*
+ Functions:
+ CGLM_INLINE mat3s glms_translate2d(mat3 m, vec2 v)
+ CGLM_INLINE mat3s glms_translate2d_x(mat3s m, float x)
+ CGLM_INLINE mat3s glms_translate2d_y(mat3s m, float y)
+ CGLM_INLINE mat3s glms_translate2d_make(vec2s v)
+ CGLM_INLINE mat3s glms_scale2d_make(vec2s v)
+ CGLM_INLINE mat3s glms_scale2d(mat3s m, vec2s v)
+ CGLM_INLINE mat3s glms_scale2d_uni(mat3s m, float s)
+ CGLM_INLINE mat3s glms_rotate2d_make(float angle)
+ CGLM_INLINE mat3s glms_rotate2d(mat3s m, float angle)
+ CGLM_INLINE mat3s glms_rotate2d_to(mat3s m, float angle)
+ */
+
+#ifndef cglms_affine2ds_h
+#define cglms_affine2ds_h
+
+#include "../common.h"
+#include "../types-struct.h"
+#include "../affine2d.h"
+#include "vec3.h"
+#include "mat3.h"
+
+/*!
+ * @brief translate existing 2d transform matrix by v vector
+ * and stores result in same matrix
+ *
+ * @param[in] m affine transform
+ * @param[in] v translate vector [x, y]
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_translate2d(mat3s m, vec2s v) {
+ glm_translate2d(m.raw, v.raw);
+ return m;
+}
+
+/*!
+ * @brief translate existing 2d transform matrix by x factor
+ *
+ * @param[in] m affine transform
+ * @param[in] x x factor
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_translate2d_x(mat3s m, float x) {
+ glm_translate2d_x(m.raw, x);
+ return m;
+}
+
+/*!
+ * @brief translate existing 2d transform matrix by y factor
+ *
+ * @param[in] m affine transform
+ * @param[in] y y factor
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_translate2d_y(mat3s m, float y) {
+ glm_translate2d_y(m.raw, y);
+ return m;
+}
+
+/*!
+ * @brief creates NEW translate 2d transform matrix by v vector
+ *
+ * @param[in] v translate vector [x, y]
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_translate2d_make(vec2s v) {
+ mat3s m;
+ glm_translate2d_make(m.raw, v.raw);
+ return m;
+}
+
+/*!
+ * @brief creates NEW 2d scale matrix by v vector
+ *
+ * @param[in] v scale vector [x, y]
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_scale2d_make(vec2s v) {
+ mat3s m;
+ glm_scale2d_make(m.raw, v.raw);
+ return m;
+}
+
+/*!
+ * @brief scales existing 2d transform matrix by v vector
+ * and stores result in same matrix
+ *
+ * @param[in] m affine transform
+ * @param[in] v scale vector [x, y, z]
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_scale2d(mat3s m, vec2s v) {
+ mat3s r;
+ glm_scale2d_to(m.raw, v.raw, r.raw);
+ return r;
+}
+
+/*!
+ * @brief applies uniform scale to existing 2d transform matrix v = [s, s, s]
+ * and stores result in same matrix
+ *
+ * @param[in] m affine transform
+ * @param[in] s scale factor
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_scale2d_uni(mat3s m, float s) {
+ glm_scale2d_uni(m.raw, s);
+ return m;
+}
+
+/*!
+ * @brief creates NEW 2d rotation matrix by angle and axis
+ *
+ * axis will be normalized so you don't need to normalize it
+ *
+ * @param[in] angle angle (radians)
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_rotate2d_make(float angle) {
+ mat3s m;
+ glm_rotate2d_make(m.raw, angle);
+ return m;
+}
+
+/*!
+ * @brief rotate existing 2d transform matrix around given axis by angle
+ *
+ * @param[in] m affine transform
+ * @param[in] angle angle (radians)
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_rotate2d(mat3s m, float angle) {
+ glm_rotate2d(m.raw, angle);
+ return m;
+}
+
+/*!
+ * @brief rotate existing 2d transform matrix around given axis by angle
+ *
+ * @param[in] m affine transform
+ * @param[in] angle angle (radians)
+ * @returns affine transform
+ */
+CGLM_INLINE
+mat3s
+glms_rotate2d_to(mat3s m, float angle) {
+ glm_rotate2d(m.raw, angle);
+ return m;
+}
+
+#endif /* cglms_affine2ds_h */