Terrain tutorial doubt

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
killrazor
Posts: 5
Joined: Thu Oct 26, 2006 10:14 pm
Location: Barcelona (find me in the pubs)

Terrain tutorial doubt

Post by killrazor »

Hi all,
I'm following the terrain tutorial and I'm wondering about the getTriangleCount method of the scene::ITriangleSelector interface. If the height map have 256*256 pixels, the most logical triangle count should be 65532 triangles. But the triangle count is 115200. Why?

Thanks in advance
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

How do you come to 65532 triangles ????

1. - if you use a height map of 256*256 the terrain will be 240*240 !!!
This is because the height map has to be (2^x+1) * (2^y+1)...
So if you want a terrain of 256*256 the height map has to be 257*257 !!!

REMEBER: a pixle in the height map is not a sqare, its a vertex !!!
4 pixles are building 1 square !!!

2. - a triangle is build out of 3 vertices, a sqare of 4 vertices is building 2 triangles !!!

Code: Select all

        v1          v2
          +--------+
          |       /|
          |     /  |
          |   /    |
          | /      |
          +--------+
        v3          v4
with your height map you have 240*240 vertices = 57600 vertices (sqares)...
as far as each square is build out of 2 triangles you have 57600 * 2 triangles = 115200 triangles !!!
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
killrazor
Posts: 5
Joined: Thu Oct 26, 2006 10:14 pm
Location: Barcelona (find me in the pubs)

Post by killrazor »

Ahhhhh, ok. Thanks for your explanation. I thought that a pixel is a whole triangle.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

That's what I first thought, too... ;)

And another thing you should remember, too:
The terrain is fliped upside down !!!
If you have a mountain let's say in the upper right corner of the height map, the mountain is placed at the lower right corner of the terrain !!!
This is because the height map is interpreted from the left upper corner to the right lower corner (like you read a book), but the terrain is build from the lower left to the upper right corner !!!
I tried to fix this, but I have still problems with the normals...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

just use the flip image option on most paint programs left-to-right for now I've seen a few well known games with the exact same issue so the solution is probably not so obvious.

there are a lot of places you could fix that. like how it reads the height map or how it builds the terrain (starting point)

for now the simplest way is to flip the height map to get the effect you actually wanted when making the height map.
Post Reply