From 0dd89d78abd3cb24c6ce36d57fd9d8ccac3ec983 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 2 Aug 2024 22:39:21 +0800 Subject: [PATCH] renamed values --- inc/hgl/math/Matrix.h | 4 ++-- inc/hgl/math/Vector.h | 9 ++------- src/Math/Matrix4f.cpp | 12 ++++++------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index bf361fe..ecd5250 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -215,8 +215,8 @@ namespace hgl return root*child; } - const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction); - const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction); + const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &old_direction,const Vector3f &new_direction); + const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &old_direction,const Vector3f &new_direction); /** * 带误差的比较两个浮点矩阵是否相等 diff --git a/inc/hgl/math/Vector.h b/inc/hgl/math/Vector.h index e445057..5fb0449 100644 --- a/inc/hgl/math/Vector.h +++ b/inc/hgl/math/Vector.h @@ -414,14 +414,9 @@ namespace hgl &&IsNearlyEqual(a.z,b.z); } - inline const Vector3f LerpDirection(const Vector3f ¢er,const Vector3f &from_direction,const Vector3f &to_direction,const float alpha) + inline const Vector3f LerpDirection(const Vector3f &old_direction,const Vector3f &new_direction,const float alpha) { - return glm::normalize(center + (from_direction - center) * alpha + (to_direction - center) * alpha); - } - - inline const Vector3f SLerpDirection(const Vector3f ¢er,const Vector3f &from,const Vector3f &to,const float alpha) - { - return glm::normalize(glm::slerp(from - center, to - center, alpha) + center); + return glm::normalize(old_direction*(1.0f-alpha)+new_direction*alpha); } }//namespace hgl #endif//HGL_ALGORITHM_MATH_VECTOR_INCLUDE diff --git a/src/Math/Matrix4f.cpp b/src/Math/Matrix4f.cpp index 4d58b45..9952a72 100644 --- a/src/Math/Matrix4f.cpp +++ b/src/Math/Matrix4f.cpp @@ -182,16 +182,16 @@ namespace hgl /** * 计算一个方向旋转成另一个方向的变换矩阵 */ - const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction) + const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &old_direction,const Vector3f &new_direction) { - Vector3f axis=glm::cross(cur_direction,new_direction); + Vector3f axis=glm::cross(old_direction,new_direction); if(glm::length2(axis)<0.0001) return Matrix4f(1.0f); axis=glm::normalize(axis); - float angle=acos(glm::dot(cur_direction,new_direction)); + float angle=acos(glm::dot(old_direction,new_direction)); return glm::rotate(Matrix4f(1.0f),angle,axis); } @@ -199,16 +199,16 @@ namespace hgl /** * 计算一个方向旋转成另一个方向的四元数 */ - const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction) + const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &old_direction,const Vector3f &new_direction) { - Vector3f axis=glm::cross(cur_direction,new_direction); + Vector3f axis=glm::cross(old_direction,new_direction); if(glm::length2(axis)<0.0001) return Quatf(1.0f,0.0f,0.0f,0.0f); axis=glm::normalize(axis); - float angle=acos(glm::dot(cur_direction,new_direction)); + float angle=acos(glm::dot(old_direction,new_direction)); return glm::angleAxis(angle,axis); }