From 6b97ffdf79ff978fff89ca5276a21c1a18c98669 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 8 Jul 2025 01:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A9=E9=98=B5=E7=9B=B8=E5=85=B3=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=94=B9=E5=90=8D=E4=BB=A5=E8=A7=84=E9=81=BF=E4=B8=8E?= =?UTF-8?q?GLM=E5=87=BD=E6=95=B0=E5=90=8D=E7=9A=84=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/Matrix.h | 38 ++++++++++++++------------------------ inc/hgl/math/Transform.h | 8 ++++---- src/Math/Matrix4f.cpp | 14 +++++++------- src/Math/Transform.cpp | 2 +- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 627718a..6c37407 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -51,16 +51,6 @@ namespace hgl return glm::all(glm::epsilonEqual(q1,q2,err)); } - inline Matrix4f inverse(const Matrix4f &m) - { - return glm::inverse(m); - } - - inline Matrix4f transpose(const Matrix4f &m) - { - return glm::transpose(m); - } - /** * 生成一个正角视图矩阵 * @param left 左 @@ -70,7 +60,7 @@ namespace hgl * @param znear 近平面z值 * @param zfar 远平台z值 */ - Matrix4f ortho( float left, + Matrix4f OrthoMatrix( float left, float right, float bottom, float top, @@ -84,14 +74,14 @@ namespace hgl * @param znear 近平面z值 * @param zfar 远平台z值 */ - Matrix4f ortho(float width,float height,float znear,float zfar); + Matrix4f OrthoMatrix(float width,float height,float znear,float zfar); /** * 生成一个正角视图矩阵 * @param width 宽 * @param height 高 */ - Matrix4f ortho(float width,float height); + Matrix4f OrthoMatrix(float width,float height); /** * 生成一个透视矩阵 @@ -100,7 +90,7 @@ namespace hgl * @param znear 近截面 * @param zfar 远截面 */ - Matrix4f perspective( float field_of_view, + Matrix4f PerspectiveMatrix( float field_of_view, float aspect_ratio, float znear, float zfar); @@ -110,39 +100,39 @@ namespace hgl * @param target 目标位置 * @param up 向上向量 */ - Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up=AxisVector::Z); + Matrix4f LookAtMatrix(const Vector3f &eye,const Vector3f &target,const Vector3f &up=AxisVector::Z); - inline Matrix4f translate(const Vector3f &v) + inline Matrix4f TranslateMatrix(const Vector3f &v) { return glm::translate(Matrix4f(1.0f),v); } - inline Matrix4f translate(float x,float y,float z) + inline Matrix4f TranslateMatrix(float x,float y,float z) { return glm::translate(Matrix4f(1.0f),Vector3f(x,y,z)); } - inline Matrix4f translate(float x,float y) + inline Matrix4f TranslateMatrix(float x,float y) { - return translate(x,y,1.0f); + return glm::translate(Matrix4f(1.0f),Vector3f(x,y,1.0f)); } - inline Matrix4f scale(const Vector3f &v) + inline Matrix4f ScaleMatrix(const Vector3f &v) { return glm::scale(Matrix4f(1.0f),v); } - inline Matrix4f scale(float x,float y,float z) + inline Matrix4f ScaleMatrix(float x,float y,float z) { return glm::scale(Matrix4f(1.0f),Vector3f(x,y,z)); } - inline Matrix4f scale(float x,float y) + inline Matrix4f ScaleMatrix(float x,float y) { - return scale(x,y,1.0f); + return glm::scale(Matrix4f(1.0f),Vector3f(x,y,1.0f)); } - inline Matrix4f scale(float s) + inline Matrix4f ScaleMatrix(float s) { return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s)); } diff --git a/inc/hgl/math/Transform.h b/inc/hgl/math/Transform.h index a6b2520..6730a4f 100644 --- a/inc/hgl/math/Transform.h +++ b/inc/hgl/math/Transform.h @@ -101,7 +101,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=translate(offset); + mat=TranslateMatrix(offset); } public: @@ -342,7 +342,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=scale(scale3f); + mat=ScaleMatrix(scale3f); } public: @@ -395,7 +395,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=lookat(eye,center,up); + mat=LookAtMatrix(eye,center,up); } public: @@ -695,7 +695,7 @@ namespace hgl const Matrix4f GetMatrix()const //不能执行UpdateMatrix时的获取 { if(matrix_dirty) - return translate(translation_vector)*ToMatrix(rotation_quat)*scale(scale_vector); + return TranslateMatrix(translation_vector)*ToMatrix(rotation_quat)*ScaleMatrix(scale_vector); else return matrix; } diff --git a/src/Math/Matrix4f.cpp b/src/Math/Matrix4f.cpp index 92e91bf..9f42908 100644 --- a/src/Math/Matrix4f.cpp +++ b/src/Math/Matrix4f.cpp @@ -14,7 +14,7 @@ namespace hgl { - Matrix4f ortho( float left, + Matrix4f OrthoMatrix( float left, float right, float bottom, float top, @@ -51,9 +51,9 @@ namespace hgl * @param znear 近平面z值 * @param zfar 远平台z值 */ - Matrix4f ortho(float width,float height,float znear,float zfar) + Matrix4f OrthoMatrix(float width,float height,float znear,float zfar) { - return ortho(0.0f,width,height,0.0f,znear,zfar); + return OrthoMatrix(0.0f,width,height,0.0f,znear,zfar); } /** @@ -61,9 +61,9 @@ namespace hgl * @param width 宽 * @param height 高 */ - Matrix4f ortho(float width,float height) + Matrix4f OrthoMatrix(float width,float height) { - return ortho(width,height,0.0f,1.0f); + return OrthoMatrix(width,height,0.0f,1.0f); } /** @@ -73,7 +73,7 @@ namespace hgl * @param znear 近截面 * @param zfar 远截面 */ - Matrix4f perspective( float field_of_view, + Matrix4f PerspectiveMatrix( float field_of_view, float aspect_ratio, float znear, float zfar) @@ -105,7 +105,7 @@ namespace hgl //经查证,此代码等于glm::perspectiveRH_ZO之后将[1][1]乘-1,在SaschaWillems的范例中,如果反转Y轴,则[1][1]确实要乘-1。 } - Matrix4f lookat(const Vector3f &eye,const Vector3f &target,const Vector3f &up) + Matrix4f LookAtMatrix(const Vector3f &eye,const Vector3f &target,const Vector3f &up) { Vector3f forward=normalize(target-eye); Vector3f right =normalize(cross(forward,up)); diff --git a/src/Math/Transform.cpp b/src/Math/Transform.cpp index 101e1dd..e47ca0a 100644 --- a/src/Math/Transform.cpp +++ b/src/Math/Transform.cpp @@ -52,7 +52,7 @@ namespace hgl } else { - matrix=translate(translation_vector)*ToMatrix(rotation_quat)*scale(scale_vector); + matrix=TranslateMatrix(translation_vector)*ToMatrix(rotation_quat)*ScaleMatrix(scale_vector); inverse_matrix=inverse(matrix); transpose_inverse_matrix=transpose(inverse_matrix);