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

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
angel80
Posts: 22
Joined: Mon Feb 07, 2005 1:37 pm
Location: Paris (France)

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

Post 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
.: Franck :.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post 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.
Image
ntitan
Posts: 21
Joined: Tue Mar 22, 2005 2:44 pm

Post 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;
	}
angel80
Posts: 22
Joined: Mon Feb 07, 2005 1:37 pm
Location: Paris (France)

About the Spintz idea

Post 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
.: Franck :.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

You'll need to recalculate the triangles for the the selector after you scale the terrain.
Image
Suliman

Post 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
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post 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.
Image
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

the question would be why are you still using version 0.9?????????
Beam

Post 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
Post Reply