I've created the program that is here: http://www.dev-hq.co.uk/10-C++-OpenGL/180-Lesson-14-Realistic-terrain-and-Camera-movement
As it says in the lesson in which the terrain code is introduced, it uses a lot of code from the NeHe terrain tutorial (including the height function).
I attempted to add some collision detection to the program:
float CollisionDetection(float camX, float camY, float camZ){ //Our collision functionmaxBoundX = camX + 20;minBoundX = camX - 20;maxBoundY = camY - 20;minBoundY = camY + 20;maxBoundZ = camZ - 20;minBoundZ = camZ + 20;float x = camX/SCALE;float y = (camY/1.8f)/SCALE;float z = camZ/SCALE;FloorY = Height(HeightMap, x, z);FloorX = camX;FloorZ = camZ;minBoundY = (minBoundY/1.8f)/SCALE;if(FloorY >= minBoundY){cout << "Y COLLISION!\n minBoundY = " << minBoundY << "\nFloorY = " << FloorY << endl << endl;camY = FloorY;} else {cout << "No collision\n minBoundY = " << minBoundY << "\nFloorY = " << FloorY << endl << endl;}return camY;}
The camY value that is returned is then set to the players camY value in the Draw function.
I thought that this code should work, however it does not (because the Height function doesn't function as I thought). I've tried dividing things (for example I divided height by 1.8 because it's multiplied by 1.8 earlier in the program) but it still will not work.
Can anyone help with this (I really want collision detection to work),
Thanks In Advance,
Joe