How to find the ground

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

How to find the ground

Post by jbosch »

Hi,

I created a plane in 3DSMAX, in 0,0,0 position. Then I export it to FBX and use that model to create the physical environment in my game (the ground). I translate its world matrix to 0,0,0.

Then I load some cylinder entities and try to put them resting on the floor. Those cylinders have this initialization:

Code: Select all

bowl[0] = new Cylinder(new Vector3(-5.0f, 4.0f, -50.0f), 10.0f, 2.0f, 5.0f); 
But when I run the project, they "fall" on the floor, instead of rest over it. I can see that I have to put the cylinders aproximately in a Y position between 4.0f and 5.0f, if I want to make them rest on the floor, but I think it's very difficult to find the exact point for this. What am I doing wrong?

Thanks,

JB
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to find the ground

Post by Norbo »

If you can get the bowling pins to stand up and you're just looking to find the place where they won't fall any, then the best option is to enable the debug drawer and take a look at where everything is. You can also do some calculations based on the dimensions of your loaded model and cylinder to get the precise location. For example, if you know your top triangles are at Y = 0, and your cylinder has a height of 10, then your cylinder center position will need to be around 5.04 to 5.08. This comes from (height / 2) + collision margin * 2 - some small epsilon.

The collision margin is explained here: http://www.bepu-games.com/forums/viewto ... ?f=4&t=409

If you can't find a spot where they will stand up, chances are you are encountering some floating point precision issues. Cylinder-Triangle is handled by the general case collision detection system which is sensitive to such imprecision.

If your bowling surface is made up of two long, stretched out triangles, the interaction with the tall cylinders will likely be enough to introduce small errors which become visible as wobble or instability. Increasing the gravity to compensate for the scale-induced moon gravity will likely make the problem more visible.

When it comes to making robust collision meshes, it's a good idea to have fairly regular shaped triangles even if it means having a few extra triangles in the collision mesh. If the scales were smaller to begin with, this might not be necessary.

Robustness and speed of the general case collision system is something I'd like to work on in upcoming versions (collision revamps make up a good portion of what's on the version roadmap: http://www.bepu-games.com/forums/viewto ... ?f=5&t=849). But there are some fundamental limits imposed by single precision floating point numbers and the algorithms involved, so these requirements, even if looser in later versions, will probably have to stick around.
jbosch
Posts: 43
Joined: Sat May 29, 2010 4:42 pm
Contact:

Re: How to find the ground

Post by jbosch »

I was getting crazy with more than 10 decimals, and still not finding the ground.

The problem was that the ground was a simple "plane object" (in 3d max) with only 2 big triangles. I added more slices to the ground, and I could find the ground with 3 decimals, acceptable :-)

Thanks!
Jesús Bosch
XNA BLOG: http://geeks.ms/blogs/jbosch
Post Reply