Align Mesh on Terrain

Blitz3D Forums/Blitz3D Programming/Align Mesh on Terrain

CSauer(Posted 2003) [#1]
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.


Sunteam Software(Posted 2003) [#2]
It's difficult to say without seeing what the problem looks like on screen but if your manually aligning the object to the camera then I wouldn't parent it.


CSauer(Posted 2003) [#3]
Thanks for your answer.
Here is a example screenshot:


The rect - which I have drawn manually onto the screenshot in red - I want to create as a mesh in front of the camera and set it to a alpha of .5 to look under the water surface.

Do you know any solution?


Marcelo(Posted 2003) [#4]
Did you tried to reduce the camera near clip plane?


Rob(Posted 2003) [#5]
it will not be a rect. It can possibly have a maximum of five, not four points where the corners meet.

If you switch to mesh deformation, you can easily get the closest vertices in view and deform a polygon to match. This would be an easy thing to do. But not realistic. what you envision isn't realistic anyway.

Consider real life, does water look like a slice of cake to you? Reduce the near clip plane or simply force the player to miss this with a splash effect or move slightly below or above...


CSauer(Posted 2003) [#6]
Thanks Rob,

your are right, but I have problems to define beeing above or below. I actually use this when the player is swimming (not diving):

PositionEntity player(m%)\player_pivot,EntityX(player(m%)\player_pivot,1),(TerrainY(water,EntityX(player(m%)\player_pivot),0,EntityZ(player(m%)\player_pivot,1))+.4),EntityZ(player(m%)\player_pivot,1)

But this seems to be not exact, because I can create the above shown screenshot. I to this every time I animate the waves, so it isn't a tweening issue, I think.

I changed from water-mesh to terrain, because it was hard to define the position above water (swimming).

Therefore I want to create a look like water in a glas. It is a bit realistic if you say, players-eyes are a camera. A real eye cannot have lens-flares.

Rob, can you help me to create the function for a mesh-water version?
Thanks.