Hi,
I have implemented my own variation of the CreateTriMesh function which is found in the examples folder of JV-ODE. Now, it all seems to work until a dynamic body hits the static geometry created as a tri-mesh.
When a body is colliding with the tri-mesh geometry, and I call this function
I get an 'Unhandled Memory Exception' error.
This is my tri-mesh function:
This is the code I use to setup ODE
And, this is the code used to update ODE:
Any ideas.
I have implemented my own variation of the CreateTriMesh function which is found in the examples folder of JV-ODE. Now, it all seems to work until a dynamic body hits the static geometry created as a tri-mesh.
When a body is colliding with the tri-mesh geometry, and I call this function
dSpaceCollide(ODE_Space, ODE_World, ODE_ContactGroup)
I get an 'Unhandled Memory Exception' error.
This is my tri-mesh function:
' this function builds a static tri mesh from an entity ' PARAMS: ' entity - the entity to build the tri mesh from ' ode_space - the ODE space to add this tri mesh to Function BuildTriMesh:Int(entity:Int, ode_space:Int) ' locals Local vert_list:TList = New TList ' this is a temp list to store vertices Local tri_list:TList = New TList ' this is a temp list to store triangle vertex indices Local vert_bank:TBank ' the actual vertex bank Local tri_bank:TBank ' the actual index bank Local vertex_index:Int ' this is used to hold vertex indices Local surface:Int ' this holds a pointer to a surface Local Offset:Int = 0 ' the vertex offset Local TriOffset:Int = 0 ' the triangle offset ' cycle through all of the surfaces For Local surf:Int = 1 To bbCountSurfaces(entity) ' get the surface pointer surface = bbGetSurface(entity, surf) ' cycle through each triangle in this surface For Local tri:Int = 1 To bbCountTriangles(surface) - 1 ' add all three vertices and indices to the list For Local vert:Int = 0 To 2 vertex_index = bbTriangleVertex(surface, tri, vert) vert_list.AddLast(String(bbVertexX(surface, vertex_index))) vert_list.AddLast(String(bbVertexY(surface, vertex_index))) vert_list.AddLast(String(bbVertexZ(surface, vertex_index))) vert_list.AddLast("0.0") ' add the vertex index to the list tri_list.AddLast(String(vert_list.count() - 1)) Next Next Next ' now create the banks vert_bank = CreateBank(vert_list.count() * 4 * 4) tri_bank = CreateBank(tri_list.count() * 3 * 4) ' the vertex bank For Local v:String = EachIn vert_list PokeFloat(vert_bank, Offset, v.ToFloat()) Offset:+4 Next ' the triangle bank For Local t:String = EachIn tri_list PokeInt(tri_bank, TriOffset, t.ToInt()) TriOffset:+4 Next ' now create the tri mesh in ODE Local TriMeshData:Int = dGeomTriMeshDataCreate() dGeomTriMeshDataBuildSimple(TriMeshData, BankBuf(vert_bank), vert_list.count(), BankBuf(tri_bank), tri_list.count()) ' return the tri mesh Return dCreateTriMesh(ode_space, TriMeshData) End Function
This is the code I use to setup ODE
ODE_World = dWorldCreate( ) ' create the world ODE_Space = dHashSpaceCreate( 0 ) ' create the hash space ODE_ContactGroup = dJointGroupCreate( 0 ) ' create the default joint group dWorldSetAutoDisableFlag( ODE_World, True ) ' enable auto bpdy disable dWorldSetGravity(ODE_World, 0.0, - 10.0, 0.0) ' set the default gravity dContactSetMode( dContactBounce ) ' set the contact mode to bouncy dContactSetBounce( 0.2 ) ' set the bouncy-ness of the world dContactSetMu( 48 ) ' set the global friction
And, this is the code used to update ODE:
dSpaceCollide(ODE_Space, ODE_World, ODE_ContactGroup) dWorldQuickStep(ODE_World, 0.1) dJointGroupEmpty(ODE_ContactGroup)
Any ideas.