fixed matrix
This commit is contained in:
@@ -29,24 +29,24 @@ namespace hgl
|
||||
constexpr double HGL_COS_ANG_270=0;
|
||||
constexpr double HGL_COS_ANG_315=0.707106781187;
|
||||
|
||||
#define HGL_DEF_ANG2RAD(ang) constexpr double HGL_RAD_##ang=double(ang)*(HGL_PI/180.0f);
|
||||
#define HGL_DEF_DEG2RAD(ang) constexpr double HGL_RAD_##ang=double(ang)*(HGL_PI/180.0f);
|
||||
|
||||
HGL_DEF_ANG2RAD(0)
|
||||
HGL_DEF_ANG2RAD(45)
|
||||
HGL_DEF_ANG2RAD(90)
|
||||
HGL_DEF_ANG2RAD(135)
|
||||
HGL_DEF_ANG2RAD(180)
|
||||
HGL_DEF_ANG2RAD(225)
|
||||
HGL_DEF_ANG2RAD(270)
|
||||
HGL_DEF_ANG2RAD(315)
|
||||
HGL_DEF_ANG2RAD(360)
|
||||
HGL_DEF_DEG2RAD(0)
|
||||
HGL_DEF_DEG2RAD(45)
|
||||
HGL_DEF_DEG2RAD(90)
|
||||
HGL_DEF_DEG2RAD(135)
|
||||
HGL_DEF_DEG2RAD(180)
|
||||
HGL_DEF_DEG2RAD(225)
|
||||
HGL_DEF_DEG2RAD(270)
|
||||
HGL_DEF_DEG2RAD(315)
|
||||
HGL_DEF_DEG2RAD(360)
|
||||
|
||||
#undef HGL_DEF_ANG2RAD
|
||||
#undef HGL_DEF_DEG2RAD
|
||||
|
||||
/**
|
||||
* 角度转弧度
|
||||
*/
|
||||
inline double hgl_ang2rad(const double ang)
|
||||
inline double hgl_deg2rad(const double ang)
|
||||
{
|
||||
return ang*(HGL_PI/180.0f);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ namespace hgl
|
||||
/**
|
||||
* 弧度转角度
|
||||
*/
|
||||
inline double hgl_rad2ang(const double rad)
|
||||
inline double hgl_rad2deg(const double rad)
|
||||
{
|
||||
return rad*(180.0f/HGL_PI);
|
||||
}
|
||||
|
@@ -13,11 +13,6 @@ namespace hgl
|
||||
using Matrix3f=glm::mat3;
|
||||
using Matrix4f=glm::mat4;
|
||||
|
||||
inline Matrix4f identity()
|
||||
{
|
||||
return Matrix4f();
|
||||
}
|
||||
|
||||
inline Matrix4f inverse(const Matrix4f &m)
|
||||
{
|
||||
return glm::inverse(m);
|
||||
|
@@ -80,14 +80,16 @@ namespace hgl
|
||||
float znear,
|
||||
float zfar)
|
||||
{
|
||||
float f = 1.0f / tan( hgl_deg2rad( 0.5f * field_of_view ) );
|
||||
|
||||
return Matrix4f(
|
||||
field_of_view / aspect_ratio,
|
||||
f / aspect_ratio,
|
||||
0.0f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
|
||||
0.0f,
|
||||
-field_of_view,
|
||||
-f,
|
||||
0.0f,
|
||||
0.0f,
|
||||
|
||||
@@ -105,21 +107,11 @@ namespace hgl
|
||||
|
||||
Matrix4f lookat(const Vector4f &eye,const Vector4f &target,const Vector4f &up)
|
||||
{
|
||||
Vector4f forward=target-eye;
|
||||
|
||||
normalize(forward);
|
||||
|
||||
Vector4f right=cross(forward,up);
|
||||
|
||||
normalize(right);
|
||||
Vector4f forward=normalize(target-eye);
|
||||
Vector4f right=normalize(cross(forward,up));
|
||||
|
||||
Vector4f nup=cross(right,forward);
|
||||
|
||||
//Matrix4f result( right.x, right.y, right.z, 1.0f,
|
||||
// nup.x, nup.y, nup.z, 1.0f,
|
||||
// -forward.x, -forward.y, -forward.z/2.0f, 1.0f,
|
||||
// 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
Matrix4f result( right.x,
|
||||
nup.x,
|
||||
-forward.x,
|
||||
@@ -135,11 +127,11 @@ namespace hgl
|
||||
-forward.z/2.0f,
|
||||
0.0f,
|
||||
|
||||
1.0f,
|
||||
1.0f,
|
||||
1.0f,
|
||||
dot(eye,right ),
|
||||
dot(eye,nup ),
|
||||
dot(eye,forward),
|
||||
1.0f);
|
||||
|
||||
return result*translate(-Vector3f(eye));
|
||||
return result;
|
||||
}
|
||||
}//namespace hgl
|
||||
|
Reference in New Issue
Block a user