Get Rotation of Node

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
timmymorris91
Posts: 19
Joined: Tue Mar 18, 2008 9:43 pm
Location: Wagga Wagga, Australia

Get Rotation of Node

Post by timmymorris91 »

Code: Select all

vector3df v = node->getRotation
I know this gives me the relative poistion but anyway,
the return value only gives me the X and Y rotation but Z always = 0??

If I use a matrix to get absolute transformation and getrotationDegrees I have the same problem.

THE END...
(Not answered)
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

No, the result of a call to getRotation() will be the relative rotation from the parent node. If you call...

Code: Select all

node->setRotation (core::vector3df (10, 10, 10));
then the result of

Code: Select all

const core::vector3df r = node->getRotation();
should be the vector r with r.x=10, r.y=10, r.z=10. If you don't rotate the node on its Z axis, then you should expect the relative rotation on Z to be 0.

Travis
timmymorris91
Posts: 19
Joined: Tue Mar 18, 2008 9:43 pm
Location: Wagga Wagga, Australia

Post by timmymorris91 »

Im still having a problem.

Node is a gun attached to the camera.

Code: Select all


matrix4 trans =  node->getAbsoluteTranslation();
vector3f v = trans.getRotationDegress();
bullet-setRotation(v);
v should give me the rotation of the gun.
I need the rotation so I can shoot a bullet and use the rotation
as the bullets.

All the rotation works but the Z axis is always the same. If I shoot up, then the bullet will still be flat, not tilted up or down.
shogun
Posts: 162
Joined: Wed Sep 05, 2007 11:02 am
Location: inside

Post by shogun »

This would be the X axis, not the Z axis.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Actually, wouldn't it be Y? Because in XYZ coordinate system Y is "up/down"
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

timmymorris91 wrote:

Code: Select all


matrix4 trans =  node->getAbsoluteTranslation();
vector3f v = trans.getRotationDegress();
bullet-setRotation(v);
v should give me the rotation of the gun.
I need the rotation so I can shoot a bullet and use the rotation
as the bullets.

All the rotation works but the Z axis is always the same. If I shoot up, then the bullet will still be flat, not tilted up or down.
If you post pseudo-code, then we have to guess what you really meant. I think it was this:

Code: Select all

    ISceneNode * actor = smgr->addEmptySceneNode();
    actor->setRotation(vector3df(10, 20, 30));
    actor->updateAbsolutePosition();

    ISceneNode * gun = smgr->addEmptySceneNode(actor);
    // Presumably the gun doesn't have any rotation of its own
    gun->updateAbsolutePosition();

    matrix4 trans = gun->getAbsoluteTransformation();
    vector3df rotation = trans.getRotationDegrees(); 
    (void)printf("%f %f %f\n", rotation.X, rotation.Y, rotation.Z);
Works For Me.
Eigen wrote:
shogun wrote:This would be the X axis, not the Z axis.
Actually, wouldn't it be Y? Because in XYZ coordinate system Y is "up/down"
No. What's returned isn't a direction vector, it's three Euler axis rotations. X axis is pitch.

I imagine that's timmy's issue as well. Unless your nodes are rolled (tilted to the side), the Z rotation will be 0. That's good, as if you're doing your own trig calculations, you really only want to be dealing with rotations in 2 axes, not 3.

I suspect that what you may want is a direction vector for your bullet, not rotations. If so, then you can just use matrix4::rotateVect().

Code: Select all

    ISceneNode * actor = smgr->addEmptySceneNode();
    actor->setRotation(vector3df(45, 90, 0));  // Face right, and 45 degrees up.
    actor->updateAbsolutePosition();

    ISceneNode * gun = smgr->addEmptySceneNode(actor);
    // Presumably the gun doesn't have any rotation of its own
    gun->updateAbsolutePosition();

    matrix4 trans = gun->getAbsoluteTransformation();

    vector3df direction(0, 0, 1);
    trans.rotateVect(direction); 
    direction.normalize();
    (void)printf("%f %f %f\n", direction.X, direction.Y, direction.Z);
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
timmymorris91
Posts: 19
Joined: Tue Mar 18, 2008 9:43 pm
Location: Wagga Wagga, Australia

Post by timmymorris91 »

rogerborg wrote:

Code: Select all

   matrix4 trans = gun->getAbsoluteTransformation(); 
   vector3df rotation = trans.getRotationDegrees(); 
   (void)printf("%f %f %f\n", rotation.X, rotation.Y, rotation.Z); 
I have used this method before.
But when I use the rotation vector and set the bullet being shot to the same direction as the gun, it doesnt apply the right transformation to the bullet.
Maybe It could be the actual model of the bullet, it could be facing towards a different direction.[/code]
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

timmymorris91 wrote:
rogerborg wrote:

Code: Select all

   matrix4 trans = gun->getAbsoluteTransformation(); 
   vector3df rotation = trans.getRotationDegrees(); 
   (void)printf("%f %f %f\n", rotation.X, rotation.Y, rotation.Z); 
I have used this method before.
But when I use the rotation vector and set the bullet being shot to the same direction as the gun, it doesnt apply the right transformation to the bullet.
It doesn't apply the transformation that you expect.

How are you using the Euler rotations returned by getRotationDegrees() to produce a direction for the bullet?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
timmymorris91
Posts: 19
Joined: Tue Mar 18, 2008 9:43 pm
Location: Wagga Wagga, Australia

Post by timmymorris91 »

I am just setting the rotation of the bullet to the rotation of the gun.

Code: Select all

vector3df rotation = trans->getRotationDegrees();
bullet->setRotation(v);
I would expect that the bullet would face the same direction as the gun.
I dont understand what euler rotations are??
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Euler angles are described here.

First, you should know about axes and the left hand rule (note that Irrlicht is left handed, not right handed). Get used to the idea of holding up your left hand and twisting it around; you'll be doing it a lot. ;)

The Euler angles just describe 3 rotations around those axes. Irrlicht applies them in 'reverse' order, i.e. Z (roll around your index finger) then Y (yaw around your thumb) then X (pitch around your middle finger).

Now, you can pick any axis to be "forwards", but most people interpret the +Z axis as forwards, i.e. the direction that your index finger is pointing.

Do some pointing around with that finger. Notice how you can point in any direction by first rotating your hand around your thumb (Y rotation) followed by pitching it up or down around your middle finger (X rotation). To "point" your index finger in any direction, you don't have to roll around that finger (a Z rotation).

Did any of that make sense? If not, point, point and point again until you get it.

... all pointed out?

OK, the code you provided looks fine. If trans is the absolute transformation of the gun, then that should (absent issues in the code that we haven't seen) give the bullet the same rotation as the gun. If they aren't pointing in the same directions, check that the models are oriented the same way.

That's half the problem. You also need to create a direction vector for the bullet. You can do this using the rotation angles:

Code: Select all

    // Your code so far
    vector3df rotation = trans->getRotationDegrees();
    bullet->setRotation(rotation);

    // Build a rotation matrix for the direction
    matrix4 rotationMatrix;
    rotationMatrix.setRotationDegrees(rotation);

    // Assume that +Z is forwards
    vector3df bulletDirection(0, 0, 1);

    // Rotate that vector to point in the direction that the bullet is facing
    rotationMatrix.rotateVect(bulletDirection);

    // bulletDirection is the direction in which bulletNode should move
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply