TGC Codebase Backup



Open source car physics for DB classic. by Muddleglum

29th Oct 2007 20:13
Summary

Working, mathematically based car simulation code for all to use.



Description

The code is based on work by 'Marco monstsr' adapted by 'Masked Coder' for dark basic. It has been around since 2002, and muddleglum has modiifed it for placing here so it can be studied and used without the download of models.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    REM                                CAR PHYSICS OPEN SOURCE - THE MASKED CODER ( 2002 )
` ------------------------------------------------------------------------------------
    ` NOTE  BY MUDDLEGLUM   2007
` this version seems to have had a track added by me EARLIER ( muddleglum)
` For this file , I have  replaced the 3ds jeep with a  box, wheels swith spheres.
` note that the keyboard controls can be restored.    This has no changing  grip levels with g force effects
` and no summing up of the grip change due to steerangle and braking.
` but it is  perfectly functional and convincing without that.
` to add pitching forward/aft detect  each program loop, the change  occuring to  'velociy# ' variable .
` this  is proportional to the forward/ aft g force
` in experiment, it took some complicated additions to get the body flowing smoothly ( shock absorbed.spring like)
` over the sharp matrix, ,, the wheels still follow the actual sharp matrix surface.
` the problem with this code is that a matrix is not ideal for a detailed  landscape or track.  being square in form
`  still, many matrices can be combined with modern computers.
` -------------------------------------------------------------------------------------

hide mouse
set display mode 800,600,16
sync on
sync rate 28
draw to front


`load image "grass1.bmp",1

gosub makeimageg
gosub makeimager

ink rgb(255,255,255),0

landsize = 5000 : rem size of matrix - 5000 x 5000 .
rem Make a matrix landscape
make matrix 1,landsize,landsize,30,30 : rem size of each tile on matrix .

rem Prepare matrix with grass texture
prepare matrix texture 1,1,1,1

rem fill matrix with image 1 and set height to 0
fill matrix 1,0,1

`TO MAKE A FLAT WORLD  ..REM OUT THIS LINE .  THE  'TRACK' MUDDLEGLUM ADDED WILL THEN BE VISIBLE
randomize matrix 1, 40 : update matrix

` make a 'car' with wheels

make object box 1,5,2,8

make object sphere 2,3.5
scale object 2,40,100,100
texture object 2,2

make object sphere 3,3.5
scale object 3,40,100,100
texture object 3,2

make object sphere 4,3.5
scale object 4,40,100,100
texture object 4,2

make object sphere 5,3.5
scale object 5,40,100,100
texture object 5,2



REM *** ALL VARIABLES ARE GLOBAL **********************************************************


rem physics variables

rem change these physics variables for various effects on the jeep .
rem drag and resistance together go to make a maximum velocity allowed . No maximum speed capping is needed .
DRAG# = .2  : rem wind resistance which slows the jeep down proprtionally to forward velocity .
RESISTANCE# = 4.0  : rem rolling resistance (slows the jeep down when free rolling)
frontgrip# = -40 : rem cornering stiffness front = front slippyness of jeep .lower the number the less traction there is .
reargrip# = -40 : rem cornering stiffness rear = rear slippyness of jeep . lower the number the less traction there is .
CAR1_cartype_mass# = 450  : rem effects the sluggishness of the handling
CAR1_cartype_inertia# = 450 : rem how much momentum is generated by the jeep . Usual to set this equal to mass .
whichdrive = 0 : rem 0 = four wheel drive (best handling) : 1 = front wheel drive : 2 = rear wheel drive



rem leave these variables pretty much as they are .
delta_t# = 0.01
M_PI# = 3.1415926
tempcar = reargrip#
tempcaf = frontgrip#
MAX_GRIP# = 2.0 : rem seems to have little efect
MULT# = 57 : rem =180 / M_PI#
MULT2# = .1 : rem MULT2# = fish tailing factor
CAR1_cartype = 1
CAR1_cartype_b# = 1.0
CAR1_cartype_c# = 1.0
CAR1_cartype_wheelbase# = CAR1_cartype_b# + CAR1_cartype_c#
CAR1_cartype_h# = 1.0
CAR1_cartype_width# = 1.5
CAR1_cartype_length# = 3.0
CAR1_cartype_wheellength# = 0.7
CAR1_cartype_wheelwidth# = 0.3
CAR1_car_position_wc_x# = 2000:`landsize / 2 : rem start position x in world frame (centre of matrix)
CAR1_car_position_wc_y# = 2000:`landsize / 2 : rem start position z in world frame (centre of matrix)
CAR1_car_velocity_wc_x# = 0
CAR1_car_velocity_wc_y# = 0
CAR1_car_angle# = 0
CAR1_car_angularvelocity# = 0
CAR1_car_steerangle# = 0
CAR1_car_throttle# = 0
CAR1_car_brake# = 0
front_slip = 0
rear_slip = 0




