transfer bone/joint rotation to another scenenode?

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
kimgar
Posts: 37
Joined: Fri Apr 13, 2007 2:53 pm
Location: norway

transfer bone/joint rotation to another scenenode?

Post by kimgar »

i'm trying to copy the rotations of an animated x's bone to a scenenode, but the scenenode's rotation flips at the x axis.
it's a little hard to explain so i tried to draw a little sketch :

Image

the blue arrow is the animated x with a linked bone which rotates properly around the Y axis, and the green arrow is supposed to pick up the rotation from the bone, but it will not go below z<0

the code i have:

Code: Select all

irr::core::vector3df CreateGeometry::getBoneRot(std::string str){
    irr::scene::ISceneNode* joint;
    joint = node->getXJointNode(str.c_str());
    return joint->getRotation();
}

//mainloop:
irr::core::vector3df rot = animNode->getBoneRot("Bone03");
node->setRotation(irr::core::vector3df(0,rot.Y,0));
i just wanted to confirm if this behaviour is expected and if i need to learn about quaternion rotations and gimbal locks?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I think you should be able to use a child-parent relationship in some way so that the scenenode is a child of the joint... See if you can find some functions in the API to do that, i'm pretty sure i've done something like that before by attaching an hatchet to an animated character's hand and when the character moved his hand around the hatchet went with it with the correct rotation and everything.
Image Image Image
kimgar
Posts: 37
Joined: Fri Apr 13, 2007 2:53 pm
Location: norway

Post by kimgar »

yes that worked, but the reason i wanted to find the rotation directly is that i eventually wanted to attach a camera to that bone and use the bone's rotation to calculate a setTarget()

i guess parenting a node to the bone and read rotations from the node won't make any difference either, since the node would also inherit the flipping issues...
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You could just add the camera as a child of the joint instead of the node (as the camera is a node as well) and then you wouldn't need to calculate the target for the camera as it would be rotated for you.
Image Image Image
kimgar
Posts: 37
Joined: Fri Apr 13, 2007 2:53 pm
Location: norway

Post by kimgar »

would that work? i thought the camera target was independent of camera position/rotation, so that it would always stay at the same coordinates unless in some way calculated otherwise?

i tried linking the cam to the bone and it always looks at the same spot - am i missing something?
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

can you try using,

node->setRotation(irr::core::vector3df(rot.X,rot.Y,rot.Z));

if you want just the yaw, you might need to do some maths, as the roll and pitch may effect it.
kimgar
Posts: 37
Joined: Fri Apr 13, 2007 2:53 pm
Location: norway

Post by kimgar »

hah, Luke, that worked! i got so carried away with the Y rotation i forgot that there is some 360 flipping going on with the other axes!

hmhm, rotation is ok now. but this flipping issues are causing weirdness when trying to calculate a position with sin and cos.
the sin calc is ok, but cos has the same flipping symptoms, it refuses to go negative. i have another sketch:
Image
the green arrow is supposed stay at the end of the blue arrow all the time, but when blue rotates in yellow area, cos will not give an x<0)

Code: Select all

float x = rot.X*irr::core::DEGTORAD;
float y = rot.Y*irr::core::DEGTORAD;
float z = rot.Z*irr::core::DEGTORAD;

debugNode->node->setPosition(irr::core::vector3df(cos(y)*20,0,sin(y)*20));
i *almost* understand what is going here, but just almost...is there anyone that does understand? :)
Post Reply