Page 1 of 1

Can we get the height of the terrain at (x,z) coordinate??

Posted: Mon Mar 28, 2005 6:14 pm
by angel80
I have juste a question about the last version of irrlicht (0.9)
Is there a function to get the height of the terrain generate with TerrainSceneNode at the point (x,z)?
Thank for your help

Posted: Mon Mar 28, 2005 6:37 pm
by Spintz
Not a direct function.

You can get it using a triangle selector and getting a line intersection point.

Or, if you just want the height at a specific vertex, you could get the Y position value by getting the meshBuffer. To figure out the index for a specific vertex, you would multiply X * the width of your heightmap and then adding Y.

Posted: Mon Mar 28, 2005 11:34 pm
by ntitan
I just wrote some code for something similar. I was trying to determine the distance of my object in the air from the terrain below.

I used a raycast to determine the distance. This same method could be used to determine the height of the terrain as well.

Just another approach to the problem, thought I'd mention it. Not sure what the best way would be though.



Here's my code if you're interested:

Code: Select all

f32 GroundDistance(ISceneNode *node)
	{
	vector3df start = node->getPosition();
	vector3df end = start;
	end.Y=end.Y-1000;

	triangle3df triangle;

	line3d<f32> line(start, end);

	smgr->getSceneCollisionManager()->getCollisionPoint(line, terrainSelector, end, triangle);

	f32 distance = (start.Y-end.Y);

	return distance;
	}

About the Spintz idea

Posted: Mon Apr 04, 2005 12:30 pm
by angel80
Hi Spintz,
It your methods works with a scaled terrain??? I don't know how it's work when we scalled the terrain.

Some code exemple will be very helpfull
Thank for your help

Posted: Wed Apr 06, 2005 1:28 pm
by Spintz
You'll need to recalculate the triangles for the the selector after you scale the terrain.

Posted: Mon Jun 13, 2005 6:31 pm
by Suliman
I would love to know the answer to the original question. I dont get that GroundDistance function to work. It gives me 1000 as return which is crazy, and all stuff in it seemes to be correctly set up.

What we need is something like this:

float getTerrainHeight(float x,float y);

Is it possible to do? Thanx
Suliman

Posted: Mon Jun 13, 2005 9:13 pm
by Spintz
It is possible to do, however it's not efficient at all. It would require the terrain node to maintain it's own selector of it's data and recalculating that selector every time the terrain is scaled.

The terrain will not always be used with Irrlicht collision, so doing this wouldn't really make sense.

The function posted in this forum will work, as long as your test line intersects with the terrain.

Posted: Wed Jun 15, 2005 5:15 am
by Midnight
the question would be why are you still using version 0.9?????????

Posted: Thu Jun 16, 2005 8:01 pm
by Beam
Here ya go
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=7363

ok, you get the value of the pixel in the heightmap, but that will give you the height of map, plus it's very fast and easy to use. Hell, i got it to work!

Beam