private void UpdateCamera(GameTime gameTime) { if (camera.ObjectToFollow != null) { if (camera.CurrentBehavior == Camera.Behavior.FreeView) { camera.Position = camera.ObjectToFollow.Position + Vector3.UnitY * 1000; } if (camera.CurrentBehavior == Camera.Behavior.FirstPerson) { camera.Position = camera.ObjectToFollow.Position - camera.ObjectToFollow.ViewDirection; if (camera.ObjectToFollow.Target != null && camera.ObjectToFollow.IsShooting) { camera.LookAt(camera.ObjectToFollow.Target.Position); } else { camera.LookAt(camera.ObjectToFollow.Position + camera.ObjectToFollow.ViewDirection * 10); } camera.UndoRoll(); } } Vector3 pos = camera.Position; float gridSpacing = terrain.TerrainHeightMap.GridSpacing; float size = terrain.TerrainHeightMap.Size * gridSpacing; float lowerBounds = 2.0f * gridSpacing; float upperBounds = size - (2.0f * gridSpacing); float height = terrain.TerrainHeightMap.HeightAt(pos.X, pos.Z) + 50.0f; if (pos.X < lowerBounds) { pos.X = lowerBounds; } if (pos.X > upperBounds) { pos.X = upperBounds; } switch (camera.CurrentBehavior) { case Camera.Behavior.FirstPerson: pos.Y = height; break; case Camera.Behavior.Spectator: case Camera.Behavior.Flight: if (pos.Y < height) { pos.Y = height; } if (pos.Y > terrain.TerrainSize * 0.5f) { pos.Y = terrain.TerrainSize * 0.5f; } break; case Camera.Behavior.FreeView: if (pos.Y < height) { pos.Y = height; } if (pos.Y > terrain.TerrainSize * 3) { pos.Y = terrain.TerrainSize * 3; } break; default: break; } if (pos.Z < lowerBounds) { pos.Z = lowerBounds; } if (pos.Z > upperBounds) { pos.Z = upperBounds; } camera.Position = pos; }