problem with includeing OgreNewt with ETM

prathap

28-07-2008 15:37:39

hi pra,

iam not able to get the collision body for the terrain when iam using with ETM.so please send me the code how can i create the collision body, once check my code
bla...bla..........bla..
createterrain(terraininfo);
scenennode* terr=
mscenemanager->getscenenode("ETTerrain/...");
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);
terrainBody->setPositionOrientation(terrainnode->getPosition(),..);
}

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

pra

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:
http://www.ogre3d.org/phpBB2addons/view ... 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.

prathap

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

prathap

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