Jump to content
  • Advertisement
Sign in to follow this  
CadeF

[Solved]Using ODE in a large world map enviroment

This topic is 4520 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I've got a physics demo, using ODE, up and running. It is rigid body physics of meshes (like chairs, tables, etc) on a flat plane. I plan on using ODE in my game engine. How would I represent the world to ODE? Should I just dump the poly soup in, with the normals facing inwards, into a trimesh? And how would I partition the map? Should I have a different trimesh for each node of my octree? I would appreciate any help, tips and past experiences anyone might have had. Thanks :) [Edited by - CadeF on March 7, 2006 4:09:27 PM]

Share this post


Link to post
Share on other sites
Advertisement
I tried putting my polygon soup into a tri mesh. One single body falling/sliding and hitting the tri mesh works fine. But if another body hits that body, it goes down into the tri mesh and out of the map. If I define each face of a map as a plane, it works correctly. The test map I am using is a large cube. If I use a convex map, finding collision planes every frame will not be so efficient. I tried creating a trimesh for every polygon of the map, leaving it to ODE's AABB tree, but this crashed ODE at Space.Collide.

Does anyone have any implementation ideas?

Share this post


Link to post
Share on other sites
I'd suggest you break the world up into groups of polygons, and treat each as a separate object. However, two objects hitting the same thing at the same time should work fine, so if I was you I'd worry about fixing that first, and then worry about breaking it up if it's not fast enough.

Share this post


Link to post
Share on other sites
The test map is a simple cube, 6 faces. If each face is defined as a plane, it works fine. If each face is defined as a trimesh, ODE crashes. If the entire map is defined as a trimesh, ODE doesn't work correctly.

Any idea how I would use the planes?

Edit:
If I use this code
For I = 0 To FaceCount - 1
If Face(I).bSolid Then PhysSpace.Add(Face(I).PhysTri)
PhysSpace.Collide()
Next
It will crash on PhysSpace.Collide due to some internal error in ODE, on the second face.

For I = 0 To FaceCount - 1
If I > 0 Then
Dim I2 As Integer = 0
For I2 = I - 1 To 0
PhysSpace.Remove(Face(I2).PhysTri)
Next
End If
If Face(I).bSolid Then PhysSpace.Add(Face(I).PhysTri)
PhysSpace.Collide()
Next
This code removes all previous faces, so at one time, only one face is there. This does not crash on PhysSpace.Collide

I get the same problem in my test app, which works perfectly until 2 or more polygonal tri meshes are added.
Dim p(2) As Vector3
p(0) = New Vector3(0, 0, 0)
p(1) = New Vector3(100, 0, 0)
p(2) = New Vector3(0, 0, 100)
Space.Add(New Geoms.TriMesh(p))

p(0) = New Vector3(0, 0, 0)
p(1) = New Vector3(100, 5, 0)
p(2) = New Vector3(0, 3, 100)
Space.Add(New Geoms.TriMesh(p))
If I just add the one above, the rigid body simulation of crates and some meshes works perfectly. If I add both, it crashes. My meshes are too high poly to use TriMesh, so for now, I'm using AABB collisions for them.

Any ideas why it crashes when I've added more than 1 TriMesh?

[Edited by - CadeF on March 5, 2006 5:22:33 PM]

Share this post


Link to post
Share on other sites
If I put the poly soup of my map into a float3 array and pass it off to ODE as a tri mesh, the test block in my cube map

-TimeStep 0.05
Lands correctly, if I push it, it goes sliding into the wall(correct), right through the wall and out of the map, falling down into nothingness outside the map

-QuickStep 0.05, 5 iterations
Lands correctly, if I push it, it goes into the floor

-Quickstep 0.05, 100 iterations
Same as above

Any ideas?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You should try TimeStep, and call dGeomTriMeshClearTCCache to reset the collision cache, but I'm not sure how you would call that from ODE.NET

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How many contacts are you generating? It could be that it isn't generating all the contacts you want it to.

Share this post


Link to post
Share on other sites
Got it working now. I first test all meshes. Then, I push eash rigid body mesh down the BSP tree, testing it with all planes it encounters, one at a time. Then, I integrate and clear contacts. This seems to work nicely, and using the BSP for world collisions seems like its much faster.

Share this post


Link to post
Share on other sites
Hi CadeF,

Can you please give more details couse I am stuck in the sme problem with ODE.
I kind of take it as ... first I partition the objects in the BSP,
and finaly they land in a leaf or more leafs (convex regions).
Here I add the leaf sides (side planes) in the collision scene.
along with all other bodies potentially hit (same leaf).
There are no more than 100 polygons and 3-6 bodies
meshes added but is getting real slow inside ODE.

Thank you.

Share this post


Link to post
Share on other sites
Firstly, are you using a node-based BSP tree or a leafy BSP tree? If you are using a leafy BSP tree, I guess you would modify the following code a bit.

Camera.PhysicsRep is a capped cylinder representing the camera

Camera.PhysicsRep.Position = Camera.CamPos
Camera.PhysicsRep.RigidBody.Velocity = Vector3.Empty

PhysSpace.Collide()

Dim I As Integer = 0

For I = 0 To World.EntityCount - 1
If World.Entity(I).InVisibleOctreeNode Then
If Not IsNothing(World.Entity(I).RigidBody.Body) Then
World.Entity(I).Collide()
End If
End If
Next

PhysWorld.TimeStep(dt)
PhysContactJoints.Clear()




And then, for Entity.Collide

Public Sub Collide()
If IsNothing(RigidBody.Body) Then Return

Dim cFaceCount As Integer = 0
Dim cFace() As Integer = Nothing

Dim tV() As Vector3 = Nothing
tV = Vector3.TransformCoordinate(RigidBody.CubeV, RigidBody.GetMatrix)
World.BSP.Node(0).TestCube(RigidBody.Body.Position, tV, cFace, cFaceCount)

If cFaceCount = 0 Then Return

Dim I As Integer = 0
For I = 0 To cFaceCount - 1
With World.Face(cFace(I))
.PhysPlane.Enabled = True
End With
Next

PhysSpace.Collide()

For I = 0 To cFaceCount - 1
With World.Face(cFace(I))
.PhysPlane.Enabled = False
End With
Next
End Sub



Quite simple, really. Post any questions you might have. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!