Align Mesh on Terrain

Blitz3D Forums/Blitz3D Programming/Align Mesh on Terrain

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi all!

I am creating a game with a terrainy water. The player can swim and dive, so that I must solve the view, where I have a splitted screen: a)upper water and b)under water.

Therefore I would like to align a mesh on the terrain in front of the camera (to show the under water in a foggy look). For a first and easy solution I tried to test this with only a rectangle. Later it should be better to have a complete alignment to the first visible terrain peaks. Here is what I actually use to create the mesh:

camera_lens_underwater = CreateMesh(camera)
camera_lens_underwater_surface=CreateSurface(camera_lens_underwater)
AddVertex camera_lens_underwater_surface,-.1,0,0,0,0
AddVertex camera_lens_underwater_surface,+.1,0,0,1,0
AddVertex camera_lens_underwater_surface,+1.5,-5,0,1,1
AddVertex camera_lens_underwater_surface,-1.5,-5,0,0,1
AddTriangle camera_lens_underwater_surface,0,1,2
AddTriangle camera_lens_underwater_surface,0,2,3
PositionEntity camera_lens_underwater,0,0,1
EntityFX camera_lens_underwater,16
EntityOrder camera_lens_underwater,-1
EntityColor camera_lens_underwater,13,95,205
EntityAlpha camera_lens_underwater,.6
HideEntity camera_lens_underwater

camera_lens_pivot_left = CreatePivot(camera)
PositionEntity camera_lens_pivot_left,-1,0,1
camera_lens_pivot_right = CreatePivot(camera)
PositionEntity camera_lens_pivot_right,1,0,1

Parallel to the animation I tried to align the mesh realtime to the terrain, but this does not work correctly:

ty# = TerrainY(water,EntityX(camera_lens_pivot_left,1),0,EntityZ(camera_lens_pivot_left,1)) - EntityY(camera_lens_pivot_left,1)
VertexCoords camera_lens_underwater_surface,0,EntityX(camera_lens_pivot_left),EntityY(camera_lens_pivot_left),EntityZ(camera_lens_pivot_left)

ty# = TerrainY(water,EntityX(camera_lens_pivot_right,1),0,EntityZ(camera_lens_pivot_right,1)) - EntityY(camera_lens_pivot_right,1)
VertexCoords camera_lens_underwater_surface,1,EntityX(camera_lens_pivot_right),EntityY(camera_lens_pivot_right),EntityZ(camera_lens_pivot_right)

This does not align to the camera view (although I used the mesh as a child of the camera) and this does not align to the terrain-peaks.

What do you think?
Has somebody a hint or a function to solve this problem?
Thanks a lot in advance.