Yacoby
12-05-2008 10:34:13
I decided to use Newton for the physics, however, the problem I have hit is that generating the physics for my terrain is very slow. 5 minutes slow.
I know my code isn't a work of art, but there must be a faster way of generating the terrain collision mesh (the mesh is only 257x257 verts)
I am not even sure if the code works, but anyway, this is what I am doing:
I know my code isn't a work of art, but there must be a faster way of generating the terrain collision mesh (the mesh is only 257x257 verts)
I am not even sure if the code works, but anyway, this is what I am doing:
OgreNewt::CollisionPrimitives::TreeCollision* col = new OgreNewt::CollisionPrimitives::TreeCollision( mWorld );
col->start();
const ET::TerrainInfo* ti = &mTerrainMgr->getTerrainInfo();
std::vector<float> terrain = ti->getHeightmapData();
Ogre::Vector3 square[4];
Ogre::Vector3 verts[3];
for ( long w = 0; w < ti->getWidth()-1; w++){
for ( long h = 0; h < ti->getHeight()-1; h++){
long arryPos = w*ti->getWidth()+h;
/*
2--3
| |
0--1
*/
square[0].y = terrain[arryPos]*ti->getScaling().y;
square[1].y = terrain[arryPos + 1]*ti->getScaling().y;
square[2].y = terrain[arryPos + ti->getWidth()]*ti->getScaling().y;
square[3].y = terrain[arryPos + ti->getWidth() + 1]*ti->getScaling().y;
//get the pos of the vertex of point 0
square[0].x = (w*ti->getScaling().x) + ti->getOffset().x;
square[0].z = (h*ti->getScaling().z) + ti->getOffset().z;
//bvase the rest of the poses off point 0
square[1].x = square[0].x + ti->getScaling().x;
square[1].z = square[0].z;
square[2].x = square[0].x;
square[2].z = square[0].z + ti->getScaling().z;
square[1].x = square[1].x;
square[1].z = square[2].z;
//add the pollys to tghe meshg.
verts[0] = square[0];
verts[1] = square[1];
verts[2] = square[2];
col->addPoly(verts, 0);
verts[0] = square[1];
verts[1] = square[3];
verts[2] = square[2];
col->addPoly(verts, 0);
}
}
col->finish();
OgreNewt::Body* body = new OgreNewt::Body(mWorld, col );