Not had much chance to work on this for while,but another couple of posts have sparked my interest in it again.It follows on from some of my other posts regarding generating media at run time and blending images to get a shader like effect without any of the overheads.
The code is made up of 3 seperate routines for ease of testing,the first is
Track Editor.
`Track Editor v1.0
`======================
`P.Parkinson
`======================
`Main Source File
randomize timer()
set display mode 1024,768,32
sync on
sync rate 60
autocam off
color backdrop 0,rgb(128,128,255)
set text font "Arial"
set text size 16
set text transparent
position camera 0,800,0
point camera 0,0,0
make_track_images()
vec1=make vector3(1)
vec2=make vector3(2)
vec3=make vector3(3)
vec4=make vector3(4)
vec5=make vector3(5)
type pointType
x as float
y as float
z as float
endtype
global maxPoints as integer=100
global numPoints as integer=4
dim points(maxPoints) as pointType
global numSections as integer=20
global maxSections as integer
global joined as integer=0
dim trackData(maxPoints*numSections,5) as float
global roll as integer=0
global roll_multiplyer as float=3.0
global editMode as integer=0
global angle#=0
dim pos(maxPoints*numSections,16)as pointType
`set up start points
for l=1 to numPoints
points(l).x=l*70-200
points(l).y=25.0
next l
create_point_objects()
position_point_objects()
`main loop
do
if joined=0 and editMode=0 then add_point()
if editMode=0 then move_points(1,numPoints)
if editMode=1 then adjust_height(1,numPoints)
maxSections=add_sections()
set_section_angles_and_positions()
add_point_numbers()
`add_section_angles()
check_for_loop_join()
check_for_change_mode()
check_for_camera_move()
if editMode=0
ink rgb(255,255,255),0
text 0,0,"Num. Control Points "+str$(numPoints)
text 0,20,"Num. Sections "+str$(maxSections-999)+" Parts Per Sector(Used For LOD) "+str$(numSections)
if joined=0 then text 0,40,"Loop Is Open And Points Can Be Added":text 0,60,"Press ' j ' To Close The Loop"
if joined=1 then text 0,40,"Loop Is Joined And Points Cant Be Added":text 0,60,"Press ' u ' To Open The Loop"
text 0,80,"You Are In Point Edit Mode,To Switch To Hight Press ' h '"
text 0,100,"LMB Add Point"
text 0,120,"RMB Move Point"
text 0,140,"SPACE To Switch On And Off Test Mode"
text 0,160,"' s ' To Save Track Data Out As A Text File"
text 0,180,"' l ' To Use Test Track Data"
endif
if editMode=1
ink rgb(255,255,255),0
text 0,0,"Num. Control Points "+str$(numPoints)
text 0,20,"Num. Sections "+str$(maxSections-999)+" Parts Per Sector(Used For LOD) "+str$(numSections)
if joined=0 then text 0,40,"Loop Is Open And Points Can Be Added":text 0,60,"Press ' j ' To Close The Loop"
if joined=1 then text 0,40,"Loop Is Joined And Points Cant Be Added":text 0,60,"Press ' u ' To Open The Loop"
text 0,80,"You Are In Hight Edit Mode,To Switch To Point Press ' p '"
text 0,100,"LMB Lower Point"
text 0,120,"RMB Raise Point"
text 0,140,"L Arrow Spin Left"
text 0,160,"R Arrow Spin Right"
text 0,180,"U Arrow Zoom In"
text 0,200,"D Arrow Zoom Out"
text 0,220,"SPACE To Switch On And Off Test Mode"
text 0,240,"' s ' To Save Track Data Out As A Text File"
text 0,260,"' l ' To Use Test Track Data"
endif
if spacekey() then free_flight()
if inkey$()="s" then save_data()
if inkey$()="l" then use_test_track_data()
if inkey$()="+" and numSections<50 then inc numSections
if inkey$()="-" and numSections>5
for l=1000 to maxSections
if object exist(l) then delete object l
next l
dec numSections
endif
sync
loop
function create_point_objects()
for l=1 to numPoints
if object exist(l)=0
make object sphere l,20
endif
color object l,rgb(255,255,0)
if l=1 then color object l,rgb(255,0,0)
if l=numPoints then color object l,rgb(0,255,0)
next l
endfunction
function position_point_objects()
for l=1 to numPoints
if object exist(l)
position object l,points(l).x,points(l).y,points(l).z
endif
next l
endfunction
function add_point()
if mouseclick()=1
if numPoints<maxPoints
inc numPoints
Pick Screen MouseX(),MouseY(),1000
psx = Get Pick Vector X() + Camera Position X()
psy = 25
psz = Get Pick Vector Z() + Camera Position Z()
points(numPoints).x=psx
points(numPoints).y=psy
points(numPoints).z=psz
create_point_objects()
position_point_objects()
while mouseclick()=1
endwhile
endif
endif
endfunction
function add_point_numbers()
ink rgb(0,0,255),0
for l=1 to numPoints
text object screen x(l)-6,object screen y(l)-6,str$(l)
next l
endfunction
function add_sections()
obj=1000
for l=1 to numPoints-3
`Fill vectors with point coordinates
set vector3 1,points(l).x,points(l).y,points(l).z
set vector3 2,points(l+1).x,points(l+1).y,points(l+1).z
set vector3 3,points(l+2).x,points(l+2).y,points(l+2).z
set vector3 4,points(l+3).x,points(l+3).y,points(l+3).z
`Loop through the sections between points
for y = 1 to numSections
`Work out point on catmull rom spline (filledVector,pointA,pointB,pointC,pointD,value (0.0 = beginning of curve, 1.0 = end of curve, 0.5 = half way down curve))
catmullrom vector3 5,1,2,3,4,1.0/numSections*y
`Draw point
if object exist(obj)
position object obj,x vector3(5),y vector3(5),z vector3(5)
else
make object box obj,20,1,1:position object obj,x vector3(5),y vector3(5),z vector3(5)
endif
inc obj
next y
next l
if joined=1
`Fill vectors with point coordinates
set vector3 1,points(numPoints-2).x,points(numPoints-2).y,points(numPoints-2).z
set vector3 2,points(numPoints-1).x,points(numPoints-1).y,points(numPoints-1).z
set vector3 3,points(numPoints).x,points(numPoints).y,points(numPoints).z
set vector3 4,points(1).x,points(1).y,points(1).z
`Loop through the sections between points
for y = 1 to numSections
`Work out point on catmull rom spline (filledVector,pointA,pointB,pointC,pointD,value (0.0 = beginning of curve, 1.0 = end of curve, 0.5 = half way down curve))
catmullrom vector3 5,1,2,3,4,1.0/numSections*y
`Draw point
if object exist(obj)
position object obj,x vector3(5),y vector3(5),z vector3(5)
else
make object box obj,20,1,1:position object obj,x vector3(5),y vector3(5),z vector3(5)
endif
inc obj
next y
`Fill vectors with point coordinates
set vector3 1,points(numPoints-1).x,points(numPoints-1).y,points(numPoints-1).z
set vector3 2,points(numPoints).x,points(numPoints).y,points(numPoints).z
set vector3 3,points(1).x,points(1).y,points(1).z
set vector3 4,points(2).x,points(2).y,points(2).z
`Loop through the sections between points
for y = 1 to numSections
`Work out point on catmull rom spline (filledVector,pointA,pointB,pointC,pointD,value (0.0 = beginning of curve, 1.0 = end of curve, 0.5 = half way down curve))
catmullrom vector3 5,1,2,3,4,1.0/numSections*y
`Draw point
if object exist(obj)
position object obj,x vector3(5),y vector3(5),z vector3(5)
else
make object box obj,20,1,1:position object obj,x vector3(5),y vector3(5),z vector3(5)
endif
inc obj
next y
`Fill vectors with point coordinates
set vector3 1,points(numPoints).x,points(numPoints).y,points(numPoints).z
set vector3 2,points(1).x,points(1).y,points(1).z
set vector3 3,points(2).x,points(2).y,points(2).z
set vector3 4,points(3).x,points(3).y,points(3).z
`Loop through the sections between points
for y = 1 to numSections
`Work out point on catmull rom spline (filledVector,pointA,pointB,pointC,pointD,value (0.0 = beginning of curve, 1.0 = end of curve, 0.5 = half way down curve))
catmullrom vector3 5,1,2,3,4,1.0/numSections*y
`Draw point
if object exist(obj)
position object obj,x vector3(5),y vector3(5),z vector3(5)
else
make object box obj,20,1,1:position object obj,x vector3(5),y vector3(5),z vector3(5)
endif
inc obj
next y
endif
dec obj
point_sections_to_next_one()
endfunction obj
function move_points(s,e)
obj=0
if mouseclick()=2
obj=pick object (mousex(),mousey(),s,e)
if obj>0
d#=get pick distance()
Pick Screen MouseX(),MouseY(),d#
psx = Get Pick Vector X() + Camera Position X()
psz = Get Pick Vector Z() + Camera Position Z()
points(obj).x=psx
points(obj).z=psz
position_point_objects()
endif
endif
endfunction
function point_sections_to_next_one()
for l=1000 to maxSections
if object exist(l) and object exist(l+1)
point object l,object position x(l+1),object position y(l+1),object position z(l+1)
endif
next l
if joined=1
if object exist(maxSections) and object exist(1000)
point object maxSections,object position x(1000),object position y(1000),object position z(1000)
endif
endif
endfunction
function add_section_angles()
ink rgb(255,0,0),0
for l=1000 to maxSections
if object exist(l)
text object screen x(l),object screen y(l)+16,str$(int(trackData(l-999,5)))
text object screen x(l),object screen y(l)+36,str$(int(trackData(l-999,4)))
endif
next l
endfunction
function set_section_angles_and_positions()
for l=1000 to maxSections
if object exist(l)
trackData(l-999,1)=object position x(l)
trackData(l-999,2)=object position y(l)
trackData(l-999,3)=object position z(l)
trackData(l-999,4)=object angle y(l)
endif
next l
set_relative_section_angle()
endfunction
function set_relative_section_angle()
for l=1000 to maxSections
if object exist(l) and object exist(l+1)
ang1#=object angle y(l)
ang2#=object angle y(l+1)
turn#=ang2#-ang1#
if turn#>180.0 then turn#=turn#-360.0
if turn#<-180.0 then turn#=turn#+360.0
trackData(l-999,5)=turn#
if roll=1
if turn#>0.0 then roll object right l,turn#*roll_multiplyer
if turn#<0.0 then roll object left l,abs(turn#*roll_multiplyer)
endif
endif
next l
if joined=1
if object exist(maxSections) and object exist(1000)
ang1#=object angle y(maxSections)
ang2#=object angle y(1000)
turn#=ang2#-ang1#
if turn#>180.0 then turn#=turn#-360.0
if turn#<-180.0 then turn#=turn#+360.0
trackData(maxSections-999,5)=turn#
if roll=1
if turn#>0.0 then roll object right maxSections,turn#*roll_multiplyer
if turn#<0.0 then roll object left maxSections,abs(turn#*roll_multiplyer)
endif
endif
endif
endfunction
function check_for_loop_join()
if inkey$()="j" and joined=0
joined=1
endif
if inkey$()="u" and joined=1
for l=1000 to maxSections
if object exist(l) then delete object l
next l
joined=0
endif
endfunction
function MouseControl(Speed as float)
xrotate camera camera angle x()+mousemovey()
yrotate camera camera angle y()+mousemovex()
if mouseclick()=1 then move camera Speed
if mouseclick()=2 then move camera (0-Speed)
r=mousemovex()
r=mousemovey()
endfunction
function free_flight()
cls
text 0,0,"Building Track"
sync
if file exist ("track poly data.txt") then delete file "track poly data.txt"
open to write 1,"track poly data.txt"
ms#=maxSections-999
ns#=numSections
write float 1,ms#
write float 1,ns#
`wait for spacekey release
while spacekey()
endwhile
`delete editable track
for l=1 to numPoints
if object exist(l) then delete object l
next l
for l=1000 to maxSections
if object exist(l) then delete object l
next l
for x=1 to 6
`smooth track
for l=1000 to maxSections-1
tot#=trackData(l-999,5)
tot#=tot#+trackData(l+1-999,5)
trackData(l-999,5)=tot#/2.2
next l
if joined=1
tot#=trackData(maxSections-999,5)
tot#=tot#+trackData(1000-999,5)
trackData(maxSections-999,5)=tot#/2.2
endif
next x
`create new track objects here
for l=1000 to maxSections
make_straight_ahead_object(l)
position object l,trackData(l-999,1)*5,trackData(l-999,2)*5,trackData(l-999,3)*5
yrotate object l,trackData(l-999,4)
next l
`make mesh from object data
obj=10000
for l=1000 to maxSections-1
make_strip(obj,l,l+1)
texture object obj,1
inc obj
next l
make_strip(obj,maxSections,1000)
texture object obj,1
inc obj
`delete objects no longer needed
for l=1000 to maxSections
if object exist(l) then delete object l
next l
close file 1
set ambient light 30
hide light 0
make light 1
set spot light 1,20,90
set light range 1,500
`movement
l=1000
do
text 0,0,"fps"+str$(screen fps())
position camera trackData(l-999,1)*5,trackData(l-999,2)*5+15,trackData(l-999,3)*5
point camera trackData(l-998,1)*5,trackData(l-998,2)*5+15,trackData(l-998,3)*5
position light 1, trackData(l-999,1)*5,trackData(l-999,2)*5+25,trackData(l-999,3)*5
point light 1, trackData(l-990,1)*5,trackData(l-990,2)*5,trackData(l-990,3)*5
sync
if spacekey() then exit
inc l
if l>maxSections then l=1000
` mouseControl(5.0)
` sync
loop
delete light 1
show light 0
set ambient light 100
`wait for spacekey release
while spacekey()
endwhile
`delete non editable track
for l=1 to maxSections
if object exist(l) then delete object l
next l
for l=10000 to obj
if object exist(l) then delete object l
next l
`create editable track
create_point_objects()
position_point_objects()
maxSections=add_sections()
`reset camera to proper mode
if editMode=0
position camera 0,800,0
point camera 0,0,0
endif
if editMode=1
position camera 0,400,-400
point camera 0,0,0
endif
endfunction
function check_for_change_mode()
if inkey$()="h" and editMode=0
editMode=1
position camera 0,400,-400
point camera 0,0,0
endif
if inkey$()="p" and editMode=1
editMode=0
position camera 0,800,0
point camera 0,0,0
endif
endfunction
function check_for_camera_move()
if editMode=1
if leftkey()
spincameraaround(-5)
endif
if rightkey()
spincameraaround(5)
endif
if upkey() then move camera 1.0
if downkey() then move camera -1.0
endif
endfunction
function SpinCameraAround( Speed#)
angle# = wrapvalue(angle# + Speed#)
xPos# =cos(angle#) * 400
yPos# =400
zPos# =sin(angle#) * 400
position camera xPos#, yPos#, zPos#
point camera 0,0,0
endfunction
function adjust_height(s,e)
obj=0
if mouseclick()=1
obj=pick object (mousex(),mousey(),s,e)
while mouseclick()=1
if obj>0
inc points(obj).y
position_point_objects()
maxSections=add_sections()
sync
endif
endwhile
endif
if mouseclick()=2
obj=pick object (mousex(),mousey(),s,e)
while mouseclick()=2
if obj>0
dec points(obj).y
position_point_objects()
maxSections=add_sections()
sync
endif
endwhile
endif
endfunction
`function make_straight_ahead_object(obj)
` make object cube obj,1
` if object exist(50000) then delete object 50000
` make object cube 50000,1
` if mesh exist(1) then delete mesh 1
` make mesh from object 1,50000
`
` add limb obj,1,1
` offset limb obj,1,40,10,0
`
` add limb obj,2,1
` offset limb obj,2,-40,10,0
`
` add limb obj,3,1
` offset limb obj,3,70,30,0
`
` add limb obj,4,1
` offset limb obj,4,-70,30,0
`
` add limb obj,5,1
` offset limb obj,5,90,70,0
`
` add limb obj,6,1
` offset limb obj,6,-90,70,0
`
` if object exist(50000) then delete object 50000
` if mesh exist(1) then delete mesh 1
`
`endfunction
function make_straight_ahead_object(obj)
make object cube obj,1
if object exist(50000) then delete object 50000
make object cube 50000,1
if mesh exist(1) then delete mesh 1
make mesh from object 1,50000
add limb obj,1,1
offset limb obj,1,50,0,0
add limb obj,2,1
offset limb obj,2,-50,0,0
add limb obj,3,1
offset limb obj,3,100,0,0
add limb obj,4,1
offset limb obj,4,-100,0,0
add limb obj,5,1
offset limb obj,5,150,0,0
add limb obj,6,1
offset limb obj,6,-150,0,0
if object exist(50000) then delete object 50000
if mesh exist(1) then delete mesh 1
endfunction
function create_memblockobject(memnum,v)
make memblock memnum,12+(36*v)
write memblock dword memnum,0,338
write memblock dword memnum,4,36
write memblock dword memnum,8,v
endfunction
function create_vertex(memnum,v,vposx#,vposy#,vposz#,color as dword,u#,v#)
write memblock float memnum,v*36+12,vposx#
write memblock float memnum,v*36+16,vposy#
write memblock float memnum,v*36+20,vposz#
write memblock dword memnum,v*36+36,color
write memblock float memnum,v*36+40,u#
write memblock float memnum,v*36+44,v#
endfunction
function set_normal(memnum,v,normalx#,normaly#,normalz#)
write memblock float memnum,v*36+24,normalx#
write memblock float memnum,v*36+28,normaly#
write memblock float memnum,v*36+32,normalz#
endfunction
function make_strip(obj_num,t1,t2)
`write track angle
write float 1,trackData(t1-999,4)
`write the bend angle
write float 1,trackData(t1-999,5)
`write track center line
write float 1,trackData(t1-999,1)*5
write float 1,trackData(t1-999,2)*5
write float 1,trackData(t1-999,3)*5
`make a memblock big enough to hold the data
memblock_size=36
if memblock exist(1) then delete memblock 1
create_memblockobject(1,memblock_size)
posx1=limb position x(t1,6)
posy1=limb position y(t1,6)
posz1=limb position z(t1,6)
posx2=limb position x(t1,4)
posy2=limb position y(t1,4)
posz2=limb position z(t1,4)
posx3=limb position x(t1,2)
posy3=limb position y(t1,2)
posz3=limb position z(t1,2)
posx4=object position x(t1)
posy4=object position y(t1)
posz4=object position z(t1)
posx5=limb position x(t1,1)
posy5=limb position y(t1,1)
posz5=limb position z(t1,1)
posx6=limb position x(t1,3)
posy6=limb position y(t1,3)
posz6=limb position z(t1,3)
posx7=limb position x(t1,5)
posy7=limb position y(t1,5)
posz7=limb position z(t1,5)
posx8=limb position x(t2,6)
posy8=limb position y(t2,6)
posz8=limb position z(t2,6)
posx9=limb position x(t2,4)
posy9=limb position y(t2,4)
posz9=limb position z(t2,4)
posx10=limb position x(t2,2)
posy10=limb position y(t2,2)
posz10=limb position z(t2,2)
posx11=object position x(t2)
posy11=object position y(t2)
posz11=object position z(t2)
posx12=limb position x(t2,1)
posy12=limb position y(t2,1)
posz12=limb position z(t2,1)
posx13=limb position x(t2,3)
posy13=limb position y(t2,3)
posz13=limb position z(t2,3)
posx14=limb position x(t2,5)
posy14=limb position y(t2,5)
posz14=limb position z(t2,5)
u#=1.0/6.0
v_num=0
create_vertex(1,v_num,posx8,posy8,posz8,rgb(255,255,255),0,0)
write float 1,posx8:write float 1,posy8:write float 1,posz8
inc v_num
create_vertex(1,v_num,posx2,posy2,posz2,rgb(255,255,255),u#*1,1)
write float 1,posx2:write float 1,posy2:write float 1,posz2
inc v_num
create_vertex(1,v_num,posx1,posy1,posz1,rgb(255,255,255),0,1)
write float 1,posx1:write float 1,posy1:write float 1,posz1
inc v_num
create_vertex(1,v_num,posx8,posy8,posz8,rgb(255,255,255),0,0)
write float 1,posx8:write float 1,posy8:write float 1,posz8
inc v_num
create_vertex(1,v_num,posx9,posy9,posz9,rgb(255,255,255),u#*1,0)
write float 1,posx9:write float 1,posy9:write float 1,posz9
inc v_num
create_vertex(1,v_num,posx2,posy2,posz2,rgb(255,255,255),u#*1,1)
write float 1,posx2:write float 1,posy2:write float 1,posz2
inc v_num
create_vertex(1,v_num,posx9,posy9,posz9,rgb(255,255,255),u#*1,0)
write float 1,posx9:write float 1,posy9:write float 1,posz9
inc v_num
create_vertex(1,v_num,posx3,posy3,posz3,rgb(255,255,255),u#*2,1)
write float 1,posx3:write float 1,posy3:write float 1,posz3
inc v_num
create_vertex(1,v_num,posx2,posy2,posz2,rgb(255,255,255),u#*1,1)
write float 1,posx2:write float 1,posy2:write float 1,posz2
inc v_num
create_vertex(1,v_num,posx9,posy9,posz9,rgb(255,255,255),u#*1,0)
write float 1,posx9:write float 1,posy9:write float 1,posz9
inc v_num
create_vertex(1,v_num,posx10,posy10,posz10,rgb(255,255,255),u#*2,0)
write float 1,posx10:write float 1,posy10:write float 1,posz10
inc v_num
create_vertex(1,v_num,posx3,posy3,posz3,rgb(255,255,255),u#*2,1)
write float 1,posx3:write float 1,posy3:write float 1,posz3
inc v_num
create_vertex(1,v_num,posx10,posy10,posz10,rgb(255,255,255),u#*2,0)
write float 1,posx10:write float 1,posy10:write float 1,posz10
inc v_num
create_vertex(1,v_num,posx4,posy4,posz4,rgb(255,255,255),u#*3,1)
write float 1,posx4:write float 1,posy4:write float 1,posz4
inc v_num
create_vertex(1,v_num,posx3,posy3,posz3,rgb(255,255,255),u#*2,1)
write float 1,posx3:write float 1,posy3:write float 1,posz3
inc v_num
create_vertex(1,v_num,posx10,posy10,posz10,rgb(255,255,255),u#*2,0)
write float 1,posx10:write float 1,posy10:write float 1,posz10
inc v_num
create_vertex(1,v_num,posx11,posy11,posz11,rgb(255,255,255),u#*3,0)
write float 1,posx11:write float 1,posy11:write float 1,posz11
inc v_num
create_vertex(1,v_num,posx4,posy4,posz4,rgb(255,255,255),u#*3,1)
write float 1,posx4:write float 1,posy4:write float 1,posz4
inc v_num
create_vertex(1,v_num,posx11,posy11,posz11,rgb(255,255,255),u#*3,0)
write float 1,posx11:write float 1,posy11:write float 1,posz11
inc v_num
create_vertex(1,v_num,posx5,posy5,posz5,rgb(255,255,255),u#*4,1)
write float 1,posx5:write float 1,posy5:write float 1,posz5
inc v_num
create_vertex(1,v_num,posx4,posy4,posz4,rgb(255,255,255),u#*3,1)
write float 1,posx4:write float 1,posy4:write float 1,posz4
inc v_num
create_vertex(1,v_num,posx11,posy11,posz11,rgb(255,255,255),u#*3,0)
write float 1,posx11:write float 1,posy11:write float 1,posz11
inc v_num
create_vertex(1,v_num,posx12,posy12,posz12,rgb(255,255,255),u#*4,0)
write float 1,posx12:write float 1,posy12:write float 1,posz12
inc v_num
create_vertex(1,v_num,posx5,posy5,posz5,rgb(255,255,255),u#*4,1)
write float 1,posx5:write float 1,posy5:write float 1,posz5
inc v_num
create_vertex(1,v_num,posx12,posy12,posz12,rgb(255,255,255),u#*4,0)
write float 1,posx12:write float 1,posy12:write float 1,posz12
inc v_num
create_vertex(1,v_num,posx6,posy6,posz6,rgb(255,255,255),u#*5,1)
write float 1,posx6:write float 1,posy6:write float 1,posz6
inc v_num
create_vertex(1,v_num,posx5,posy5,posz5,rgb(255,255,255),u#*4,1)
write float 1,posx5:write float 1,posy5:write float 1,posz5
inc v_num
create_vertex(1,v_num,posx12,posy12,posz12,rgb(255,255,255),u#*4,0)
write float 1,posx12:write float 1,posy12:write float 1,posz12
inc v_num
create_vertex(1,v_num,posx13,posy13,posz13,rgb(255,255,255),u#*5,0)
write float 1,posx13:write float 1,posy13:write float 1,posz13
inc v_num
create_vertex(1,v_num,posx6,posy6,posz6,rgb(255,255,255),u#*5,1)
write float 1,posx6:write float 1,posy6:write float 1,posz6
inc v_num
create_vertex(1,v_num,posx13,posy13,posz13,rgb(255,255,255),u#*5,0)
write float 1,posx13:write float 1,posy13:write float 1,posz13
inc v_num
create_vertex(1,v_num,posx7,posy7,posz7,rgb(255,255,255),u#*6,1)
write float 1,posx7:write float 1,posy7:write float 1,posz7
inc v_num
create_vertex(1,v_num,posx6,posy6,posz6,rgb(255,255,255),u#*5,1)
write float 1,posx6:write float 1,posy6:write float 1,posz6
inc v_num
create_vertex(1,v_num,posx13,posy13,posz13,rgb(255,255,255),u#*5,0)
write float 1,posx13:write float 1,posy13:write float 1,posz13
inc v_num
create_vertex(1,v_num,posx14,posy14,posz14,rgb(255,255,255),u#*6,0)
write float 1,posx14:write float 1,posy14:write float 1,posz14
inc v_num
create_vertex(1,v_num,posx7,posy7,posz7,rgb(255,255,255),u#*6,1)
write float 1,posx7:write float 1,posy7:write float 1,posz7
inc v_num
make mesh from memblock 1,1
make object obj_num,1,0
set object texture obj_num,2,0
set object normals obj_num
endfunction
function make_track_images()
ink rgb(50,50,50),0
box 0,0,256,256
for l=1 to 60000
col=rnd(50)+100
dot rnd(256),rnd(256),rgb(col,col,col)
next l
ink rgb(255,0,0),0
box 0,0,10,128
ink rgb(255,255,255),0
box 0,128,10,256
ink rgb(255,255,255),0
box 246,0,256,128
ink rgb(255,0,0),0
box 246,128,256,256
get image 1,0,0,256,256
ink rgb(200,200,200),0
box 0,0,256,256
ink rgb(190,190,190),0
box 1,1,255,255
ink rgb(180,180,180),0
box 2,2,254,254
ink rgb(50,50,50),0
box 3,3,253,253
for l=1 to 60000
col=rnd(50)+100
dot rnd(250)+3,rnd(250)+3,rgb(col,col,col)
next l
get image 2,0,0,256,256
endfunction
function save_data()
cls
sync
text 0,0,"Saving Track Data To Text File Ready To Cut And Paste"
sync
for l= 1 to 1000000
next l
if file exist("track data.txt") then delete file "track data.txt"
open to write 1,"track data.txt"
write string 1,"data "+str$(numPoints)+"`number of points"
write string 1,"data "+str$(joined)+"`joined"
for l=1 to numPoints
write string 1,"data "+str$(points(l).x)+","+str$(points(l).y)+","+str$(points(l).z)
next l
close file 1
endfunction
function use_test_track_data()
cls
sync
text 0,0,"Loading Test Track Data"
sync
for l=1 to 1000000
next l
restore track_data
read numPoints
read joined
for l= 1 to numPoints
read points(l).x
read points(l).y
read points(l).z
next l
for l= 1 to maxPoints
if object exist(l) then delete object l
next l
for l= 1000 to numSections*maxPoints
if object exist(l) then delete object l
next l
`create editable track
create_point_objects()
position_point_objects()
maxSections=add_sections()
`reset camera to proper mode
if editMode=0
position camera 0,800,0
point camera 0,0,0
endif
if editMode=1
position camera 0,400,-400
point camera 0,0,0
endif
endfunction
track_data:
`data 35`number of points
`data 1`joined
`data -130,0,0
`data -60,-26,0
`data 10,-32,0
`data 80,0,0
`data 172,4,41
`data 164,16,128
`data 106,16,165
`data 61,0,146
`data 29,0,85
`data -40,0,59
`data -141,0,95
`data -138,0,167
`data -76,0,224
`data 1,0,236
`data 102,0,227
`data 179,0,201
`data 229,27,162
`data 265,0,82
`data 272,21,-20
`data 241,0,-93
`data 161,28,-178
`data 108,0,-217
`data -2,27,-259
`data -91,0,-226
`data -82,-25,-164
`data 38,0,-173
`data 69,0,-97
`data 32,0,-49
`data -68,0,-68
`data -151,0,-126
`data -206,0,-176
`data -288,37,-129
`data -322,29,5
`data -260,0,75
`data -211,0,34
data 27`number of points
data 1`joined
data -185,25,27
data -64,17,-19
data 81,19,14
data 221,25,-33
data 363,25,13
data 380,25,141
data 242,25,210
data 94,25,175
data -64,25,153
data -167,40,266
data -87,45,388
data 76,25,385
data 255,33,337
data 401,50,258
data 489,25,123
data 486,25,-37
data 435,16,-184
data 294,25,-255
data 192,33,-372
data 41,34,-360
data -123,18,-235
data -297,25,-186
data -465,33,-197
data -544,40,-93
data -520,38,70
data -405,31,153
data -266,18,138
When running press the "l" key to load in a bsaic map to get you started,notice there are no sharp bends and ive kept the distance between the points roughly even.
Press the space bar to switch to test mode and save out the track data ready for the next stage.
Landscape Editor.
`%ProjectTitle%
`======================
`P.Parkinson
`======================
`Main Source File
set display mode 1024,768,32
sync on
sync rate 60
autocam off
color backdrop 0, rgb(150,150,255)
set text font "Arial"
set text size 12
set bitmap format 21
set text transparent
position camera 200,1600,-1600
point camera 0,0,0
set ambient light 0
position light 0,2000,2000,2000
set light range 0,5000
set camera range 10,20000
sync
type pointType
x as float
y as float
z as float
endtype
global texture_size as integer=2048
global gridSizeX as integer=256
global gridSizeZ as integer=256
global tileSize as integer=32
dim land(gridSizeX,gridSizeZ) as pointType
dim temp(4096,4096) as float
dim track_data(36) as pointType
dim tex(texture_size,texture_size)
`***********************************
cls
text 0,0," Making Landscape Texture"
sync
make_landscape_texture()
`***********************************
cls
text 0,0," Making Track Texture"
sync
make_track_textures()
`***********************************
cls
text 0,0," Load And Build Track"
sync
t=load_track_data(1000)
`***********************************
cls
text 0,0," Build Fractal Data For Landscape"
sync
hmap_fractal(256,0.001)
`transfer ´temp´ array to ´land´ array
for z=0 to gridSizeZ
for x=0 to gridSizeX
land(x,z).x = x*tileSize-(gridSizeX*tileSize/2):land(x,z).y=temp(x,z):land(x,z).z = z*tileSize-(gridSizeZ*tileSize/2)
next x
next z
`************************************
cls
text 0,0," Model Landscape Data To Track Data"
sync
sculpt_landscape(5)
`************************************
cls
text 0,0," Building Track Meshes"
sync
l=build_land()
`************************************
save_land()
make_sky(10000)
cls
`*******main loop********
do
text 0,0,"Done "+str$(l)+" Landscape objects"
text 0,15,"Done "+str$(t-999)+" Track objects"
text 0,30,"Screen FPS "+str$(screen fps())
mousecontrol(10.0)
sync
loop
function MouseControl(Speed as float)
xrotate camera camera angle x()+mousemovey()
yrotate camera camera angle y()+mousemovex()
if mouseclick()=1 then move camera Speed
if mouseclick()=2 then move camera (0-Speed)
r=mousemovex()
r=mousemovey()
endfunction
function load_track_data(obj)
u#=1.0/6.0
open to read 1,"track poly data.txt"
read float 1,numPolys#
read float 1,st#
memblock_size=36
if memblock exist(10) then delete memblock 10
create_memblockobject(10,memblock_size)
for l=1 to int(numPolys#)
read float 1,ang#
read float 1,turn#
read float 1,x#:read float 1,y#:read float 1,z#
v_num=0
for p=1 to 36
read float 1,x#:read float 1,y#:read float 1,z#
track_data(p).x=x#:track_data(p).y=y#+1.0:track_data(p).z=z#
next p
for p=0 to 5
create_vertex(10,v_num,track_data(1+p*6).x,track_data(1+p*6).y,track_data(1+p*6).z,rgb(255,255,255),p*u#,0):inc v_num
create_vertex(10,v_num,track_data(2+p*6).x,track_data(2+p*6).y,track_data(2+p*6).z,rgb(255,255,255),(p+1)*u#,1):inc v_num
create_vertex(10,v_num,track_data(3+p*6).x,track_data(3+p*6).y,track_data(3+p*6).z,rgb(255,255,255),p*u#,1):inc v_num
create_vertex(10,v_num,track_data(4+p*6).x,track_data(4+p*6).y,track_data(4+p*6).z,rgb(255,255,255),p*u#,0):inc v_num
create_vertex(10,v_num,track_data(5+p*6).x,track_data(5+p*6).y,track_data(5+p*6).z,rgb(255,255,255),(p+1)*u#,0):inc v_num
create_vertex(10,v_num,track_data(6+p*6).x,track_data(6+p*6).y,track_data(6+p*6).z,rgb(255,255,255),(p+1)*u#,1):inc v_num
next p
make mesh from memblock 1,10
make object obj,1,0
set object texture obj,2,0
set object normals obj
set object transparency obj,1
if l<5
texture object obj,2`adds start/finish line chequers
else
texture object obj,1
endif
set object transparency obj,2
SC_setUpComplexObject obj,0,2
inc obj
next l
sync
close file 1
endfunction obj
function create_memblockobject(memnum,v)
make memblock memnum,12+(36*v)
write memblock dword memnum,0,338
write memblock dword memnum,4,36
write memblock dword memnum,8,v
endfunction
function create_vertex(memnum,v,vposx#,vposy#,vposz#,color as dword,u#,v#)
write memblock float memnum,v*36+12,vposx#
write memblock float memnum,v*36+16,vposy#
write memblock float memnum,v*36+20,vposz#
write memblock dword memnum,v*36+36,color
write memblock float memnum,v*36+40,u#
write memblock float memnum,v*36+44,v#
endfunction
function set_normal(memnum,v,normalx#,normaly#,normalz#)
write memblock float memnum,v*36+24,normalx#
write memblock float memnum,v*36+28,normaly#
write memblock float memnum,v*36+32,normalz#
endfunction
function build_land()
memblock_size=20*20*6
if memblock exist(10) then delete memblock 10
create_memblockobject(10,memblock_size)
obj=1
uv#=1.0/128.0
for lz=0 to 11
for lx=0 to 11
v_num=0
for z=lz*20 to (lz+1)*20-1
for x=lx*20 to (lx+1)*20-1
create_vertex(10,v_num,land(x,z).x,land(x,z).y,land(x,z).z,rgb(255,255,255),x*uv#,z*uv#):inc v_num
create_vertex(10,v_num,land(x,z+1).x,land(x,z+1).y,land(x,z+1).z,rgb(255,255,255),x*uv#,(z+1)*uv#):inc v_num
create_vertex(10,v_num,land(x+1,z+1).x,land(x+1,z+1).y,land(x+1,z+1).z,rgb(255,255,255),(x+1)*uv#,(z+1)*uv#):inc v_num
create_vertex(10,v_num,land(x,z).x,land(x,z).y,land(x,z).z,rgb(255,255,255),x*uv#,z*uv#):inc v_num
create_vertex(10,v_num,land(x+1,z+1).x,land(x+1,z+1).y,land(x+1,z+1).z,rgb(255,255,255),(x+1)*uv#,(z+1)*uv#):inc v_num
create_vertex(10,v_num,land(x+1,z).x,land(x+1,z).y,land(x+1,z).z,rgb(255,255,255),(x+1)*uv#,z*uv#):inc v_num
next x
next z
make mesh from memblock 1,10
make object obj,1,0
set object texture obj,2,0
set object normals obj
texture object obj,11
inc obj
next lx
next lz
endfunction obj
function save_land()
if file exist("land data.txt")
delete file "land data.txt"
endif
open to write 1,"land data.txt"
for z=0 to gridSizeZ
for x=0 to gridSizeX
write float 1,land(x,z).x
write float 1,land(x,z).y
write float 1,land(x,z).z
next x
next z
endfunction
function Distance3D( x1# as float, y1# as float, z1# as float, x2# as float, y2# as float, z2# as float )
distance# = Abs(Sqrt((x1# - x2#) ^ 2 + (y1# - y2#) ^ 2 + (z1# - z2#) ^ 2))
endfunction distance#
function PointInTriangle( x as float, y as float, x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float)
x1=x1*1.01
y1=y1*1.01
x2=x2*1.01
y2=y2*1.01
x3=x3*1.01
y3=y3*1.01
local AB as float
local BC as float
local CA as float
AB = ((y-y1)*(x2-x1)) - ((x-x1)*(y2-y1))
BC = ((y-y2)*(x3-x2)) - ((x-x2)*(y3-y2))
if AB * BC <= 0 then exitfunction 0
CA = (y-y3)*(x1-x3) - (x-x3)*(y1-y3)
if BC * CA <= 0 then exitfunction 0
endfunction 1
function make_track_textures()
create bitmap 1,256,256
set current bitmap 1
ink rgb(50,50,50),0
box 0,0,256,256
for l=1 to 60000
col=rnd(50)+100
dot rnd(256),rnd(256),rgb(col,col,col)
next l
ink rgb(255,0,0),0
box 50,0,60,128
ink rgb(255,255,255),0
box 50,128,60,256
ink rgb(255,255,255),0
box 196,0,206,128
ink rgb(255,0,0),0
box 196,128,206,256
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to 256
al=40
for x=1 to 256
if x<30 then al=al+10
if al>200 then al=200
if x>226 then al=al-10
if al<50 then al=50
inc pos
inc pos
inc pos
write memblock byte 1,pos,al
inc pos
next x
next y
make image from memblock 1,1
delete memblock 1
save image "track.bmp",1
create bitmap 1,256,256
set current bitmap 1
ink rgb(50,50,50),0
box 0,0,256,256
for l=1 to 60000
col=rnd(50)+100
dot rnd(256),rnd(256),rgb(col,col,col)
next l
for x=0 to 256 step 50
ink rgb(255,255,255),0
box x,0,x+25,128
box x+25,128,x+50,256
next x
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to 256
al=40
for x=1 to 256
if x<30 then al=al+10
if al>255 then al=255
if x>226 then al=al-10
if al<50 then al=50
inc pos
inc pos
inc pos
write memblock byte 1,pos,al
inc pos
next x
next y
make image from memblock 2,1
delete memblock 1
save image "start.bmp",2
cls
endfunction
function make_sprite(r#,g#,b#,image_num)
if bitmap exist(1) then delete bitmap 1
create bitmap 1,128,128
set current bitmap 1
set image colorkey 0,0,0
for l=1 to 1000
x=rnd(128)
z=rnd(128)
dot x,z,rgb(r#,g#,b#)
next l
for l=1 to 1000
x=rnd(128)
z=rnd(128)
col#=rnd(30)
r2#=r#+col#
if r2#>255 then r2#=255
if r2#<0 then r2#=0
g2#=g#+col#
if g2#>255 then g2#=255
if g2#<0 then g2#=0
b2#=b#+col#
if b2#>255 then b2#=255
if b2#<0 then b2#=0
dot x,z,rgb(r2#,g2#,b2#)
next l
for l=1 to 100
x=rnd(128)
z=rnd(128)
col#=rnd(50)+50
r2#=col#
g2#=col#
b2#=col#
dot x,z,rgb(r2#,g2#,b2#)
next l
get image image_num,0,0,128,128
set current bitmap 0
endfunction
function hmap_fractal(size,n#)
`thanks to who ever did this code,had it so long,and it never fails to work for me
av as float
rn as float:rn=n#
s=size ` units and array size; must be a power of 2
dim a(s,s,1) as float
` do the diamond square algorithm
` paying special attention to wrapping around
c=s
repeat
for z=0 to (s-c) step c
for x=0 to (s-c) step c
av=(a(x,z)+a(x+c,z)+a(x,z+c)+a(x+c,z+c))/4.0
av=av+((-50+rnd(100))/rn)
a(x+(c/2),z+(c/2))=av
next x
next z
w=1
for z=0 to (s-(c/2)) step (c/2)
for x=0 to (s-c) step c
x2=x+(w*(c/2))
av=a(x2,z+(c/2))+a(x2+(c/2),z)
if x2=0
av=av+a(s-(c/2),z)
else
av=av+a(x2-(c/2),z)
endif
if z=0
av=av+a(x2,s-(c/2))
else
av=av+a(x2,z-(c/2))
endif
av=av/4.0
av=av+((-50+rnd(100))/rn)
a(x2,z,0)=av
if x2=0 then a(s,z,0)=av
if z=0 then a(x2,s,0)=av
next x
w=1-w
next z
c=c/2
rn=rn*2.0
until c < 2
`find min/max height
minh#=5000:maxh#=-5000
for z=0 to size
for x=0 to size
a(z,x,0)=a(z,x,0)
if a(x,z,0)<minh# then minh#=a(x,z,0)
if a(x,z,0)>maxh# then maxh#=a(x,z,0)
next x
next z
`update data array and raise it up so the lowest point is>=0 and find new max height then set all heights to 0 to 255 range
maxh#=-50000
for z=0 to size
for x=0 to size
av=a(x,z,0)
if minh#<0 then temp(x,z) = av+abs(minh#)
if minh#>=0 then temp(x,z) = av-minh#
if temp(x,z)>maxh# then maxh#=temp(x,z)
next x
next z
if maxh#>255
newh#=255.0/maxh#
for z=0 to size
for x=0 to size
temp(x,z)=temp(x,z)*newh#
next x
next z
endif
endfunction
function sculpt_landscape(smt)
`smooth the result and sculpt to track position
for l=1 to smt
for z=1 to gridSizeZ-1
for x=1 to gridSizeX-1
tot#=0
tot#=tot#+land(x,z).y
tot#=tot#+land(x+1,z).y
tot#=tot#+land(x-1,z).y
tot#=tot#+land(x,z+1).y
tot#=tot#+land(x,z-1).y
tot#=tot#/5.0
land(x,z).y=tot#
hit=SC_rayCast(0,land(x,z).x,1000,land(x,z).z,land(x,z).x,-1000,land(x,z).z,0)
if hit>0
land(x,z).y=SC_getStaticCollisionY ()-1.0
endif
next x
next z
next smt
endfunction
function make_landscape_texture()
`sand grass rock
make_sprite(235,180,50,1000):sprite 1,-128,-128,1000
make_sprite(205,128,50,1001):sprite 2,-128,-128,1001
make_sprite(128,50,50,1002):sprite 3,-128,-128,1002
make_sprite(0,200,0,1003):sprite 4,-128,-128,1003
make_sprite(0,128,0,1004):sprite 5,-128,-128,1004
make_sprite(0,50,0,1005):sprite 6,-128,-128,1005
make_sprite(30,30,30,1006):sprite 7,-128,-128,1006
make_sprite(70,70,70,1007):sprite 8,-128,-128,1007
make_sprite(120,120,120,1008):sprite 9,-128,-128,1008
make_sprite(170,170,170,1009):sprite 10,-128,-128,1009
make_sprite(220,220,220,1010):sprite 11,-128,-128,1010
make_sand_texture(1,texture_size)
make_grass_texture(2,texture_size)
make_rock_texture(3,texture_size)
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,255
inc pos
next x
next y
make image from memblock 4,1
delete memblock 1
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,255
inc pos
next x
next y
make image from memblock 5,1
delete memblock 1
blend_images(1,2,4,10,texture_size,texture_size)
blend_images(10,3,5,11,texture_size,texture_size)
save image "merged.bmp",11
delete image 1
delete image 2
delete image 3
delete image 4
delete image 5
delete image 10
endfunction
function make_sand_texture(img,size)
if bitmap exist(img) then delete bitmap img
create bitmap img,size,size
set current bitmap img
for z=0 to size step 8
for x= 0 to size step 8
num=rnd(100)
if num<33
rotate sprite 1,rnd(90)
paste sprite 1,x,z
endif
if num>=33 and num<66
rotate sprite 2,rnd(90)
paste sprite 2,x,z
endif
if num>=66
rotate sprite 3,rnd(90)
paste sprite 3,x,z
endif
next x
next z
get image img,0,0,size,size
set current bitmap 0
delete bitmap img
endfunction
function make_grass_texture(img,size)
if bitmap exist(img) then delete bitmap img
create bitmap img,size,size
set current bitmap img
for z=0 to size step 8
for x= 0 to size step 8
num=rnd(100)
if num<33
rotate sprite 4,rnd(90)
paste sprite 4,x,z
endif
if num>=33 and num<66
rotate sprite 5,rnd(90)
paste sprite 5,x,z
endif
if num>=66
rotate sprite 6,rnd(90)
paste sprite 6,x,z
endif
next x
next z
get image img,0,0,size,size
set current bitmap 0
delete bitmap img
endfunction
function make_rock_texture(img,size)
if bitmap exist(img) then delete bitmap img
create bitmap img,size,size
set current bitmap img
for z=0 to size step 8
for x= 0 to size step 8
num=rnd(100)
if num<33
rotate sprite 7,rnd(90)
paste sprite 7,x,z
endif
if num>=33 and num<66
rotate sprite 8,rnd(90)
paste sprite 8,x,z
endif
if num>=66
rotate sprite 9,rnd(90)
paste sprite 9,x,z
endif
next x
next z
get image img,0,0,size,size
set current bitmap 0
delete bitmap img
endfunction
function blend_Images( iUpper, iLower, iAlpha, iResult, Width, Height)
`Dont know the author of this but thanks for great piece of code
Local Percent as float
Local UpperBlue as byte
Local UpperGreen as byte
Local UpperRed as byte
Local LowerBlue as byte
Local LowerGreen as byte
Local LowerRed as byte
Local ResultBlue as byte
Local ResultGreen as byte
Local ResultRed as byte
Local mUpper as integer
Local mLower as integer
Local mAlpha as integer
Local mResult as integer
mUpper = find free memblock(1,10)
mLower = find free memblock(11,10)
mAlpha = find free memblock(21,10)
mResult = find free memblock(31,10)
make memblock from image mUpper,iUpper
make memblock from image mLower,iLower
make memblock from image mAlpha,iAlpha
make memblock from image mResult,iUpper
mbSize = get memblock size(mUpper)
for Pos = 12 to mbSize - 12 step 4
Percent = (memblock byte(mAlpha,Pos)/255.0)
UpperBlue = memblock byte(mUpper,Pos+0)
UpperGreen = memblock byte(mUpper,Pos+1)
UpperRed = memblock byte(mUpper,Pos+2)
LowerBlue = memblock byte(mLower,Pos+0)
LowerGreen = memblock byte(mLower,Pos+1)
LowerRed = memblock byte(mLower,Pos+2)
ResultBlue = UpperBlue*(1-Percent)+LowerBlue*Percent
ResultGreen = UpperGreen*(1-Percent)+LowerGreen*Percent
ResultRed = UpperRed*(1-Percent)+LowerRed*Percent
write memblock byte mResult,Pos+0,ResultBlue
write memblock byte mResult,Pos+1,ResultGreen
write memblock byte mResult,Pos+2,ResultRed
write memblock byte mResult,Pos+3,255
next Pos
make image from memblock iResult, mResult
delete memblock mUpper
delete memblock mLower
delete memblock mAlpha
delete memblock mResult
endfunction
function make_sky(img)
hmap_fractal(texture_size,0.1)
`transfer ´temp´ array to ´tex´ array
for z=0 to texture_size
for x=0 to texture_size
tex(x,z)=temp(x,z)
next x
next z
create bitmap 1,texture_size,texture_size
make memblock from bitmap 1,1
delete bitmap 1
pos=12
for y=1 to texture_size
for x=1 to texture_size
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
write memblock byte 1,pos,tex(x,y)
inc pos
next x
next y
make image from memblock img,1
delete memblock 1
make object sphere img,-10000
texture object img,img
set object transparency img,2
save image "sky.bmp",img
endfunction
Not an editor of such as yet but just sit back and wait,takes about a minuet on my pc to build the landscape and textures,once done it saves everything out ready to be loaded in when ever needed and lets you fly around the landsacpe with mouse.
Loader.
`Track Loader v1.0
`======================
`P.Parkinson
`======================
`Main Source File
set display mode 1024,768,32
sync on
sync rate 60
autocam off
color backdrop rgb(150,150,255)
set text font "Arial"
set text size 12
set text transparent
set image colorkey 0,0,0
position camera 200,1600,-1600
point camera 0,0,0
set ambient light 30
position light 0,2000,2000,2000
set light range 0,5000
set camera range 10,20000
load image "merged.bmp",1
load image "track.bmp",2
load image "start.bmp",3
load image "sky.bmp",4
make object sphere 10000,-10000
texture object 10000,4
set object transparency 10000,2
type pointType
x as float
y as float
z as float
t as float
a as float
endtype
dim track_data(36) as pointType
dim track_pos(5000) as pointType
dim pos(5000,16)as pointType
global gridSizeX as integer=256
global gridSizeZ as integer =256
global tileSize as integer=25
dim land(gridSizeX,gridSizeZ) as pointType
num_track_sections=load_track_data(1)
num_land_sections=load_land_data(num_track_sections+1)
l=1
do
position camera track_pos(l).x,track_pos(l).y+25,track_pos(l).z
if l<num_track_sections
point camera track_pos(l+1).x,track_pos(l+1).y+25,track_pos(l+1).z
else
point camera track_pos(1).x,track_pos(l).y+25,track_pos(1).z
endif
inc l
if l>num_track_sections then l=1
text 0,0,"Screen FPS "+str$(screen fps())
wait 50
` mousecontrol(5.0)
sync
loop
function MouseControl(Speed as float)
xrotate camera camera angle x()+mousemovey()
yrotate camera camera angle y()+mousemovex()
if mouseclick()=1 then move camera Speed
if mouseclick()=2 then move camera (0-Speed)
r=mousemovex()
r=mousemovey()
endfunction
function load_track_data(obj)
text 0,0,"loading track"
sync
sync
u#=1.0/6.0
open to read 1,"track poly data.txt"
read float 1,numPolys#
read float 1,st#
memblock_size=36
if memblock exist(1) then delete memblock 1
create_memblockobject(1,memblock_size)
for l=1 to int(numPolys#)
read float 1,ang#
read float 1,turn#
read float 1,x#:read float 1,y#:read float 1,z#
track_pos(l).x=x#
track_pos(l).y=y#+1.0
track_pos(l).z=z#
track_pos(l).a=ang#
track_pos(l).t=turn#
v_num=0
for p=1 to 36
read float 1,x#:read float 1,y#:read float 1,z#
track_data(p).x=x#:track_data(p).y=y#+1.0:track_data(p).z=z#
next p
for p=0 to 5
create_vertex(1,v_num,track_data(1+p*6).x,track_data(1+p*6).y,track_data(1+p*6).z,rgb(255,255,255),p*u#,0):inc v_num
create_vertex(1,v_num,track_data(2+p*6).x,track_data(2+p*6).y,track_data(2+p*6).z,rgb(255,255,255),(p+1)*u#,1):inc v_num
create_vertex(1,v_num,track_data(3+p*6).x,track_data(3+p*6).y,track_data(3+p*6).z,rgb(255,255,255),p*u#,1):inc v_num
create_vertex(1,v_num,track_data(4+p*6).x,track_data(4+p*6).y,track_data(4+p*6).z,rgb(255,255,255),p*u#,0):inc v_num
create_vertex(1,v_num,track_data(5+p*6).x,track_data(5+p*6).y,track_data(5+p*6).z,rgb(255,255,255),(p+1)*u#,0):inc v_num
create_vertex(1,v_num,track_data(6+p*6).x,track_data(6+p*6).y,track_data(6+p*6).z,rgb(255,255,255),(p+1)*u#,1):inc v_num
next p
make mesh from memblock 1,1
make object obj,1,0
set object texture obj,2,0
set object normals obj
if l<5
texture object obj,3
else
texture object obj,2
endif
set object transparency obj,2
inc obj
next l
sync
close file 1
endfunction obj
function create_memblockobject(memnum,v)
make memblock memnum,12+(36*v)
write memblock dword memnum,0,338
write memblock dword memnum,4,36
write memblock dword memnum,8,v
endfunction
function create_vertex(memnum,v,vposx#,vposy#,vposz#,color as dword,u#,v#)
write memblock float memnum,v*36+12,vposx#
write memblock float memnum,v*36+16,vposy#
write memblock float memnum,v*36+20,vposz#
write memblock dword memnum,v*36+36,color
write memblock float memnum,v*36+40,u#
write memblock float memnum,v*36+44,v#
endfunction
function set_normal(memnum,v,normalx#,normaly#,normalz#)
write memblock float memnum,v*36+24,normalx#
write memblock float memnum,v*36+28,normaly#
write memblock float memnum,v*36+32,normalz#
endfunction
function load_land_data(obj)
if file open(1) then close file 1
open to read 1,"land data.txt"
for z=0 to gridSizeZ
for x=0 to gridSizeX
read float 1,land(x,z).x
read float 1,land(x,z).y
read float 1,land(x,z).z
next x
next z
memblock_size=20*20*6
if memblock exist(10) then delete memblock 10
create_memblockobject(10,memblock_size)
uv#=1.0/128.0
for lz=0 to 11
for lx=0 to 11
v_num=0
for z=lz*20 to (lz+1)*20-1
for x=lx*20 to (lx+1)*20-1
create_vertex(10,v_num,land(x,z).x,land(x,z).y,land(x,z).z,rgb(255,255,255),x*uv#,z*uv#):inc v_num
create_vertex(10,v_num,land(x,z+1).x,land(x,z+1).y,land(x,z+1).z,rgb(255,255,255),x*uv#,(z+1)*uv#):inc v_num
create_vertex(10,v_num,land(x+1,z+1).x,land(x+1,z+1).y,land(x+1,z+1).z,rgb(255,255,255),(x+1)*uv#,(z+1)*uv#):inc v_num
create_vertex(10,v_num,land(x,z).x,land(x,z).y,land(x,z).z,rgb(255,255,255),x*uv#,z*uv#):inc v_num
create_vertex(10,v_num,land(x+1,z+1).x,land(x+1,z+1).y,land(x+1,z+1).z,rgb(255,255,255),(x+1)*uv#,(z+1)*uv#):inc v_num
create_vertex(10,v_num,land(x+1,z).x,land(x+1,z).y,land(x+1,z).z,rgb(255,255,255),(x+1)*uv#,z*uv#):inc v_num
next x
next z
make mesh from memblock 1,10
make object obj,1,0
set object texture obj,2,0
set object normals obj
`set object smoothing obj,95
`set object wireframe obj,1
texture object obj,1
inc obj
next lx
next lz
close file 1
dec obj
endfunction obj
Basic routine to load in all the data,make the meshes and speed around the track,notice the "wait 50" command in the main loop to slow it down a bit.
Hope you like it and have a look at the video of it in action.
http://www.youtube.com/watch?v=MX6wCdkpFQw