Assume that Z is the up axis.
I have a heightmapped terrain. A 1024x1024 texture maps to a 1024x1024 vert mesh that represents a 1024m x1024m game area (In reality it actualy gets splitted into much smaller meshes so proper LOD and frustum culling can happen but thats irrelevant to this question). I have taken the characters x and y coords. Rounded them to the nearest Integer and used that to retrieve the height value from the heightmap texture and then I set the characters z coord to that value. Now my character can move over the terrain but its ofcourse horribly jumpy.
I need to take the height values of the 4 heightmap pixels around my character and based on where he is reletive to those 4 pixels work out the final height value but im strugling with that abit.
what i tried so far was simply this:
aDist,bDist,cDist,dDist; //characters distance to the 4 surrounding pixels (on the xy plane).
aHeight,bHeight,cHeight,dHeight; //the 4 surrounding pixels height value\
totalDist = aDist + bDist + cDist + dDist;
aDist = aDist / totalDist;
bDist = bDist / totalDist;
cDist = cDist / totalDist;
dDist = dDist / totalDist;
finalHeight = aHeight * aDist + bHeight * bDist + cHeight * cDist + dHeight * dDist;
Unless i made a mistake somewhere in my code (wich is very possible ) this is not the solution.
Any help appreciated. Thnx in Advance!
Edited by Wilhelm van Huyssteen, 17 August 2012 - 03:32 AM.