In the previous chapter I let you off easily, so this time it should be a little harder. Your job is to check out the CarPhysics class and to figure out how the same physics code and collision detection is actually used in the Racing Game itself to keep the car on the road and how it handles the collision with the guard rails, which are not just straight lines like in the unit test.
The best thing for this job would be to write a unit test that renders the road and lets you control the car the same way you controlled it in the TestCarPhysicsOnPlaneWithGuardRails unit test and the same way it is actually handled in the game itself. But you can also use the game to test the physics by setting a breakpoint in the Update method of the CarPhysics class and then stepping through the code to see how the variables change. Figure 13-16 shows such a unit test in action.
You can of course also try to improve the physics or maybe even try to implement a physics engine if you are really eager to extend the game and add more features. At least on the Windows platform this can be an opportunity to change the game play, add effects, and to handle more complex collision scenarios.
For a little tip if you don’t know where to look or how the road can even use the same simple collision logic as the simple plane unit test does, please look at the UpdateCarMatrixAndCamera method of CarPhysics and the GetTrackPositionMatrix of the Track class. The track matrix transforms the current road piece into a space that can be used in the exact same way you used the car matrix in the simple plane collision unit test.