Racing_Sim Stage 1 Help

Free Roam and Third person Camera

Rendering a Terrain

Dealing with height

As the vehicle moves over the terrain it needs to move up and down according to the height of the terrain at that point. Your terrain class needs to be able to return the height at any point.

 

This will also be useful in preventing the camera from "going under ground"

 

Orienting a Vehicle on the terrain

In order to position the vehicle correctly on the terrain we need to know the terrain normal under the vehicle;

  1. Find normal of grid point nearest to the vehicle, or
  2. Average normals of 4 grid points of the grid square the vehicle is in, or
  3. Weighed or intepolated normals of 3 grid points of the grid triangle the vehicle is in.

A matrix to orient the vehicle is construxted as follows

  1. R=Up x TerrainNormal gives axis about which we should pitch and roll (cross product)
  2. a=Up•TerrainNormal gives cos(angle) we should rotate (dot product)
  3. angle = acos(a), recover angle
  4. Upright = Matrix.CreateFromAxisAngle(R, angle) matrix to apply

World Matrix for vehicle;

Matrix.CreateRotationY(yaw)*Upright*Matrix.CreateTranslation(position);