CHAPTER 5 ■ GETTING THE MOST OUT OF VERTICES
457
private Ray LinearSearch(Ray ray)
{
ray.Direction /= 300.0f;
Vector3 nextPoint = ray.Position + ray.Direction;
float heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z);
while (heightAtNextPoint < nextPoint.Y)
{
ray.Position = nextPoint;
nextPoint = ray.Position + ray.Direction;
heightAtNextPoint = terrain.GetExactHeightAt(nextPoint.X, -nextPoint.Z);
}
return ray;
}
In this example, the Ray is divided into no less than 300 steps. Increasing this value will
increase the probability of detecting peaks but will require more processing power.
For each point, you calculate the next point and check whether that next point is above or
below the terrain. As long as it is above the ...