CHAPTER 5 ■ GETTING THE MOST OUT OF VERTICES
452
float heightLxLz = heightData[xLower, zLower];
float heightLxHz = heightData[xLower, zHigher];
float heightHxLz = heightData[xHigher, zLower];
float heightHxHz = heightData[xHigher, zHigher];
bool pointAboveLowerTriangle = (xRelative + zRelative < 1);
float finalHeight;
if (pointAboveLowerTriangle )
{
finalHeight = heightLxLz;
finalHeight += zRelative * (heightLxHz - heightLxLz);
finalHeight += xRelative * (heightHxLz - heightLxLz);
}
else
{
finalHeight = heightHxHz;
finalHeight += (1.0f - zRelative) * (heightHxLz - heightHxHz);
finalHeight += (1.0f - xRelative) * (heightLxHz - heightHxHz);
}
return finalHeight;
}
5-10. Calculate the Collision Point Between the
Pointer and the Terrain: Surface ...