Page 1 of 1

CompoundBody drawing

Posted: Sun Jun 19, 2011 9:50 pm
by slayeriq
Hello,

I am trying to draw a compound body, I have a couple of models of which I calculate a BoxShape and I add it together to form a compound body. The problem is now drawing every single model I am using CompoundShapeEntry.LocalTransform.Matrix as WorldMatrix when drawing, but its always the same. The compoundBody is being created properly because I can see other models interacting with it where it is supposed to be drawn. Am i doing something wrong ? How can i calculate the worldmatrix of a single ShapeEntry so I can draw it properly ?

Thanks in advance,

Re: CompoundBody drawing

Posted: Sun Jun 19, 2011 9:56 pm
by Norbo
The LocalTransform of an entry is local to the compound body. If the entry is transformed by the local transform (into local space), and then transformed using the transform of the parent (and so on if it's nested), it will be in the proper world space location.

An example of this can be found in the DisplayCompoundBody in the BEPUphysicsDemos project, where it constructs a local version of the shape by transforming everything by their local transforms. That whole chunk is then transformed using the world transform when drawing.

Re: CompoundBody drawing

Posted: Mon Jun 20, 2011 10:27 am
by slayeriq
So it will be compoundBody.worldTransform*compoundShapeEntry.localTransform.matrix, compoundBody being the parent of compoundShapeEntry.

EDIT:

I am using ShapeEntry.LocalTransform.Matrix* CompoundBody.WorldTransform as worldmatrix now the objects draw but not at the actual position. Do i have to add something else ?

Re: CompoundBody drawing

Posted: Mon Jun 20, 2011 9:59 pm
by Norbo
Are they offset by some arbitrary translation? If so, that means the origin of your graphic is different than the origin of the shape. In local space, the center of mass of a convex shape is at the origin. If a graphic is positioned using the shape's world transform, but the graphic has an origin at the bottom of the shape (or some other offset location), it will appear to be offset.

To address that, you can apply an extra local transformation based on how much your graphic is offset. Or, you can change the graphic such that it is aligned consistently.