float height(float fx,float fz)
{
float x2=x-floor(fx),z2=z-floor(fz);
int x=(int) fx;
int z=(int) fz;
return (height[x,z]*(1-x2)+height[x+1,z]*x2)*(1-z2)+(height[x,z+1]*(1-x2)+height[x+1,z+1]*x2)*z2;
};
I think that should work. If you really want to test your triangles...hm...lemme see...something like (pseudocode)
float height(float fx,float fz)
{
float x2=x-floor(fx),z2=z-floor(fz);
int x=(int) fx;
int z=(int) fz;
cvector v1=vec(0,0,height[x,z]); //lower left
cvector v2=vec(0,1,height[x,z+1]); //upper left
cvector v3=vec(1,1,height[x+1,z+1]); //upper right
cvector v4=vec(1,0,height[x+1,z]); //lower right
cvector v5;
if((x2+z2)<1) //lower left tri?
{
v5=StretchVec(VSumm(v1,v2),0.5); //middlepoint between upper right and lower left fieldcorner
v4=VSumm(v2,StretchVec(VDiff(v5,v2),2)); //v4 now contains the 4th edge, if we had a flat quad using points v1,v2,v3 as first three points
return (v1*(1-x2)+v4*x2)*(1-z2)+(v2*(1-x2)+v3*x2)*z2;
}
else
{
...
};
VSumm = V+V2 //simple addition of all components
VDiff = V2-V //vector from V2 -> V
StretchVec = V*f //multiplication of all components with 2nd parameter