CompoundBody drawing

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
slayeriq
Posts: 2
Joined: Sun Jun 19, 2011 8:48 pm

CompoundBody drawing

Post 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,
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CompoundBody drawing

Post 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.
slayeriq
Posts: 2
Joined: Sun Jun 19, 2011 8:48 pm

Re: CompoundBody drawing

Post 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 ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CompoundBody drawing

Post 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.
Post Reply