Commit f7eb2e9a authored by lukeph's avatar lukeph

added identity check on getInverse() in CMatrix4

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1018 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2780743d
......@@ -271,7 +271,7 @@ namespace core
void setDefinitelyIdentityMatrix( bool isDefinitelyIdentityMatrix);
//! gets if the matrix is definitely identity matrix
bool getDefinitelyIdentityMatrix() const;
bool getDefinitelyIdentityMatrix() const;
private:
//! Matrix data, stored in row-major order
......@@ -550,7 +550,7 @@ namespace core
template <class T>
inline CMatrix4<T> CMatrix4<T>::operator*(const CMatrix4<T>& m2) const
{
// Testing purpose..
// Testing purpose..
if ( this->isIdentity() )
return m2;
if ( m2.isIdentity() )
......@@ -765,6 +765,7 @@ namespace core
if (j != i)
if (!iszero((*this)(i,j)))
return false;
return true;
}
......@@ -932,7 +933,7 @@ namespace core
f32 Amax[3];
f32 Bmin[3];
f32 Bmax[3];
Amin[0] = box.MinEdge.X;
Amin[1] = box.MinEdge.Y;
Amin[2] = box.MinEdge.Z;
......@@ -948,9 +949,9 @@ namespace core
u32 i, j;
const CMatrix4<T> &m = *this;
for (i = 0; i < 3; ++i)
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
for (j = 0; j < 3; ++j)
{
f32 a = m(j,i) * Amin[j];
f32 b = m(j,i) * Amax[j];
......@@ -1025,6 +1026,12 @@ namespace core
/// The inverse is calculated using Cramers rule.
/// If no inverse exists then 'false' is returned.
if ( this->isIdentity() )
{
out=*this;
return true;
}
const CMatrix4<T> &m = *this;
f32 d = (m(0, 0) * m(1, 1) - m(0, 1) * m(1, 0)) * (m(2, 2) * m(3, 3) - m(2, 3) * m(3, 2)) -
......@@ -1349,7 +1356,7 @@ namespace core
M[12] = (T)(-plane.D * light.X);
M[13] = (T)(-plane.D * light.Y);
M[14] = (T)(-plane.D * light.Z);
M[15] = (T)(-plane.D * point + d);
M[15] = (T)(-plane.D * point + d);
definitelyIdentityMatrix=false;
}
......@@ -1504,13 +1511,13 @@ namespace core
/*!
Generate texture coordinates as linear functions so that:
u = Ux*x + Uy*y + Uz*z + Uw
u = Ux*x + Uy*y + Uz*z + Uw
v = Vx*x + Vy*y + Vz*z + Vw
The matrix M for this case is:
Ux Vx 0 0
Uy Vy 0 0
Uz Vz 0 0
Uw Vw 0 0
Ux Vx 0 0
Uy Vy 0 0
Uz Vz 0 0
Uw Vw 0 0
*/
template <class T>
......@@ -1590,7 +1597,7 @@ namespace core
template <class T>
inline void CMatrix4<T>::setM(const T* data)
{
for (u32 i = 0; i < 16; ++i)
for (u32 i = 0; i < 16; ++i)
M[i] = data[i];
definitelyIdentityMatrix = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment