I am using ETM v2.3.1 and need to get the location on the tiles in world coordinates (w.r.t SceneRoot). The location of the tiles seem to have no correlation whatsoever to the world coordinates of other nearby objects.
For eg. here is a model placed directly over the terrain, where its attached to a scenenode at 600, 150, 600 global.
Now when I try...
Vector3 loc = mgr->getSceneNode("ETTerrain/Terrain")->_getDerivedPosition() + mgr->getSceneNode("ETTerrain/Terrain/Tile")->getPosition();
...it gives me 0,0,0 for all the tiles(!). Also, I know we are supposed to use TerrainInfo class method vertexToPosX,Z and these seem to give me the coordinates of the tiles wrt to the ETTerrain/Terrain scenenode.
Even so, what I really dont understand is how
Vector3 loc = mgr->getSceneNode("ETTerrain/Terrain")->_getDerivedPosition() + Vector3(mTerrainInfo->vertexToPosX(0) ,0, mTerrainInfo->vertexToPosZ(2) );
gives me coordinates 23.2558,0,11.6279 whereas the model located right on it has world coordinates of 600, 150, 600?
Shouldnt atleast that second snippet for loc give me the global coordinates? Is there something glaringly noobish that I am doing? Please help.
You really shouldn't use the terrain's scene nodes, they don't give useful information. More specifically, their positions all point to the lower left (x=0, z=0) corner of the whole terrain. That's why both code segments give you results different from what you expect; your mesh is placed at the mid of the terrain, not at the corner.
You really shouldn't use the terrain's scene nodes, they don't give useful information.
Alright. However using vertexToPosX/Z doesn't seem to help either (as I've described in the earlier post).
So, in short, how would one go about getting the global coordinates of the individual tiles?
vertexToPosX is fine, the problem is that your model is placed in the centre of the terrain whereas you gave a vertex which is at a corner of the terrain.
I really don't know why you would want to have the individual tile coordinates (tiles are just rendering primitives), but to get them you will have to calculate them manually. When you setup the terrain, you supply the position of one corner of the terrain, and furthermore you supply the size of a terrain tile in vertices. You need to calculate the world size of one tile from the latter, and then you can add it to the former to get your results.
Thank you. That clarified things. What I do now is as follows:
Using this code to initialise the terrain (as in the sample app with ETM)
// create terrain manager
mTerrainMgr = new ET::TerrainManager(mSceneMgr);
mTerrainMgr->setUseLODMorphing(true, 0.2, "morphFactor");
// create a fresh, mid-high terrain for editing
ET::TerrainInfo terrainInfo ((RESOLUTION+1), (RESOLUTION+1), std::vector<float>( (RESOLUTION+1) *(RESOLUTION+1), 0.5f));
// set position and size of the terrain
terrainInfo.setExtents(AxisAlignedBox(0, 0, 0, TERRAIN_EXT_X, 300,TERRAIN_EXT_Z));
then I use this to get the width and height of the tile, and thereafter use it to get the world coordinates as you (CABAListic) mentioned in the previous post.
int Num_Rows_X = RESOLUTION/TILESIZE;
int Num_Rows_Z = RESOLUTION/TILESIZE;
float tileWidthX = TERRAIN_EXT_X/Num_Rows_X;
float tileWidthZ = TERRAIN_EXT_Z/Num_Rows_Z;
I really don't know why you would want to have the individual tile coordinates
This is in order to implement torroidal world in the terrain for which I need to do tile rearrangement.
Thanks again for your prompt replies.
Tiles share common borders, i. e. they replicate the vertices at the edges. Visually, though, they shouldn't be overlapping. That might just be a slight mistake when calculating the bounding boxes.
Well, let's say your terrain has 129x65 vertices, and the tile size is 65. Then obviously the 65. vertex column of the first tile is the same as the first column of the second tile. These vertices do overlap, but a vertex doesn't have any width, so they are not visually overlapping, they are just closely lying together with no visual gap between them. So if you move them, then of course you get a gap.
vertex column of the first tile is the same as the first column of the second tile.
That is exactly what I wanted to know! I am now able to stitch the terrain up good now even after rearranging by simply taking that overlap into account (by compensating for the space between one pair of vertex columns). Thanks a ton!