I'm generating my terrain on the GPU, using diamond square subdivision (no height map involved). How can I anchor the camera's position to always be on top of the generated terrain?
Thanks
I'm generating my terrain on the GPU, using diamond square subdivision (no height map involved). How can I anchor the camera's position to always be on top of the generated terrain?
Thanks
The most expeditious way to extract height information might be to draw it:
I think this method will give you everything you need. It won't require a non-GPU implementation of your algorithm. It can be re-run if your camera moves to a new area of terrain. It can be low resolution; allowing you to interpolate between its "pixels".
cameraPos_Y = desiredDistanceFromGround + currentTerrainVertex_Y
.
As the camera moves, keep updating cameraPosY
checking the height of which vertex the camera is over or closest to. Use the the camera's X and Z coordinates to help single out which vertex the camera is over.
In case you you have big faces for your terrain, you may have to use a bounding box and get the average height of all vertices detected.
cameraPos_Y = desiredDistanceFromGround + ((vertex1 + vertex2 + vertex3) / 3)
.
Lets say your bounding box for your camera at whatever current position detects 3 vertices with heights of 3.5, 4.2 and 2.9. You also want to camera to stay at a distance of 2 off the ground. The average height will be 3.53, so roughly, cameraPosY = 2.0 + 3.53
.
From here, you may need to incorporate change in height smoothly.