Collision problem between CompoundBody and other types

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JabberWorx
Posts: 10
Joined: Sat Mar 26, 2011 9:33 am

Collision problem between CompoundBody and other types

Post by JabberWorx »

If I create a compound body consisting of three boxes like so: http://i.imgur.com/S80zU.png

And create a 1x1 box and drop it in the box penetrates it (the box of 1x1 was created right in the center 3 units above, it fell down and ended up going through the middle box some way, you can see where it penetrates it): http://i.imgur.com/Kbbuy.png

Odd thing is if I create two compound bodies of the same 3 body shape they collide perfectly: http://i.imgur.com/xFb7Y.png

AND if I create a triangle mesh from the 3 box model (instead of creating the body for that box using a compound object it collides perfectly with the single box: http://i.imgur.com/6i2TM.png

If I create a triangle mesh from the 3 box model and create a dynamic compound body from the three boxes and try to make them collide I get this result (where the three box model on top if dynamic compound, bottom is static mesh): http://i.imgur.com/matwE.png

My theory as of now is that I'm getting the positions of the compound actor wrong, basically I'm saying create three boxes at positions: (-1,1,0),(0,0,0),(1,1,0) and I'm just assuming that settingt he position is done around the origin (i.e. (0,0,0)) but it's likely the position is being set by the average position of all three boxes? Or am I completely off target? If this is the case then how should I set the center position of the model the 3 box compound object is based on?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision problem between CompoundBody and other types

Post by Norbo »

When creating a CompoundShape (the local space geometry object of the CompoundBody's Collidable), the elements are recentered such that the offsets are from the local origin, instead of the world origin. The local origin is determined by the weighted average of the shape positions, so I wouldn't recommend trying to duplicate the calculation. The center position computed by the shape is returned and used as the entity's position.

To match the graphics, you can check the entity's position. Offset the graphics by the negative position and they should overlap correctly.

Also, you may want to use the latest development version (http://bepuphysics.codeplex.com/SourceC ... evelopment) when working with compound shapes. There have been some bugfixes and cleanings. v0.15.2 (the version that will contain the stuff in the development fork) will be released as a 'stable' version pretty soon.
JabberWorx
Posts: 10
Joined: Sat Mar 26, 2011 9:33 am

Re: Collision problem between CompoundBody and other types

Post by JabberWorx »

Is it the weighted average of the shapes positions or the weighted average of the shapes in the extreme ends of the body? For example if I create a line of boxes with one box at position (0,0) followed by boxes at positions (1000,0),(1001,0),(1002,0),(1003,0) the weighted average would be (801.2, 0) but the actual center of the line would be (501.5, 0). I'm assuming the local position of the shapes is used so that position/rtotation data is around the local origin and won't look like it's on a pivot, so wouldn't the center need to be be calculated based on the left, top, lowest, right most extreme points instead of the average of all the points?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision problem between CompoundBody and other types

Post by Norbo »

so wouldn't the center need to be be calculated based on the left, top, lowest, right most extreme points instead of the average of all the points?
I don't really follow; imagine a single box of weight 1 at (0,0,0) and another box of weight 100 at (100,0,0). By using the weighted average, the position comes out to be (~99, 0, 0). That is the desired center of mass, and the CompoundShape repositions its children relative to that origin so that, when rotating, it has the right apparent center of mass.

Using the center of the compound's bounding box for the position would be a simple and sometimes acceptable approximation, but it would not match the actual weight distribution.
JabberWorx
Posts: 10
Joined: Sat Mar 26, 2011 9:33 am

Re: Collision problem between CompoundBody and other types

Post by JabberWorx »

Norbo wrote:
so wouldn't the center need to be be calculated based on the left, top, lowest, right most extreme points instead of the average of all the points?
I don't really follow; imagine a single box of weight 1 at (0,0,0) and another box of weight 100 at (100,0,0). By using the weighted average, the position comes out to be (~99, 0, 0). That is the desired center of mass, and the CompoundShape repositions its children relative to that origin so that, when rotating, it has the right apparent center of mass.

Using the center of the compound's bounding box for the position would be a simple and sometimes acceptable approximation, but it would not match the actual weight distribution.
Oh right, yeah I'm starting to gain a clearer picture. My assumption before was when you were referring to the center you meant the center of the entire body, not center of mass :P Just assumed when you said 'weighted average' you meant in reference to the spacial center of the object...
Post Reply