[DEV] update the mtric parspective anf frunctrum

This commit is contained in:
Edouard DUPIN 2012-12-19 00:45:41 +01:00
parent e3890a6c14
commit 5e87dea87f
2 changed files with 15 additions and 8 deletions

View File

@ -31,19 +31,13 @@ void etk::Matrix4::Translate(etk::Vector3D<float>& vect)
} }
etk::Matrix4 etk::matPerspective(float fovx, float aspect, float zNear, float zFar) etk::Matrix4 etk::matFrustum(float xmin, float xmax, float ymin, float ymax, float zNear, float zFar)
{ {
etk::Matrix4 tmp; etk::Matrix4 tmp;
for(int32_t iii=0; iii<4*4 ; iii++) { for(int32_t iii=0; iii<4*4 ; iii++) {
tmp.m_mat[iii] = 0; tmp.m_mat[iii] = 0;
} }
float xmax = zNear * tanf(fovx * M_PI / 360.0);
float xmin = -xmax;
float ymin = xmin / aspect;
float ymax = xmax / aspect;
// 0 1 2 3 // 0 1 2 3
// 4 5 6 7 // 4 5 6 7
// 8 9 10 11 // 8 9 10 11
@ -60,6 +54,18 @@ etk::Matrix4 etk::matPerspective(float fovx, float aspect, float zNear, float zF
return tmp; return tmp;
} }
etk::Matrix4 etk::matPerspective(float fovx, float aspect, float zNear, float zFar)
{
//TK_DEBUG("drax perspective: fovx=" << fovx << "->" << aspect << " " << zNear << "->" << zFar);
float xmax = zNear * tanf(fovx/2.0);
float xmin = -xmax;
float ymin = xmin / aspect;
float ymax = xmax / aspect;
//TK_DEBUG("drax perspective: " << xmin << "->" << xmax << " & " << ymin << "->" << ymax << " " << zNear << "->" << zFar);
return etk::matFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
etk::Matrix4 etk::matOrtho(float left, float right, float bottom, float top, float nearVal, float farVal) etk::Matrix4 etk::matOrtho(float left, float right, float bottom, float top, float nearVal, float farVal)
{ {
etk::Matrix4 tmp; etk::Matrix4 tmp;

View File

@ -291,7 +291,8 @@ namespace etk
*/ */
Matrix4 Invert(void); Matrix4 Invert(void);
}; };
Matrix4 matPerspective(float fovx, float aspect, float zNear, float zFar); Matrix4 matFrustum(float xmin, float xmax, float ymin, float ymax, float zNear, float zFar);
Matrix4 matPerspective(float foxy, float aspect, float zNear, float zFar);
Matrix4 matOrtho(float left, float right, float bottom, float top, float nearVal, float farVal); Matrix4 matOrtho(float left, float right, float bottom, float top, float nearVal, float farVal);
Matrix4 matTranslate(etk::Vector3D<float> vect); Matrix4 matTranslate(etk::Vector3D<float> vect);
Matrix4 matScale(etk::Vector3D<float> vect); Matrix4 matScale(etk::Vector3D<float> vect);