Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement missing 3D Affine Transforms in the Struct API #317

Merged
merged 4 commits into from Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -163,6 +163,7 @@ cglm_struct_HEADERS = include/cglm/struct/mat4.h \
include/cglm/struct/mat2.h \
include/cglm/struct/affine-pre.h \
include/cglm/struct/affine-post.h \
include/cglm/struct/affine-mat.h \
include/cglm/struct/affine.h \
include/cglm/struct/affine2d.h \
include/cglm/struct/vec2.h \
Expand Down
1 change: 1 addition & 0 deletions include/cglm/affine-mat.h
Expand Up @@ -8,6 +8,7 @@
/*
Functions:
CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest);
CGLM_INLINE void glm_mul_rot(mat4 m1, mat4 m2, mat4 dest);
CGLM_INLINE void glm_inv_tr(mat4 mat);
*/

Expand Down
90 changes: 90 additions & 0 deletions include/cglm/struct/affine-mat.h
@@ -0,0 +1,90 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/

/*
Functions:
CGLM_INLINE mat4s glms_mul(mat4 m1, mat4 m2);
CGLM_INLINE mat4s glms_mul_rot(mat4 m1, mat4 m2);
CGLM_INLINE mat4s glms_inv_tr();
*/

#ifndef cglms_affine_mat_h
#define cglms_affine_mat_h

#include "../common.h"
#include "../types-struct.h"
#include "../affine-mat.h"
#include "vec3.h"
#include "vec4.h"
#include "mat4.h"

/*!
* @brief this is similar to glms_mat4_mul but specialized to affine transform
*
* Matrix format should be:
* R R R X
* R R R Y
* R R R Z
* 0 0 0 W
*
* this reduces some multiplications. It should be faster than mat4_mul.
* if you are not sure about matrix format then DON'T use this! use mat4_mul
*
* @param[in] m1 affine matrix 1
* @param[in] m2 affine matrix 2
* @returns destination matrix
*/
CGLM_INLINE
mat4s
glms_mul(mat4s m1, mat4s m2){
mat4s r;
glm_mul(m1.raw, m2.raw, r.raw);
return r;
}

/*!
* @brief this is similar to glm_mat4_mul but specialized to affine transform
*
* Right Matrix format should be:
* R R R 0
* R R R 0
* R R R 0
* 0 0 0 1
*
* this reduces some multiplications. It should be faster than mat4_mul.
* if you are not sure about matrix format then DON'T use this! use mat4_mul
*
* @param[in] m1 affine matrix 1
* @param[in] m2 affine matrix 2
* @returns destination matrix
*/
CGLM_INLINE
mat4s
glms_mul_rot(mat4s m1, mat4s m2){
mat4s r;
glm_mul_rot(m1.raw, m2.raw, r.raw);
return r;
}

/*!
* @brief inverse orthonormal rotation + translation matrix (ridig-body)
*
* @code
* X = | R T | X' = | R' -R'T |
* | 0 1 | | 0 1 |
* @endcode
*
* @param[in] mat matrix
* @returns destination matrix
*/
CGLM_INLINE
mat4s
glms_inv_tr(mat4s m){
glm_inv_tr(m.raw);
return m;
}
#endif /* cglms_affine_mat_h */
1 change: 1 addition & 0 deletions include/cglm/struct/affine.h
Expand Up @@ -39,6 +39,7 @@
#include "vec3.h"
#include "vec4.h"
#include "mat4.h"
#include "affine-mat.h"

/*!
* @brief creates NEW translate transform matrix by v vector
Expand Down
1 change: 1 addition & 0 deletions win/cglm.vcxproj
Expand Up @@ -184,6 +184,7 @@
<ClInclude Include="..\include\cglm\struct.h" />
<ClInclude Include="..\include\cglm\struct\affine-post.h" />
<ClInclude Include="..\include\cglm\struct\affine-pre.h" />
<ClInclude Include="..\include\cglm\struct\affine-mat.h" />
<ClInclude Include="..\include\cglm\struct\affine.h" />
<ClInclude Include="..\include\cglm\struct\affine2d.h" />
<ClInclude Include="..\include\cglm\struct\box.h" />
Expand Down
3 changes: 3 additions & 0 deletions win/cglm.vcxproj.filters
Expand Up @@ -603,5 +603,8 @@
<ClInclude Include="..\include\cglm\struct\affine-pre.h">
<Filter>include\cglm\struct</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\struct\affine-mat.h">
<Filter>include\cglm\struct</Filter>
</ClInclude>
</ItemGroup>
</Project>