bool Matrix4::hasRotation()

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

bool Matrix4::hasRotation()

Post by REDDemon »

snippet proposal for irrlicht (based on pre-existing "isIdentity") for the matrix 4 class:

Code: Select all

 
template <class T>
        inline bool CMatrix4<T>::hasRotation()
        {
#if defined ( USE_MATRIX_TEST )
                if (definitelyIdentityMatrix)  //if identity there is no rotation
                        return false;
#endif
                if (!core::equals( M[ 0], (T)1 )|| 
                                !core::equals( M[ 5], (T)1 ) ||
                                !core::equals( M[10], (T)1 )   )     // if diag(3x3matrix) != (1,1,1) there will be rotation.
                        return true;
 
                for (s32 i=0; i<3; ++i)
                        for (s32 j=0; j<3; ++j)
                                if ((j != i) && (!iszero((*this)(i,j))))   //check in 3x3 if any left value is not 0
                                        return true;
 
                return false;
        }
 
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: bool Matrix4::hasRotation()

Post by CuteAlien »

That would also return true on scaling.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: bool Matrix4::hasRotation()

Post by REDDemon »

you are right:) I'm making some test for that function but removing a piece of code seems to works now

Code: Select all

 
template <class T>
        inline bool CMatrix4<T>::hasRotation()
        {
#if defined ( USE_MATRIX_TEST )
                if (definitelyIdentityMatrix)  //if identity there is no rotation
                        return false;
#endif
 
                for (s32 i=0; i<3; ++i)
                        for (s32 j=0; j<3; ++j)
                                if ((j != i) && (!iszero((*this)(i,j))))   //check in 3x3 if any value out the diagonal is different from 0
                                        return true;
 
                return false;
        }
 
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: bool Matrix4::hasRotation()

Post by REDDemon »

and here's some test case too:

Code: Select all

 
#include <irrlicht.h>
#include <cassert>
 
using namespace irr;
using namespace core;
 
bool hasRotation(irr::core::matrix4 & matrix)
{
    for (s32 i=0; i<3; ++i)
            for (s32 j=0; j<3; ++j)
                    if ((j != i) && (!iszero(matrix(i,j))))   //check in 3x3 if any value out the diagonal is different from 0
                            return true;
 
    return false;
}
 
bool test1()
{
    irr::core::vector3df  Rot = irr::core::vector3df(0,0,0);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(0,0,0);
 
    irr::core::matrix4 mat1;
    mat1.setRotationDegrees(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat1*= mat2*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat1)!=test);
}
 
bool test2()
{
    irr::core::vector3df  Rot = irr::core::vector3df(90,0,0);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(0,0,0);
 
    irr::core::matrix4 mat1;
    mat1.setRotationRadians(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat1*= mat2*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat1)!=test);
}
 
bool test3()
{
    irr::core::vector3df  Rot = irr::core::vector3df(0,270,0);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(0,100,0);
 
    irr::core::matrix4 mat1;
    mat1.setRotationDegrees(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat1*= mat2*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat1)!=test);
}
 
bool test4()
{
    irr::core::vector3df  Rot = irr::core::vector3df(0,0,-90);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(1,2,3);
 
    irr::core::matrix4 mat1;
    mat1.setRotationRadians(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat1*= mat2*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat1)!=test);
}
 
bool test5()
{
    irr::core::vector3df  Rot = irr::core::vector3df(1,2,3);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(3,2,1);
 
    irr::core::matrix4 mat1;
    mat1.setRotationRadians(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat1*= mat2*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat1)!=test);
}
 
bool test6()
{
    irr::core::vector3df  Rot = irr::core::vector3df(100,90,80);
    irr::core::vector3df  Scl = irr::core::vector3df(0,0,1);
    irr::core::vector3df  Pos = irr::core::vector3df(30,5,17);
 
    irr::core::matrix4 mat1;
    mat1.setRotationRadians(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat1*= mat2*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat1)!=test);
}
 
bool test7()
{
    irr::core::vector3df  Rot = irr::core::vector3df(0,0,0);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(0,0,0);
 
    irr::core::matrix4 mat1;
    mat1.setRotationDegrees(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat2*= mat1*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat2)!=test);
}
 
bool test8()
{
    irr::core::vector3df  Rot = irr::core::vector3df(90,0,0);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(0,0,0);
 
    irr::core::matrix4 mat1;
    mat1.setRotationDegrees(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat2*= mat1*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat2)!=test);
}
 
bool test9()
{
    irr::core::vector3df  Rot = irr::core::vector3df(0,270,0);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(0,100,0);
 
    irr::core::matrix4 mat1;
    mat1.setRotationRadians(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat2*= mat1*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat2)!=test);
}
 
bool test10()
{
    irr::core::vector3df  Rot = irr::core::vector3df(0,0,-90);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(1,2,3);
 
    irr::core::matrix4 mat1;
    mat1.setRotationDegrees(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat2*= mat1*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat2)!=test);
}
 
bool test11()
{
    irr::core::vector3df  Rot = irr::core::vector3df(1,2,3);
    irr::core::vector3df  Scl = irr::core::vector3df(1,1,1);
    irr::core::vector3df  Pos = irr::core::vector3df(3,2,1);
 
    irr::core::matrix4 mat1;
    mat1.setRotationDegrees(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat2*= mat1*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat2)!=test);
}
 
bool test12()
{
    irr::core::vector3df  Rot = irr::core::vector3df(100,90,80);
    irr::core::vector3df  Scl = irr::core::vector3df(0,0,1);
    irr::core::vector3df  Pos = irr::core::vector3df(30,5,17);
 
    irr::core::matrix4 mat1;
    mat1.setRotationRadians(Rot);
    irr::core::matrix4 mat2;
    mat2.setScale(Scl);
    irr::core::matrix4 mat3;
    mat3.setTranslation(Pos);
 
 
    mat2*= mat1*mat3;
 
    bool test = Rot.equals(irr::core::vector3df(0,0,0),0.001f);
 
    return (hasRotation(mat2)!=test);
}
 
 
int main()
{
    assert(test1());
    assert(test2());
    assert(test3());
    assert(test4());
    assert(test5());
    assert(test6());
    assert(test7());
    assert(test8());
    assert(test9());
    assert(test10());
    assert(test11());
    assert(test12());
 
 
    return 0;
}
 
 
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Post Reply