I did think about this long time ago as something to achieve back in Jan last year - but thread is 90 days old, so thought start a new one
Possible Twister
// Project: chair
// Created: 2017-12-15
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "twister" )
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( 0,0, 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
plane = CreateObjectPlane(30000,30000)
SetObjectRotation(plane,90,0,0)
SetObjectPosition(plane,0,-100,0)
//SetObjectColor(plane,0,255,0,100)
SetObjectImage(plane,CreateTexture(128,128,MakeColor(0,255,0),240,255),1)
player = CreateObjectSphere(1,20,20)
type _engine
arm
roof
legs as integer[4]
camera
endtype
global enginearm as _engine
type _stairs
id
x#
y#
z#
colorred
colorgreen
colorblue
coloralpha
stepid as integer[4]
endtype
global stairs as _stairs[12]
global stairblocks as integer[48] // each stairs has 4 steps and 12 sets of stairs around the permimeter of the ride - 4 x 12 = 48 steps
global barriers as integer[ 48]
global platforms as integer[12]
global currentplatform=1
global stepsize#
global cashier as integer
global currentbarrier=1
SetCameraRange(1,1,100000)
stepsize#=800
stairs[0].id = CreateObjectSphere(30,30,30)
stairs[0].colorblue=255 : stairs[0].colorgreen = 255 : stairs[0].colorred=255
stairs[1].id = createobject(stepsize#,"stairs",4, 0, 0, 255)
stairs[1].colorred=255 : stairs[1].colorgreen=255 : stairs[1].colorblue=0 : stairs[1].coloralpha=255
for a=2 to 12
if (mod(a,2)=0)
stairs[a].colorred=0
stairs[a].colorgreen=0
stairs[a].colorblue=255
stairs[a].coloralpha=255
else
stairs[a].colorred=255
stairs[a].colorgreen=255
stairs[a].colorblue=0
stairs[a].coloralpha=255
endif
stairs[a].id = createobject(stepsize#,"stairs",4, stairs[a].colorred, stairs[a].colorgreen, stairs[a].colorblue)
next
buildcashunit()
buildengine()
ridespeed#=0 : speed#=.1
angx#=0: angy#=0:angz#=0
camx#=0: camy#=0:camz#=0
rotation#=0 : rot#=0 : enginerotation#=0:currentbarrier=1:camera#=0
do
// place the player
SetObjectPosition(player,camx#,camy#,camz#)
// Rotate the steps and platforms
x#=0: z#=0
staircount=0
rotation#=90
for a=0 to 360 step 30
// position the steps and platforms
x#=stepsize# + (stepsize#*4) * cos(a)
z#=stepsize# + (stepsize#*4) * sin(a)
y#=(rotation#) + sin(a) // turn the steps around the perimeter in 3D space = 30 degrees for 12 rotations around 360 degs
SetObjectPosition(stairs[staircount].id,x#,0,z#)
SetObjectRotation(stairs[staircount].id,450,y#,0)
SetObjectColor(stairs[staircount].id,stairs[staircount].colorred,stairs[staircount].colorgreen,stairs[staircount].colorblue,stairs[staircount].coloralpha)
// move the platforms
if staircount>0
SetObjectPosition(platforms[staircount],0,getobjecty(stairs[staircount].id)/3-(stepsize#*2)-30,-10)
SetObjectRotation(platforms[staircount],180,90,90)
endif
inc staircount
inc rotation#,-30
if staircount>12 then staircount=0
next
for a=camera# to camera#+360
// position the steps and platforms
x#=stepsize# + (stepsize#*4) * cos(a*speed#)
z#=stepsize# + (stepsize#*4) * sin(a*speed#)
y#=(rotation#) + sin(a) // turn the steps around the perimeter in 3D space = 30 degrees for 12 rotations around 360 degs
next
SetCameraPosition(1,getobjectx(enginearm.legs[1])+x#,getobjecty (enginearm.legs[1])+stepsize#+y#,getobjectz(enginearm.legs[1])-stepsize#+z#)
SetCameraRotation(1,(camera#)/100,(camera#)+y#/100,0)
inc camera#
// rotate the engine arm
dec enginerotation#,2
SetObjectPosition(enginearm.arm, stepsize#, stepsize#,stepsize#)
SetObjectRotation(enginearm.arm,0,enginerotation#,0)
//SetObjectColor(enginearm.roof, random(1,255),Random(1,255),random(1,255),255)
SetObjectPosition(cashier,-stepsize#*3,stepsize#,0)
// change barrier colours
for a=1 to 12
SetObjectColor(barriers[a],0,255,255,255/(a*12))
next
SetObjectColor(barriers[currentbarrier],255,0,0,255)
inc currentbarrier
if currentbarrier>12 then currentbarrier=1
//end of barrier colour changes
// Position pictureangz#)
inc angx#,0
inc angz#,0
inc angy#,0
inc rot#, 3
if GetRawKeyState(81) then ridespeed#=.1
if GetRawKeyState(65) then dec ridespeed#,.002
inc speed#, .001
if GetRawKeyState(38) then inc camz#,50
if GetRawKeyState(40) then dec camz#,50
if GetRawKeyState(37) then dec camx#,50
if GetRawKeyState(39) then inc camx#,50
// SetCameraLookAt(1,getobjectx(enginearm.legs[2])*100,getobjecty(enginearm.legs[2]), getobjectz(enginearm.legs[2])*100,1)
Print ("Press cursors to move around")
Print( ScreenFPS() )
print(getobjectx(enginearm.legs[1])+x#)
print(getobjecty(enginearm.legs[1])+y#)
print(getobjectz(enginearm.legs[1])+z#)
print( GetRawLastKey())
Sync()
loop
function movearmsup()
SetObjectRotation(enginearm.legs[1],GetObjectAngleX(enginearm.legs[1])-.5, GetObjectAngleY(enginearm.legs[1]), getobjectz(enginearm.legs[1]))
SetObjectRotation(enginearm.legs[2],GetObjectAngleX(enginearm.legs[2])-.5, GetObjectAngleY(enginearm.legs[2]), getobjectz(enginearm.legs[2]))
SetObjectRotation(enginearm.legs[3],GetObjectAngleX(enginearm.legs[3])-.5, GetObjectAngleY(enginearm.legs[3]), getobjectz(enginearm.legs[3]))
endfunction
function createobject(size#, seat as string, howmany, colorred, colorgreen, colorblue as integer)
if seat="stairs"
position#=0
for loops=1 to howmany
stairblocks[loops]=CreateObjectBox(size#*2, size#/2, 90)
if loops=1 then SetObjectPosition(stairblocks[loops],0,0,0)
if loops>1
SetObjectPosition(stairblocks[loops],getobjectx(stairblocks[loops-1]),getobjecty(stairblocks[loops-1])+GetObjectSizeMaxY(stairblocks[1]),getobjectz(stairblocks[loops-1])+GetObjectSizeMaxZ(stairblocks[1]))
SetObjectColor(stairblocks[loops],colorred,colorgreen,colorblue,255)
FixObjectToObject(stairblocks[loops],stairblocks[1])
endif
next
chair = stairblocks[1]
platforms[currentplatform] = CreateObjectBox(size#*4,.1,size#*2)
// SetObjectColor(platforms[currentplatform], 100,100,100,255)
SetObjectImage(platforms[currentplatform], createtexture(64,64,MakeColor(100,100,100),50,255),1)
FixObjectToObject(platforms[currentplatform],chair)
barriers[currentbarrier] = CreateObjectCylinder(200,50,50)
SetObjectRotation(barriers[currentbarrier],90,0,0)
//SetObjectImage(barriers[currentbarrier],Createtexture(64,64,MakeColor(255,0,0),100,255),1)
FixObjectToObject(barriers[currentbarrier], chair)
inc currentplatform
inc currentbarrier
// SetObjectRotation(chair,90,90,0)
endif
endfunction chair
function buildcashunit()
cashier= CreateObjectBox(100,200,100)
endfunction
function buildengine()
enginearm.arm = CreateObjectCylinder(stepsize#*2,stepsize#/2,50)
SetObjectImage(enginearm.arm,createtexture(64,64,MakeColor(255,255,0),200,255),1)
enginearm.legs[1]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
SetObjectImage(enginearm.legs[1],createtexture(64,64,MakeColor(0,100,255),200,255),1)
SetObjectRotation(enginearm.legs[1],90,0,0)
SetObjectPosition(enginearm.legs[1],0,stepsize#,stepsize#)
FixObjectToObject(enginearm.legs[1], enginearm.arm)
enginearm.camera=CreateObjectSphere(10,10,10)
FixObjectToObject(enginearm.camera, enginearm.legs[1])
enginearm.legs[2]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
SetObjectImage(enginearm.legs[2],createtexture(64,64,MakeColor(0,100,255),200,255),1)
SetObjectRotation(enginearm.legs[2],90,120,0)
SetObjectPosition(enginearm.legs[2],getobjectx(enginearm.arm)+(stepsize#),getobjecty(enginearm.arm)+stepsize#,getobjectz(enginearm.arm)-stepsize#/2)
FixObjectToObject(enginearm.legs[2], enginearm.arm)
enginearm.legs[3]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
SetObjectImage(enginearm.legs[3],createtexture(64,64,MakeColor(0,100,255),200,255),1)
SetObjectRotation(enginearm.legs[3],90,240,0)
SetObjectPosition(enginearm.legs[3],getobjectx(enginearm.arm)-(stepsize#),getobjecty(enginearm.arm)+stepsize#,getobjectz(enginearm.arm)-stepsize#/2)
FixObjectToObject(enginearm.legs[3], enginearm.arm)
//enginearm.legs[3]= CreateObjectCylinder(stepsize#*2,stepsize#/4,50)
//SetObjectImage(enginearm.legs[3],createtexture(64,64,MakeColor(0,100,255),200,255),1)
//SetObjectRotation(enginearm.legs[3],90,360,0)
//SetObjectPosition(enginearm.legs[3],stepsize#,stepsize#,stepsize#/3)
//FixObjectToObject(enginearm.legs[3], enginearm.arm)
enginearm.roof = CreateObjectCone(stepsize#,stepsize#,50)
SetObjectPosition(enginearm.roof, 0, stepsize#*1.5, 0)
SetObjectColor(enginearm.roof,255,0,0,255)
FixObjectToObject(enginearm.roof, enginearm.arm)
endfunction
// 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, alpha 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, alpha)
next
deleteimage (img)
img = CreateImageFromMemblock(memblockid)
DeleteMemblock(memblockid)
endfunction img
Possible Walzter - In progress
// 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)
ticketofficeplatform = CreateObjectCylinder(1,18,50)
SetObjectPosition(ticketofficeplatform,0,-3,0)
FixObjectToObject(ticketofficeplatform, ticketoffice)
roof = CreateObjectCone(7,61,18)
SetObjectPosition(roof,0,16,0)
type _arms
fitting
lplatform
rplatform
car
lpatformangle#
rpatformangle#
lpassengerplatform
rpassengerplatform
lights as integer[18]
endtype
arm as _arms[9]
outsidebars as integer[18]
outsidepanels as integer[18]
roofpanels as integer[18]
//panels= LoadImage("\media\panel.png")
floora = CreateObjectCone(.001,120,18)
SetObjectPosition(floora,0,-1,0)
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,30,.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
if a<7 or a>10
outsidepanels[a] = CreateObjectPlane(12,20)
else
outsidepanels[a] = CreateObjectPlane(12,5)
endif
SetObjectPosition(outsidepanels[a],5,1,0)
SetObjectRotation(outsidepanels[a],0,9,0)
SetObjectColor(outsidepanels[a],0,0,0,255)
FixObjectToObject(outsidepanels[a],outsidebars[a])
// SetObjectImage(outsidepanels[a],panels,0)
endif
endif
x#=32 * sin( a * (360/outsidebars.length))
z#=32 * cos( a * (360/outsidebars.length))
roofpanels[a] = CreateObjectPlane(11,5)
SetObjectPosition(roofpanels[a],4,13,0)
SetObjectRotation(roofpanels[a],0,8,0)
FixObjectToObject(roofpanels[a],outsidebars[a])
next
lightstart=100000
for armcount = 0 to arm.length-1
arm[armcount].fitting=CreateObjectBox(.5,.1,60)
SetObjectPosition(arm[armcount].fitting,0,10,0)
SetObjectRotation(arm[armcount].fitting,0,0,180)
// 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,-.2,a *1.5,3,255,0,0)
inc lightstart
else
SetObjectColor(arm[armcount].lights[a],0,0,255,255)
CreatePointLight(lightstart,0,-.2,a *1.5,3,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
*/
// create the waltzer turner
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)+spread#,180)
SetObjectColor(arm[armcount].lplatform,255,0,0,255)
// FixObjectToObject(arm[armcount].lplatform,lightswheel)
arm[armcount].rplatform=CreateObjectFromMeshWithColor(meshid)
emptymesh()
SetObjectRotation(arm[armcount].rplatform,0,armcount * (360 / arm.length)-spread#,180)
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)
// create the car on the platform
arm[armcount].car = CreateObjectCylinder(4,5,18)
SetObjectPosition(arm[armcount].car,0,-2,-20)
// SetObjectRotation(arm[armcount].car,0,armcount * (360 / arm.length)-spread#,180)
FixObjectToObject(arm[armcount].car,arm[armcount].lplatform)
randomcolor=random(0,3)
if randomcolor=0 then SetObjectColor(arm[armcount].car,255,0,0,255)
if randomcolor=1 then SetObjectColor(arm[armcount].car,0,255,0,255)
if randomcolor=2 then SetObjectColor(arm[armcount].car,0,0,255,255)
if randomcolor=3 then SetObjectColor(arm[armcount].car,255,255,255,255)
//FixObjectToObject(arm[armcount].car,arm[armcount].rplatform)
/*
// create the passenger floor
createMeshObjectTriangleBlock(0,0,0, -8,31,8,31,.1)
spread#=1
arm[armcount].lpassengerplatform=CreateObjectFromMeshWithColor(meshid)
SetObjectRotation(arm[armcount].lpassengerplatform,0,armcount * (360 / arm.length)+spread#,180)
SetObjectColor(arm[armcount].lpassengerplatform,0,0,200,255)
//FixObjectToObject(arm[armcount].lpassengerplatform,lightswheel)
arm[armcount].rpassengerplatform=CreateObjectFromMeshWithColor(meshid)
emptymesh()
SetObjectRotation(arm[armcount].rpassengerplatform,0,armcount * (360 / arm.length)-spread#,180)
// FixObjectToObject(arm[armcount].rpassengerplatform,lightswheel)
SetObjectColor(arm[armcount].rpassengerplatform,0,0,200,255)
SetObjectPosition(arm[armcount].lpassengerplatform,0,.2,0)
SetObjectPosition(arm[armcount].rpassengerplatform,0,.2,0)
arm[armcount].lpatformangle# =9
arm[armcount].rpatformangle# =-9
RotateObjectLocalZ(arm[armcount].lpassengerplatform,armcount*.5)
RotateObjectLocalZ(arm[armcount].rpassengerplatform,-armcount*.5)
*/
/// RotateObjectLocalZ(arm[armcount].lplatform,armcount)333
// RotateObjectLocalZ(arm[armcount].rplatform,armcount)
FixObjectToObject(arm[armcount].lplatform,arm[armcount].rplatform)
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=8 : speed#=0.5
do
//movecamerawithmouse()
// RotateObjectLocalY(lightswheel,speed#)
for armcount = 0 to arm.length-1
RotateObjectLocalY(arm[armcount].lplatform,-speed#)
RotateObjectLocalY(arm[armcount].rplatform,-speed#)
inc velocity#,.1
if angleup=0
// inc speed#,.01
RotateObjectLocalZ(arm[armcount].lplatform,-.01)
RotateObjectLocalZ(arm[armcount].rplatform,.01)
RotateObjectLocalX(arm[armcount].lplatform,-.06)
RotateObjectLocalX(arm[armcount].rplatform,.06)
endif
if angleup=1
// dec speed#,.01
RotateObjectLocalZ(arm[armcount].lplatform,.01)
RotateObjectLocalZ(arm[armcount].rplatform,-.01)
RotateObjectLocalX(arm[armcount].lplatform,.06)
RotateObjectLocalX(arm[armcount].rplatform,-.06)
endif
if velocity#>.5
velocity#=.5
angleup=1
endif
if velocity#<-.5
velocity#=-.5
angleup=0
endif
// 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=0
inc arm[armcount].lpatformangle#,.1
dec arm[armcount].rpatformangle#,.1
endif
if angleup=1
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#,.05 // C UP
if GetRawKeyPressed(40) then dec speed#,.05 // C DOWN
/*
camerax#=GetObjectx (arm[1].lplatform)
cameray#=GetObjecty (arm[1].lplatform)
cameraz#=GetObjectz (arm[1].lplatform)
camerax#=0
cameray#=5
cameraz#=-50
*/
SetCameraPosition(1,camerax#,cameray#+1,cameraz#)
// SetCameraLookAt(1,getobjectx(ticketoffice),getobjecty(ticketoffice),getobjectz(ticketoffice),0)
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
Waltzer car
// Project: waltzer car
// Created: 2018-11-10
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "waltzer car" )
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
type _cars
carfloor
carbacks as integer[180]
handle as integer[3]
handlepivot
endtype
cars as _cars[]
car as _cars
car.carfloor = CreateObjectCylinder(.4,5,18)
for a=0 to 360 / 2
car.carbacks[a] = CreateObjectCylinder(4,.2,50)
rotateamount# = 1
x#=2.5 * sin( a * (rotateamount#))
z#=2.5 * cos( a * (rotateamount#))
SetObjectPosition(car.carbacks[a],x#,2,z#)
FixObjectToObject(car.carbacks[a],car.carfloor)
SetObjectColor(car.carbacks[a],255,0,0,255)
SetObjectColor(car.carfloor,100,100,100,255)
next
// create a centre pivot for the 3 handles to attach
car.handlepivot = CreateObjectSphere(1,10,10)
SetObjectPosition(car.handlepivot,-1,.1,0)
FixObjectToObject(car.handlepivot, car.carfloor)
// create the handlebars
car.handle[0] = CreateObjectCylinder(2.5,.1,8)
SetObjectPosition(car.handle[0],1,1,1)
SetObjectRotation(car.handle[0],50,0,-30)
FixObjectToObject(car.handle[0], car.handlepivot)
car.handle[1] = CreateObjectCylinder(2.5,.1,8)
SetObjectPosition(car.handle[1],1,1,-1)
SetObjectRotation(car.handle[1],-50,0,-50)
FixObjectToObject(car.handle[1], car.handlepivot)
car.handle[2] = CreateObjectCylinder(2.9,.1,8)
SetObjectPosition(car.handle[2],2,1.5,0)
SetObjectRotation(car.handle[2],90,0,0)
FixObjectToObject(car.handle[2], car.handlepivot)
cars.insert(car)
RotateObjectLocalY(cars[0].carfloor,270)
ridestart#=0 : ridestartup=1
carspeed#=0
carvelocity#=0.9
do
// SetCameraPosition(1,getobjectx(cars[0].carfloor),getobjecty(cars[0].carfloor),getobjectz(cars[0].carfloor))
// SetCameraRotation(1,GetObjectAngleX(cars[0].carfloor)+5,carspeed#/100,GetObjectAngleZ(cars[0].carfloor)+6)
// SetCameraLookAt(1,getobjectx(cars[0].handlepivot),getobjecty(cars[0].handlepivot)+2,getobjectz(cars[0].handlepivot)-2,0)
if ridestartup<>3
RotateObjectLocalZ(cars[0].handlepivot,ridestart#)
if ridestartup=1 then inc ridestart#,.1
if ridestartup=0 then dec ridestart#,.1
if ridestart#>=3
ridestart#=3
ridestartup=0
endif
if ridestart#<=-3
ridestart#=-3
ridestartup=3
RotateObjectLocalZ(cars[0].handlepivot,-50)
endif
endif
if ridestartup=3
RotateObjectLocalY(cars[0].carfloor,carspeed#)
if random(0,100)>50
inc carspeed#,carvelocity#
else
dec carspeed#,carvelocity#
endif
if carspeed#>10
carspeed#=0
endif
if carspeed#<-10
carspeed#=-10
endif
endif
Print( ScreenFPS() )
Sync()
loop