# [solved] ETM and OgreNewt

pra

25-07-2008 03:03:47

So, now I'm trying to use ETM with OgreNewt, and for that I need the vertices.
From what i've seen in the code, the tiles have the vertices, but how can I acces them, and then their vertexdata?
Or do I have to calculate it from the heightmap myself? I not really understand the part in ETTile.cpp that does it CABAListic

25-07-2008 08:23:26

You can't access tiles, not without hacking ETM, anyway. Indeed you need to calculate them yourself from the TerrainInfo object. Basically TerrainInfo stores a 2D array representing the vertices, and for each vertex it stores a height in [0, 1]. So what you have for each vertex is a 2D index (i, j) and its height. You need to transform these into Ogre coordinates, so basically multiply the height with the scaling factor in y direction, then divide the scaling in x and z by the number of vertices in each direction (minus one) and multiply this single vertex scaling with the indices of the vertex.

pra

25-07-2008 16:59:51

ok...
i guess if I want the polygons, I have to do something like
v1 = getVertex(i,j)
v2 = getVertex(i+1,j)
v3 = getVertex(i,j+1)
to actually get a triangle, right?

pra

25-07-2008 18:15:19

It works. Here is my 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<hmWidth-1;x++)//hmWidth and hmHeight are the dimensions of the heightmap { for(size_t z=0;z<hmHeight-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; poly_verts = v1; poly_verts = v2; poly_verts = v4; col->addPoly( poly_verts, 0 ); poly_verts = v2; poly_verts = v3; poly_verts = v4; col->addPoly( poly_verts, 0 ); } } col->finish(false); terrainBody = new OgreNewt::Body(mWorld,col); } ```

prathap

30-07-2008 10:45:20

hi,
iam i correct that hmWidth is terraininfo->getwidth();

and hmHeigt is terraininfo->getHeight();

pra

30-07-2008 10:52:31

yes.

prathap

30-07-2008 18:54:17

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;

v1.y+=terraingeight;//height at the position where we place the vehicle on the terrain
v2.y+=terrainhight;
v3.y+=terraingeight;
v4.y+=terrainhight;

poly_verts = v1;
poly_verts = v2;
poly_verts = v4;

poly_verts = v2;
poly_verts = v3;
poly_verts = v4;

}
}
col->finish(false);

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

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

i add the vehicle in my code but iam not able to move the vehicle properly on the terrain when i move the vehicle it is falling from the terrrain,if u need i will send u my screen shots

pra

06-08-2008 13:15:26

you just copypasted my code, without any adjustments to your own app. There is no way it could even compile.
My guess would be you ignored the compile error and started the last succesful version