**Quote: **"Today I played with gerstner waves to distort the terrain mesh. "

Curious how that works out as i tried a parabola effect with memblocks but when i tried to animate it the frame rates went out the window

// Project: Parabola
// Created: 2018-04-06
// show all errors
SetErrorMode(2)
#constant screenWidth=1024
#constant screenHeight=768
#constant mapX=1024
#constant mapY=50
#constant mapZ=512
SetWindowSize(screenWidth,screenHeight,0)
Setvirtualresolution(screenWidth,screenHeight)
SetScissor(0,0,0,0)
SetCameraRange( 1, 0.1, 900000 )
SetGlobal3DDepth(10000)
type _heights
meshposition
height
PointX
PointZ
endtype
rem for sine cosine calculations
#constant centreX=5
#constant yPosition=1
#constant amplitude=150
//#constant speedX#=.1251
#constant WaveWidth=10
#constant frequency#=15
global TerrainImageID
global TerrainObjectID
TerrainImageID=createtexture(32,32, makecolor(0,200,0),155)
Image1=createtexture(512,512, makecolor(200,200,200),5)
//Image1=createtexture(512,512, makecolor(200,200,200),255) //creates like a grass over terrain
saveImage(image1,"height.png")
DeleteImage(image1):rem DeleteObject(mem)
// create the terrain object from a height map
TerrainObjectID=CreateObjectFromHeightMap( "height.png", mapX,mapY, mapZ, 0, 0 )
//TerrainObjectID=CreateObjectBox(mapX,1,mapZ)
SetObjectCollisionMode( TerrainObjectID, 1 ) //On needed for object raycasting
SetObjectImage( TerrainObjectID, TerrainImageID, 0 )
SetObjectTransparency(TerrainObjectID,0)
TerrainMemblock= CreateMemblockFromObjectMesh(TerrainObjectID,1)
rem num=mapX*126
maxIndices=GetMemblockInt(terrainMemblock,0)
maxX=(SQRT(maxIndices))
Dim heights[maxIndices] as _heights
meshposition=0:num=0:pointX=0:pointZ=0
for num = 0 to maxIndices //max vertices
pointX=pointX+1
if pointX>maxX
pointX=1
pointZ=PointZ+1
endif
// add to array
heights[num].height=1
heights[num].meshposition=meshposition
heights[num].PointX=pointX
heights[num].PointZ=pointZ
inc meshposition
next num
//setupArray()
//SetCameraRange(1,1,2000 )
SetCameraPosition(1, 805, 378, -41)
steps = -1
do
checkCameraMovement()
pointerState=GetRawMouseLeftState()
if GetRawMouseRightPressed()
for i = 0 to maxIndices-1 //max vertices -1
xWave#=Cos(heights[i].PointX)*(wavewidth/2)+centreX:xWave2#=Cos(heights[i].PointZ)*(wavewidth/2)+centreX
yWave#=Sin(xWave#*frequency#)*(amplitude)+yposition:yWave2#=Sin(xWave2#*frequency#)*(amplitude)+yposition
SetMeshMemblockVertexPosition(TerrainMemblock,heights[i].meshposition,GetMeshMemblockVertexX(TerrainMemblock,i),GetMeshMemblockVertexY(TerrainMemblock,i)+(yWave#+ywave2#),GetMeshMemblockVertexZ(TerrainMemblock,i))
rem used for the animation
heights[i].pointX=heights[i].pointX+1
if heights[i].pointX>maxX
heights[i].pointX=1
endif
next
SetObjectMeshFromMemblock(TerrainObjectID,1,TerrainMemblock)
endif
//endif
// show some information
Print( "FPS: " + str(ScreenFPS(),1) )
Print( "Polygons: " + str(GetPolygonsDrawn()))
print("vertices="+str(GetMemblockInt(terrainMemblock,0)))
print("Arrows move camera")
print("Click right mouse to apply sine curve")
sync()
loop
function checkCameraMovement()
if GetRawKeyState(37) then MoveCameraLocalX(1,-5) //Left
if GetRawKeyState(39) then MoveCameraLocalX(1,5) //Right
if GetRawKeyState(38) then MoveCameraLocalZ(1,5) //Forward
if GetRawKeyState(40) then MoveCameraLocalZ(1,-5) //Backward
if GetRawKeyState(87) then MoveCameraLocalY(1,-5) //87 W
if GetRawKeyState(83) then MoveCameraLocalY(1,5) //87 S
if GetRawKeyState(65) then RotateCameraLocalY(1,1)
if GetRawKeyState(68) then RotateCameraLocalY(1,-1)
// if cameray#<(blocksizey*10) then cameray#=(blocksizey*10)
if GetRawKeyPressed(27) then end
endfunction
function resetTerrain (msblk as integer)
count = GetMemblockInt( msblk ,0 )
for i = 0 to count
SetMeshMemblockVertexPosition(msblk,i,GetMeshMemblockVertexX(msblk,i),0,GetMeshMemblockVertexZ(msblk,i)) //make it flat
next
SetObjectMeshFromMemblock(TerrainObjectID,1,msblk)
Endfunction
// 102, 51, 0
// Function to create a texture
//
// Inputs - Sizex - size of the texture to create - width
// Sizey - size of the texture to create - height
// Color - is the main color of the image
// Denisity - is a the depth of the texture - the lower the value, the more detail. higher value = no detail
//
// Returns the image for the resulting texture
//
// EG. CreateTexture ( 100, 100, makecolor(0,0,255), 100)
// This could create a DEEP water effect texture?
function createtexture(sizex# as float, sizey# as float, color, density as integer)
swap()
drawbox(0,0,sizex#, sizey#, color, color,color,color, 1)
render()
img = getimage(0,0,sizex#, sizey#)
memblockid = CreateMemblockFromImage (img)
imgwidth = GetMemblockInt(memblockid, 0)
imgheight = GetMemblockInt(memblockid, 4)
size=GetMemblockSize(memblockid)
for offset=12 to size-4 step 4
r=GetMemblockByte(memblockid, offset)
g=GetMemblockByte(memblockid, offset+1)
b=GetMemblockByte(memblockid, offset+2)
a=GetMemblockByte(memblockid, offset+3)
strength=random(1,density)
SetMemblockByte (memblockid, offset, r-strength)
SetMemblockByte (memblockid, offset+1, g-strength)
SetMemblockByte (memblockid, offset+2, b-strength )
SetMemblockByte (memblockid, offset+3, a-strength)
next
deleteimage (img)
img = CreateImageFromMemblock(memblockid)
DeleteMemblock(memblockid)
endfunction img

fubar