To expand on ZMan's recommendation, you could do this with a BoundingBox object around the vehicle and finish line. Here is a sample class. I put the full sample at http://www.gamedeveloperonline.com/creators/lapCounter.zip
This actually just shows a triangle moving back and forth to keep it simple but the counter works and displays as you might need it.
class LapCounter
{
private BoundingBox finishLine;
private BoundingBox vehicleBox;
private int lapCount;
private bool checkPointA;
private bool checkPointB;
public LapCounter()
{
// set bounding box around finish line
finishLine.Max = new Vector3(+1.0f,+0.5f,+0.5f);
finishLine.Min = new Vector3(-1.0f,-0.5f,-0.5f);
// start at 0 laps
lapCount = 0;
// clear check points
checkPointA = checkPointB = false;
}
private void setVehicleBox(Vector3 vehiclePosition)
{
vehicleBox.Max = new Vector3(vehiclePosition.X + 0.3f,
vehiclePosition.Y + 1.0f,
vehiclePosition.Z + 0.1f);
vehicleBox.Min = new Vector3(vehiclePosition.X - 0.3f,
vehiclePosition.Y,
vehiclePosition.Z - 0.1f);
}
public void CountLaps(Vector3 vehiclePosition)
{
if (checkPointA && checkPointB)
{
setVehicleBox(vehiclePosition);
// check if vehicle intersects finish line
if (vehicleBox.Intersects(finishLine))
{
lapCount += 1;
// clear check points
checkPointA = checkPointB = false;
}
}
}
public void setCheckPointA()
{
checkPointA = true;
}
public void setCheckPointB()
{
checkPointB = true;
}
public int LapCount()
{
return lapCount;
}
}