This commit is contained in:
2025-07-08 13:02:35 +08:00
5 changed files with 48 additions and 56 deletions

View File

@@ -82,19 +82,17 @@ namespace hgl
/**
* 角度转弧度
*/
template<typename T>
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<typename T>
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);
}
/**

View File

@@ -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,66 +100,70 @@ 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));
}
inline Matrix4f rotate(float angle,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),angle,axis);
return glm::rotate(Matrix4f(1.0f),rad,axis);
}
inline Matrix4f rotate(float angle,float x,float y,float z)
inline Matrix4f AxisRotate(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 AxisRotate(float rad,float x,float y)
{
return rotate(angle,x,y,1.0f);
return AxisRotate(rad,x,y,1.0f);
}
inline Matrix4f rotate(float angle,const Vector4f &axis)
inline Matrix4f AxisRotate(float rad,const Vector4f &axis)
{
return rotate(angle,Vector3f(axis.x,axis.y,axis.z));
return AxisRotate(rad,Vector3f(axis.x,axis.y,axis.z));
}
inline Vector3f rotate(const Vector3f &v3f,float angle,const Vector3f &axis)
inline Vector3f AxisRotate(const Vector3f &v3f,float rad,const Vector3f &axis)
{
Vector4f result = rotate(angle, axis)*Vector4f(v3f, 1.0f);
Vector4f result = AxisRotate(rad, axis)*Vector4f(v3f, 1.0f);
return Vector3f(result.x,result.y,result.z);
}

View File

@@ -101,7 +101,7 @@ namespace hgl
void MakeNewestData(Matrix4f &mat) override
{
mat=translate(offset);
mat=TranslateMatrix(offset);
}
public:
@@ -215,7 +215,7 @@ namespace hgl
void MakeNewestData(Matrix4f &mat) override
{
mat=rotate(angle,axis);
mat=AxisRotate(angle,axis);
}
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;
}
@@ -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;
}

View File

@@ -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));

View File

@@ -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);