Hi!
I started with my first attempt to reder heightfields with LWJGL.
The heightmap is rendered using triangle strips (flat filled at the moment or wireframe)
with NO optimizations - each frame all polys are rendered.
I can fly over the terrain, but now I want to implement collision detection
so that the camera always stays at a fixed height above the ground.
Now, how do I know on which triangle I am standing?
My camera holds a vector (x,y,z) for the position in space
and 2 angles for orientation (y-, and x-rotation to look left/right and up/down).
The terrain is scaled by a constant factor in x-, and z-direction and also translated,
so that the origin is in the middle of the map.
I do the following:
a = (int) camera.x / scale + mapsize/2
b = (int) camera.z / scale + mapsize/2
This gives me the square (a,b) on which I stay, right?
But how do I know on which one of the two triangles I am standing?
Btw. , is this the right way to handle collision on terrains?
I hope my explanation is clear enough since I’m very tired
Thanks in advance, Adam.