build texture transform matrix helper

This commit is contained in:
Recep Aslantas
2025-04-05 13:32:47 +03:00
parent ebc65782f8
commit 5fde20d65c
13 changed files with 191 additions and 1 deletions

View File

@@ -84,6 +84,10 @@ CGLM_EXPORT
void
glmc_mat3_make(const float * __restrict src, mat3 dest);
CGLM_EXPORT
void
glmc_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest);
#ifdef __cplusplus
}
#endif

View File

@@ -125,6 +125,10 @@ CGLM_EXPORT
void
glmc_mat4_make(const float * __restrict src, mat4 dest);
CGLM_EXPORT
void
glmc_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest);
#ifdef __cplusplus
}
#endif

View File

@@ -31,6 +31,7 @@
CGLM_INLINE void glm_mat3_swap_row(mat3 mat, int row1, int row2);
CGLM_INLINE float glm_mat3_rmc(vec3 r, mat3 m, vec3 c);
CGLM_INLINE void glm_mat3_make(float * restrict src, mat3 dest);
CGLM_INLINE void glm_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest);
*/
#ifndef cglm_mat3_h
@@ -448,4 +449,32 @@ glm_mat3_make(const float * __restrict src, mat3 dest) {
dest[2][2] = src[8];
}
/*!
* @brief Create mat3 matrix from texture transform parameters
*
* @param[in] sx scale x
* @param[in] sy scale y
* @param[in] rot rotation in radians CCW/RH
* @param[in] tx translate x
* @param[in] ty translate y
* @param[out] dest texture transform matrix
*/
CGLM_INLINE
void
glm_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest) {
float c, s;
c = cosf(rot);
s = sinf(rot);
glm_mat3_identity(dest);
dest[0][0] = c * sx;
dest[0][1] = -s * sy;
dest[1][0] = s * sx;
dest[1][1] = c * sy;
dest[2][0] = tx;
dest[2][1] = ty;
}
#endif /* cglm_mat3_h */

View File

@@ -44,6 +44,7 @@
CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2);
CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c);
CGLM_INLINE void glm_mat4_make(float * restrict src, mat4 dest);
CGLM_INLINE void glm_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest);
*/
#ifndef cglm_mat_h
@@ -799,4 +800,32 @@ glm_mat4_make(const float * __restrict src, mat4 dest) {
dest[2][3] = src[11]; dest[3][3] = src[15];
}
/*!
* @brief Create mat4 matrix from texture transform parameters
*
* @param[in] sx scale x
* @param[in] sy scale y
* @param[in] rot rotation in radians CCW/RH
* @param[in] tx translate x
* @param[in] ty translate y
* @param[out] dest texture transform matrix
*/
CGLM_INLINE
void
glm_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest) {
float c, s;
c = cosf(rot);
s = sinf(rot);
glm_mat4_identity(dest);
dest[0][0] = c * sx;
dest[0][1] = -s * sy;
dest[1][0] = s * sx;
dest[1][1] = c * sy;
dest[3][0] = tx;
dest[3][1] = ty;
}
#endif /* cglm_mat_h */

View File

@@ -29,6 +29,7 @@
CGLM_INLINE mat3s glms_mat3_swap_row(mat3s mat, int row1, int row2);
CGLM_INLINE float glms_mat3_rmc(vec3s r, mat3s m, vec3s c);
CGLM_INLINE mat3s glms_mat3_make(const float * __restrict src);
CGLM_INLINE mat3s glms_mat3_textrans(float sx, float sy, float rot, float tx, float ty);
*/
#ifndef cglms_mat3s_h
@@ -300,4 +301,22 @@ glms_mat3_(make)(const float * __restrict src) {
return r;
}
/*!
* @brief Create mat3 matrix from texture transform parameters
*
* @param[in] sx scale x
* @param[in] sy scale y
* @param[in] rot rotation in radians CCW/RH
* @param[in] tx translate x
* @param[in] ty translate y
* @return texture transform matrix
*/
CGLM_INLINE
mat3s
glms_mat3_(textrans)(float sx, float sy, float rot, float tx, float ty) {
mat3s r;
glm_mat3_textrans(sx, sy, rot, tx, ty, r.raw);
return r;
}
#endif /* cglms_mat3s_h */

View File

@@ -43,6 +43,7 @@
CGLM_INLINE mat4s glms_mat4_swap_row(mat4s mat, int row1, int row2);
CGLM_INLINE float glms_mat4_rmc(vec4s r, mat4s m, vec4s c);
CGLM_INLINE mat4s glms_mat4_make(const float * __restrict src);
CGLM_INLINE mat4s glms_mat4_textrans(float sx, float sy, float rot, float tx, float ty);
*/
#ifndef cglms_mat4s_h
@@ -474,4 +475,22 @@ glms_mat4_(make)(const float * __restrict src) {
return r;
}
/*!
* @brief Create mat4 matrix from texture transform parameters
*
* @param[in] sx scale x
* @param[in] sy scale y
* @param[in] rot rotation in radians CCW/RH
* @param[in] tx translate x
* @param[in] ty translate y
* @return texture transform matrix
*/
CGLM_INLINE
mat4s
glms_mat4_(textrans)(float sx, float sy, float rot, float tx, float ty) {
mat4s r;
glm_mat4_textrans(sx, sy, rot, tx, ty, r.raw);
return r;
}
#endif /* cglms_mat4s_h */