rem how much the jeep body rolls
rollscalefactor# = 89000 : rem 49000 .

minspeed = 10 : rem check if jeep is below the speed of 10, if so, then stop jeep. (counteracts drifting)

wheelpitchangle# = 0 : rem angle by which the wheels are rotated down, to simulate rolling forward as the jeep moves forward.


rem position jeep on the matrix at the start .
position object (1),CAR1_car_position_wc_x#,0,CAR1_car_position_wc_y#
gosub alignjeep

rem position camera in centre of the world frame just behind the jeep .
position camera landsize / 2,object position y(1)+10,(landsize / 2) - 40


camflag = 1 : rem camera tracking or stationary flag. 0 = stationary : 1 = follow jeep .
cameraspeed = 10 : rem speed of camera tracking .
set camera range 1,12000

gosub maketrack

color backdrop RGB(0,188,200)
fog on
 fog color RGB(0,188,200)



REM **** MAIN LOOP *******************************************************************************
REM **** MAIN LOOP *******************************************************************************
while mouseclick()=0


if inkey$()="r":`reset
CAR1_car_position_wc_x# = 2000:`landsize / 2 : rem start position x in world frame (centre of matrix)
CAR1_car_position_wc_y# = 2000:`
endif

set cursor 0,0


print "                             CAR  PHYSICS  DEMO  OPEN SOURCE  ( The Masked Coder 2002 )-- PLUS "
`print
print "FPS = ";screen fps()
print
print "F1 = Drop Camera"
print "F2 = Camera Follow"
print
print " F3-  4WD,    F4 - Front,   F5 - rear wheel "

print
print "1 - 2 = Front amount of grip = ",tempcaf
print "3 - 4 = Rear amount of grip = ",tempcar
print
print "5 - 6 = Increase / Decrease MASS = ",CAR1_cartype_mass#
print "7 - 8 = Increase / Decrease INERTIA = ",CAR1_cartype_inertia#


if SCANCODE() = 59 then camflag = 0 : rem check for F1 key pressed .
if SCANCODE() = 60 then camflag = 1 : rem check for F2 key pressed .


if SCANCODE() = 61 then whichdrive = 0 : rem check for F3 key pressed .
if SCANCODE() = 62 then whichdrive = 1 : rem check for F4 key pressed .
if SCANCODE() = 63 then whichdrive = 2 : rem check for F5 key pressed .


if SCANCODE() = 2 then tempcaf = tempcaf + 2 : rem check for 1 key pressed .
if SCANCODE() = 3
tempcaf = tempcaf - 2 : rem check for 2 key pressed .
endif

if SCANCODE() = 4 then tempcar = tempcar + 2 : rem check for 3 key pressed .
if SCANCODE() = 5
 tempcar = tempcar - 2 : rem check for 4 key pressed .
endif


if SCANCODE() = 6
 CAR1_cartype_mass# = CAR1_cartype_mass# - 10 : rem check for 5 key pressed .
 if CAR1_cartype_mass#<1 then CAR1_cartype_mass#=1
endif
if SCANCODE() = 7
 CAR1_cartype_mass# = CAR1_cartype_mass# + 10 : rem check for 6 key pressed .
endif

if SCANCODE() = 8
 CAR1_cartype_inertia# = CAR1_cartype_inertia# - 10 : rem check for 7 key pressed .
if CAR1_cartype_inertia#<1 then CAR1_cartype_inertia#=1
endif
if SCANCODE() = 9 then CAR1_cartype_inertia# = CAR1_cartype_inertia# + 10 : rem check for 8 key pressed .



gosub checkkeys : rem check for cursor keys pressed .
gosub carphysics : rem rotate and place jeep in the world frame based on the physics engine .
gosub updatecamera : rem track jeep with camera .

sync
endwhile


rem Free your obejct from memory
for a = 0 to 500
if object exist(a) = 1 then delete object a
`if image exist(a) = 1 then delete image a
next a
end
rem End the program ********************************************************************************************
rem End the program ********************************************************************************************




