Original Post
i have a heightfield and i am moving objects over it.. but how do i get correct y-value for object from any point at heightfield? i''ve tried to write interpolation routine but i haven''t succeed. this is what i''ve tried:
// x = object_x (0-300), z = object_z (0-200)
int cx = (int)(x/10.0f);
int cz = (int)(z/10.0f);
float mixx = x/10.0f-cx;
float mixz = z/10.0f-cz;
int xheight1 = gridx[cx][cz];
int xheight2 = gridx[cx+1][cz];
int zheight1 = gridy[cx][cz];
int zheight2 = gridy[cx][cz+1];
int u = xheight1*mixx + xheight2*(1.0f-mixx);
int v = zheight1*mixz + zheight2*(1.0f-mixz);
// object_y = u+v
at some areas this routine works.. but i would like to get it working everywhere