Page 1 of 1
Draw boundingBox and dancing cylinders... [RESOLVED]
Posted: Sat Jan 31, 2009 4:28 pm
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...

Re: Draw boundingBox and dancing cylinders...
Posted: Sat Jan 31, 2009 5:05 pm
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."
Re: Draw boundingBox and dancing cylinders...
Posted: Sat Jan 31, 2009 5:55 pm
by AlmostNoob
No, the floor is a flat box i built in Lightwave (like everything), it is a box entity.
Re: Draw boundingBox and dancing cylinders...
Posted: Sat Jan 31, 2009 9:12 pm
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.
Re: Draw boundingBox and dancing cylinders...
Posted: Sun Feb 01, 2009 5:05 pm
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...

)
Re: Draw boundingBox and dancing cylinders...
Posted: Sun Feb 01, 2009 7:00 pm
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.
Re: Draw boundingBox and dancing cylinders...
Posted: Mon Feb 02, 2009 4:41 pm
by AlmostNoob
Thank you for your precious help, my code comes more robust day after day...
Although i've setted the right parameters, there's a little gap between cylinders (picture below), how can i fix that?

- gap.jpg (3.6 KiB) Viewed 9821 times
Re: Draw boundingBox and dancing cylinders...
Posted: Mon Feb 02, 2009 6:00 pm
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.