Game Development Community

Getting terrain altitude (server side)?

by Isidore · in Torque Game Engine · 08/07/2003 (4:53 am) · 6 replies

Hello to everybody!

Would somebody know a script or C++ function that could retrieve the terrain z-coordinate, given an x and a y coords? (on the server side)

Basically, I would like to place an object at coords X,Y, just on the ground.

I am currently investigating on how to do this, but there might be a simple function that already does this...

Any information much appreciated.

Cheers,

Isi

#1
08/07/2003 (5:12 am)
C++: bool TerrainBlock::getHeight(const Point2F &pos, F32 *height)
Script: .getTerrainHeight(x, y)

I hope this helps,

Stefan.
#2
08/07/2003 (5:21 am)
Yeah, the TerrainBlock has a "getHeight()" method, which is also exported to the scripting engine ...
So in script it would be:
%height = getTerrainHeight(%x,%y);
in C++ it would be something like:
SimObject* current;
TerrainBlock *terrain;
SimGroup * group = dynamic_cast<SimGroup*>(Sim::findObject("MissionGroup"));
for (SimGroup::iterator i = group->begin(); i != group->end(); i++)
{
     current = dynamic_cast<SimObject*>(*i);
     if (dStrstr(current->getClassName(),"TerrainBlock") != NULL)
     {
          terrain = dynamic_cast<TerrainBlock*>(*i);
	  Con::warnf("TerrainBlock found in MissionGroup!");
     }
}
Point2F tempPos(312.0f, 222.0f);
F32 tempZ = 0.0f;
if (!terrain->getHeight(tempPos, &tempZ))
   Con::errorf("Failed to get height for tempPos(%d.%d)", tempPos.x, tempPos.y);
...
tempZ would hold the height value then...
#3
08/07/2003 (5:30 am)
Thank you both for the info :)

By the way, I found these lines in the code:
TerrainBlock *terrBlock = dynamic_cast<TerrainBlock*>(Sim::findObject("Terrain"));

I was just wondering if this wouldn't be simpler to get the TerrainBlock object?
(sorry if it is a noob question :) )

Anyway, thank you very much for your replies,

Isi
#4
08/07/2003 (5:33 am)
Yeah, thats easier, true... it's assuming that the terrainblock is named "terrain", but that should be the convention anyways...
so you should be ok using that, yep :)
#5
08/07/2003 (5:34 am)
Ok I got it ;)

Thanks again,

Isi
#6
08/07/2003 (9:57 am)
By the way, just a small note.

I got a wrong altitude at first, because tempPos is - I guess - not a mission coord. .
I had to use this to have it work:

Point3F terrPt = tempPos;
[b]terrBlock->getWorldTransform().mulP(terrPt);[/b]
terrBlock->getHeight(Point2F(terrPt.x,terrPt.y), &the_height) ){
...

but now it seems fine. /me is glad