Here is a little more with on sreen keys info
// Project: lights
// Created: 2018-11-09
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "lights" )
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( 30, 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 ang#, angx#, angy#, fDiffY#, fDiffX#,newX#,startx#, starty#, camerax#, cameray#, cameraz#
// MeshMeblock TYpes
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
// End of meshmemblock types
setupskyandfog()
lightswheel as integer
lightswheel = CreateObjectSphere(.01,.01,.01)
TicketOffice = CreateObjectBox(10,10,10)
SetObjectPosition(ticketoffice,0,5,0)
roof = CreateObjectCone(10,65,18)
SetObjectPosition(roof,0,16,0)
type _arms
fitting
lplatform
rplatform
lpatformangle#
rpatformangle#
lights as integer[18]
endtype
arm as _arms[18]
outsidebars as integer[18]
outsidepanels as integer[18]
floora = CreateObjectCone(.001,120,18)
SetObjectColor(floora,0,100,0,255)
for a=0 to outsidebars.length
// only make 17 outside bars cause the missing bar will look like an entrance area
if a<>9
outsidebars[a] = CreateObjectBox(.5,20,.5)
x#=30 * sin( a * (360/outsidebars.length))
z#=30 * cos( a * (360/outsidebars.length))
SetObjectPosition(outsidebars[a],x#,1,z#)
SetObjectRotation(outsidebars[a], 0,a * (360/outsidebars.length),0)
x#=32 * sin( a * (360/outsidebars.length))
z#=32 * cos( a * (360/outsidebars.length))
if a<>8
outsidepanels[a] = CreateObjectPlane(10,5)
SetObjectPosition(outsidepanels[a],4,1,0)
SetObjectRotation(outsidepanels[a],0,11,0)
FixObjectToObject(outsidepanels[a],outsidebars[a])
endif
endif
next
lightstart=100000
for armcount = 0 to arm.length
arm[armcount].fitting=CreateObjectBox(.5,.1,60)
SetObjectPosition(arm[armcount].fitting,0,10,0)
// create triangular platform
for a=0 to arm[armcount].lights.length
arm[armcount].lights[a] = CreateObjectSphere(.5,20,20)
SetObjectPosition(arm[armcount].lights[a],0,-.2,a *1.5)
if mod(armcount,2)
SetObjectColor(arm[armcount].lights[a],255,0,0,255)
CreatePointLight(lightstart,0,0,0,1000,255,0,0)
inc lightstart
else
SetObjectColor(arm[armcount].lights[a],0,0,255,255)
CreatePointLight(lightstart,0,.2,a,10,0,0,255)
inc lightstart
endif
SetObjectTransparency(arm[armcount].lights[a],1)
SetObjectRotation(arm[armcount].fitting,0,armcount*(360/arm.length*2),0)
FixObjectToObject(arm[armcount].lights[a],arm[armcount].fitting)
// SetObjectLightMode(arm[armcount].lights[a],0)
next
spread#=9.5
createMeshObjectTriangleBlock(0,0,0, -4.5,25,4.5,25,.1)
arm[armcount].lplatform=CreateObjectFromMeshWithColor(meshid)
SetObjectRotation(arm[armcount].lplatform,0,armcount * (360 / arm.length*2)+spread#,0)
SetObjectColor(arm[armcount].lplatform,255,255,255,255)
FixObjectToObject(arm[armcount].lplatform,lightswheel)
arm[armcount].rplatform=CreateObjectFromMeshWithColor(meshid)
emptymesh()
SetObjectRotation(arm[armcount].rplatform,0,armcount * (360 / arm.length*2)-spread#,0)
FixObjectToObject(arm[armcount].rplatform,lightswheel)
SetObjectColor(arm[armcount].rplatform,155,155,155,255)
SetObjectPosition(arm[armcount].lplatform,0,1,0)
SetObjectPosition(arm[armcount].rplatform,0,1,0)
arm[armcount].lpatformangle# =9
arm[armcount].rpatformangle# =-9
RotateObjectLocalZ(arm[armcount].lplatform,9)
RotateObjectLocalZ(arm[armcount].rplatform,-9)
FixObjectToObject(arm[armcount].lplatform,lightswheel)
FixObjectToObject(arm[armcount].rplatform,lightswheel)
next
camerax#=0
cameray#=10
cameraz#=-70
SetCameraRotation(1,0,0,0)
startx#=1024/2
starty#=768/2
//alpha=255
alpha=1 : fade=1 : angle=0 : angleup=1 : speed#=0
do
//movecamerawithmouse()
RotateObjectLocalY(lightswheel,speed#)
/*
for armcount = 0 to arm.length
RotateObjectLocalY(arm[armcount].fitting,speed#)
RotateObjectLocalZ(arm[armcount].lplatform, arm[armcount].lpatformangle#)
RotateObjectLocalZ(arm[armcount].rplatform, arm[armcount].rpatformangle#)
// SetCameraPosition(1,getobjectx(arm[armcount].rplatform),getobjecty(arm[armcount].rplatform)+4,getobjectz(arm[armcount].rplatform))
// SetCameraLookAt(1,getobjectx(ticketoffice),getobjecty(ticketoffice),getobjectz(ticketoffice),0)
print(arm[armcount].rpatformangle#)
if angleup=1
inc arm[armcount].lpatformangle#,.1
dec arm[armcount].rpatformangle#,.1
endif
if angleup=0
dec arm[armcount].lpatformangle#,.1
inc arm[armcount].rpatformangle#,.1
endif
if arm[armcount].rpatformangle#<-2
arm[armcount].lpatformangle#=2
arm[armcount].rpatformangle#=-2
angleup=0
endif
if arm[armcount].rpatformangle#>2
arm[armcount].lpatformangle#=-2
arm[armcount].rpatformangle#=2
angleup=1
endif
next
*/
if GetRawKeyState(82) then RotateCameraLocalX(1,-.1) // R
if GetRawKeyState(70) then RotateCameraLocalX(1,.1) // F
if GetRawKeyState(69) then inc cameray#,.3 // E
if GetRawKeyState(68) then dec cameray#,.3 // D
if GetRawKeyState(83) then dec cameraz#,.3 // W
if GetRawKeyState(87) then inc cameraz#,.3 // S
if GetRawKeyPressed(38) then inc speed#,.3 // C UP
if GetRawKeyPressed(40) then dec speed#,.3 // C DOWN
SetCameraPosition(1,camerax#,cameray#,cameraz#)
Print( ScreenFPS() )
Print("W - Camera forward")
Print("S - Camera backward")
Print("E - Camera tilt UP")
Print("D - Camera tilt DOWN")
Print("R - Camera move UP")
Print("D - Camera move DOWN")
Print("Cursor UP - speed up the waltzer")
Print("Cuser Down - Speed down the waltzer")
print (GetRawLastKey())
Sync()
loop
function emptymesh()
meshid.TriangleList.length=-1
MeshID.VertexList.length=-1
endfunction
function movecamerawithmouse()
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.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
// X#,Y#,Z# location of where you want it
// First vetex always in centre 0 of x,y,z
// X2# is the 2nd vertex
// X3# is the 3rd
// X4# is the 4th
// X#,Y#,Z# location of where you want it
// First vetex always in centre 0 of x,y,z
// X2# is the 2nd vertex
// X3# is the 3rd
function createMeshObjectTriangleBlock(x#,y#,z#,x2#,z2#,x3#,z3#,height#)
Color=MakeColor(255,255,255)
// bottom
AddVertex(MeshID, x#, y#, z# , 0 ,1, 0, .5,.5,Color)
AddVertex(MeshID, x3#, y#, z3# , 0 ,1, 0, 0, 0,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1, 0, 0, 1,Color)
// top
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5, .5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 0, 0,Color)
AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 0, 1,Color)
// side 1
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0, 1,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 1, 0,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 0, 0,Color)
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0,1,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 1,1,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 1,0,Color)
// side 2
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,1,Color)
AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 1,0,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 0,0,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,1,Color)
AddVertex(MeshID, x3#, y#, z3# , 0 ,1,0, 1,1,Color)
AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 1,0,Color)
// side 3
AddVertex(MeshID, x3#, y#, z3# , 0 ,1,0, 0,1,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 1,0,Color)
AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 0,0,Color)
AddVertex(MeshID, x3#, y#, z3# , 0 ,1,0, 0,1,Color)
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 1,1,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 1,0,Color)
// AddVertex(MeshID, x#, y#+height#, z3# , 0 ,1,0, .5,.5,Color)
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 CreateObjectFromMeshWithColor(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
Function CreateObjectFromMeshWithUVTexturing(m ref as mesh, texture)
DeleteMemblock(memblock)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 2
IndexOffset = 60 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,3)
SetMemblockInt(memblock,12,32) // no color - 36 if color
SetmemblockInt(memblock,16,60)
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,60+i*32,m.VertexList[i].x)
SetMemblockFloat(memblock,64+i*32,m.VertexList[i].y)
SetMemblockFloat(memblock,68+i*32,m.VertexList[i].z)
SetMemblockFloat(memblock,72+i*32,m.VertexList[i].nx)
SetMemblockFloat(memblock,76+i*32,m.VertexList[i].ny)
SetMemblockFloat(memblock,80+i*32,m.VertexList[i].nz)
SetMemblockFloat(memblock,84+i*32,m.VertexList[i].u)
SetMemblockFloat(memblock,88+i*32,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
DeleteObject(id)
id = CreateObjectFromMeshMemblock(memblock)
SetObjectImage(id,texture,0)
// if mode=1 // creates the world or it creates for other small things - like explosion blocks
// we need to keep the world chunk in memory so we can keep updating the vertices
meshmemory = memblock
// endif
// DeleteMemblock(memblock)
endfunction id
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,90000)
endfunction
Youll get the idea
Enjoy! - will provide more when got the maths right for the rotations and maybe put you on the ride too (in time)