Hi all,
for some days i try to get this done - and i am ashamed that i cant figure it out on my own…
i am doind a simple ground-hight detection for my game.
The ground is a mesh of triangles.
I allready can test in with triangle i am, but when i coms to calculating the hight of the position on the triangle i fail.
As my point ( player ) is floting abouve the triangle i only need to work with X and Z and than find the propper Y.
here is my function with should find the propper Y. it only works points close to the triangle corners - and i know why …
but i cant find a way to improve it:
GLfloat getYbalanced( GLfloat x , GLfloat y, GLfloat z, GLfloat * dreiArray )
{
// x, y ,z = Point to test
// dreiArray = array holding points of triangle - some offset in it !
GLfloat result = 0.0f;
// distance point 1 x + z
GLfloat w1 = sqrt( powit( ( dreiArray[0] - x ) ) + powit( ( dreiArray[2] - z ) ) );
// distance point 2 x + z
GLfloat w2 = sqrt( powit( ( dreiArray[8] - x ) ) + powit( ( dreiArray[10] - z ) ) );
// distance point 3 x + z
GLfloat w3 = sqrt( powit( ( dreiArray[16] - x ) ) + powit( ( dreiArray[18] - z ) ) );
// total distance
GLfloat w_all = absu( w1 ) + absu( w2 ) + absu( w3 );
// get points relativ distance -> as a factor to multiply later
GLfloat f1 = ( 1.0f / ( w1 / w_all ) );
GLfloat f2 = ( 1.0f / ( w2 / w_all ) );
GLfloat f3 = ( 1.0f / ( w3 / w_all ) );
result += f1 * dreiArray[1]; // factor for point - multiply with hight of point
result += f2 * dreiArray[9]; // factor for point - multiply with hight of point
result += f3 * dreiArray[17]; // factor for point - multiply with hight of point
return ( result / ( f1 + f2 + f3 ) ); // result needs to be devided by total factor sum
}
Here a screen, at the corners i am almost fine but in the middel of the triangle the hight is not correct …
i now what is wrong with the function and why i get the result - but i cant figure a way to improve it…
OPEN IMG LINK: [ATTACH=CONFIG]361[/ATTACH]
thanx for any improvment of my function … i guess its easy …
cu
uwi2k2