How to realize rotation in two steps

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

How to realize rotation in two steps

Post by Magnet »

How to realize rotation in two steps?

I need to rotate object as presented on scheme.
Image
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I think this is basically what i've been trying to do today.

What i wanted to do was to rotate my node backwards, on the x axis, and also at the same time rotate it on the y axis so it spins around. But the result i got was for it to spin around wildly, not how i wanted it to. I think i realise why it does this. it firstly rotated on one axis and then rotated on the next without "resetting" the axis so the next rotation would not be affected by the previous one... I'm not sure if that will make sense to anyone :lol:

I'm not sure if i've got some code that i've done before which would take care of this problem or not but it's just confusing me quite a lot :lol:
Image Image Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

First off, the images show a rotation along Y and then a translation along Y. I don't see two rotations.

If you want to do multiple rotations, you should be able to create a matrix for each, and then apply them to a final composite matrix...

Code: Select all

core::matrix4 m;
m.makeIdentity();

// later
core::matrix4 r1;
r1.setRotationDegrees(core::vector3df(0, 135, 0));

// later
core::matrix4 r2;
r2.setRotationDegrees(core::vector3df(90, 0, 0));

m *= r1;
m *= r2;
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Do you then apply the matrix to the node by applying it to getAbsoluteTransformation() ?
Image Image Image
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

you can just use node->setRotation(m->getRotationDegrees())
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

Hm. Senks.
I realize this task with another "funny" method ^-)
I am create one more scenenode and put my node there.
After I am rotate parent scenode and my scenenode :-)

I am find scenenode matrix but not found it :-) I am not guess to create new matrix :-)

Thanks!
itzjac
Posts: 57
Joined: Fri Nov 17, 2006 7:41 pm
Location: Mexico City

Post by itzjac »

Hi to all!!!

Are you toalking about a similar GoogleEarth interface? because I'm looking for that kind of movement only for one of the nodes on my scene, there are lots of other nodes on my scene but only one has to do that behavior :shock:
Warren
Posts: 60
Joined: Fri Jul 07, 2006 11:41 pm
Location: Santiago De Compostela, Spain

Post by Warren »

Hi!

I have a problem using this stuff:

Code: Select all

     core::matrix4 m;
     m.makeIdentity();
     
     // later
     core::matrix4 r1;
     r1.setRotationDegrees(core::vector3df(0
                            , node->getRotation().Y+roll_inc)
                            , 0));

     // later
     core::matrix4 r2;
     r2.setRotationDegrees(core::vector3df(0, 0, 30));
     
     m *= r2; 
     m *= r1;
     
     node->setRotation( m.getRotationDegrees() ); 
I want to rotate the direction of my node using the keyboard, so I plus the roll_inc variable to the Y angle. And then, keep a constant inclination at the Z angle.
This code make a rare behavior,
the r1 matrix´s Y component ranges between [272,271,....,0,1,....82] and do not exceeds that limits (272-82)

Besides it I do not obtain the result of doing a rotation in two steps,
the results are the same that making the common rotation

node->setRotation( vector3df( 0, node->getRotation().Y+roll_inc, 30) );


I hope that i explain myself,
Tnx in advance!!
------------------------------------------------
Irrlicht Ussers Map
Join now!!
http://www.frappr.com/irrlichtusers
Post Reply