diff --git a/include/c3d/maths.h b/include/c3d/maths.h index 1587231..bca1aa8 100644 --- a/include/c3d/maths.h +++ b/include/c3d/maths.h @@ -489,6 +489,12 @@ void Mtx_PerspStereoTilt(C3D_Mtx* mtx, float fovy, float aspect, float near, flo * @param[in] isLeftHanded If true, output matrix is left-handed. If false, output matrix is right-handed. */ void Mtx_LookAt(C3D_Mtx* out, C3D_FVec cameraPosition, C3D_FVec cameraTarget, C3D_FVec cameraUpVector, bool isLeftHanded); + +/** + *@brief Transposes the matrix. Row => Column, and vice versa. + *@param[in,out] out Output matrix. + */ +void Mtx_Transpose(C3D_Mtx* out); ///@} ///@name Quaternion Math diff --git a/source/maths/mtx_transpose.c b/source/maths/mtx_transpose.c new file mode 100644 index 0000000..f5addff --- /dev/null +++ b/source/maths/mtx_transpose.c @@ -0,0 +1,15 @@ +#include + +void Mtx_Transpose(C3D_Mtx* out) +{ + float swap; + for (int i = 0; i < 4; i++) + { + for (int j = i+1; j < 4; j++) + { + swap = out->r[j].c[i]; + out->r[j].c[i] = out->r[i].c[j]; + out->r[i].c[j] = swap; + } + } +}