View Full Version : Terrain Generation / Displaying terrain

_Syndic

05-02-2013, 12:43 PM

Well I've pretty much got this figured out now I think except in this tutorial I'm following the author leaves out a vital detail;

For the Triangle class, he leaves out the variable 'STEPS' (int triangleCount = (steps * steps * 2);)

and this is for generating fractal terrain

private int[] i,j = new int[3];

public Triangle(int i0, int j0, int i1, int j1, int i2, int j2){

i[0] = i0; i[1] = i1; i[2] = i2;

j[0] = j0; j[1] = j1; j[2] = j2;

int triangleCount = (steps * steps * 2);

Triangle[] triangles = new Triangle[triangleCount];

int triangle = 0;

for (int i = 0; i < steps; i++){

for (int j = 0; j < steps; j++){

triangles[triangle++] = new Triangle (i, j, i + 1, j, i, j + 1);

triangles[triangle++] = new Triangle (i + 1, j, i + 1, j + 1, i, j + 1);

}

}

}

mobeen

05-02-2013, 06:22 PM

I think steps refers to the number of quads in 1 dimentions. steps * steps is the total number of quads in 2 dimensions. Since each quad has 2 triangles hence the multiplication by 2

_Syndic

05-02-2013, 06:45 PM

Thing is, even if it did, or didn't, I wouldn't know how to apply it. Can you show me an example please?

Thanks!

_Apollo_

05-03-2013, 03:28 AM

I agree with mobeen.

The sample code works in squares.

If you have a grid of 4 by 4 quads (steps = 4)(16 quads in total).

Each quad is made out of 2 triangles (32 triangle in total).

So this is 4 * 4 * 2.

The code let i vary from 0 to steps, and for every i vary j from 0 to steps.

For every state there are 2 triangles created.

The region is filled from bottom up and left to right.

1017

_Syndic

05-03-2013, 03:14 PM

I agree with mobeen.

The sample code works in squares.

If you have a grid of 4 by 4 quads (steps = 4)(16 quads in total).

Each quad is made out of 2 triangles (32 triangle in total).

So this is 4 * 4 * 2.

The code let i vary from 0 to steps, and for every i vary j from 0 to steps.

For every state there are 2 triangles created.

The region is filled from bottom up and left to right.

1017

I need to GET the number of quads, I'm generating this terrain so I don't know how many there are

_Apollo_

05-06-2013, 03:29 AM

The steps is something that depends on the source of the terrain data and the detail level that you want for your terrain.

For instance if you use a heightmap as source for you terrain, then the number of pixels can be used as your steps value.

If you are using a 256 x 256 bitmap to create the heights then your step can be 256.

But you can also use 128, then the resolution of your terrain is divided by 2, so your detail level is lower.

If you are using external data to create the heights then you decide what your input is.

Example:

If a height data is available for every meter and you want a terrain of 100 x 100m

Then you can use 100 as step value: then for every meter you use a new value for your height.

You can use 50 as step value: then you must assign a new value every 2 m

you can use 25 as step value :then you must assign a new value every 4m

and so on.

Conclusion:

So the "steps" in function of the size of your terrain determine the detail level.

Off course how bigger the "steps" value (more steps) how higher de detail level, how lower the performance and the more memory is used.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.