Today we want to inform you about the newest progresses we made in our project: We are proud to say that we invented our own working way of collision detection and implemented it too. So now we can drive our car over our terrain using the keyborad while the car follows the surface in a reasonable way. At this point our car has no physics like acceleration, mass and so on but it’s still a great step! So here is how we did it
Our basic Idea is to have four controlpoints for our car. Each of these points checks for the exact altitude the terrain under the point has. Having this altitude for all the 4 points (tires) of the car we can calculate the exact position and alignment of the car. This Image shows the mesh of our terrain seen from above. As you can see each vertex has an offset of one worldunit in X and Y direction. The green point represents one of the four controlpoints (tires) of our car, while the red points represent the vertices of the terrain mesh.
Our approach to calculate the height of a control point is to intersect a line, which is parallel to the z axis and includes the control point, with the triangle located under this point. While the line is defined by the controlpoint and the direction of the z-axis, the triangle is defined by the tree vertexes of the terrain (they form a plane). These three points can be calculated easily by looking at the X and Y value of the controlpoint. If X < Y then we need the Points one to three (see image), otherwise two to four. To obtain their coordinates we simply have to round to integers as shown on the image. This works perfectly because the distance between our vertices is, in this case, one unit.
The Z value can then be read from an array called heightdata, which is a two-dimensional array containing the z-positions for each vertex. We have this array because we generate our terrain from a heightmap. Now we have a line and a plane, enough to calculate the intersection point, which is at the same time the point where our tire has to be

