so I searched around a lot and usually when this question came up the answer was just “Look at what the KinematicRagdollControl does”, but it is still very complicated and I just don’t get it!
All this quaternion stuff is very confusing. And then there is the bone hierarchy stuff that adds to the complexity…
My ultimate goal would be to set world position and rotation of multiple bones in a skeleton. Imagine setting a look-at-target for a head bone (which is a child in a chain of several other bones) or something like that. It should be a fairly general solution that works for any given bone of arbitrary skeletons.
If anyone could explain this to me, that would be great!
But the kinematic ragdoll does exactly that, transforming a world rotation from the physics object to a bone translation of the skeleton… If its too complicated for you maybe then its just too complicated for you…
Ok, then let me get started to try to explain some issues of understanding that I have with the ragdoll control.
I think the relevant function here is
Because that’s where it gets the world location and rotation of the rigid bodies for each bone link and applies it to the bones.
In there it then takes the world rotation of the rigid body and multiplies it with the
But this initial world rotation isn’t actually the world rotation as far as I can see. The only way it is ever set is like this in
link.initalWorldRotation = bone.getModelSpaceRotation().clone();
So that’s model space rotation. Why is that?
Idea: Shouldn’t it be possible to just substitute the rigid body transforms inside ragdoll update to arbitrary locations and rotations to achieve what I want? I could then get rid of the bullet physics stuff and just have something like target location and rotation for each bone link.
bone location is relative to the model location, the “world” term isn’t exactly correct there.
So let me summarize the algorithm for rotating a bone to a given world rotation, just so I get this right:
(This is how I interpret the code of
- Get desired world rotation quaternion
q (the rotation the bone should finally have)
- Multiply this rotation
q with the initial rotation of the bone (in model space, set on init by
- Get the inverse of the world rotation of the
spatial (the one that has the
SkeletonControl) and multiply it with
q, afterwards normalize
- If the bone is the root then multiply the original target world rotation with the bind rotation of the bone and calculate the inverse of it, then set the local roation of the
spatial to the resulting rotation
- If the bone is not the root (has a parent) then set its user transform in model space to the result of (3.)
Does that sound correct?
I’m a bit unsure specially about the last two points, so please feel free to correct me if I’m wrong.