Thanks and yeah there is some cool stuff on there already.
Im fighting with myself as to how we can acomplish this one.
Maybe perhaps making use of what i have done before but much on a grand smaller scale
// Project: codingtrain-terrain
// Created: 2018-08-17
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "codingtrain-terrain" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global perlinheight=20
type _perlinmap
r,g, b, a, x, y
level
texture
noise
endtype
#constant perlinw = 512 //power of 2
#constant perlinh = 512 //power of 2
#constant perlinz = 0
global perlinmap as _perlinmap[perlinw,perlinh,perlinz]
global perlinx, perlinzz
global ang#, angx#, angy#, fDiffY#, fDiffX#,newX#,startx#, starty#, camerax#,cameray#,cameraz#,memblock, numberofcubes, inventorycubecount
global landsizex#=32
global landsizez#=32
Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype
global MeshID as Mesh
NoiseInit()
setupskyandfog()
offsetx#=0:offsety#=0
//next
meshobject = buildlandscape(offsetx#,offsety#)
SetCameraRange(1,.01,10000)
//SetObjectRotation(meshobject,0,180,0)
camerax#=landsizex#/2
cameray#=1
cameraz#=landsizez#/2
SetRawMousePosition(1024/2,768/2)
do
if GetRawKeyState(32)
DeleteObject(meshobject)
meshobject = buildlandscape(offsetx#, offsety#)
inc offsetx#,.1
inc offsety#,.1
endif
// RotateObjectLocalY(meshobject,.1)
//RotateObjectLocalX(meshobject,.1)
//RotateObjectLocalZ(meshobject,.1)
movecamerawithmouse()
if GetRawKeyPressed(38) then dec camerax#,.1
SetCameraPosition(1,camerax#,cameray#,cameraz#)
print (GetMemblockSize(memblock))
Print( ScreenFPS() )
Sync()
loop
function buildlandscape(offsetx#, offsety#)
meshID.TriangleList.length=-1
meshID.VertexList.length=-1
// build triangle strip
randomheight=3
col=255
scale#=1
noiseterrain#=12.0 // the higher this is the lower the hills and vica versa - 10-12 is a nice smooth effect
for x#=1 to landsizex#
for y#=1 to landsizez#
//noise = 255.0*noise2d(x/120.0,y/120.0)
colvertice1 = checkcolorlevels(noise2d((x#+offsetx#)/noiseterrain# ,(y#+offsety#)/noiseterrain#)*col)
colvertice2 = checkcolorlevels(noise2d(((x#+offsetx#)+1)/noiseterrain# ,((y#+offsety#)-1)/noiseterrain#)*col)
colvertice3 = checkcolorlevels(noise2d(((x#+offsetx#)+1)/noiseterrain# ,(y#+offsety#)/noiseterrain#)*col)
colvertice4 = checkcolorlevels(noise2d((x#+offsetx#)/noiseterrain# ,(y#+offsety#)/noiseterrain#)*col)
colvertice5 = checkcolorlevels(noise2d((x#+offsetx#)/noiseterrain# ,((y#+offsety#)-1)/noiseterrain#)*col)
colvertice6 = checkcolorlevels(Noise2D(((x#+offsetx#)+1)/noiseterrain# ,((y#+offsety#)-1)/noiseterrain#)*col)
AddVertex(meshID,((x#)*scale#) ,noise2d((x#+offsetx#)/noiseterrain#, (y#+offsety#)/noiseterrain#) ,y# *scale# ,0,1,0, 0,0, colvertice1)
AddVertex(meshID,((x#)+scale#)*scale# ,Noise2D(((x#+offsetx#)+scale#)/noiseterrain#, ((y#+offsety#)-scale#)/noiseterrain#) ,(y#-scale#)*scale# ,0,1,0, 0,0, colvertice2)
AddVertex(meshID,((x#)+scale#)*scale# ,Noise2D(((x#+offsetx#)+scale#)/noiseterrain#, ((y#+offsety#)/noiseterrain#)) ,y# *scale# ,0,1,0, 0,0, colvertice3)
AddVertex(meshID,((x#)*scale#) ,Noise2D((x#+offsetx#)/noiseterrain#, (y#+offsety#)/noiseterrain#) ,y# * scale# ,0,1,0, 0,0, colvertice4)
AddVertex(meshID,((x#)*scale#) ,Noise2D((x#+offsetx#)/noiseterrain#, ((y#+offsety#)-1)/noiseterrain#) ,(y#-scale#)*scale# ,0,1,0, 0,0, colvertice5)
AddVertex(meshID,((x#)+scale#)*scale# ,Noise2D(((x#+offsetx#)+scale#)/noiseterrain#, ((y#+offsety#)-1)/noiseterrain#) ,(y#-scale#)*scale# ,0,1,0, 0,0, colvertice6)
next
next
DeleteObject(meshobject)
meshobject = CreateObjectFromMeshTest(meshID)
endfunction meshobject
function checkcolorlevels(formula)
//formula = abs(formula)
if (formula<=0) then colvertice1=MakeColor(46,139,87)
if (formula>-50) then colvertice1=MakeColor(100,100,0) // sand
if (formula<-100) then colvertice1=MakeColor(0,0,70) // water
if (formula>0) then colvertice1=MakeColor(0,100,0) //
if (formula>100) then colvertice1=MakeColor(0,200,0)
if (formula>200) then colvertice1=MakeColor(255,255,255)
endfunction colvertice1
function movecamerawithmouse()
fDiffX# = (GetPointerX() - startx#)/1.0
fDiffY# = (GetPointerY() - starty#)/1.0
newX# = angx# + fDiffY#
// if ( newX# > 360 ) then newX# = 360
// if ( newX# < -360 ) then newX# = -360
// if we keep hold of the left mouse button then rotate the view otherwise the camera stays put
// so can concentrate on adding/removing blocks at that positon
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endfunction
function setupskyandfog()
// setup a skybox
SetSunActive(1)
SetSkyBoxHorizonSize(4.1,4)
SetSkyBoxHorizonColor(90,132,150)//nice horizon blue
SetSkyBoxSkyColor(0,122,193)//thunder horison thunderblue
SetSkyBoxVisible(1)
SetFogColor(155,155,155)
SetFogRange(1000,2000)
SetFogMode(0)
SetCameraRange(1,0.1,10000)
endfunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction
Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer)
t as Triangle
t.v1 = v1
t.v2 = v2
t.v3 = v3
m.TriangleList.Insert(t)
endfunction
Function CreateObjectFromMeshTest(m ref as mesh)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 2
IndexOffset = 72 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,4)
SetMemblockInt(memblock,12,36) // no color - 36 if color
SetmemblockInt(memblock,16,72)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
SetMemblockInt(memblock,60,0x08010401) // maybe one day or year in 2019 lol
SetMemblockString(memblock,64,"color") // maybe one day or year in 2019 lol
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,72+i*36,m.VertexList[i].x)
SetMemblockFloat(memblock,76+i*36,m.VertexList[i].y)
SetMemblockFloat(memblock,80+i*36,m.VertexList[i].z)
SetMemblockFloat(memblock,84+i*36,m.VertexList[i].nx)
SetMemblockFloat(memblock,88+i*36,m.VertexList[i].ny)
SetMemblockFloat(memblock,92+i*36,m.VertexList[i].nz)
SetMemblockFloat(memblock,96+i*36,m.VertexList[i].u)
SetMemblockFloat(memblock,100+i*36,m.VertexList[i].v)
SetMemblockInt(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol
next
// for i = 0 to m.TriangleList.Length
// SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
// SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
// SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
//next
id = CreateObjectFromMeshMemblock(memblock)
// DeleteMemblock(memblock)
endfunction id
// ***************************************************************************************************
// Ken Perlin's Simplex Noise 2D. AGK Version.
// Ported from Stefan Gustavson's Java implementation
// (http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf)
// 2015.02.03
// AGK reference https://forum.thegamecreators.com/thread/213532
// Thank you Thank you
#constant PN3DF2 = 0.5*(sqrt(3.0)-1.0)
#constant PN3DG2 = (3.0-sqrt(3.0))/6.0
Type sPNVECTOR
x as float
y as float
z as float
endtype
Global PNHash as integer[512]
Global PNGrad3 as sPNVECTOR[256]
Function NoiseInit()
Local n as integer, rn as integer
For n=0 To 255
PNHash[n] = n
Next n
For n=0 To 255
rn=Random(0, 255)
PNHash.swap(n,rn)
Next n
For n=0 To 255
PNHash[256 + n] = PNHash[n]
Next n
PNHash[511] = PNHash[0]
For n=0 To 15
PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0
PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0
PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0
PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0
PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1
PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1
PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1
PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1
PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1
PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1
PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1
PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1
PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0
PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0
PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1
PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1
Next n
endfunction
function Noise2D(xin as float, yin as float)
local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float
local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer
local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float
s = (xin + yin) * PN3DF2
xs = xin + s
i = floor(xs)
ys = yin + s
j = floor(ys)
t = (i + j) * PN3DG2
x0 = xin - (i - t)
y0 = yin - (j - t)
if x0>y0
i1=1
j1=0
else
i1=0
j1=1
endif
x1 = x0 - i1 + PN3DG2
y1 = y0 - j1 + PN3DG2
x2 = x0 - 1.0 + 2.0 * PN3DG2
y2 = y0 - 1.0 + 2.0 * PN3DG2
i = i && 255
j = j && 255
gi0 = PNHash[i + PNHash[j]] && 15
gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15
gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15
t0 = 0.5 - x0*x0-y0*y0
if t0<0
n0 = 0.0
else
t0 = t0 * t0
n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0)
endif
t1 = 0.5 - x1*x1-y1*y1
if t1<0
n1 = 0.0
else
t1 = t1 * t1
n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1)
endif
t2 = 0.5 - x2*x2-y2*y2
if t2<0
n2 = 0.0
else
t2 = t2 * t2
n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2)
endif
endfunction 70.0 * (n0 + n1 + n2)
/*
AddVertex(meshID,x# *scale# ,noise2d(x#,y#)*randomheight ,y# *scale# ,0,1,0, 0,0, MakeColor(0,noise2d(x#,y#)*col,0))
AddVertex(meshID,(x#+scale#)*scale# ,noise2d(x#+scale#,y#-scale#)*randomheight ,(y#-scale#)*scale# ,0,1,0, 0,0, MakeColor(0,noise2d(x#+1,y#-1)*col,0))
AddVertex(meshID,(x#+scale#)*scale# ,noise2d(x#+scale#,y#)*randomheight ,y# *scale# ,0,1,0, 0,0, MakeColor(0,noise2d(x#+1,y#)*col,0))
AddVertex(meshID,x#*scale# ,noise2d(x#,y#)*randomheight ,y# * scale# ,0,1,0, 0,0, MakeColor(0,noise2d(x#,y#)*col,0))
AddVertex(meshID,x#*scale# ,noise2d(x#,y#-1)*randomheight ,(y#-scale#)*scale# ,0,1,0, 0,0, MakeColor(0,noise2d(x#,y#-1)*col,0))
AddVertex(meshID,(x#+scale#)*scale# ,noise2d(x#+scale#,y#-scale#)*randomheight ,(y#-scale#)*scale# ,0,1,0, 0,0, MakeColor(0,Noise2D(x#+1,y#-1)*col,0))
*/
Let me have a play around
We need to build something similar to these
Either in 2D or 3D boxes with the vertexs aligned to the adjacent cubes height
Need to have a think
Tier 1 Developer