From 0ac2a9431a14767c018f6f20a8ea0a3604b859ee Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 30 Aug 2024 00:29:47 +0800 Subject: [PATCH] Added GetRotateAxis/Angle from Quat. Added MakeMatrix functions. --- inc/hgl/math/Matrix.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 19454d9..801a49c 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -190,6 +190,16 @@ namespace hgl axis=glm::axis(quat); } + inline const Vector3f &GetRotateAxis(const Quatf &quat) + { + return glm::axis(quat); + } + + inline const float GetRotateAngle(const Quatf &quat) + { + return glm::degrees(glm::angle(quat)); + } + inline Quatf LerpQuat(const Quatf &from,const Quatf &to,const float t) { return glm::lerp(from,to,t); @@ -200,6 +210,20 @@ namespace hgl return glm::slerp(from,to,t); } + inline Matrix4f MakeMatrix(const Vector3f &move,const Quatf &rotate_quat,const Vector3f &scale_xyz) + { + return glm::translate(Identity4f,move) + *glm::toMat4(rotate_quat) + *glm::scale(Identity4f,scale_xyz); + } + + inline Matrix4f MakeMatrix(const Vector3f &move,const Vector3f &rotate_axis,const float &rotate_angle,const Vector3f &scale_xyz) + { + return glm::translate(Identity4f,move) + *glm::rotate(Identity4f,glm::radians(rotate_angle),rotate_axis) + *glm::scale(Identity4f,scale_xyz); + } + inline Vector3f TransformPosition(const Matrix4f &m,const Vector3f &v) { return Vector3f(m*Vector4f(v,1.0f));