Thanks Santman - ill head towards that type of thing - and Janbo's idea soon
I think I will work with this
2 Examples here
This one shows a bit of invisible in a set camera range (Thanks Golelorn)
Just to show how it works
// Project: perlin
// Created: 2018-01-27
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "perlin" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
if GetDeviceName()="windows" then SetSyncRate( 6000, 0 ) // 30fps instead of 60 to save battery
if GetDeviceName()="android" then SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
// 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
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
if GetDeviceName()="windows" then SetSyncRate( 6000, 0 ) // 30fps instead of 60 to save battery
if GetDeviceName()="android" then SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
#constant playsizex#=20
#constant playsizey#=20
#constant playsizez#=4
type _textures
id // texture store
r,g,b // colors
dr,dg,db // depths (because minecraft tiles is built with rectangular different shades of the color)
texturessize
endtype
global textures as _textures[8]
type _cube
id
pivot
top
frnt
lft
bottom
rght
back
visible
endtype
global cube as _cube
// Assign the properties to build the world of Blocks 2D level
type _blocks
pivot
full
top
bottom
lft
rght
front
back
visible
x#
y#
z#
texture
endtype
global blocks as _blocks[playsizex#,playsizey#,playsizez#]
global grasshalf, grassfull, dirtfull
global cubesize#=1
definetextures()
grasshalf = CreateTextures(64,64,4,0,1) // sides
grassfull = CreateTextures(64,64,4,0,0) // top
dirtfull = CreateTextures(64,64,4,1,1) // bottom
for a=0 to playsizex#
for b=0 to playsizey#
for c=0 to playsizez#
//function buildcube(sizex#,sizey#,t,l,b,r,f,ba)
// grassfull
// Set top layer
k=random(0,1)
if k=1
if c=playsizez#
blocks[a,b,c].full=buildcube(cubesize#,grassfull,grasshalf,dirtfull,grasshalf,grasshalf,grasshalf)
else
blocks[a,b,c].full=buildcube(cubesize#,dirtfull,dirtfull,dirtfull,dirtfull,dirtfull,dirtfull)
endif
blocks[a,b,c].front = cube.frnt
blocks[a,b,c].back= cube.back
blocks[a,b,c].rght = cube.rght
blocks[a,b,c].lft = cube.lft
blocks[a,b,c].top = cube.top
blocks[a,b,c].bottom= cube.bottom
SetObjectPosition(blocks[a,b,c].full,a*cubesize#,c*cubesize#,b*cubesize#)
checkandapplyfaces(a,b,c)
endif
next
// sync()
// sleep(100)
next
next
SetCameraRange(1,.01,100)
x#=0:y#=0:z#=0
player=CreateObjectSphere(1,1,1)
cx#=random(1,playsizex#):cy#=playsizez#+cubesize#:cz#=random(1,playsizey#)
rcx#=0:rcy#=0:rcz#=0
SetObjectPosition(player,cx#,cy#,cz#)
//cx#=0:cy#=0:cz#=0#
rotatemax#=.5:camerastep#=.01
do
rcx#=0:rcy#=0:rcz#=0
// set the speed of the character depending on the current fps
if GetRawKeyState(38) then MoveObjectLocalZ(player,camerastep#)
if GetRawKeyState(40) then MoveObjectLocalZ(player,-camerastep#)
if GetRawKeyState(37) then RotateObjectLocalY(player,-camerastep#*50)
if GetRawKeyState(39) then RotateObjectLocalY(player,camerastep#*50)
//S - move down
if GetRawKeyState(83)
camerakeypressed=1
if rotatemax#>0
RotateObjectLocalX(player,rotatemax#)
dec rotatemax#,.1
else
rotatemax#=0
endif
else
if camerakeypressed=1
if rotatemax#<1
RotateObjectLocalX(player,-rotatemax#)
inc rotatemax#,.1
else
rotatemax#=1
endif
endif
endif
//S - move up
if GetRawKeyState(87)
endif
// RotateObjectLocalX(player,-camerastep#*50)
cx#=getobjectx(player)
cy#=getobjecty(player)
cz#=getobjectz(player)
setcameraposition(1,cx#,cy#,cz#)
setcamerarotation(1,0,getobjectangley(player),0)
cull_objs_behind_camera()
print("Cursors to move, WASD for camera look around")
print (str(cx#) + " + " + str(cy#) + " - " + str(cz#))
print(str(ScreenFPS()) + " - LK " + str(GetRawLastKey()))
sync()
loop
function checkandapplyfaces(x,y,z)
if x-1=>0 //check boundary
if GetObjectExists(blocks[x-1,y,z].full)=1
SetObjectVisible(blocks[x-1,y,z].rght,0)
SetObjectVisible(blocks[x,y,z].lft,0)
endif
endif
if y-1>0 //check boundary
if blocks[x,y-1,z].visible=1
SetObjectVisible(blocks[x,y-1,z].front,0)
SetObjectVisible(blocks[x,y,z].back,0)
endif
endif
endfunction
function buildcube(size#,t,l,b,r,f,ba)
//type block - 1 main grass with dirt
cube.pivot = CreateObjectSphere(.01,.01,.01)
cube.top=CreateObjectPlane(size#,size#)
SetObjectImage(cube.top,t,1)
SetObjectPosition(cube.top,0,size#/2,0)
SetObjectRotation(cube.top,90,0,0)
FixObjectToObject(cube.top,cube.pivot)
cube.bottom=CreateObjectPlane(size#,size#)
SetObjectImage(cube.bottom,b,1)
SetObjectPosition(cube.bottom,0,-size#/2,0)
SetObjectRotation(cube.bottom,90,0,0)
FixObjectToObject(cube.bottom,cube.pivot)
cube.lft = CreateObjectPlane(size#,size#)
SetObjectImage(cube.lft,l,1)
SetObjectRotation(cube.lft,0,90,0)
SetObjectPosition(cube.lft,-size#/2,0,0)
FixObjectToObject(cube.lft, cube.pivot)
cube.rght = CreateObjectPlane(size#,size#)
SetObjectImage(cube.rght,r,1)
SetObjectRotation(cube.rght,0,90,0)
SetObjectPosition(cube.rght,size#/2,0,0)
FixObjectToObject(cube.rght, cube.pivot)
cube.frnt = CreateObjectPlane(size#,size#)
SetObjectImage(cube.frnt,f,1)
SetObjectRotation(cube.frnt,0,0,0)
SetObjectPosition(cube.frnt,0,0,-size#/2)
FixObjectToObject(cube.frnt, cube.pivot)
cube.back = CreateObjectPlane(size#,size#)
SetObjectImage(cube.back,ba,1)
SetObjectRotation(cube.back,0,0,0)
SetObjectPosition(cube.back,0,0,size#/2)
FixObjectToObject(cube.back, cube.pivot)
endfunction cube.pivot
function definetextures()
// grass=createtexture(64,64,0,200,0,8)
//grass
textures[0].r=0 :textures[0].dr=50
textures[0].g=80 :textures[0].dg=100
textures[0].b=0 :textures[0].db=50
//dirt
textures[1].r=139 :textures[1].dr=20
textures[1].g=69:textures[1].dg=20
textures[1].b=19:textures[1].db=20
//goldgold=createtexture(8,8,255,215,100,1)
textures[2].r=255 :textures[2].dr=100
textures[2].g=215 :textures[2].dg=1
textures[2].b=100 :textures[2].db=1
// water=createtexture(8,8,0,0,100,1)
textures[3].r=0 :textures[3].dr=50
textures[3].g=0 :textures[3].dg=1
textures[3].b=100 :textures[3].db=1
// emeralds=createtexture(8,8,39,89,45,1)
textures[4].r=39 :textures[4].dr=5
textures[4].g=89 :textures[4].dg=5
textures[4].b=45 :textures[4].db=5
endfunction
function createtextures(sizex# as float, sizey# as float,density, toptexture, bottomtexture)
/*
fire=createtexture(8,8,255,0,0,1)
sand=createtexture(8,8,194,178,128,1)
wood=createtexture(8,8,102,51,0,1)
grassfull=createtexture(64,64,0,200,0,8)
// SetObjectImage(plane,grassfull,1)
*/
if bottomtexture=0
//do a full block of the same texture
texturecount=toptexture
swap()
for a=0 to sizex# step density
for b=0 to sizey# step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
render()
textures[texturecount].id = getimage(0,0,sizex#, sizey#)
else
// do an half block with a different texture at bottom
texturecount=toptexture
swap()
for a=0 to sizex# step density
for b=0 to sizey#/3 step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
texturecount=bottomtexture
for a=0 to sizex# step density
for b=sizey#/3 to sizey# step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
render()
textures[texturecount].id = getimage(0,0,sizex#, sizey#)
endif
sleep(0)
endfunction textures[texturecount].id
function GetObjectInFront(obj, cam)
x1# = GetCameraX(cam)
y1# = GetCameraY(cam)
z1# = GetCameraZ(cam)
dx# = GetObjectX(obj) - x1#
dy# = GetObjectY(obj) - y1#
dz# = GetObjectZ(obj) - z1#
d# = sqrt(dx#*dx# + dy#*dy# + dz#*dz#)
ux1# = dx#/d#
uy1# = dy#/d#
uz1# = dz#/d#
d# = 1000
MoveCameraLocalZ(cam, d#)
dx# = GetCameraX(cam) - x1#
dy# = GetCameraY(cam) - y1#
dz# = GetCameraZ(cam) - z1#
MoveCameraLocalZ(cam, -d#)
ux2# = dx#/d#
uy2# = dy#/d#
uz2# = dz#/d#
res# = ux1# * ux2# + uy1# * uy2# + uz1# * uz2#
angle# = acos(res#)
inFront = 0
if angle# < 30 then inFront = 1
endfunction inFront
function cull_objs_behind_camera() /// adapted to my own project but the jist is too cull all objects
for x = 0 to playsizex#
for y = 0 to playsizey#
for z= 0 to playsizez#
if GetObjectExists( blocks[x,y,z].full )
v = GetObjectInFront( blocks[x,y,z].full, 1 )
if v = 0 then SetBoxVisible( x,y,z, 0 )
if v = 1 then SetBoxVisible( x,y,z, 1 )
endif
next
next
next
endfunction
function SetBoxVisible (x,y,z, mode)
if mode=1
SetObjectVisible(blocks[x,y,z].top,1)
SetObjectVisible(blocks[x,y,z].back,1)
SetObjectVisible(blocks[x,y,z].front,1)
SetObjectVisible(blocks[x,y,z].lft,1)
SetObjectVisible(blocks[x,y,z].rght,1)
SetObjectVisible(blocks[x,y,z].back,1)
SetObjectVisible(blocks[x,y,z].bottom,1)
else
SetObjectVisible(blocks[x,y,z].top,0)
SetObjectVisible(blocks[x,y,z].back,0)
SetObjectVisible(blocks[x,y,z].front,0)
SetObjectVisible(blocks[x,y,z].lft,0)
SetObjectVisible(blocks[x,y,z].rght,0)
SetObjectVisible(blocks[x,y,z].back,0)
SetObjectVisible(blocks[x,y,z].bottom,0)
endif
checkandapplyfaces(x,y,z)
endfunction
Example 2- same code but the camera range been changed from 30 to 90-line 397 - to make it not look better but does make objects behind invisible
// Project: perlin
// Created: 2018-01-27
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "perlin" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
if GetDeviceName()="windows" then SetSyncRate( 6000, 0 ) // 30fps instead of 60 to save battery
if GetDeviceName()="android" then SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
// 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
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
if GetDeviceName()="windows" then SetSyncRate( 6000, 0 ) // 30fps instead of 60 to save battery
if GetDeviceName()="android" then SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
#constant playsizex#=20
#constant playsizey#=20
#constant playsizez#=4
type _textures
id // texture store
r,g,b // colors
dr,dg,db // depths (because minecraft tiles is built with rectangular different shades of the color)
texturessize
endtype
global textures as _textures[8]
type _cube
id
pivot
top
frnt
lft
bottom
rght
back
visible
endtype
global cube as _cube
// Assign the properties to build the world of Blocks 2D level
type _blocks
pivot
full
top
bottom
lft
rght
front
back
visible
x#
y#
z#
texture
endtype
global blocks as _blocks[playsizex#,playsizey#,playsizez#]
global grasshalf, grassfull, dirtfull
global cubesize#=1
definetextures()
grasshalf = CreateTextures(64,64,4,0,1) // sides
grassfull = CreateTextures(64,64,4,0,0) // top
dirtfull = CreateTextures(64,64,4,1,1) // bottom
for a=0 to playsizex#
for b=0 to playsizey#
for c=0 to playsizez#
//function buildcube(sizex#,sizey#,t,l,b,r,f,ba)
// grassfull
// Set top layer
k=random(0,1)
if k=1
if c=playsizez#
blocks[a,b,c].full=buildcube(cubesize#,grassfull,grasshalf,dirtfull,grasshalf,grasshalf,grasshalf)
else
blocks[a,b,c].full=buildcube(cubesize#,dirtfull,dirtfull,dirtfull,dirtfull,dirtfull,dirtfull)
endif
blocks[a,b,c].front = cube.frnt
blocks[a,b,c].back= cube.back
blocks[a,b,c].rght = cube.rght
blocks[a,b,c].lft = cube.lft
blocks[a,b,c].top = cube.top
blocks[a,b,c].bottom= cube.bottom
SetObjectPosition(blocks[a,b,c].full,a*cubesize#,c*cubesize#,b*cubesize#)
checkandapplyfaces(a,b,c)
endif
next
// sync()
// sleep(100)
next
next
SetCameraRange(1,.01,100)
x#=0:y#=0:z#=0
player=CreateObjectSphere(1,1,1)
cx#=random(1,playsizex#):cy#=playsizez#+cubesize#:cz#=random(1,playsizey#)
rcx#=0:rcy#=0:rcz#=0
SetObjectPosition(player,cx#,cy#,cz#)
//cx#=0:cy#=0:cz#=0#
rotatemax#=.5:camerastep#=.01
do
rcx#=0:rcy#=0:rcz#=0
// set the speed of the character depending on the current fps
if GetRawKeyState(38) then MoveObjectLocalZ(player,camerastep#)
if GetRawKeyState(40) then MoveObjectLocalZ(player,-camerastep#)
if GetRawKeyState(37) then RotateObjectLocalY(player,-camerastep#*50)
if GetRawKeyState(39) then RotateObjectLocalY(player,camerastep#*50)
//S - move down
if GetRawKeyState(83)
camerakeypressed=1
if rotatemax#>0
RotateObjectLocalX(player,rotatemax#)
dec rotatemax#,.1
else
rotatemax#=0
endif
else
if camerakeypressed=1
if rotatemax#<1
RotateObjectLocalX(player,-rotatemax#)
inc rotatemax#,.1
else
rotatemax#=1
endif
endif
endif
//S - move up
if GetRawKeyState(87)
endif
// RotateObjectLocalX(player,-camerastep#*50)
cx#=getobjectx(player)
cy#=getobjecty(player)
cz#=getobjectz(player)
setcameraposition(1,cx#,cy#,cz#)
setcamerarotation(1,0,getobjectangley(player),0)
cull_objs_behind_camera()
print("Cursors to move, WASD for camera look around")
print (str(cx#) + " + " + str(cy#) + " - " + str(cz#))
print(str(ScreenFPS()) + " - LK " + str(GetRawLastKey()))
sync()
loop
function checkandapplyfaces(x,y,z)
if x-1=>0 //check boundary
if GetObjectExists(blocks[x-1,y,z].full)=1
SetObjectVisible(blocks[x-1,y,z].rght,0)
SetObjectVisible(blocks[x,y,z].lft,0)
endif
endif
if y-1>0 //check boundary
if blocks[x,y-1,z].visible=1
SetObjectVisible(blocks[x,y-1,z].front,0)
SetObjectVisible(blocks[x,y,z].back,0)
endif
endif
endfunction
function buildcube(size#,t,l,b,r,f,ba)
//type block - 1 main grass with dirt
cube.pivot = CreateObjectSphere(.01,.01,.01)
cube.top=CreateObjectPlane(size#,size#)
SetObjectImage(cube.top,t,1)
SetObjectPosition(cube.top,0,size#/2,0)
SetObjectRotation(cube.top,90,0,0)
FixObjectToObject(cube.top,cube.pivot)
cube.bottom=CreateObjectPlane(size#,size#)
SetObjectImage(cube.bottom,b,1)
SetObjectPosition(cube.bottom,0,-size#/2,0)
SetObjectRotation(cube.bottom,90,0,0)
FixObjectToObject(cube.bottom,cube.pivot)
cube.lft = CreateObjectPlane(size#,size#)
SetObjectImage(cube.lft,l,1)
SetObjectRotation(cube.lft,0,90,0)
SetObjectPosition(cube.lft,-size#/2,0,0)
FixObjectToObject(cube.lft, cube.pivot)
cube.rght = CreateObjectPlane(size#,size#)
SetObjectImage(cube.rght,r,1)
SetObjectRotation(cube.rght,0,90,0)
SetObjectPosition(cube.rght,size#/2,0,0)
FixObjectToObject(cube.rght, cube.pivot)
cube.frnt = CreateObjectPlane(size#,size#)
SetObjectImage(cube.frnt,f,1)
SetObjectRotation(cube.frnt,0,0,0)
SetObjectPosition(cube.frnt,0,0,-size#/2)
FixObjectToObject(cube.frnt, cube.pivot)
cube.back = CreateObjectPlane(size#,size#)
SetObjectImage(cube.back,ba,1)
SetObjectRotation(cube.back,0,0,0)
SetObjectPosition(cube.back,0,0,size#/2)
FixObjectToObject(cube.back, cube.pivot)
endfunction cube.pivot
function definetextures()
// grass=createtexture(64,64,0,200,0,8)
//grass
textures[0].r=0 :textures[0].dr=50
textures[0].g=80 :textures[0].dg=100
textures[0].b=0 :textures[0].db=50
//dirt
textures[1].r=139 :textures[1].dr=20
textures[1].g=69:textures[1].dg=20
textures[1].b=19:textures[1].db=20
//goldgold=createtexture(8,8,255,215,100,1)
textures[2].r=255 :textures[2].dr=100
textures[2].g=215 :textures[2].dg=1
textures[2].b=100 :textures[2].db=1
// water=createtexture(8,8,0,0,100,1)
textures[3].r=0 :textures[3].dr=50
textures[3].g=0 :textures[3].dg=1
textures[3].b=100 :textures[3].db=1
// emeralds=createtexture(8,8,39,89,45,1)
textures[4].r=39 :textures[4].dr=5
textures[4].g=89 :textures[4].dg=5
textures[4].b=45 :textures[4].db=5
endfunction
function createtextures(sizex# as float, sizey# as float,density, toptexture, bottomtexture)
/*
fire=createtexture(8,8,255,0,0,1)
sand=createtexture(8,8,194,178,128,1)
wood=createtexture(8,8,102,51,0,1)
grassfull=createtexture(64,64,0,200,0,8)
// SetObjectImage(plane,grassfull,1)
*/
if bottomtexture=0
//do a full block of the same texture
texturecount=toptexture
swap()
for a=0 to sizex# step density
for b=0 to sizey# step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
render()
textures[texturecount].id = getimage(0,0,sizex#, sizey#)
else
// do an half block with a different texture at bottom
texturecount=toptexture
swap()
for a=0 to sizex# step density
for b=0 to sizey#/3 step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
texturecount=bottomtexture
for a=0 to sizex# step density
for b=sizey#/3 to sizey# step density
rr=random(1,textures[texturecount].dr)
if textures[texturecount].dr-rr >0 then colorred=textures[texturecount].r - rr
if textures[texturecount].dg-rr >0 then colorgreen=textures[texturecount].g - rr
if textures[texturecount].db-rr >0 then colorblue=textures[texturecount].b - rr
if colorred<0 then colorred=textures[texturecount].r
if colorgreen<0 then colorgreen=textures[texturecount].g
if colorblue<0 then colorblue=textures[texturecount].b
drawbox(a,b,(A+density),(B+density), MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue),MakeColor(colorred,colorgreen,colorblue), 1)
next
next
render()
textures[texturecount].id = getimage(0,0,sizex#, sizey#)
endif
sleep(0)
endfunction textures[texturecount].id
function GetObjectInFront(obj, cam)
x1# = GetCameraX(cam)
y1# = GetCameraY(cam)
z1# = GetCameraZ(cam)
dx# = GetObjectX(obj) - x1#
dy# = GetObjectY(obj) - y1#
dz# = GetObjectZ(obj) - z1#
d# = sqrt(dx#*dx# + dy#*dy# + dz#*dz#)
ux1# = dx#/d#
uy1# = dy#/d#
uz1# = dz#/d#
d# = 1000
MoveCameraLocalZ(cam, d#)
dx# = GetCameraX(cam) - x1#
dy# = GetCameraY(cam) - y1#
dz# = GetCameraZ(cam) - z1#
MoveCameraLocalZ(cam, -d#)
ux2# = dx#/d#
uy2# = dy#/d#
uz2# = dz#/d#
res# = ux1# * ux2# + uy1# * uy2# + uz1# * uz2#
angle# = acos(res#)
inFront = 0
////////CHANGE THIS////////////
if angle# < 90 then inFront = 1
endfunction inFront
function cull_objs_behind_camera() /// adapted to my own project but the jist is too cull all objects
for x = 0 to playsizex#
for y = 0 to playsizey#
for z= 0 to playsizez#
if GetObjectExists( blocks[x,y,z].full )
v = GetObjectInFront( blocks[x,y,z].full, 1 )
if v = 0 then SetBoxVisible( x,y,z, 0 )
if v = 1 then SetBoxVisible( x,y,z, 1 )
endif
next
next
next
endfunction
function SetBoxVisible (x,y,z, mode)
if mode=1
SetObjectVisible(blocks[x,y,z].top,1)
SetObjectVisible(blocks[x,y,z].back,1)
SetObjectVisible(blocks[x,y,z].front,1)
SetObjectVisible(blocks[x,y,z].lft,1)
SetObjectVisible(blocks[x,y,z].rght,1)
SetObjectVisible(blocks[x,y,z].back,1)
SetObjectVisible(blocks[x,y,z].bottom,1)
else
SetObjectVisible(blocks[x,y,z].top,0)
SetObjectVisible(blocks[x,y,z].back,0)
SetObjectVisible(blocks[x,y,z].front,0)
SetObjectVisible(blocks[x,y,z].lft,0)
SetObjectVisible(blocks[x,y,z].rght,0)
SetObjectVisible(blocks[x,y,z].back,0)
SetObjectVisible(blocks[x,y,z].bottom,0)
endif
checkandapplyfaces(x,y,z)
endfunction