[fixed]Rotation around vector matrix

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.

[fixed]Rotation around vector matrix

Postby Randajad » Sun Aug 12, 2012 1:14 pm

I try to find it method, but there is no such method. :(
So I google and a little rewrite.

cpp Code: Select all
matrix4 rotation_matrix;
 
            {
                f32 angle = ANGLE_VALUE;
 
                f32 x = VECTOR_X;
                f32 y = VECTOR_Y;
                f32 z = VECTOR_Z;
 
                f32 s = sin(angle);
                f32 c = cos(angle);
                f32 omc = 1.0 - c;
 
                f32 xomc = x * omc;
                f32 yomc = y * omc;
                f32 zomc = z * omc;
 
                f32 xxomc = x * xomc;
                f32 xyomc = x * yomc;
                f32 xzomc = x * zomc;
                f32 yyomc = y * yomc;
                f32 yzomc = y * zomc;
                f32 zzomc = z * zomc;
 
                f32 xs = x * s;
                f32 ys = y * s;
                f32 zs = z * s;
 
                rotation_matrix[0] = xxomc + c;
                rotation_matrix[1] = xyomc + zs;
                rotation_matrix[2] = xzomc - ys;
                rotation_matrix[3] = 0;
                rotation_matrix[4] = xyomc - zs;
                rotation_matrix[5] = yyomc + c;
                rotation_matrix[6] = yzomc + xs;
                rotation_matrix[7] = 0;
                rotation_matrix[8] = xzomc + ys;
                rotation_matrix[9] = yzomc - xs;
                rotation_matrix[10] = zzomc + c;
                rotation_matrix[11] = 0;
                rotation_matrix[12] = 0;
                rotation_matrix[13] = 0;
                rotation_matrix[14] = 0;
                rotation_matrix[15] = 1;
            }


Please, wrap it to matrix4 class. It's very useful, i think.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Sun Aug 12, 2012 1:53 pm

No test-code, no examples, it's not even a function ... just some code which you found on the web (using which license, who is the author?) and tell us will work. We can not simply apply something like that to the engine. Ensuring that things really work is what takes most programming time, not the googling.

But you can certainly still use that - you have access to all interna of the matrix so you can make a function for this in your own code.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Rotation around vector matrix

Postby Randajad » Sun Aug 12, 2012 2:56 pm

It's copy-paste from my code. =_= I don't view matrix class internally, so don't make it's a function. But okay.
Original have no license and free to use, i think.

matrix4.h:175, add:
cpp Code: Select all
 
            //! Make a rotation matrix around vector. The 4th row and column are unmodified.
            CMatrix4<T>& setRotationVectorRadians( const vector3d<T>& vec, f32 angle);
 


matrix4.h:823, add:
cpp Code: Select all
 
    template <class T>
    inline CMatrix4<T>& CMatrix4<T>::setRotationVectorRadians( const vector3d<T>& vec, f32 angle)
    {
        f32 x = vec.X;
        f32 y = vec.Y;
        f32 z = vec.Z;
 
        f32 s = sin(angle);
        f32 c = cos(angle);
        f32 omc = 1.0 - c;
 
        f32 xomc = x * omc;
        f32 yomc = y * omc;
        f32 zomc = z * omc;
 
        f32 xxomc = x * xomc;
        f32 xyomc = x * yomc;
        f32 xzomc = x * zomc;
        f32 yyomc = y * yomc;
        f32 yzomc = y * zomc;
        f32 zzomc = z * zomc;
 
        f32 xs = x * s;
        f32 ys = y * s;
        f32 zs = z * s;
 
        M[0] = xxomc + c;
        M[1] = xyomc + zs;
        M[2] = xzomc - ys;
 
        M[4] = xyomc - zs;
        M[5] = yyomc + c;
        M[6] = yzomc + xs;
 
        M[8] = xzomc + ys;
        M[9] = yzomc - xs;
        M[10] = zzomc + c;
 
#if defined ( USE_MATRIX_TEST )
        definitelyIdentityMatrix=false;
#endif
 
        return *this;
    }
 


Quake2map example:125, add:
cpp Code: Select all
    core::matrix4 mat;
    mat.setRotationVectorRadians(core::vector3df(1, 0, 0), 1.57);
 
    smgr->getMeshManipulator()->transform(mesh->getMesh(0), mat);
 


Now quake2 world rotated at X axis by 90 degrees.
Now it can pretend to be added in trunk? :3
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Sun Aug 12, 2012 3:53 pm

Theoretically... but practically I just noticed there are already setRotationAxisRadiansLH and setRotationAxisRadiansRH functions in the matrix class in Irrlicht svn. So someone already did this. Sorry, I didn't notice this when looking for it this morning, I'm just not a morning person ...

Generally when doing feature-patches try to make them again svn trunk as that's where new features have to be added (stable versions only get bugfixes).

Better luck next time.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Rotation around vector matrix

Postby Randajad » Sun Aug 12, 2012 4:17 pm

What RH and LH mean? I don't found any documentation. I try to use that functions, but result doesn't like i expected. Also i think setRotationAxisRadiansRH is broken: it makes Y ordinate = 0.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Sun Aug 12, 2012 5:11 pm

rh = right handed and lh = left handed. setRotationAxisRadiansLH is probably what you need as that is the usual coordinate system in Irrlicht. If you get different results than in your function please give me an example for values where we get different results so we can compare and figure out which one is correct.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Rotation around vector matrix

Postby Randajad » Mon Aug 13, 2012 3:45 pm

Okay. I decide to modify hello world example a little.
Just change
cpp Code: Select all
 
        IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
 


to

cpp Code: Select all
 
    IMesh *m = mesh->getMesh(0, 0);
 
    matrix4 mat;
    //mat.setRotationVectorRadians(vector3df(X, Y, Z), 3.14); /// MY FUNC
    //mat.setRotationAxisRadiansLH (3.14, vector3df(X, Y, Z)); /// IRR FUNC
    smgr->getMeshManipulator()->transform(m, mat);
 
    IMeshSceneNode* node = smgr->addMeshSceneNode( m );
 


And comment out:
cpp Code: Select all
 
//node->setMD2Animation(scene::EMAT_STAND);
 


We have result:
Image

Now about tests. All rotation is about 3.14(180 degrees).

vector3df(1, 0, 0): about x axis.
MY FUNCTION:
Image
IRRLICHT FUNCTION:
Image

No difference.

vector3df(0, 1, 0): about y axis.
MY FUNCTION:
Image
IRRLICHT FUNCTION:
Image

No difference.

vector3df(0, 0, 1): about z axis.
MY FUNCTION:
Image
IRRLICHT FUNCTION:
Image

WTF? It's looks irrlicht goes in wrong way.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby Randajad » Mon Aug 13, 2012 4:23 pm

Also:
Generally when doing feature-patches try to make them again svn trunk as that's where new features have to be added (stable versions only get bugfixes).


I have latest trank build, of course. =_=
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Mon Aug 13, 2012 5:09 pm

Ok, I just wrote a test:

cpp Code: Select all
 
#include <irrlicht.h>
 
using namespace irr;
using namespace core;
using namespace scene;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
void setRotationVectorRadians(irr::core::matrix4 &M, const irr::core::vector3df& vec, irr::f32 angle)
{
    f32 x = vec.X;
    f32 y = vec.Y;
    f32 z = vec.Z;
 
    f32 s = sin(angle);
    f32 c = cos(angle);
    f32 omc = 1.0 - c;
 
    f32 xomc = x * omc;
    f32 yomc = y * omc;
    f32 zomc = z * omc;
 
    f32 xxomc = x * xomc;
    f32 xyomc = x * yomc;
    f32 xzomc = x * zomc;
    f32 yyomc = y * yomc;
    f32 yzomc = y * zomc;
    f32 zzomc = z * zomc;
 
    f32 xs = x * s;
    f32 ys = y * s;
    f32 zs = z * s;
 
    M[0] = xxomc + c;
    M[1] = xyomc + zs;
    M[2] = xzomc - ys;
 
    M[4] = xyomc - zs;
    M[5] = yyomc + c;
    M[6] = yzomc + xs;
 
    M[8] = xzomc + ys;
    M[9] = yzomc - xs;
    M[10] = zzomc + c;
}
 
 
int main(int argc, char *argv[])
{
    IrrlichtDevice * device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640,480) );
    if (!device)
        return false;
   
    scene::ISceneManager* smgr = device->getSceneManager();
    video::IVideoDriver* videoDriver =  device->getVideoDriver();  
    ITimer * timer = device->getTimer();
 
    ICameraSceneNode * cam = smgr->addCameraSceneNodeFPS(0);
    cam->setPosition(core::vector3df(0, 0, -150));
 
    IMesh* mesh = smgr->getGeometryCreator()->createArrowMesh( 2, 2, 50.f, 20, 15, 20);
    mesh->getMeshBuffer(0)->getMaterial().setTexture( 0, videoDriver->getTexture("../../media/irrlichtlogo3.png") );
    mesh->getMeshBuffer(0)->getMaterial().Lighting = false;
    mesh->getMeshBuffer(1)->getMaterial().setTexture( 0, videoDriver->getTexture("../../media/irrlichtlogo3.png") );
    mesh->getMeshBuffer(1)->getMaterial().Lighting = false;
 
 
    core::array<IDummyTransformationSceneNode*> nodes;
    for ( int i=0; i<9; ++i )
    {
        IDummyTransformationSceneNode * dummy = smgr->addDummyTransformationSceneNode();
        dummy->getRelativeTransformationMatrix().setTranslation( core::vector3df((i%3-1)* 60.f, -(i/3-1)*60.f, 0) );
        ISceneNode* node = smgr->addMeshSceneNode(mesh, dummy);
        nodes.push_back(dummy);
    }
 
    mesh->drop();
 
    u32 oldTime = timer->getTime();
    f32 rot = 0.f;
    while ( device->run() )
    {
        if ( device->isWindowActive() )
        {
            videoDriver->beginScene(true, true);
 
            smgr->drawAll();
 
            videoDriver->endScene();
 
            u32 newTime = timer->getTime();
            rot += (newTime-oldTime)* 0.001f;
            oldTime = newTime;
   
            for ( int i=0; i < 9; ++ i )
            {
                vector3df axis;
                if ( i%3 == 0 )
                    axis = vector3df(1, 0, 0);
                else if( i%3 == 1 )
                    axis = vector3df(0, 1, 0);
                else
                    axis = vector3df(0, 0, 1);
 
                matrix4& m = nodes[i]->getRelativeTransformationMatrix();
                if ( i < 3 )
                    setRotationVectorRadians (m, axis, rot);
                else if ( i < 6 )
                    m.setRotationAxisRadiansLH (rot, axis);
                else
                    m.setRotationAxisRadiansRH (rot, axis);
            }
        }
        device->sleep( 1 );
    }
 
    device->closeDevice();
    device->drop();
   
    return 0;
}
 


