diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index f1b278f94..c52830340 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -66,6 +66,7 @@ class NzMatrix4 NzMatrix4& MakeTranslation(const NzVector3& translation); NzMatrix4& MakeTransform(const NzVector3& translation, const NzQuaternion& rotation); NzMatrix4& MakeTransform(const NzVector3& translation, const NzQuaternion& rotation, const NzVector3& scale); + NzMatrix4& MakeViewMatrix(const NzVector3& translation, const NzQuaternion& rotation); NzMatrix4& MakeZero(); NzMatrix4& Set(T r11, T r12, T r13, T r14, @@ -118,6 +119,7 @@ class NzMatrix4 static NzMatrix4 Translate(const NzVector3& translation); static NzMatrix4 Transform(const NzVector3& translation, const NzQuaternion& rotation); static NzMatrix4 Transform(const NzVector3& translation, const NzQuaternion& rotation, const NzVector3& scale); + static NzMatrix4 ViewMatrix(const NzVector3& translation, const NzQuaternion& rotation); static NzMatrix4 Zero(); private: diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 32f34ae19..87e34ef24 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -709,9 +709,16 @@ NzMatrix4& NzMatrix4::MakeTransform(const NzVector3& translation, const MakeTransform(translation, rotation); // Ensuite on fait une mise à l'échelle des valeurs déjà présentes - ApplyScale(scale); + return ApplyScale(scale); +} - return *this; +template +NzMatrix4& NzMatrix4::MakeViewMatrix(const NzVector3& translation, const NzQuaternion& rotation) +{ + // Une matrice de vue doit appliquer une transformation opposée à la matrice "monde" + NzQuaternionf invRot = rotation.GetConjugate(); // Inverse de la rotation + + return MakeTransform(-(invRot*translation), invRot); } template @@ -765,6 +772,7 @@ NzMatrix4& NzMatrix4::Set(const T matrix[16]) template NzMatrix4& NzMatrix4::Set(const NzMatrix4& matrix) { + // Le membre isIdentity est copié en même temps que les valeurs std::memcpy(this, &matrix, sizeof(NzMatrix4)); return *this; @@ -774,12 +782,12 @@ template template NzMatrix4& NzMatrix4::Set(const NzMatrix4& matrix) { - Set(F(matrix.m11), F(matrix.m12), F(matrix.m13), F(matrix.m14), - F(matrix.m21), F(matrix.m22), F(matrix.m23), F(matrix.m24), - F(matrix.m31), F(matrix.m32), F(matrix.m33), F(matrix.m34), - F(matrix.m41), F(matrix.m42), F(matrix.m43), F(matrix.m44)); + Set(F(matrix[ 0]), F(matrix[ 1]), F(matrix[ 2]), F(matrix[ 3]), + F(matrix[ 4]), F(matrix[ 5]), F(matrix[ 6]), F(matrix[ 7]), + F(matrix[ 8]), F(matrix[ 9]), F(matrix[10]), F(matrix[11]), + F(matrix[12]), F(matrix[13]), F(matrix[14]), F(matrix[15])); - m_isIdentity = matrix.IsIdentity(); + m_isIdentity = false; return *this; } @@ -884,6 +892,7 @@ NzVector4 NzMatrix4::Transform(const NzVector4& vector) const template NzMatrix4& NzMatrix4::Transpose() { + // N'affecte pas l'identité (La transposée d'une matrice identité est la matrice identité elle-même) std::swap(m12, m21); std::swap(m13, m31); std::swap(m14, m41); @@ -1091,6 +1100,15 @@ NzMatrix4 NzMatrix4::Transform(const NzVector3& translation, const NzQu return mat; } +template +NzMatrix4 NzMatrix4::ViewMatrix(const NzVector3& translation, const NzQuaternion& rotation) +{ + NzMatrix4 mat; + mat.MakeViewMatrix(translation, rotation); + + return mat; +} + template NzMatrix4 NzMatrix4::Zero() {