rem check for cursor keys pressed and set flags accordingly .
rem this way of checking for keys means the system only has to poll the keyboard once per pass of the code .
rem just my prefered way of reading keys .
checkkeys:

if inkey$()="a"
  upkeypressed=1
    else
    upkeypressed=0
endif

if inkey$()="s"
  downkeypressed=1
    else
    downkeypressed=0
endif

if leftkey()=1
  leftkeypressed=1
    else
    leftkeypressed=0
endif

if rightkey()=1
  rightkeypressed=1
    else
    rightkeypressed=0
endif
return



rem this subroutine places all 4 wheels under the jeep, relative to the jeeps orientation .
positionwheels:

wheelonground# = 2.2 : rem height offset so wheels sit on the ground .

rem orientate wheels to match jeep .
for a = 2 to 5
 set object to object orientation a,1
next a

rem place front left wheel .
position object 2,object position x(1),object position y(1),object position z(1)
move object 2,4.4
turn object left 2,90
move object 2,2.5
turn object right 2,90
pitch object down 2,90
move object 2,wheelonground#
pitch object up 2,90

rem place front right wheel .
position object 3,object position x(1),object position y(1),object position z(1)
move object 3,4.4
turn object right 3,90
move object 3,2.5
turn object left 3,90
pitch object down 3,90
move object 3,wheelonground#
pitch object up 3,90

rem place rear right wheel .
position object 4,object position x(1),object position y(1),object position z(1)
turn object left 4,180
move object 4,3.3
turn object left 4,180
turn object right 4,90
move object 4,2.5
turn object left 4,90
pitch object down 4,90
move object 4,wheelonground#
pitch object up 4,90

rem place rear left wheel .
position object 5,object position x(1),object position y(1),object position z(1)
turn object left 5,180
move object 5,3.3
turn object left 5,180
turn object left 5,90
move object 5,2.5
turn object right 5,90
pitch object down 5,90
move object 5,wheelonground#
pitch object up 5,90


rem rotate front left wheel for steering and pitch for rolling along .
turn object right 2,CAR1_car_steerangle# * (180 / M_PI#)
if downkeypressed = 0
  if velocity_x# > minspeed then pitch object down 2,wheelpitchangle#
endif

rem rotate front right wheel for steering and pitch for rolling along .
turn object right 3,CAR1_car_steerangle#  * (180 / M_PI#)
if downkeypressed = 0
  if velocity_x# > minspeed then pitch object down 3,wheelpitchangle#
endif

rem pitch rear wheels for rolling on ground .
if downkeypressed = 0
  if velocity_x# > minspeed then pitch object down 4,wheelpitchangle#
endif

if downkeypressed = 0
  if velocity_x# > minspeed then pitch object down 5,wheelpitchangle#
endif
return




rem CAR PHYSICS ALGORITHM BASED ON MARCO MONSTERS ORIGINAL C++ SOURCE CODE . ( cheers marco ) :)

CARPHYSICS:
sn# = Sin(CAR1_car_angle# * MULT#)
cs# = Cos(CAR1_car_angle# * MULT#)

rem velocity_x# = forward speed of jeep .
velocity_x# = (cs# * CAR1_car_velocity_wc_y#) + (sn# * CAR1_car_velocity_wc_x#)
rem velocity_y# = sideways(lateral) speed of jeep .
velocity_y# = ((0-sn#) * CAR1_car_velocity_wc_y#) + (cs# * CAR1_car_velocity_wc_x#)