It looks like your function is identical to the right-handed rotation. Why didn't you just try out both man? There were 2 functions to check out and you don't even give both a shot but waited until I waste an hour to reproduce it and then one just works _exactly_ like yours? *sigh*
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Rotation around vector matrix

Postby Randajad » Mon Aug 13, 2012 5:48 pm

I try RH function too. Same result, btw. Where u have result as my function?
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Mon Aug 13, 2012 5:58 pm

First 3 nodes in my example (top row) are using your function. Bottom 3 nodes are using setRotationAxisRadiansRH. Rotation in all 3 axis looks identical as can be easily seen when running it (just copy it over one of the examples for testing). When you still find a difference then please do post actual values - it's a function taking a vector, a matrix and an angle - so if there is a bug then do post the actual values to reproduce it. Everything looks fine to me so far so I need an actual example of anything going wrong ...
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Rotation around vector matrix

Postby Randajad » Mon Aug 13, 2012 9:31 pm

I posted screens above... setRotationAxisRadiansRH on screens works as setRotationAxisRadiansLH. Difference is on last sceen pair.
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Mon Aug 13, 2012 10:54 pm

Yes - and I tried to reproduce it and the example code I did use to reproduce it is already posted here! And the visible result was just as I wrote above - setRotationAxisRadiansLH and setRotationAxisRadiansRH are different and the latter one has the _same_ results as your function. The code is here - all you have to do is copy-paste it over an example and run it to see it yourself, that takes you less than a minute! I tried reproducing your reported problem for an hour and _can't_ . I also already told you how to report it - it's a simple function which uses 3 variables (matrix, axis, angle) - all you have to do is give me the values where it really is wrong (just print them or copy them in the debugger - the matrix values both before and after certainly).

