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_270=0;
|
||||||
constexpr double HGL_COS_ANG_315=0.707106781187;
|
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_DEG2RAD(0)
|
||||||
HGL_DEF_ANG2RAD(45)
|
HGL_DEF_DEG2RAD(45)
|
||||||
HGL_DEF_ANG2RAD(90)
|
HGL_DEF_DEG2RAD(90)
|
||||||
HGL_DEF_ANG2RAD(135)
|
HGL_DEF_DEG2RAD(135)
|
||||||
HGL_DEF_ANG2RAD(180)
|
HGL_DEF_DEG2RAD(180)
|
||||||
HGL_DEF_ANG2RAD(225)
|
HGL_DEF_DEG2RAD(225)
|
||||||
HGL_DEF_ANG2RAD(270)
|
HGL_DEF_DEG2RAD(270)
|
||||||
HGL_DEF_ANG2RAD(315)
|
HGL_DEF_DEG2RAD(315)
|
||||||
HGL_DEF_ANG2RAD(360)
|
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);
|
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);
|
return rad*(180.0f/HGL_PI);
|
||||||
}
|
}
|
||||||
|
@@ -13,11 +13,6 @@ namespace hgl
|
|||||||
using Matrix3f=glm::mat3;
|
using Matrix3f=glm::mat3;
|
||||||
using Matrix4f=glm::mat4;
|
using Matrix4f=glm::mat4;
|
||||||
|
|
||||||
inline Matrix4f identity()
|
|
||||||
{
|
|
||||||
return Matrix4f();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Matrix4f inverse(const Matrix4f &m)
|
inline Matrix4f inverse(const Matrix4f &m)
|
||||||
{
|
{
|
||||||
return glm::inverse(m);
|
return glm::inverse(m);
|
||||||
|
@@ -80,14 +80,16 @@ namespace hgl
|
|||||||
float znear,
|
float znear,
|
||||||
float zfar)
|
float zfar)
|
||||||
{
|
{
|
||||||
|
float f = 1.0f / tan( hgl_deg2rad( 0.5f * field_of_view ) );
|
||||||
|
|
||||||
return Matrix4f(
|
return Matrix4f(
|
||||||
field_of_view / aspect_ratio,
|
f / aspect_ratio,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
0.0f,
|
0.0f,
|
||||||
-field_of_view,
|
-f,
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
@@ -105,41 +107,31 @@ namespace hgl
|
|||||||
|
|
||||||
Matrix4f lookat(const Vector4f &eye,const Vector4f &target,const Vector4f &up)
|
Matrix4f lookat(const Vector4f &eye,const Vector4f &target,const Vector4f &up)
|
||||||
{
|
{
|
||||||
Vector4f forward=target-eye;
|
Vector4f forward=normalize(target-eye);
|
||||||
|
Vector4f right=normalize(cross(forward,up));
|
||||||
normalize(forward);
|
|
||||||
|
|
||||||
Vector4f right=cross(forward,up);
|
|
||||||
|
|
||||||
normalize(right);
|
|
||||||
|
|
||||||
Vector4f nup=cross(right,forward);
|
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,
|
Matrix4f result( right.x,
|
||||||
nup.x,
|
nup.x,
|
||||||
-forward.x,
|
-forward.x,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
right.y,
|
right.y,
|
||||||
nup.y,
|
nup.y,
|
||||||
-forward.y,
|
-forward.y,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
right.z,
|
right.z,
|
||||||
nup.z,
|
nup.z,
|
||||||
-forward.z/2.0f,
|
-forward.z/2.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
|
||||||
1.0f,
|
dot(eye,right ),
|
||||||
1.0f,
|
dot(eye,nup ),
|
||||||
1.0f,
|
dot(eye,forward),
|
||||||
1.0f);
|
1.0f);
|
||||||
|
|
||||||
return result*translate(-Vector3f(eye));
|
return result;
|
||||||
}
|
}
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Reference in New Issue
Block a user