rem stop the car shuddering at different speeds - different grip levels at different speeds .
reargrip# = tempcar
frontgrip# = tempcaf
CAR1_cartype_b# = 1.0
CAR1_cartype_c# = 1.0
if velocity_x# < 30  then reargrip# = -10 : frontgrip# = -10 : CAR1_cartype_b# = 1.0 : CAR1_cartype_c# = 1.0
if velocity_x# < 10  then reargrip# = -.3 : frontgrip# = -.3 : CAR1_cartype_b# = .5 : CAR1_cartype_c# = .5



yawspeed# = CAR1_cartype_wheelbase# * 0.5 * CAR1_car_angularvelocity#

If velocity_x# = 0
  rot_angle# = 0
    Else
    rot_angle# = atanfull(yawspeed#,velocity_x#) * MULT2#
EndIf

If velocity_x# = 0
  sideslip# = 0.0
    Else
    sideslip# = atanfull(velocity_y#,velocity_x#) * MULT2#
EndIf

slipanglefront# = sideslip# + rot_angle# - CAR1_car_steerangle#
slipanglerear# = sideslip# - rot_angle#

weight# = CAR1_cartype_mass# * 9.8 * 0.5

rem 4 wheel drive .
if whichdrive = 0
  flatf_x# = 0
  flatr_x# = 0
  flatr_y# = reargrip# * slipanglerear# / ((CAR1_car_throttle# / 15000.0)+1):` was 5000
  flatf_y# = frontgrip# * slipanglefront# / ((CAR1_car_throttle# / 15000.0)+1)
endif

rem front wheel drive .
if whichdrive = 1
  flatr_y# = reargrip# * slipanglerear#
  flatf_y# = frontgrip# * slipanglefront# / ((CAR1_car_throttle# / 15000.0)+1)
endif

rem rear wheel drive .
if whichdrive = 2
  flatr_y# = reargrip# * slipanglerear# / ((CAR1_car_throttle# /15000.0)+1)
  flatf_y# = frontgrip# * slipanglefront#
endif

rem add weight .
flatf_y# = flatf_y# * weight#
flatr_y# = flatr_y# * weight#


rem set flag for whether jeep is travelling forwards or backwards based on the sign of forward velocity .
if velocity_x# >= 0
   sgn# = 1
   else
   sgn# = 0 - 1
endif


ftraction_x# = 100.0 * (CAR1_car_throttle# - CAR1_car_brake# * Sgn#)
ftraction_y# = 0.0

resistance_x# = (0-( RESISTANCE# * velocity_x# + DRAG# * velocity_x# * Abs( velocity_x# ) ))
resistance_y# = (0-( RESISTANCE# * velocity_y# + DRAG# * velocity_y# * Abs( velocity_y# ) ))

force_x# = ftraction_x# + (Sin( CAR1_car_steerangle# * MULT# )) * flatf_x# + flatr_x# + resistance_x#
force_y# = ftraction_y# + (Cos( CAR1_car_steerangle# * MULT# )) * flatf_y# + flatr_y# + resistance_y#

torque# = CAR1_cartype_b# * flatf_y# - CAR1_cartype_c# * flatr_y#

acceleration_x# = force_x# / CAR1_cartype_mass#
acceleration_y# = force_y# / CAR1_cartype_mass#


angular_acceleration# = torque# / CAR1_cartype_inertia#

acceleration_wc_x# = (cs# * acceleration_y#) + (sn# * acceleration_x#)
acceleration_wc_y# = ((0-sn#) * acceleration_y#) + (cs# * acceleration_x#)

CAR1_car_velocity_wc_x# = CAR1_car_velocity_wc_x# + (delta_t# * acceleration_wc_x#)
CAR1_car_velocity_wc_y# = CAR1_car_velocity_wc_y# + (delta_t# * acceleration_wc_y#)

CAR1_car_angularvelocity# = CAR1_car_angularvelocity# + (delta_t# * angular_acceleration#)


