Thanks fubarpk I'm glad you like it .
Here's un update to avoid some vertices mismatches.
// Project: road creator
// Created: 2019-01-25
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "road creator" )
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
createobjectbox(5000,1,1,2)
loadimage(1,"road.png")
createobjectbox(1001,1000,0,1000)
SetObjectColor(1001,0,255,0,0)
setobjectposition(1001,0,-3,0)
`our Sky
createobjectsphere(4000,1000,180,40)
SetObjectCullMode(4000,0)
SetObjectColorEmissive(4000,100,100,255)
cont=0
ob=1
setcameraposition(1,0,20,-40)
SetCameraLookAt(1,0,0,0,0)
do
if ( GetRawKeyState( 32 ) ) then MoveObjectLocalZ(5000,0.02)
if ( GetRawKeyState( 65 ) ) then setobjectrotation(5000,0,getobjectangley(5000)-0.12,0)
if ( GetRawKeyState( 68 ) ) then setobjectrotation(5000,0,getobjectangley(5000)+0.12,0)
if ( GetRawKeyState( 32 ) )
cont=cont+1
if cont=100
cont=0
gosub pon
endif
endif
`Create road
if ( GetRawKeyState( 17) )
r=r+1
if r=2 then gosub make
else
r=0
endif
if ( GetRawKeyState( 18) )
gosub save
sleep( 1000)
endif
gosub camara
print("Press Spacebar to go ahead")
print("Use a/d to turn left/right")
print("Press Ctrl to render chunk " )
Print("Camera Fly with cursor and mouse")
Print("When ready press Alt to save to .Obj ")
Sync()
loop
pon:
wide=3 `play with this value
createobjectbox(ob,0.2,0.2,0.2)
setobjectposition(ob,getobjectx(5000),0,getobjectz(5000))
setobjectrotation(ob,0,GetObjectAngleY(5000),0)
setobjectcolor(ob,255,0,0,0)
moveobjectlocalx(ob,wide)
createobjectbox(ob+1,0.2,0.2,0.2)
setobjectposition(ob+1,getobjectx(5000),0,getobjectz(5000))
setobjectrotation(ob+1,0,GetObjectAngleY(5000),0)
setobjectcolor(ob+1,0,0,255,0)
moveobjectlocalx(ob+1,-wide)
inc ob,2
return
make:
for i= 1 to (ob/2)-1
if GetObjectExists(i+50000) then deleteobject( i+50000)
next i
tt=50000
pan=1
pen=2
pin=3
pon=4
for i= 1 to (ob/2)-1
inc tt
pl(tt,pan,pen,pin,pon)
inc pan,2
inc pen,2
inc pin,2
inc pon,2
next
return
function pl(n,a,b,c,d)
height=3 `play with this value
if getobjectexists(a) then a1#=getobjectworldx(a)
if getobjectexists(a) then a2#=getobjectworldy(a)
if getobjectexists(a) then a3#=getobjectworldz(a)
if getobjectexists(b) then b1#=getobjectworldx(b)
if getobjectexists(b) then b2#=getobjectworldy(b)
if getobjectexists(b) then b3#=getobjectworldz(b)
if getobjectexists(c) then c1#=getobjectworldx(c)
if getobjectexists(c) then c2#=getobjectworldy(c)
if getobjectexists(c) then c3#=getobjectworldz(c)
if getobjectexists(d) then d1#=getobjectworldx(d)
if getobjectexists(d) then d2#=getobjectworldy(d)
if getobjectexists(d) then d3#=getobjectworldz(d)
createobjectbox(n,10,10,10)
setobjectimage(n,1,0)
mesh = CreateMemblockFromObjectMesh(n,1)
verts= GetMemblockInt( mesh, 0 )
SetMeshMemblockVertexPosition(mesh,2, a1#,a2#,a3#)
SetMeshMemblockVertexPosition(mesh,4, a1#,a2#,a3#)
SetMeshMemblockVertexPosition(mesh,11, a1#,a2#,a3#)
SetMeshMemblockVertexPosition(mesh,3, a1#,a2#-height,a3#)
SetMeshMemblockVertexPosition(mesh,5, a1#,a2#-height,a3#)
SetMeshMemblockVertexPosition(mesh,22, a1#,a2#-height,a3#)
SetMeshMemblockVertexPosition(mesh,0, b1#,b2#,b3#)
SetMeshMemblockVertexPosition(mesh,9, b1#,b2#,b3#)
SetMeshMemblockVertexPosition(mesh,18, b1#,b2#,b3#)
SetMeshMemblockVertexPosition(mesh,1, b1#,b2#-height,b3#)
SetMeshMemblockVertexPosition(mesh,20, b1#,b2#-height,b3#)
SetMeshMemblockVertexPosition(mesh,19, b1#,b2#-height,b3#)
SetMeshMemblockVertexPosition(mesh,6, c1#,c2#,c3#)
SetMeshMemblockVertexPosition(mesh,10, c1#,c2#,c3#)
SetMeshMemblockVertexPosition(mesh,12, c1#,c2#,c3#)
SetMeshMemblockVertexPosition(mesh,7, c1#,c2#-height,c3#)
SetMeshMemblockVertexPosition(mesh,13, c1#,c2#-height,c3#)
SetMeshMemblockVertexPosition(mesh,23, c1#,c2#-height,c3#)
SetMeshMemblockVertexPosition(mesh,8, d1#,d2#,d3#)
SetMeshMemblockVertexPosition(mesh,14, d1#,d2#,d3#)
SetMeshMemblockVertexPosition(mesh,16, d1#,d2#,d3#)
SetMeshMemblockVertexPosition(mesh,15, d1#,d2#-height,d3#)
SetMeshMemblockVertexPosition(mesh,17, d1#,d2#-height,d3#)
SetMeshMemblockVertexPosition(mesh,21, d1#,d2#-height,d3#)
`take away vertex
SetMeshMemblockVertexPosition(mesh,0, 0,0,0)
SetMeshMemblockVertexPosition(mesh,2, 0,0,0)
SetMeshMemblockVertexPosition(mesh,1, 0,0,0)
SetMeshMemblockVertexPosition(mesh,3, 0,0,0)
SetMeshMemblockVertexPosition(mesh,12, 0,0,0)
SetMeshMemblockVertexPosition(mesh,13, 0,0,0)
SetMeshMemblockVertexPosition(mesh,14, 0,0,0)
SetMeshMemblockVertexPosition(mesh,15, 0,0,0)
for t= 0 to 7
SetMeshMemblockVertexUV(mesh,t,0,0)
next
for t= 12 to 23
SetMeshMemblockVertexUV(mesh,t,0,0)
next
DeleteMemblock(1)
SetObjectMeshFromMemblock(n,1,mesh)
endfunction
camara:
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 0.1 ) // cursor up
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -0.1 ) // cursor down
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -0.1 ) // cursor iz
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 0.1 ) // cursor derecha
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if ( GetPointerState() = 1 )
fDiffX# = (GetPointerX() - startx#)/1.0
fDiffY# = (GetPointerY() - starty#)/1.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
endif
return
save:
OpenToWrite ( 1, "raw:d:\agk2\road creator\media\road.obj", 0 )
Writeline ( 1, "mtllib texture.mtl" )
`number of material
m=0
nor=0
n=0
for t= 50001 to tt
mesh = CreateMemblockFromObjectMesh(t,1)
`get object vertex quantity
verts= GetMemblockInt( mesh, 0 )
// writeline(1,"g ") //GROUP for the road we don't really need groups
`VERTEX
for i= 0 to verts -1
x#=GetMeshMemblockVertexX(mesh,i)
y#=GetMeshMemblockVertexy(mesh,i)
z#=GetMeshMemblockVertexz(mesh,i)
ox#=GetObjectWorldX(t)
oy#=GetObjectWorldY(t)
oz#=GetObjectWorldZ(t)
Writeline ( 1, " v " + str(x#+ox#)+ " "+str(y#+oy#)+ " "+str(z#+oz#))
next i
`TEXTURE VERTEX
for i= 1 to verts
uu#=GetMeshMemblockVertexU( mesh, i )
vv#=GetMeshMemblockVertexV( mesh, i )
writeline(1, " vt "+str(uu#)+" "+str(vv#))
next
`NORMALS
for i= 0 to verts -1
x#=GetMeshMemblockVertexnormalX(mesh,i)
y#=GetMeshMemblockVertexnormaly(mesh,i)
z#=GetMeshMemblockVertexnormalz(mesh,i)
Writeline ( 1, " vn " + str(x#)+ " "+str(y#)+ " "+str(z#))
next i
`FACES
inc m,1
Writeline ( 1,"usemtl Material.001")
s=0 `reseting variable s
for i= 1 to verts-4
inc s,1
if s=3
n=n+1
nor=nor+4
writeline (1, " f "+ str(n+1)+"/"+str(n+1)+"/"+str(nor) +" "+str(n) +"/"+str(n+2)+"/"+str(nor) +" "+str(n+2)+"/"+str(n)+"/"+str(nor) +" "+str(n+3)+"/"+str(n+3)+"/"+str(nor))
s=0
n=n+3
endif
next
DeleteMemblock(1)
next
CloseFile ( 1 )
return
And here an example of a road . Driving like crazy without IA .
// Project: Road
// Created: 2019-01-25
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Road" )
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
loadimage(1,"road.png")
loadobject(1,"road.Obj")
b=makecolor(10,10,10)
drawbox(0,0,5,5,b,b,b,b,1)
setobjectimage(1,1,0)
getimage(2,0,0,5,5)
SetObjectLightMap(1,2)
createobjectbox(2,2,1,3)
setobjectposition(2,3,0,0)
fixobjectpivot(2)
`camera
setcameraposition(1,30,15,-130)
SetCameraLookAt(1,0,0,5,0)
`setup lights
SetAmbientColor(15,15,15)
SetSunActive(0)
CreatePointLight(1,0,0,0,40,255,255,0)
`floor
createobjectbox(4,200,1,200)
SetObjectColor(4,0,115,0,0)
setobjectposition(4,0,-2,0)
createobjectsphere(1000,1000,10,10)
SetObjectCullMode(1000,0)
SetObjectColorEmissive(1000,60,20,0)
v=11
mesh = CreateMemblockFromObjectMesh(1,1)
verts= GetMemblockInt( mesh, 0 )
do
`Car Animation
v=v+24
if v>verts then v=11
`car coords
x#=GetMeshMemblockVertexX(mesh,v)
y#=GetMeshMemblockVertexy(mesh,v)
z#=GetMeshMemblockVertexz(mesh,v)
`coords to force car to point to
x2#=GetMeshMemblockVertexX(mesh,v+24)
y2#=GetMeshMemblockVertexy(mesh,v+24)
z2#=GetMeshMemblockVertexz(mesh,v+24)
`getting vertex ehead to place lights
x3#=GetMeshMemblockVertexX(mesh,v+48)
y3#=GetMeshMemblockVertexy(mesh,v+48)
z3#=GetMeshMemblockVertexz(mesh,v+48)
setobjectposition(2,x#,0.5,z#)
SetObjectLookAt(2,x2#,getobjecty(2),z2#,0)
setpointlightposition(1,x3#,2,z3#)
if ( GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, 1 ) // cursor up
if ( GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -1 ) // cursor down
if ( GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -1 ) // cursor iz
if ( GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, 1 ) // cursor derecha
SetCameraLookAt(1,getobjectx(2),getobjecty(2),getobjectz(2),0)
Print( ScreenFPS() )
print("use cursor")
Sync()
loop
Here the whole project if you want to test .
I'm not a grumpy grandpa