PDA

View Full Version : water waves



primo
15-03-2016, 11:34
using a plane 50x50 the waves are more precise . using the waves TBGL code by Petr as a base http://www.thinbasic.com/community/showthread.php?8150-Height-of-ground-how-to-get-this and the equation
YY = 30*(Sin(gFrameTime/600+(x^2+z^2)/10))/(x^2 + z^2 + 1.0)
we got strange interesting water waves.
9589

attached the files: plane.M15, plane.obj, plane.mtl, water_waves.tbasic

Petr Schreiber
15-03-2016, 19:44
Superhypnotic! :) Thanks for sharing!

The m15 mesh could be also created at run-time, this way:


Function BuildPlane_AsM15(modelSlot As Long, width As Long, height As Long, detailStep As Single)
Long vertexCount = (width / detailStep + 1) * (height / detailStep + 1) * 4
TBGL_m15InitModelBuffers modelSlot, vertexCount
TBGL_m15SetModelVertexcount(modelSlot, vertexCount)

Single x, z
Long index

For x = -width / 2 To width / 2 Step detailStep
For z = -height / 2 To height / 2 Step detailStep
Incr index
TBGL_m15SetVertexXYZ(modelSlot, index, x, 0, z)

Incr index
TBGL_m15SetVertexXYZ(modelSlot, index, x+detailStep, 0, z)

Incr index
TBGL_m15SetVertexXYZ(modelSlot, index, x+detailStep, 0, z+detailStep)

Incr index
TBGL_m15SetVertexXYZ(modelSlot, index, x, 0, z+detailStep)
TBGL_m15SetVertexPStop(modelSlot, index, 1)
Next
Next
TBGL_m15SetVertexRGB(modelSlot, 1, index, 255, 255, 255)
End Function


So, instead of TBGL_m15LoadModel, you just call, for example:


BuildPlane_AsM15(1, 20, 20, 0.5)



Petr

ErosOlmi
16-03-2016, 04:22
Thanks for the example primo!
Very nice also to change some parameter in formula to see wave behave.
Maybe some UI with slider to change formula params in real time.

Looking at .M15 files and their size ... maybe adding a native TBGL zLib functionality to open compressed files can save a lot of space.
TBGL_m15LoadModel maybe can accept a ZIP file from which load compressed files.
Or maybe accept M15 data from string buffer so user can load it from ZIP files using zLib functions.
Just ideas :D

Petr Schreiber
16-03-2016, 07:47
You are right Eros,

m15 needs some care -it is a format I designed on high school :D.

I am currently in process of refactoring the code in order to:
- be able to dynamically create m15 models on the fly (without the need for tbgl_m15InitModelBuffers)
- manipulate them in dotted way, like:


Dim model as m15Model
model.Vertex(1).Position.Set(1, 2, 3)

- allow the loading from memory (with the possible ZIP compression)


Petr

primo
16-03-2016, 08:50
thanks Eros , thanks Petr very much. i never saw a mesh made from rectangles, usually we see meshes from triangles. but i see you have used TBGL_m15SetVertexPStop to stop the polygon construction to a square. it seems this mesh produces a clean waves while the triangular mesh produces some chaotic waves. i have read before occasionally about these types of meshes but never saw one and i don't know yet if it can be recognized by the usual models viewers, in Other engine there is meshface(v1,v2,v3) but we can't add v4
thanks again for this jewel.