Bone Look At

Problems building or running the engine, queries about how to use features etc.
Toadcop
Gnoblar
Posts: 15
Joined: Sat Jul 18, 2009 9:37 pm

Bone Look At

Post by Toadcop »

Ok it's a common question, and the main point is not about the quaternion rotation. to achive proper rotation of a bone you need to make it "manual" and also remove it from all animations.
and here is the problem

Code: Select all

			Bone *b = skelet->getBone(i);

			int numAnimations = skelet->getNumAnimations();
			for(int i=0;i<numAnimations;i++){
				Ogre::Animation * anim = skelet->getAnimation(i);
				anim->destroyNodeTrack(b->getHandle()); // <- destroy track
			}
is there a way to DISABLE and not to destroy the track ? so i can reactivate it later ?
or should i copy the track and re add it later ? (my system potentialy should allow to manipulate any bone for some time span)

and the second question is about rotating ^_^ (i am not that good at rotations and stuff)
i have the followinf code

Code: Select all

b ... // bone
Vector3 pos = b->getPosition() + (ent->_getParentNodeFullTransform() * b->_getDerivedPosition()); // should get the world position for the bone ?
b->setOrientation(pos.getRotationTo(vLookAt));   // vLookAt - a world position vector.
the sense is what bone should rotate to (look at) requested point, what is wrong here ? (well it kind a works but not correct)
//as for now i can see i don't encounter nodes current relative rotation

tnx and sorry for noobish questions.
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 51

Re: Bone Look At

Post by madmarx »

Don't worry about asking questions.

I am not convinced you need b->getPosition() in the pos calculation : ent->_getParentNodeFullTransform() * b->_getDerivedPosition() should be enough IMO.

Another problem is that you have position 1 (source), and position2(target) in world space. To make a rotation between the 2 of them will give you something that is not interesting, not related to your problem. You would prefer : vectorDirectionSource and vectorDirectionTarget both in worldspace(ws). There are several ways to do it. One of them is to calculate the position of the parent of the bone in ws.
Then you can make vectorDirectionSource = bonePositionWorld - positionParentBoneWorld and vectorDirectionTarget = targetPositionWorld - positionParentBoneWorld (and you might normalise them after that, although I think getRotationTo already does that).

pos.getRotationTo(vLookAt)
=> is a rotation not an orientation. Which means I don't think you want to use setOrientation() in your case. More something like rotate().

You have now everything to solve your problem (I teach inverse kinematics with ogre :mrgreen: ).
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Toadcop
Gnoblar
Posts: 15
Joined: Sat Jul 18, 2009 9:37 pm

Re: Bone Look At

Post by Toadcop »

tnx for reply and help ! i mostly figured out what is required =)
Toadcop
Gnoblar
Posts: 15
Joined: Sat Jul 18, 2009 9:37 pm

Re: Bone Look At

Post by Toadcop »

ok then i have an another question related to this topic.

1) the question about disabling animation tracks havent been answered at all =O
2) my rotation do "work" only in local (parent) space and i do rotate the node (to which entety is attached) it will continue to keep the local orientation (will lose world rotation)
so about the second question how properly to adapt the rotation to relative one (make them to point the same direction in the world not depending on node or any other rotations etc)

tnx.
Toadcop
Gnoblar
Posts: 15
Joined: Sat Jul 18, 2009 9:37 pm

Re: Bone Look At

Post by Toadcop »

is there a way to DISABLE and not to destroy the animation track ? so i can reactivate it later ?
bump