Offsetting position from center

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
drjaydenm
Posts: 11
Joined: Sun Apr 17, 2011 9:13 am

Offsetting position from center

Post by drjaydenm »

Hi Norbo,

BEPU Physics has been working nicely with my engine so far, good work on making it so stable and flexible :). I have only come across one problem so far. The position for the box entity is in the center of the box. I am trying to make a model of a box align with the physics entity and it has been working nicely. The only problem is that in the 3D editor, the box must be centered along the XYZ axis so that it matches the way the physics box entities position works. Now that I have come to making more complex models such as a human, centering the object on the Y axis in the 3D editor is a pain as the position must be just right to align with the physics entity(the pelvis must be at position 0,0,0 instead of the bottom of the feet). I know the solution is just some simple maths, but is there a way to work out the position of the centre-bottom of a box (assuming I know the side lengths) so that it aligns with the models 0,0,0 point.

This might be confusing to understand what I am trying to accomplish so just ask me if you dont understand. I can also upload screenshots to help if need be.

Thanks for any help :)

EDIT: BTW, I have tried dividing the Y axis by 2 and subtracting it from the position, this works but as is obvious, when the model rotates, the models position on the Y axis goes wacky. Im thinking it has to be multiplied by the orientation but dont know how.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Offsetting position from center

Post by Norbo »

Here's a thread which goes into some detail about this issue in general: viewtopic.php?f=4&t=1511

The basic idea is, as you've found, the graphic needs to be offset. The offset is computed such that the body's data is centered on (0,0,0). So, a ConvexHull constructed from a model will recenter itself on the origin and output an offset that can be applied to the graphical representation to make it match.

Boxes are always constructed centered on the origin, so to match a model to it, it's just a matter of offsetting the graphic so it is within the box. So, you were almost there:
EDIT: BTW, I have tried dividing the Y axis by 2 and subtracting it from the position, this works but as is obvious, when the model rotates, the models position on the Y axis goes wacky. Im thinking it has to be multiplied by the orientation but dont know how.
The key is that the offset should be applied in local space. That means apply the offset first, and the entity's world transform second. That way, the offset is transformed appropriately.
Post Reply