CAR1_car_position_wc_x# = CAR1_car_position_wc_x# + (delta_t# * CAR1_car_velocity_wc_x#)
CAR1_car_position_wc_y# = CAR1_car_position_wc_y# + (delta_t# * CAR1_car_velocity_wc_y#)

rem position jeep at new world coordinates .
position object (1),CAR1_car_position_wc_x#,object position y(1),CAR1_car_position_wc_y#

if velocity_x# > minspeed : rem stop car below minimum speed to stop car shuddering due to inconsistancies in the physics engine .
  CAR1_car_angle# = CAR1_car_angle# + (delta_t# * CAR1_car_angularvelocity#)
  if CAR1_car_angle# > (M_PI# * 2) then CAR1_car_angle# = CAR1_car_angle# - (M_PI# * 2)
  if CAR1_car_angle# < (0 - M_PI# * 2) then CAR1_car_angle# = CAR1_car_angle# + (M_PI# * 2)
endif

rem turn jeep to new yaw angle .
`set object to object orientation 1,6
rotate object 1,0,0,0
turn object right 1,wrapvalue(CAR1_car_angle# * (180 / M_PI#))


rem update steering
turn#= joystick x()/160.0
CAR1_car_steerangle# = CAR1_car_steerangle# - ((0-M_PI#) / 180) * turn#
CAR1_car_steerangle# = CAR1_car_steerangle#*.8
` keyboard  below
`If leftkeypressed = 1  and CAR1_car_steerangle# > 0 - .7 then CAR1_car_steerangle# = CAR1_car_steerangle# + ((0-M_PI#) / 180) * 4
`If rightkeypressed = 1 and CAR1_car_steerangle# < .7 then CAR1_car_steerangle# = CAR1_car_steerangle# + (M_PI# / 180) * 4

`if leftkeypressed = 0 and rightkeypressed = 0
  `if CAR1_car_steerangle# < .1 and CAR1_car_steerangle# > 0 - .1 then CAR1_car_steerangle# = 0
  `if CAR1_car_steerangle# > 0 then  CAR1_car_steerangle# = CAR1_car_steerangle# - (M_PI# / 180) * 7
  `if CAR1_car_steerangle# < 0 then  CAR1_car_steerangle# = CAR1_car_steerangle# + (M_PI# / 180) * 7
`endif

rem check for throttle pressed .
If upkeypressed=1
  CAR1_car_throttle# = CAR1_car_throttle# +80:` addition for acceleration of engine
  if  CAR1_car_throttle#> 1000.0 then  CAR1_car_throttle# =1000
   rem 2000  = throttle power . Increase for faster acceleration .
    else
    CAR1_car_throttle# = 0.0
endif

rem check for brake pressed .
If downkeypressed=1
  CAR1_car_throttle# = 0.0
  CAR1_car_brake# = 1000.0
    if velocity_x# <= 0 then gosub stopall : rem reset physics engine if car stopped .
    Else
    CAR1_car_brake# = 0.0
EndIf


gosub alignjeep

rem new pitch angle for the wheels . rolling along forwards .
wheelpitchangle# = wrapvalue(wheelpitchangle# + (velocity_x# / 4))
doroll:
rem roll jeep body due to lateral forces on jeep . change rollscalefactor# for more or less roll .
rollamount# = force_y# / rollscalefactor#
roll object left 1,rollamount#

return



rem pitch and roll jeep to align on matrix .
alignjeep:

rem position car in world frame and rotate car body
h# = get ground height(1,object position x(1),object position z(1))
position object (1),object position x(1), h# ,object position z(1)

foot# = 2.5
ta#=wrapvalue((CAR1_car_angle# * (180 / M_PI#))-45)
frontleftx#=newxvalue(CAR1_car_position_wc_x#,ta#,foot#) : frontleftz#=newzvalue(CAR1_car_position_wc_y#,ta#,foot#)
ta#=wrapvalue((CAR1_car_angle# * (180 / M_PI#))+45)
frontrightx#=newxvalue(CAR1_car_position_wc_x#,ta#,foot#) : frontrightz#=newzvalue(CAR1_car_position_wc_y#,ta#,foot#)
ta#=wrapvalue((CAR1_car_angle# * (180 / M_PI#))+225)
backleftx#=newxvalue(CAR1_car_position_wc_x#,ta#,foot#) : backleftz#=newzvalue(CAR1_car_position_wc_y#,ta#,foot#)
ta#=wrapvalue((CAR1_car_angle# * (180 / M_PI#))+135)
backrightx#=newxvalue(CAR1_car_position_wc_x#,ta#,foot#) : backrightz#=newzvalue(CAR1_car_position_wc_y#,ta#,foot#)

