This project is read-only.

Translating a vector into the local position of a bone?

Jun 9, 2009 at 9:07 PM
Edited Jun 9, 2009 at 9:10 PM

I'm trying to set up a relatively simple physics system at the moment, and this is driving me crazy.  If I have a joint, I want to be able to rotate the object around the joint using an external force, for example gravity.  If I want to manually apply a rotation, I can do it fairly easily by changing the animationcontroller.localboneposes.orientation[i], however this is in local bone axis.  If I want the joint to rotate, say due to gravity, that force will be in world units, and I need transform that into the local bone x, y, and z coordinates before I can apply the force on the joint, and I'm having problems doing that.  If that's not totally clear, here's a quick mock up of what I'm trying to do.  Any help is appreciated, thanks.

Jun 10, 2009 at 6:34 AM
Edited Jun 10, 2009 at 7:18 AM

Alright, I think I've figured it out, to get the rotation matrix from local coordinates to world coordinates you have to multiply the inverse of the inversebindpose by the skinnedbonetransforms, and if you normalize the vectors in the resulting matrix that gives you the proper rotation matrix.  The only strange thing is that it appears to be a left handed coordinate system when all the rotations are done in a right handed system, so instead of taking the Right, Up, and Forward vectors as the local X, Y, and Z vectors, you have to take Right, Up, and Backwards in order to do the proper calculations.  (actually, never mind this, I must have been doing something wrong because now it's a right handed system, strange.)


Oh yeah, I forgot to mention that you have to set the transformation vector equal to zero for this or it will add the distance from the origin to the world position of your bone, which is what I initially didn't realize and was why my rotations were initially way off.  It also will scale the vector by some value, but you can easily get around that, I just store the length of the vector I'm transforming and then multiple the normalized transformed vector by the original length.