Hello Folks
Currently I work on the Insel Simulator infinite water code. My aim is to create an infinite water terrain by some kind of tile mapping.
A current demo is added in V1 code down here
The idea
Create an infinite 3d water map by using some type of tile-mapping
Image 1: The player stands in the corner, only the grey
water_tiles will be rendered.
Image 2: The player moves. All tiles will be
refreshed.
The demo code looks like this:
There are two main settings in the demo here, first, you may comment the "setobjectcolor" function for the water creation out, so it will be an full instance of the water terrain.
The Size of the water tiles is given by water_planesize=1000
If you dont want the water tiles to overlap, set the scale of the orginal object "wam" to water_planesize/10, without the +10
Here is the code:
(media+stuff attached)
setVirtualResolution(getDeviceWidth(),getDeviceHeight())
setsyncrate(60,0)
type water_planes_def
model as integer
model2 as integer
wave as integer
endtype
dim water_planes[2,2] as water_planes_def
dim player_rastpos[1] as integer
global water_planesize as integer
water_planesize=1000
SetCameraRange(1,1,3000)
SetCameraPosition(1,0,40,0)
SetCamerarotation(1,0,0,0)
AddVirtualJoystick( 1, getDeviceHeight()/10,getDeviceHeight()-getDeviceHeight()/10,getDeviceHeight()/5)
wai=loadimage("water.png")
wam=loadobject("water.obj")
setobjectimage(wam,wai,0)
setobjectscale(wam,water_planesize/10+10,10,water_planesize/10+10)
setobjectvisible(wam,0)
for i=1 to 9
if x=3
x=0
inc y
endif
rem level=createobjectplane(water_planesize,water_planesize)
level=instanceobject(wam)
setobjectvisible(level,1)
rem setobjectscale(level,10,10,10)
setobjectposition(level,water_planesize*x,0,water_planesize*y)
rem setobjectrotation(level,90,0,0)
setobjectcolor(level,200,random(0,255),random(0,255),random(0,255))
water_planes[x,y].model=level
level2=instanceobject(wam)
setobjectvisible(level2,1)
rem setobjectscale(level,10,10,10)
setobjectposition(level2,water_planesize*x,0,water_planesize*y)
setobjectrotation(level2,0,180,0)
setobjectcolor(level2,200,random(0,255),random(0,255),random(0,255))
water_planes[x,y].model2=level2
inc x
next i
Do
for x=0 to 2
for y=0 to 2
inc water_planes[x,y].wave
if water_planes[x,y].wave=>360 then water_planes[x,y].wave=0
next y
next x
rem x#,y#,z#, XAcc#,YAcc#,ZAcc#, amount,grav,col,life, sx#,sy#
fps=ScreenFPS()
//////////////// Light Movements
if x#>=500
incX#=-10.0
elseif x#<=-500
incX#=10.0
endif
x#=x#+incX#
///////////////////////////////////////////////////////////////////////////////
/// Player Movements (Camera) /////////////////
oldx#=GetCameraX(1)
oldy#=GetCameraY(1)-25.0
oldz#=GetCameraZ(1)
RotateCameraLocalY(1,5*GetVirtualJoystickX( 1 ))
MoveCameraLocalZ(1,-2*GetVirtualJoystickY( 1 ))
newx#=GetCameraX(1)
newy#=GetCameraY(1)-45.0
newz#=GetCameraZ(1)
/// Collisions ///////////////////////////////////
if ObjectSphereSlide(0,oldx#,oldy#,oldz#,newx#,newy#,newz#,19.0)>0
newx#=GetObjectRayCastSlideX(0)
newy#=GetObjectRayCastSlideY(0)
newz#=GetObjectRayCastSlideZ(0)
SetCameraPosition(1,newx#,newy#+45.0,newz#)
endif
//////////////////////////////////////////////////
handle_water_planes()
Render3D()
Render2DFront()
Swap()
if GetRawKeyPressed(27)=1 then exit
Loop
function handle_water_planes()
for x=0 to 2
for y=0 to 2
next y
next x
newx#=GetCameraX(1)
newz#=GetCameraZ(1)
rastx=val(str(((newx#)/water_planesize)))+4
rasty=val(str(((newz#)/water_planesize)))+4
remstart
if player_rastpos[0]<>rastx or player_rastpos[1]<>rasty
endif
remend
reset_water_planes()
player_rastpos[0]=rastx
player_rastpos[1]=rasty
remstart
print(rastx)
print(rasty)
print(newx#)
print(newz#)
print(newx#/water_planesize)
print(newz#/water_planesize)
remend
endfunction
function reset_water_planes()
for x=0 to 2
for y=0 to 2
rem water_planes[x,y].model
setobjectposition(water_planes[x,y].model,(water_planesize*x)+((player_rastpos[0]-5)*water_planesize),sin(water_planes[x,y].wave)*5,(water_planesize*y)+((player_rastpos[1]-5)*water_planesize))
setobjectposition(water_planes[x,y].model2,(water_planesize*x)+((player_rastpos[0]-5)*water_planesize),cos(water_planes[x,y].wave)*5,(water_planesize*y)+((player_rastpos[1]-5)*water_planesize))
next y
next x
endfunction