I mean I don't even see the difference in that last screenshot except that the animation is in another state at that moment - the figure is rotated on the head and looking to the left in both shots which is exactly what I would expect by a 180° rotation around z - isn't it?
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Rotation around vector matrix

Postby Randajad » Tue Aug 14, 2012 9:18 am

Why u don't hear me? My example HAS NO animation. It's should give same result per pixel! I simple create meshscenenode from first mesh of animation. Rotation is 180 degrees and it's no matter use LH or RH function.
Three screens:
RH:
Image
LH:
Image
MY:
Image

Irrlicht function broken in M[9].
Sorry for my English, i'm from Russia.
If i makes mistakes in phrases you can correct me btw. ^_^
Randajad
 
Posts: 59
Joined: Thu May 03, 2012 10:08 am

Re: Rotation around vector matrix

Postby CuteAlien » Tue Aug 14, 2012 9:53 am

Randajad wrote:Why u don't hear me? My example HAS NO animation. It's should give same result per pixel!

Ok, sorry - I did indeed oversee the part where you replaced the animated mesh with a static one. Well still thanks for the values ... will try to find some more time for this.

And for exactly 180° LH and RH should certainly be the same as 180° will reach the same place no matter in which direction you go - but for every other values it's obviously different.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5364
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Next

Return to Bug reports

Who is online

Users browsing this forum: No registered users and 1 guest