Draw boundingBox and dancing cylinders... [RESOLVED]

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
AlmostNoob
Posts: 13
Joined: Sun Jan 11, 2009 6:34 pm

Draw boundingBox and dancing cylinders... [RESOLVED]

Post by AlmostNoob »

Hi Norbo, i need your help again. For now i've only experimented with simple boxes 1x1x1, my code arrange them as pyramid after i specify the pyramid level (lines), then i can break it down (funny!): the simulation is pretty fine ('though seems to me margins aren't exactly 1, it's about defaultMargin parameter??). Now i want to arrange a cylinder pyramid, here is the problem: when the cylinders come down they rebound&rebound&rebound ad libitum on the floor, it seems like dancing!! What's the matter??
Another question: how can i draw a boundingBox so i can see it? I've seen your Demo but i'm still confused... :shock:
Last edited by AlmostNoob on Tue Feb 10, 2009 5:13 pm, edited 1 time in total.
diadem
Posts: 10
Joined: Sat Jan 17, 2009 4:19 am

Re: Draw boundingBox and dancing cylinders...

Post by diadem »

What type of object are you using to draw your floor? If it's a StaticTriangleGroup, you can modify the coefficientOfRestitution property to change the "bounciness."
AlmostNoob
Posts: 13
Joined: Sun Jan 11, 2009 6:34 pm

Re: Draw boundingBox and dancing cylinders...

Post by AlmostNoob »

No, the floor is a flat box i built in Lightwave (like everything), it is a box entity.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Draw boundingBox and dancing cylinders...

Post by Norbo »

Assuming everything has a bounciness value of 0, the leading suspect would be the size of the ground and/or cylinders. The box-box collision detection is handled by a special case which performs much, much more accurately with large objects. Cylinder-box falls back to the default MPR/GJK methods which are more sensitive to odd shapes (such as giant flat boxes). If it is large, try shrinking it down to the scales in the demos.

For reference, I duplicated your results with a 1000x1000 box as the ground. 200x200 pretty much got rid of all the artifacts. I would recommend below 100x100 for total robustness, though.

The bounding boxes are drawn in one of the demo's draw method regions. Basically, it compiles a list of the endpoints for lines and passes it into a DrawUserPrimitives call.
AlmostNoob
Posts: 13
Joined: Sun Jan 11, 2009 6:34 pm

Re: Draw boundingBox and dancing cylinders...

Post by AlmostNoob »

I've scaled the box and now it works, but still there are some issues...

If a cylinder falls standing, its behavior is pretty much like when you drop a coin, it rotates&rotates... until it stops.
If a cylinder falls on its side, it rolls on the floor continuosly, it never stops.

I've tried modifying both cylinder and floor parameters: mass, bounciness, dynamicFriction, density... Which is the right parameter? (if it's about parameter, of course... :) )
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Draw boundingBox and dancing cylinders...

Post by Norbo »

The quickest way to fix the odd rotation is to use conservative angular motion and RK4 angular integration. You can enable them using:

space.simulationSettings.conserveAngularMomentum = true;
space.simulationSettings.useRK4AngularIntegration = true;

There's a marginal performance hit, but it is quite a bit more accurate.

A cylinder laying down and rolling forever won't be stopped by more friction (since it's rolling, every point in contact with the ground is stationary due to friction already). To slow it down over time, you could add some damping using Entity.linearDamping or Entity.angularDamping.
AlmostNoob
Posts: 13
Joined: Sun Jan 11, 2009 6:34 pm

Re: Draw boundingBox and dancing cylinders...

Post by AlmostNoob »

Thank you for your precious help, my code comes more robust day after day... :D

Although i've setted the right parameters, there's a little gap between cylinders (picture below), how can i fix that?
gap.jpg
gap.jpg (3.6 KiB) Viewed 6475 times
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Draw boundingBox and dancing cylinders...

Post by Norbo »

That's caused by the collision margin. You can scale up the graphics or reduce the shape size or margin (but avoid going too small with the margin or accuracy/performance will suffer). You can find more information in this post: http://bepu-games.com/forums/viewtopic.php?f=4&t=409.
Post Reply