Terrain creation parameters

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
chrisp3d
Posts: 4
Joined: Wed Mar 18, 2009 3:21 am

Terrain creation parameters

Post by chrisp3d »

Hey all,

I have bepuphysics up and running in a game I have going outside of terrain, I can't seem to get it to work. I have the spacing set right, and it's using the same heights as what's drawing the terrain is using, so my last guess is that its the terrain initialization parameters,

Code: Select all

Terrain terrain = new Terrain(.5f, 0, Vector3.Zero, .02f, .01f, .5f, 0, 50);
so that would be creating a new instance of the class terrain with the properties:
Time Interval - .5f
Max Age - 0
Position - 0,0,0
Terrain Margin -0.02f
Allowed Penetration - 0.01f
Coefficient Of Friction - 0.5f
Coefficient Of Restitution - 0
Maximum Rescue Depth - 50

okay, so I'm fine with all of those except these few:
Time Interval - I'm guessing this is how often it's updated?
Max Age - ??
Terrain Margin - What is this?

Can anybody tell me what those are and how they effect the terrain?
thanks ahead of time,
-Chris
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain creation parameters

Post by Norbo »

The interval can be thought of the unit of 'age' for each triangle in the Terrain. When a triangle is added or refreshed by an object coming close, its age is set to 0. Each tick (separated by the interval), the triangle's age is incremented by 1. If this age exceeds the maximum age, then the triangle is removed. This system exists to allow previously created triangles to stick around just in case an object might hit them again. The addition/removal of triangles isn't extremely expensive, but it's worth waiting a tiny amount of time to make sure that the object should actually be removed.

Every object has a collision margin which defines a bit of extra space around the body that helps with collision detection. A terrain's margin is used as each triangle's individual collision margin. Some more detailed information about margins can be found in this thread: http://www.bepu-games.com/forums/viewto ... ?f=4&t=409.

The values you gave are acceptable; what is the problem you are encountering? You might also try updating to the latest version (0.9.0) of BEPUphysics. The constructor is a bit simplified; it now takes only a position since the rest of the parameters are generally left unchanged. They are still modifiable in the terrain's properties and fields, though.
chrisp3d
Posts: 4
Joined: Wed Mar 18, 2009 3:21 am

Re: Terrain creation parameters

Post by chrisp3d »

Hey, thanks for the reply, that really helps me understand a lot about whats going on. My problem is that I have a box falling on to the terrain, but it always just falls right through. This may be because of the size of my terrain, I'm working in a very large world, the terrain spacing X and Y are 480 in my current build. The box is big enough, though, that it should be colliding with several triangles.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain creation parameters

Post by Norbo »

The first thing I'd try is just scaling down the world. The engine is tuned to deal with sizes on a similar order of magnitude to 1 unit. While this can be retuned a bit by changing collision margins, allowed penetrations, space.simulationSettings.contactInvalidationLengthSquared, etc. it is generally easier and more robust to keep things on a more normal scale. Some algorithms, primarily the general case collision detection systems, can be a bit sensitive to numerical error- especially with very large flat shapes.

That said, this may not be the only issue. At those scales there should be still at least some interference between the triangles and the box, if not a perfectly correct collision. Does it fall through without disrupting its velocity at all?
chrisp3d
Posts: 4
Joined: Wed Mar 18, 2009 3:21 am

Re: Terrain creation parameters

Post by chrisp3d »

Recently it has been rotating a lot while it falls through the terrain, but just keeps on falling straight down, no stopping or changing position, just rotation
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain creation parameters

Post by Norbo »

That's good, it means its at the very least detecting contact points (just not in good locations or enough of them most likely). Scaling down will most likely fix the issues.
chrisp3d
Posts: 4
Joined: Wed Mar 18, 2009 3:21 am

Re: Terrain creation parameters

Post by chrisp3d »

Scaling down just gave it a cleaner fall, when it hits the terrain it starts rotating randomly still, and it still falls through, I think this may be a problem with the Box entity, but I don't see anything wrong, you don't have to set any parameters after you initialize it and add it into the space, do you?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain creation parameters

Post by Norbo »

The basic constructor and adding it to the space should be sufficient for a box. What are the new sizes, and are you sure that the graphics match the physics? If the box has a larger model associated with it, it will appear that it both falls through and rotates wildly. Similarly, if the terrain is in the wrong spot relative to the graphics, it would be very hard to define what is 'falling through.'
Post Reply