Starnut coder
12-30-2001, 06:16 PM
I created a Terrain Engine which consists
of Traingles in the following fashion:
h2__dist___h3
| /|
| / |
dist| / |dist
| / |
|/________|
h1 dist h4
These Squares with the length 'dist' are
put next to eachother. The amount of
squares in x-Direction is 'xlength'.
The amount in z-Direction is 'zlength'.
Now the Terrain works perfectly so I
will not go into the creation code.
Here comes the Problem:
I made an Algorithm that calculates the
Height of the Terrain in any Point (x;z)
but it doesn't seem to work perfectly.
Heres the code maybe you can give me a
better solution or correct mine:
float GetHeightXZ(float x, float z)
{
int xx, zz;
float halfx = (dist*xlength)/2;
float halfz = (dist*zlength)/2;
xx = (int)(xlength/2)+(x/dist);
zz = (int)(zlength/2)+(z/dist);
float xxw = x-((xx*dist)-halfx);
float zzw = z-((zz*dist)-halfz);
float h11, h33;
if(zzw > xxw)
{
h11 = h1-h2;
h33 = h3-h2;
float prozent1 = h11/10000;
float prozent2 = h33/10000;
float prozent3 = dist/10000;
x = h2+((((dist-zzw)/prozent3) *prozent1)+((xxw/prozent3)*prozent2));
}
else
{
h11 = h1-h4;
h33 = h3-h4;
float prozent1 = h11/10000;
float prozent2 = h33/10000;
float prozent3 = dist/10000;
x = h4+(((zzw/prozent3)*prozent1)+(((dist-xxw)/prozent3)*prozent2));
}
return x;
}
Many thanks in advance.
-Starnut
[This message has been edited by Starnut coder (edited 12-30-2001).]
[This message has been edited by Starnut coder (edited 12-30-2001).]
[This message has been edited by Starnut coder (edited 12-30-2001).]
of Traingles in the following fashion:
h2__dist___h3
| /|
| / |
dist| / |dist
| / |
|/________|
h1 dist h4
These Squares with the length 'dist' are
put next to eachother. The amount of
squares in x-Direction is 'xlength'.
The amount in z-Direction is 'zlength'.
Now the Terrain works perfectly so I
will not go into the creation code.
Here comes the Problem:
I made an Algorithm that calculates the
Height of the Terrain in any Point (x;z)
but it doesn't seem to work perfectly.
Heres the code maybe you can give me a
better solution or correct mine:
float GetHeightXZ(float x, float z)
{
int xx, zz;
float halfx = (dist*xlength)/2;
float halfz = (dist*zlength)/2;
xx = (int)(xlength/2)+(x/dist);
zz = (int)(zlength/2)+(z/dist);
float xxw = x-((xx*dist)-halfx);
float zzw = z-((zz*dist)-halfz);
float h11, h33;
if(zzw > xxw)
{
h11 = h1-h2;
h33 = h3-h2;
float prozent1 = h11/10000;
float prozent2 = h33/10000;
float prozent3 = dist/10000;
x = h2+((((dist-zzw)/prozent3) *prozent1)+((xxw/prozent3)*prozent2));
}
else
{
h11 = h1-h4;
h33 = h3-h4;
float prozent1 = h11/10000;
float prozent2 = h33/10000;
float prozent3 = dist/10000;
x = h4+(((zzw/prozent3)*prozent1)+(((dist-xxw)/prozent3)*prozent2));
}
return x;
}
Many thanks in advance.
-Starnut
[This message has been edited by Starnut coder (edited 12-30-2001).]
[This message has been edited by Starnut coder (edited 12-30-2001).]
[This message has been edited by Starnut coder (edited 12-30-2001).]