diff --git a/etk/math/Matrix4.cpp b/etk/math/Matrix4.cpp index 1407068..0ac745e 100644 --- a/etk/math/Matrix4.cpp +++ b/etk/math/Matrix4.cpp @@ -31,19 +31,13 @@ void etk::Matrix4::Translate(etk::Vector3D& 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; for(int32_t iii=0; iii<4*4 ; iii++) { 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 // 4 5 6 7 // 8 9 10 11 @@ -60,6 +54,18 @@ etk::Matrix4 etk::matPerspective(float fovx, float aspect, float zNear, float zF 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 tmp; diff --git a/etk/math/Matrix4.h b/etk/math/Matrix4.h index 30b6f4a..6c0a499 100644 --- a/etk/math/Matrix4.h +++ b/etk/math/Matrix4.h @@ -291,7 +291,8 @@ namespace etk */ 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 matTranslate(etk::Vector3D vect); Matrix4 matScale(etk::Vector3D vect);