Search code examples
xnaterrainheightmap

The size of the terrain rendered from heightmap


I'm quite new to XNA so excuse me if I ask a 'silly' question but I couldn't find an answer.

I have a problem with the terrain rendered from a heightmap: the terrain I get is too small, I need something larger for my game but I'd like to keep the heigh tdata updated - so I can check for collisions later. (height data being a 2 dimensional array which holds the heights of each point - in my program it's called 'dateInaltime').

The problem is that if I modify the scale of the terrain, the collision checker will use the old values (from the original/small terrain) so I'll get wrong collision points.

My terrain class looks like this.

How can I make the terrain larger but also extend the height data array?


Solution

  • Change this part:

    vertex[x + y * lungime].Position = new Vector3(x, dateInaltime[x, y], -y);
    

    to:

    vertex[x + y * lungime].Position = new Vector3(x, dateInaltime[x, y], -y) * new Vector3(10);
    

    It should separate the vertices by a scale of 10 (or whatever number you choose).