From 2393bb43dc9f0b24ee954971e8e42f0b96a7fb1d Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 29 Jul 2024 13:38:25 +0800 Subject: [PATCH] Added AXIS, GetAxisVector --- inc/hgl/math/Matrix.h | 17 +++++++++++++++-- inc/hgl/math/Vector.h | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 26d4e2a..f06694b 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -179,7 +179,7 @@ namespace hgl { return glm::slerp(from,to,t); } - + inline Vector3f TransformPosition(const Matrix4f &m,const Vector3f &v) { return Vector3f(m*Vector4f(v,1.0f)); @@ -318,7 +318,7 @@ namespace hgl matrix_dirty=true; } - void SetRotation(const Vector3f &axis,float angle) + void SetRotation(const Vector3f &axis,const float angle) { rotation_axis=axis; rotate_angle=angle; @@ -331,6 +331,19 @@ namespace hgl UpdateQuat(); } + void SetRotation(const AXIS &axis,const float angle) + { + rotation_axis=GetAxisVector(axis); + rotate_angle=angle; + UpdateQuat(); + } + + void SetRotationAxis(const AXIS &axis) + { + rotation_axis=GetAxisVector(axis); + UpdateQuat(); + } + void SetRotateAngle(float angle) { rotate_angle=angle; diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index 61ed765..ca52a8b 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -10,6 +10,11 @@ namespace hgl { + enum class AXIS + { + X,Y,Z + }; + #define DEF_VECTOR(flag,glm_type) using Vector1##flag=glm::glm_type##1;\ using Vector2##flag=glm::glm_type##2;\ using Vector3##flag=glm::glm_type##3;\ @@ -34,6 +39,18 @@ namespace hgl #undef DEF_VECTOR + inline const Vector3f GetAxisVector(const AXIS &axis) + { + switch(axis) + { + case AXIS::X:return Vector3f(1,0,0); + case AXIS::Y:return Vector3f(0,1,0); + case AXIS::Z:return Vector3f(0,0,1); + } + + return Vector3f(0,0,0); + } + inline bool operator == (const Vector2f &lhs,const Vector2f &rhs) { if(lhs.x!=rhs.x)return(false);