problem with ETM and OgreNewt

prathap

30-07-2008 09:19:49

hi pra,sorry for posting this again,iam not able to get the solution please check this code once and tell where iam scripting wrong
Code:

Vector3 Level::getTerrainVertex(size_t x,size_t z)
{

Vector3 res;

res.x = mTerrainInfo->getOffset().x + mTerrainInfo->getScaling().x * x;
res.y = mTerrainInfo->getOffset().y + mTerrainInfo->at(x,z) * mTerrainInfo->getScaling().y;

res.z = mTerrainInfo->getOffset().z + mTerrainInfo->getScaling().z * z;
return res;

}
void Level::generateTerrainCollision()
{
OgreNewt::CollisionPrimitives::TreeCollision *col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld);
col->start();
for(size_t x=0;x<mTerrainInfo->getWidth()-1;x++)//hmWidth and hmHeight are the dimensions of the heightmap
{
for(size_t z=0;z<mTerrainInfo->getHeight()-1;z++)
{

//| |
//4---3-
//| \ |
//1---2-

Vector3 v1 = getTerrainVertex(x,z);
Vector3 v2 = getTerrainVertex(x+1,z);
Vector3 v3 = getTerrainVertex(x+1,z+1);
Vector3 v4 = getTerrainVertex(x,z+1);
Ogre::Vector3 poly_verts[3];

poly_verts[2] = v1;
poly_verts[1] = v2;
poly_verts[0] = v4;

col->addPoly( poly_verts, 0 );
poly_verts[2] = v2;
poly_verts[1] = v3;
poly_verts[0] = v4;

col->addPoly( poly_verts, 0 );

}
}
col->finish(false);

terrainBody = new OgreNewt::Body(mWorld,col);
delete col;

}
mcar=new simplevehicle(mscenemanager,m_world,Ogre::Vector(300,300,300),Ogre::Quaternion(Ogre::Quaternion::IDENTITY));


i add the vehicle in my code but iam not able to get the vehilce on the terrain it stands above the terrain and if i change the position to (200,-0.5,100) it falls from a particular height but it cont stay on terrain please tell me how can i get the vehicles on the terrain.