From 0b2050cf687a0f698b838df781a8095a9e92939d Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 17 Dec 2012 21:07:21 +0100 Subject: [PATCH] [DEBUG] corection of the roation matrix --- etk/math/Matrix4.cpp | 22 ++++++++++++++++++++-- etk/math/Matrix4.h | 11 +++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/etk/math/Matrix4.cpp b/etk/math/Matrix4.cpp index 4760c33..b5c9b40 100644 --- a/etk/math/Matrix4.cpp +++ b/etk/math/Matrix4.cpp @@ -11,6 +11,22 @@ #include #include + + +void etk::Matrix4::Rotate(etk::Vector3D& vect, float angleRad) +{ + etk::Matrix4 tmpMat = etk::matRotate(vect, angleRad); + *this *= tmpMat; +} + +void etk::Matrix4::Translate(etk::Vector3D& vect) +{ + etk::Matrix4 tmpMat = etk::matScale(vect); + *this *= tmpMat; +} + + + etk::Matrix4 etk::matPerspective(float left, float right, float bottom, float top, float nearVal, float farVal) { etk::Matrix4 tmp; @@ -44,10 +60,13 @@ etk::Matrix4 etk::matTranslate(etk::Vector3D vect) etk::Matrix4 etk::matScale(etk::Vector3D vect) { etk::Matrix4 tmp; + tmp.Scale(vect); + /* // set scale : tmp.m_mat[0] = vect.x; tmp.m_mat[5] = vect.y; tmp.m_mat[10] = vect.z; + */ //TK_INFO("Scale :"); //etk::matrix::Display(tmp); return tmp; @@ -61,7 +80,7 @@ etk::Matrix4 etk::matRotate(etk::Vector3D vect, float angleRad) float invVal = 1.0-cosVal; // set rotation : tmp.m_mat[0] = vect.x * vect.x * invVal + cosVal; - tmp.m_mat[1] = vect.x * vect.y * invVal - vect.z * cosVal; + tmp.m_mat[1] = vect.x * vect.y * invVal - vect.z * sinVal; tmp.m_mat[2] = vect.x * vect.z * invVal + vect.y * sinVal; tmp.m_mat[4] = vect.y * vect.x * invVal + vect.z * sinVal; @@ -75,7 +94,6 @@ etk::Matrix4 etk::matRotate(etk::Vector3D vect, float angleRad) } - float etk::Matrix4::CoFactor(int32_t row, int32_t col) const { return ( ( m_mat[((row+1)&3)*4 + ((col+1)&3)] * m_mat[((row+2)&3)*4 + ((col+2)&3)] * m_mat[((row+3)&3)*4 + ((col+3)&3)] diff --git a/etk/math/Matrix4.h b/etk/math/Matrix4.h index b656c60..37a5c31 100644 --- a/etk/math/Matrix4.h +++ b/etk/math/Matrix4.h @@ -259,15 +259,18 @@ namespace etk m_mat[4] = -Sin; m_mat[1] = Sin; } - +#endif /** * @brief Makes a rotation matrix about an arbitrary axis. * @param[in] vect vector to apply the angle. * @param[in] angleRad angle to apply. */ - void Rotate(etk::Vector3D vect, float angleRad=0.0); -#endif - + void Rotate(etk::Vector3D& vect, float angleRad=0.0); + /** + * @brief Makes a translation of the matrix + * @param[in] vect Translation to apply. + */ + void Translate(etk::Vector3D& vect); /** * @brief Computes a cofactor. Used for matrix inversion. * @param[in] row Id of raw.