Use BEPU Physics with any object

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spykam22
Posts: 13
Joined: Fri Dec 09, 2011 9:48 pm

Use BEPU Physics with any object

Post by Spykam22 »

Hello! I have a class that generates an infinite plane, and I would like to use it as terrain. Is there a way to use it with BEPUPhysics.Space? Thanks!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Use BEPU Physics with any object

Post by Norbo »

There is no infinite plane included in BEPUphysics (though it wouldn't be too hard to create one), but you can get something fairly similar with a single immense triangle. The triangle face collision is very robust at extreme sizes. Just be careful to make it big enough so that none of the triangle's edges can be hit during normal simulation. This is for two reasons- first, you don't want stuff falling off the map, and second, the triangle edge collision detection is not as robust as the simplistic face collision detection.

I would also be careful to ensure that the plane is axis aligned to avoid giving the plane an essentially infinite bounding box and requiring tests against every object in the Space.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Use BEPU Physics with any object

Post by Norbo »

You could also take advantage of the Terrain class's built in support for solid depths. This could come in handy if objects ever get through the surface. You could create the 1x1 terrain such that only one of the triangles would encompass the entire simulation area.
Spykam22
Posts: 13
Joined: Fri Dec 09, 2011 9:48 pm

Re: Use BEPU Physics with any object

Post by Spykam22 »

I'm kind of new. Is there an example showing how to do that?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Use BEPU Physics with any object

Post by Norbo »

Here's how to create a giant triangle:

Code: Select all

            Vector3 a = new Vector3(-100000, 0, -100000);
            Vector3 b = new Vector3(-100000, 0, 100000);
            Vector3 c = new Vector3(100000, 0, 100000);
            Triangle triangle = new Triangle(a, b, c);
            triangle.Position -= (a + b + c) / 3;
            Space.Add(triangle);
Here's how to make a massive 1x1 terrain with thickness:

Code: Select all

            Terrain terrain = new Terrain(new TerrainShape(new[,] { { 0f, 0f }, { 0f, 0f } }), new AffineTransform(new Vector3(100000, 1, 100000), Quaternion.Identity, new Vector3(-33333, 0, -33333)));
            terrain.Thickness = 10;
            Space.Add(terrain);
The BEPUphysicsDemos in the main source download show a ton of other examples too. The TerrainDemo shows how to create a Terrain. For general entity creation, the EntityConstructionDemo is a good thing to look at.
Spykam22
Posts: 13
Joined: Fri Dec 09, 2011 9:48 pm

Re: Use BEPU Physics with any object

Post by Spykam22 »

Thanks!
Post Reply