ETM Tile Coordinates

Hannofcart

02-07-2009 20:09:38

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.

[/url]

Now when I try...

[code]
Vector3 loc = mgr->getSceneNode("ETTerrain/Terrain")->_getDerivedPosition() + mgr->getSceneNode("ETTerrain/Terrain/Tile[0][2]")->getPosition();
[/code]

...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
[code]
Vector3 loc = mgr->getSceneNode("ETTerrain/Terrain")->_getDerivedPosition() + Vector3(mTerrainInfo->vertexToPosX(0) ,0, mTerrainInfo->vertexToPosZ(2) );
[/code]

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.

CABAListic

02-07-2009 21:17:53

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.

Hannofcart

03-07-2009 01:18:31


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?

CABAListic

03-07-2009 11:01:16

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.

Hannofcart

04-07-2009 20:14:28

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->setLODErrorMargin(2, mCamera->getViewport()->getActualHeight());
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.

Hannofcart

05-07-2009 13:30:01

Ok, I have one last query in relation to tile coordinates. I notice that adjacent tiles (their scenenodes) overlap slightly at the edges.
To make myself clear I am attaching a screenshot showing the overlap between tiles at the edges.

[/url]

I would like to obtain the amount of this overlap too, because I have to continuously rearrange the tiles. Since this is such a specific detail, I will dig into the ETM code to find out if you can just point me in the direction of the relevant code.

CABAListic

05-07-2009 14:32:06

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.

Hannofcart

05-07-2009 15:37:45

I dont think its just visual. Using the extents passed to the AABB during initialization of the terrain to calculate the width of each tile, when I try repositioning the scenenodes of the tiles, I get the following gaps in the terrain:

[/url]

This leads me to believe that its not just the AABB of the tile's scenenodes but the scenenodes themselves that have a certain overlap. Am I wrong?

CABAListic

05-07-2009 19:48:45

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.

Hannofcart

06-07-2009 20:57:34


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!