Jump to content
  • Advertisement
Sign in to follow this  

Finding the midpoint of a bone for a ragdoll

This topic is 2872 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[color=#282828][font=helvetica, arial, sans-serif]Hi all,[/font]

[color=#282828][font=helvetica, arial, sans-serif]I'm currently trying to solve the problem of creating a bounding volume (OBB or capsule) in the middle of my bone for ragdoll creation. I suppose it's really just a general maths problem, that my paltry maths skills can't overcome. I have a position (the head of the bone), a rotation (quaternion decomposed from the head's transformation matrix) and a bone length (a scalar).[/font]

[color=#282828][font=helvetica, arial, sans-serif]So what is the maths for finding a position given a starting position, rotation and scalar length? Or in terms of this problem, how do I find the midpoint of a bone?[/font]

[color=#282828][font=helvetica, arial, sans-serif]I'm using C++ and XNAMath by the way.[/font]

[color=#282828][font=helvetica, arial, sans-serif]Searching on the internet, I can see that every sample I've seen just uses either the parent transformation of the current bone, or the first child transformation of the current bone, to calculate the midpoint. I could go that route too, but then there are going to be bones missing out from being in the ragdoll - either the root bone (because it has no parent) or every bone at an extremity (because they have no children). I'm thinking there must be a way to calculate the midpoint of a bone without using it's parent or child???[/font]

[color=#282828][font=helvetica, arial, sans-serif]Thanks in advance,[/font]

[color=#282828][font=helvetica, arial, sans-serif]JMab [/font]

Share this post

Link to post
Share on other sites
We use our scene editor to place volumes relative to the character's bones. we save this scene purely for reference when setting up the ragdoll.

I know that would be a big step for your project, but that is how we do it. The transformation math is practically all handled by the editor.

When we go to construct the ragdoll we query the bind pose object space transform of the bone a volume is bound to. we then compute the offsets like so.

BoneToVolumeXform = invBoneObjectSpace * volumeObjectSpace
VolumeToBoneXform = invVolumeObjectSpace * boneObjectSpace

we assume the mass and body are centered around the volume. if not, the goal would be to compute the BoneToBody xforms and also the body to Volume xform so you can position the volume relative to the body.

We position the ragdoll constraints at the bone origins so that when they rotate, they rotate through the artist defined skeleton axes. skipping over joints is a little bit harder but not by much. You'll just need to decide what assumptions you'll make about the other bone's transforms but ultimately they will just be in some orientation that you'll need to integrate into the physics results when determining rig results.

Share this post

Link to post
Share on other sites
OK, thanks bzroom, I understand how you're doing it. I could go down that route too - I've built a reasonably well-functioned scene editor. Although since I'm doing this project by myself (so far), and my artistic skills are low, I'm trying to opt for automation of as much content generation as possible, i.e. re-using the same animated skeleton for all my bipeds, lots of effects to distract from my poorly-designed models (blur, glow, bloom, DOF, etc), parallax occlusion mapping with tool-generated normal and height maps, etc.

In this case, I was hoping to let my artist (me at the moment) define the width and height of the bone volume, volume type (OBB or capsule) and the joint constraints only in the 3D editor (Blender in my case), then use the bone length to calculate the entire volume and then position the volume by automatically calculating the midpoint along the bone.

However, if defining and positioning the bone bounding volumes in the scene editor is best way to go, I'll do that...

Share this post

Link to post
Share on other sites
OK, I've got the basics of the automated bone volume generation working (I had some help from another forum). Here's the code, in case anyone is interested:

// Decompose the bone head world matrix.
XMVECTOR boneHeadScale, boneHeadRotation, boneHeadPosition;
if (!XMMatrixDecompose(&boneHeadScale, &boneHeadRotation, &boneHeadPosition, worldMatrix))
Log::Warn(L"Failed to decompose bone world matrix.");

// Create the mid-point in local space.
XMVECTOR midPoint = XMVectorSet(0.0f, m_Bones.HalfLength, 0.0f, 0.0f);

// Transform the mid-point to world space.
midPoint = XMVector3TransformNormal(midPoint, worldMatrix) + boneHeadPosition;

// Construct the bounding volume world matrix.
worldMatrix = XMMatrixTransformation(XMVectorZero(), XMQuaternionIdentity(), boneHeadScale,
XMVectorZero(), boneHeadRotation, midPoint);

The ragdoll now looks like this:


[color=#282828][font=helvetica, arial, sans-serif]I was thinking of letting the artist define the bone volume "width" and "height" in the 3d editor, however I'm now thinking I should be able to automate this too - I should be able to just to min/max calculations on all of the vertices in each bone's vertex group to calculate the volume. Anyone tried this before, or should I just let the artist define the rest? [/font]

Share this post

Link to post
Share on other sites
it looks like my last post didnt save. these forums seem buggy. but that was my suggestion. just compute an AABB in bones space of all the vertices influence by the bone, shrink it down or filet the corners.

ultimately though. we found it most beneficial to let the artist (which may be you) you orient and position different shape primitives themselves to get the right behavior from the game.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!