terrain normal

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

terrain normal

Post by Seven »

What would be the best way to calculate the normal of the terrain triangle retrieved when using the x.z coordinates?

for example, getHeight(x,z) returns the height of the triangle represented by the coordinates. I am wanting to grab the normal of that same triangle such as vector3df normal = terrain->getNormal(x,z);
CuteAlien
Admin
Posts: 9644
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: terrain normal

Post by CuteAlien »

I haven't really worked with terrain yet. But usually you can get triangles from triangle-selectors (so x,z you check a ray straight down at that position with the getTriangles function that takes a line). And triangles have a getNormal function.

But be careful - terrain only works without transformation. There was some open bug that stuff like rotations doesn't work for it (usually not a problem I guess).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Seven
Posts: 1030
Joined: Mon Nov 14, 2005 2:03 pm

Re: terrain normal

Post by Seven »

sigh....i should have thought of that. thanks for the assist! working on vegetation and want to use the slope of the terrain to either prevent placement or maybe angle the veggies.
Saturn7_dev
Posts: 4
Joined: Sun Sep 24, 2023 5:48 am

Re: terrain normal

Post by Saturn7_dev »

I recently implemented this in CopperCube engine with I would expect similar code as Irrlicht terrain though dont know for sure.
I added new member to struct STerrainData called "Angle" and in the 'updateMeshesFromTerrainData() function added new formula to get normal angle and update this 'Angle' before outputting this to the external javascript via new API so I can get for each cell the terrain texture and hence appropriate sound and also update all textures based on surface angle rather than by height which worked really well.
If you need more info let me know...
Post Reply