I've been trying some track editors, and made my own one, playing with bezier curves and way points, and the most difficult, joining the two ends. I made proves letting the user to make a maximun of 20 way points and automatically closing the circle and the result was ok but too complicated code as I like small codes.
One of my old codes,it gave me an idea... I thought about making the road by hand like driving a car, instead of being automatically. The idea comes from this code:
http://forum.thegamecreators.com/?m=forum_view&t=163098&b=11
So here's a small 3D road editor.
Move camera free with arrowkey and mouse
- Space to move
- inkey$ a to go left
- inkey$ d to go right
we have three size off bend
inkey$ 1, 2 , 3
-Controlkey() to see result, fron time to time, but we can continue
-m to finish and save the road as .x
autocam off
sync on
load image "carred.jpg",1
make object box 5000,1,1,2
position object 5000,20,0,50
make object box 5001,200,0,200
ghost object on 5001
position object 5001,100,0,100
fade object 5001,10
position camera 0,50,-50
point camera 0,0,0
ob=1
curva#=0.2 rem starting bend size
do
set cursor 0,0
print ob-1
print "c ",c#
print "bend ",curva#
`acelerator and left/right turning
if spacekey() then move object 5000,0.02
if inkey$()="a" and spacekey()>0 then turn object left 5000,curva#
if inkey$()="d" and spacekey()>0 then turn object right 5000,curva#
if inkey$()="u" then turn object left 5000,0.2 rem fine trimming if needed
if inkey$()="i" then turn object right 5000,0.2 rem fine trimming if needed
`bend size
if inkey$()="1" then curva#=0.1
if inkey$()="2" then curva#=0.2
if inkey$()="3" then curva#=0.3
if spacekey() then cont=cont+1
if cont=>50 then cont=0:gosub pon
control camera using arrowkeys 0,0.1,0.1
a#=wrapvalue(a#+mousemovex()/2)
cam#=wrapvalue(cam#+mousemovey()/2)
rotate camera cam#,a#,0
if leftkey() then move camera left 0.1
if rightkey() then move camera right 0.1
if controlkey()
r=r+1
if r=2 then gosub crea
else
r=0
endif
`saving road
if inkey$()="m"
make mesh from object 1,10000
save mesh "my_road.x",1
sleep 1000
endif
sync
loop
pon:
x#=object position x(5000)
y#=object position y(5000)
z#=object position z(5000)
angy#=wrapvalue(object angle y(5000))
angx#=wrapvalue(object angle x(5000))
angz#=wrapvalue(object angle z(5000))
make object box ob,0.3,0.3,0.3:rotate object ob,angx#,angy#,angz#:position object ob,x#,y#,z#:move object right ob,2:color object ob,rgb(255,255,0)
make object box ob+1,0.3,0.3,0.3:rotate object ob+1,angx#,angy#,angz#:position object ob+1,x#,y#,z#:rotate object ob+1,angx#,angy#,angz#:move object left ob+1,2:color object ob+1,rgb(0,255,0)
inc ob,2
return
crea:
if object exist(10000) then delete object 10000
make object plain 10000,100,100,1,(ob/2)
set object radius 10000,0
texture object 10000,1:scale object texture 10000,2,ob/5
set object cull 10000,0
lock vertexdata for limb 10000,0
vertices = get vertexdata vertex count()
for i = 1 to vertices-2
x# = object position x(i)
y# = object position y(i)
z# = object position z(i)
set vertexdata position i,x#,y#,z#
set vertexdata position 0,get vertexdata position x(2),0,get vertexdata position z(2) rem ocultar el p vertice cero
set vertexdata position ob,get vertexdata position x(ob-1),0,get vertexdata position z(ob-1) rem ocultar ultimo vertice
next i
return
I'm not a grumpy grandpa