frontlefth#=get ground height(1,frontleftx#,frontleftz#)
rem print frontlefth#
frontrighth#=get ground height(1,frontrightx#,frontrightz#)
rem print frontrighth#
backlefth#=get ground height(1,backleftx#,backleftz#)
rem print backlefth#
backrighth#=get ground height(1,backrightx#,backrightz#)
rem print backrighth#

across#=((frontrighth#-frontlefth#)+(backrighth#-backlefth#))/2.0
length#=((backlefth#-frontlefth#)+(backrighth#-frontrighth#))/2.0

rem Update car model
trackh#=(frontlefth#+frontrighth#+backlefth#+backrighth#)/4.0
if trackh#>h# then h#=trackh#
pitch object down 1, wrapvalue((length#/4.0) * (180 / M_PI#))
roll object left 1, wrapvalue((across#/4.0) * (180 / M_PI#))

rem raise jeep above ground
jeepheight# = 4.2
pitch object up 1,90
move object 1,jeepheight#
pitch object down 1,90

gosub positionwheels : rem place the wheels under the jeep

return



rem this routine effectively resets the physics engine by clearing all the physics variables .
rem only used if the jeep falls below minspeed where an engine reset is needed .
rem in my later versions of this algorithm, this is unesecary, but is left here as a debugging aid .
stopall:
CAR1_car_throttle# = 0
CAR1_car_brake# = 0
sgn# = 1
resistance_x# = 0
resistance_y# = 0
force_x# = 0
force_y# = 0
torque# = 0
acceleration_x# = 0
acceleration_y# = 0
velocity_x# = 0
velocity_y# = 0
angular_acceleration# = 0
acceleration_wc_x# = 0
acceleration_wc_y# = 0
CAR1_car_velocity_wc_x# = 0
CAR1_car_velocity_wc_y# = 0
CAR1_car_angularvelocity# = 0
flatf_x# = 0
flatr_x# = 0
flatr_y# = 0
flatf_y# = 0
yawspeed# = 0
rot_angle# = 0
sideslip# = 0
slipanglefront# = 0
slipanglerear# = 0
return



rem prints all physics variables . Useful for debuging but not actually used .
printall:
print "velocity_x# = ",velocity_x#
print "velocity_y# = ",velocity_y#
print "yawspeed# = ",yawspeed#
print "rot_angle# = ",rot_angle#
print "sideslip# = ",sideslip#
print "slipanglefront# = ",slipanglefront#
print "slipanglerear# = ",slipanglerear#
print "flatf_x# = ",flatf_x#
print "flatr_x# = ",flatr_x#
print "flatr_y# = ",flatr_y#
print "flatf_y# = ",flatf_y#
print "sgn# = ",sgn#
print "ftraction_x# =",ftraction_x#
print "ftraction_y# = ",ftraction_y#
print "rear_slip =",rear_slip
print "resistance_x# = ",resistance_x#
print "resistance_y# = ",resistance_y#
print "force_x# = ",force_x#
print "force_y# = ",force_y#
print "torque# = ",torque#
print "acceleration_x# = ",acceleration_x#
print "acceleration_y# = ",acceleration_y#
print "angular_acceleration# = ",angular_acceleration#
print "acceleration_wc_x# = ",acceleration_wc_x#
print "acceleration_wc_y# = ",acceleration_wc_y#
print "CAR1_car_velocity_wc_x# = ",CAR1_car_velocity_wc_x#
print "CAR1_car_velocity_wc_y# = ",CAR1_car_velocity_wc_y#
print "CAR1_car_position_wc_x# = ",CAR1_car_position_wc_x#
print "CAR1_car_position_wc_y# = ",CAR1_car_position_wc_y#
print "CAR1_car_angularvelocity# = ",CAR1_car_angularvelocity#
print "CAR1_car_angle# = ",CAR1_car_angle#
print "CAR1_car_throttle# = ",CAR1_car_throttle#
print "CAR1_car_brake# = ",CAR1_car_brake#
return




rem camera tracking routine
updatecamera:
if camflag = 1

  cdestx#=object position x(1)
  cdesty#=object position y(1)+5 : rem +5 units above the jeep. Track slightly above the jeep .
  cdestz#=object position z(1)

  ccurrentx#=camera position x()
  ccurrenty#=camera position y()
  ccurrentz#=camera position z()

  ccurrentx#=curvevalue(cdestx#,ccurrentx#,cameraspeed)
  ccurrenty#=curvevalue(cdesty#,ccurrenty#,cameraspeed)
  ccurrentz#=curvevalue(cdestz#,ccurrentz#,cameraspeed)

 ` position camera ccurrentx#,ccurrenty#,ccurrentz#
`old view uses point below As well
` position camera object position x(1),object position y(1)+2,object position z(1)
` set camera to object orientation 1
` turn camera right  180
` move camera 5

 position camera object position x(1),object position y(1)+2,object position z(1)
 set camera to object orientation 1
 turn camera right  180
 move camera 5
point camera object position x(1),object position y(1)+2,object position z(1)
move camera 5

else
point camera object position x(1),object position y(1),object position z(1)
endif

return


` =================================     makeimage ============
makeimageg:
cls rgb(30,80,10)

ink rgb(60,100,30),0
for x=0 to 56
dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56)
dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56)
next x

ink rgb(40,110,40),0
for x=0 to 56
dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56)
dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56)
next x

ink rgb(10,65,20),0
for x=0 to 56
dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56)
dot x,rnd(56):dot x,rnd(56):dot x,rnd(56):dot x,rnd(56)
next x

get image 1,0,0,56,56
return
` =====================================================================make second image
makeimager:
cls rgb(150,150,150)

ink rgb(110,110,110),0
for x=0 to 128
dot x,rnd(128):dot x,rnd(128):dot x,rnd(128):dot x,rnd(128)
dot x,rnd(128):dot x,rnd(128):dot x,rnd(128):dot x,rnd(128)
next x

ink rgb(130,130,130),0
for x=0 to 128
dot x,rnd(128):dot x,rnd(128):dot x,rnd(128):dot x,rnd(128)
dot x,rnd(128):dot x,rnd(128):dot x,rnd(128):dot x,rnd(128)
next x

ink rgb(170,175,170),0
for x=0 to 128
dot x,rnd(128):dot x,rnd(128):dot x,rnd(128):dot x,rnd(128)
dot x,rnd(128):dot x,rnd(128):dot x,rnd(128):dot x,rnd(128)
next x

get image 2,0,0,128,128

return

` ============================================================= make track ===========
`.......................make a track!!
maketrack:
d=0
for x=30 to 34
make object plain x,150,300
texture object x,2
pitch object down x,90
position object x, 2000,.5,2100+(300*d)
inc d
next x

d=0
for x=35 to 42
make object plain x,100,300
texture object x,2
pitch object down x,90
position object x, 2300,.5,2100+(300*d)
inc d
next x
` --------------------
make object plain 44,200,200
texture object 44,2
pitch object down 44,90
position object 44, 2150,.5,2100

make object plain 45,200,300
texture object 45,2
pitch object down 45,90
position object 45, 2150,.5,3400
` -----------------------------
make object plain 46,100,400
texture object 46,2
pitch object down 46,90
position object 46, 2450,.5,3700
` two together
make object plain 47,100,400
texture object 47,2
pitch object down 47,90
position object 47, 2450,.5,4100

make object plain 48,100,150
texture object 48,2
pitch object down 48,90
position object 48, 2350,.5,4300

make object plain 49,150,150
texture object 49,2
pitch object down 49,90
position object 49, 2350,.5,3550

return
`================= end track