Thanks to gman all moves.
I have sniped the code from the tutorial of the Irrlicht web site and translated to fit gg.ibmax and newton.mod and created a function so to be able to use Maps with newton.
Here is the function:
beware that if you move the map in irrlicht you lose all the compartibility.
I have sniped the code from the tutorial of the Irrlicht web site and translated to fit gg.ibmax and newton.mod and created a function so to be able to use Maps with newton.
Here is the function:
Function T_irrAnimateMeshToNewtonCollisionTree(nWorld:Byte Ptr , g_map:T_irrIAnimatedMesh , g_newtonMap:Byte Ptr) NewtonTreeCollisionBeginBuild(g_newtonmap) Local cMeshBuffer:Int, j:Int Local v1i:Int, v2i:Int, v3i:Int Local mb:T_irrIMeshBuffer Local vArray:Float[9] '// vertex array (3*3 floats) Local tmpCount:Int = 0 For cMeshBuffer=0 To g_map.getMesh(0).getMeshBufferCount() - 1 mb = g_map.getMesh(0).getMeshBuffer(cMeshBuffer) 'video::S3DVertex2TCoords* mb_vertices = (irr::video::S3DVertex2TCoords*)mb->getVertices(); Local mb_vertices:T_irrArray_S3DVertex = mb.getVertices() 'u16* mb_indices = mb->getIndices(); Local mb_indices:T_irrArray_u16 = mb.getIndices() '// add each triangle from the mesh 'For j=0 To j<mb->getIndexCount(); j+=3) For j=0 To mb.getIndexCount() - 1 Step 3 v1i = mb_indices.elementAt(j) v2i = mb_indices.elementAt(j+1) v3i = mb_indices.elementAt(j+2) vArray[0] = mb_vertices.elementAt(v1i).getPos().getX() vArray[1] = mb_vertices.elementAt(v1i).getPos().getY() vArray[2] = mb_vertices.elementAt(v1i).getPos().getZ() vArray[3] = mb_vertices.elementAt(v2i).getPos().getX() vArray[4] = mb_vertices.elementAt(v2i).getPos().getY() vArray[5] = mb_vertices.elementAt(v2i).getPos().getZ() vArray[6] = mb_vertices.elementAt(v3i).getPos().getX() vArray[7] = mb_vertices.elementAt(v3i).getPos().getY() vArray[8] = mb_vertices.elementAt(v3i).getPos().getZ() 'NewtonTreeCollisionAddFace(g_newtonmap, 3, (Float*)vArray, 12, 1); NewtonTreeCollisionAddFace(g_newtonmap, 3,Varptr vArray[0], 12, 1) Next Next NewtonTreeCollisionEndBuild(g_newtonmap, 0); Local g_newtonmapbody:Byte Ptr = NewtonCreateBody(nWorld, g_newtonmap); Rem After loading the bsp mesh in irrlicht we must create a newton collision tree consisting of all the triangles in the bsp mesh. To do this we loop through the indices list And add vertices 3 at a time into newton. I should mention here that I was lazy when writing this And just used a straight cast To video::S3DVertex2TCoords - this is because bsp meshes have lightmap textures on them. If you are using a mesh with only 1 set of texture co-ordinates (like a landscape Or .x level) Then use (video::S3DVertex). Newton requires 2 pointers For every Object - a NewtonBody* For the rigid body, And a NewtonCollision* that describes the objects geometry. After creating the tree collision geometry, we create a body For the map And assign it To the collision. Bodys which have a tree collision For their geometry are static And their mass will be ignored by newton - so you can only use meshes For your scenery! End Rem '// set the newton world size based on the bsp size Local boxP0:Float[3] Local boxP1:Float[3] Local matrix:Float[16] NewtonBodyGetMatrix (g_newtonmapbody,Varptr matrix[0]) NewtonCollisionCalculateAABB (g_newtonmap,Varptr matrix[0], Varptr boxP0[0], Varptr boxP1[0]) '// you can pad the box here If you wish '//boxP0.y -= somevalue; '//boxP1.y += somevaluef; 'NewtonSetWorldSize (nWorld, (Float*)boxP0, (Float*)boxP1); NewtonSetWorldSize (nWorld, Varptr boxP0[0], Varptr boxP1[0]) Rem After loading the map, we can calculate the bounding box surrounding it And set the newton world size To match. Newton should automatically disable anything which falls out of the map this way. End Rem End Function
beware that if you move the map in irrlicht you lose all the compartibility.