From 24e867b0ca6c9a65f78cf6828b9c23a714948aed Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sun, 6 Jul 2025 23:45:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Transform=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E5=87=A0=E5=A4=84=E6=AF=94=E8=BE=83=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/Transform.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/hgl/math/Transform.h b/inc/hgl/math/Transform.h index 46a34ee..5fa6a08 100644 --- a/inc/hgl/math/Transform.h +++ b/inc/hgl/math/Transform.h @@ -778,7 +778,7 @@ namespace hgl { if(is_identity) { - if(IsNearlyZero(angle)==0) + if(IsNearlyZero(angle)) return; } @@ -793,7 +793,7 @@ namespace hgl { if(is_identity) { - if(IsNearlyZero(angle)==0) + if(IsNearlyZero(angle)) return; } @@ -808,7 +808,7 @@ namespace hgl { if(is_identity) { - if(IsNearlyZero(angle)==0) + if(IsNearlyZero(angle)) return; } From e5c63827ab419ab9681df12494d9bdd09c29d0e4 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 7 Jul 2025 00:28:17 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=94=B9=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E9=98=B2=E6=AD=A2=E9=94=99=E8=AF=AF=E7=90=86?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/Matrix.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 4bebb65..178ca06 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -147,29 +147,29 @@ namespace hgl return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s)); } - inline Matrix4f rotate(float angle,const Vector3f &axis) + inline Matrix4f rotate(float rad,const Vector3f &axis) { - return glm::rotate(Matrix4f(1.0f),angle,axis); + return glm::rotate(Matrix4f(1.0f),rad,axis); } - inline Matrix4f rotate(float angle,float x,float y,float z) + inline Matrix4f rotate(float rad,float x,float y,float z) { - return glm::rotate(Matrix4f(1.0f),angle,Vector3f(x,y,z)); + return glm::rotate(Matrix4f(1.0f),rad,Vector3f(x,y,z)); } - inline Matrix4f rotate(float angle,float x,float y) + inline Matrix4f rotate(float rad,float x,float y) { - return rotate(angle,x,y,1.0f); + return rotate(rad,x,y,1.0f); } - inline Matrix4f rotate(float angle,const Vector4f &axis) + inline Matrix4f rotate(float rad,const Vector4f &axis) { - return rotate(angle,Vector3f(axis.x,axis.y,axis.z)); + return rotate(rad,Vector3f(axis.x,axis.y,axis.z)); } - inline Vector3f rotate(const Vector3f &v3f,float angle,const Vector3f &axis) + inline Vector3f rotate(const Vector3f &v3f,float rad,const Vector3f &axis) { - Vector4f result = rotate(angle, axis)*Vector4f(v3f, 1.0f); + Vector4f result = rotate(rad, axis)*Vector4f(v3f, 1.0f); return Vector3f(result.x,result.y,result.z); } From 847f448ce2570be6098b58ac715d9c71bb6e7634 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 7 Jul 2025 00:34:37 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=B5=AE=E7=82=B9=E5=80=BC=E5=81=9Arad2deg/d?= =?UTF-8?q?eg2rad=E8=AE=A1=E7=AE=97=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/MathConst.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/inc/hgl/math/MathConst.h b/inc/hgl/math/MathConst.h index c6b1a45..600cfd9 100644 --- a/inc/hgl/math/MathConst.h +++ b/inc/hgl/math/MathConst.h @@ -82,19 +82,17 @@ namespace hgl /** * 角度转弧度 */ - template - inline constexpr T deg2rad(const T deg) + inline constexpr float deg2rad(const float deg) { - return T(deg*(HGL_PI/180.0f)); + return deg*(HGL_PI/180.0f); } /** * 弧度转角度 */ - template - inline constexpr T rad2deg(const T rad) + inline constexpr double rad2deg(const float rad) { - return T(rad*(180.0f/HGL_PI)); + return rad*(180.0f/HGL_PI); } /** From 8e733a241536efcaff8cbff66c8a3a4f1255ed86 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Mon, 7 Jul 2025 01:24:46 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Rotate=E9=87=8D=E5=91=BD=E5=90=8D=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E5=A2=9E=E5=8A=A0AxisXRotate/AxisYRotate/AxisZRotate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/math/Matrix.h | 20 ++++++++++++-------- inc/hgl/math/Transform.h | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/inc/hgl/math/Matrix.h b/inc/hgl/math/Matrix.h index 178ca06..627718a 100644 --- a/inc/hgl/math/Matrix.h +++ b/inc/hgl/math/Matrix.h @@ -147,29 +147,33 @@ namespace hgl return glm::scale(Matrix4f(1.0f),Vector3f(s,s,s)); } - inline Matrix4f rotate(float rad,const Vector3f &axis) + inline Matrix4f AxisXRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::X);} + inline Matrix4f AxisYRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::Y);} + inline Matrix4f AxisZRotate(float rad){return glm::rotate(Matrix4f(1.0f),rad,AxisVector::Z);} + + inline Matrix4f AxisRotate(float rad,const Vector3f &axis) { return glm::rotate(Matrix4f(1.0f),rad,axis); } - inline Matrix4f rotate(float rad,float x,float y,float z) + inline Matrix4f AxisRotate(float rad,float x,float y,float z) { return glm::rotate(Matrix4f(1.0f),rad,Vector3f(x,y,z)); } - inline Matrix4f rotate(float rad,float x,float y) + inline Matrix4f AxisRotate(float rad,float x,float y) { - return rotate(rad,x,y,1.0f); + return AxisRotate(rad,x,y,1.0f); } - inline Matrix4f rotate(float rad,const Vector4f &axis) + inline Matrix4f AxisRotate(float rad,const Vector4f &axis) { - return rotate(rad,Vector3f(axis.x,axis.y,axis.z)); + return AxisRotate(rad,Vector3f(axis.x,axis.y,axis.z)); } - inline Vector3f rotate(const Vector3f &v3f,float rad,const Vector3f &axis) + inline Vector3f AxisRotate(const Vector3f &v3f,float rad,const Vector3f &axis) { - Vector4f result = rotate(rad, axis)*Vector4f(v3f, 1.0f); + Vector4f result = AxisRotate(rad, axis)*Vector4f(v3f, 1.0f); return Vector3f(result.x,result.y,result.z); } diff --git a/inc/hgl/math/Transform.h b/inc/hgl/math/Transform.h index 5fa6a08..a6b2520 100644 --- a/inc/hgl/math/Transform.h +++ b/inc/hgl/math/Transform.h @@ -215,7 +215,7 @@ namespace hgl void MakeNewestData(Matrix4f &mat) override { - mat=rotate(angle,axis); + mat=AxisRotate(angle,axis); } public: From 6b97ffdf79ff978fff89ca5276a21c1a18c98669 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 8 Jul 2025 01:17:13 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=9F=A9=E9=98=B5=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E6=94=B9=E5=90=8D=E4=BB=A5=E8=A7=84=E9=81=BF?= =?UTF-8?q?=E4=B8=8EGLM=E5=87=BD=E6=95=B0=E5=90=8D=E7=9A=84=E5=86=B2?= =?UTF-8?q?=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);