problem with includeing OgreNewt with ETM


28-07-2008 15:37:39

hi pra,

iam not able to get the collision body for the terrain when iam using with please send me the code how can i create the collision body, once check my code
scenennode* terr=
int num =terri->numchildern();
for(int i=0;i<num;i++)
scenenode* terrainnode=mscenemanager->getscenenode(terr->getchild(i)->getName());

OgreNewt::CollisionPrimitives::TreeCollision *col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld,terrainnode,false);

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

iam requesting you to send the code how can i crete the collision body for the terrain


28-07-2008 20:23:43

first of all, you should have answered to my topic, instead of creating a new one.
Second, I alerady posted the code, if you would look in said topic: ... 5060#45060
as CABAListic said, you cannot calculate it directly from the terrain, instead you have to do it using the heightmap.
most likey you can't just copypase the two methods, because i was too lazy and let my specific code in there, but i think it is pretty much clear how it works.


29-07-2008 02:59:21

thx pra,
i will try this and if i get any problem i will come to you,once again thanks for the reply


29-07-2008 05:57:52

hi pra,

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);
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++)

//| |
//| \ |

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 );


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