Drawing Bones of a Mesh

Started by
1 comment, last by gzboli 15 years, 10 months ago
Been trying to draw the bones of an animated mesh, and despite drawing the bones being probably the easiest part of the project, its the one that I can't seem to figure out. I've got the mesh animating properly through Matrix Lerp (Yeah, not the most accurate, but it looks fine), so I know my bone matrices are all correct. Right now I've been trying to do something like: Disable the Zbuffer; Create a line using D3DXCreateLine; Set up the line with two D3DXVECTOR3s, going from (0,0,0) to (1,1,1); Then call Line->DrawTransform() on the line using the current bone matrix; Re-enable the Zbuffer; I'm not really sure on how to set up the current length of the line, but even then I should see the lines being aligned with the mesh.... or so I thought. The lines are drawn in what appears to be random locations as I animate the mesh. Dunno what to do from here. And just for the record: my bone matrices are the result of multiplying the bone offsets and the current frames combined transform matrix. Any tips would be greatly appreciated.
Advertisement
If I'm not mistaken, ID3DXLine draws in screen space, so your line needs to be unprojected.

The length of the line ( a bone ) should be the difference between it's translated position* and it's child's position** (in world space, before unprojection).

*you can get that from the transform. If the bones are only subject to rotation and not translation (common), you only have to get the length once.

**if it has no child, you'll have to pick a default.

Rather than mess with screen lines, you could use a vertex buffer of lines and render them in world space with the same transform as the bones they represent.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:my bone matrices are the result of multiplying the bone offsets and the current frames combined transform matrix.


The offset matrices bring a vertex in object space into bone space. The point you want is the origin of the bone space, as this represents a joint. Transforming (0,0,0,1) through (current frames combined transform matrix) will get you the object space location of the joint.

As for the end point of the line... As Buckeye said, it is the origin of each child the bone has. If the bone has no children you have to use a point along some "default axis." The default axis is the vector the bone would represent without any transformation... Most probably the x-axis.

This topic is closed to new replies.

Advertisement