Hey everyone, i'm having trouble moving a bone using code in the game i am making...
I am using sgmotion to animate a charictor and that all works fine.
I can place hit boxes (ragdoll parts) and things at the positions of the bones by just going.
BoneDebug.World = Matrix.Invert(skinnedModel.SkeletonBones.InverseBindPoseTransform) * animationController.SkinnedBoneTransforms;
This makes BoneDebug.World contain a matrix that is the position of the bone and the rotation of the bone in the world.
The thing is however i want to now set the animationController.SkinnedBoneTransforms with something else that comes from the ragdoll
In other words i want to go in the other direction, so that i am moving the bone using code, to another position and rotation that come from the ragdoll parts.
How can i invert the code above so that i can do this?
Anyone have any ideas?
Trying to move a bone. But in code...
Re: Trying to move a bone. But in code...
You'll need to know how the ragdoll bone Entity is transformed relative to the animation bones it will be defining.
The information can be computed when setting up the ragdoll. Most likely, the model will be in bindpose when constructing the ragdoll. Once you position an entity, transform its WorldTransform by the InverseBindPoseTransform of the connected animation bone. That resulting transformation is the offset from the animation bone to the entity.
If you know an entity's world transform and want to know what the associated animation bone's world transform should be, multiply the entity transform by the inverse of that offset. If you want to then know the offset from the bind pose to the world transform for that animation bone, multiply by the inverse bind pose.
The information can be computed when setting up the ragdoll. Most likely, the model will be in bindpose when constructing the ragdoll. Once you position an entity, transform its WorldTransform by the InverseBindPoseTransform of the connected animation bone. That resulting transformation is the offset from the animation bone to the entity.
If you know an entity's world transform and want to know what the associated animation bone's world transform should be, multiply the entity transform by the inverse of that offset. If you want to then know the offset from the bind pose to the world transform for that animation bone, multiply by the inverse bind pose.