attached u will find a code snippet of my terrain that is combined with a rigid Newton body. It is similair to any code for this purpose except the fact, that I don´t use a bsp-mesh but an obj (or.x) mesh;
unfortunatelly there is no collision between a common Newton cube and the terrain; the cube always falls through the surface; if I change to the bsp-mesh everything works fine, but usually I use x files for creating landscapes and besides of that, I don´t have a tool creating bsp files;
I guess it has something to do with the mesh buffer, because the printf code always shows me "buff 0" in the console;
does anybody has an idea what is going wrong with my code ?
I tried everything I could found in the forum, no success,
Thank´s for any help
Robert
the code:
Code: Select all
//Level
scene::IAnimatedMesh* q2levelmesh = smgr->getMesh("./data/terrain_5.obj");
scene::ISceneNode* q2node = 0;
if (q2levelmesh)
q2node = smgr->addMeshSceneNode(q2levelmesh->getMesh(0));
q2node->setPosition(core::vector3df(-1370,-130,-1400));
//q3node->setPosition(core::vector3df(0,0,0));
q2node->setMaterialTexture(0, driver->getTexture("./data/detailmap2.bmp"));
q2node->setMaterialTexture(1, driver->getTexture("./data/detail_map1.bmp"));
q2node->setMaterialType(video::EMT_DETAIL_MAP );
q2node->setScale(vector3df(500,500,500));
q2node->setRotation(vector3df(-20,0,0));
q2node->setMaterialFlag(video::EMF_LIGHTING,false);
//LevelNewtonCollision
NewtonCollision* nmapcollision = NewtonCreateTreeCollision(nWorld, NULL);
NewtonTreeCollisionBeginBuild(nmapcollision);
int cMeshBuffer=0;
int j=0;
int v1i, v2i, v3i;
IMeshBuffer *mb;
float vArray[9]; // vertex array (3*3 floats)
int tmpCount = 0;
core::aabbox3d<f32> box;
//size the box in Newton units
box = q2levelmesh->getMesh(0)->getBoundingBox();
vector3df size = box.getExtent()*IrrToNewton;
for (cMeshBuffer=0; cMeshBuffer<q2levelmesh->getMesh(0)->getMeshBufferCount(); cMeshBuffer++)
//for (cMeshBuffer=0; cMeshBuffer<10000; cMeshBuffer++)
{
mb = q2levelmesh->getMesh(0)->getMeshBuffer(cMeshBuffer);
S3DVertex* mb_vertices = (S3DVertex*)mb->getVertices();
u16* mb_indices = mb->getIndices();
// add each triangle from the mesh
for (j=0; j<mb->getIndexCount(); j+=3)
{
printf("buff %d count %d\n",cMeshBuffer,j);
v1i = mb_indices[j];
v2i = mb_indices[j+1];
v3i = mb_indices[j+2];
vArray[0] = mb_vertices[v1i].Pos.X* IrrToNewton;
vArray[1] = mb_vertices[v1i].Pos.Y* IrrToNewton;
vArray[2] = mb_vertices[v1i].Pos.Z* IrrToNewton;
vArray[3] = mb_vertices[v2i].Pos.X* IrrToNewton;
vArray[4] = mb_vertices[v2i].Pos.Y* IrrToNewton;
vArray[5] = mb_vertices[v2i].Pos.Z* IrrToNewton;
vArray[6] = mb_vertices[v3i].Pos.X* IrrToNewton;
vArray[7] = mb_vertices[v3i].Pos.Y* IrrToNewton;
vArray[8] = mb_vertices[v3i].Pos.Z* IrrToNewton;
NewtonTreeCollisionAddFace(nmapcollision, 3, &vArray[0], 12, 1);
}
}
NewtonTreeCollisionEndBuild(nmapcollision, 0);
NewtonBody* nmapbody = NewtonCreateBody(nWorld, nmapcollision);
// set the newton world size based on the bsp size
float boxP0[3];
float boxP1[3];
float matrix[4][4];
matrix4 mmm;
mmm.setTranslation(vector3df(-1370,-130,-1400)*IrrToNewton);
mmm.setRotationDegrees(vector3df(0.0f, 90.0f, 0.0f)*IrrToNewton);
NewtonBodySetMatrix(nmapbody,mmm.pointer());
NewtonCollisionCalculateAABB (nmapcollision, mmm.pointer(), &boxP0[0], &boxP1[0]);
//NewtonSetWorldSize (nWorld, (float*)boxP0, (float*)boxP1);
NewtonReleaseCollision(nWorld, nmapcollision);