There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to op
Virtual Big Trak Based on the toy of the same name, the Virtual Big Trak application requires the student to program a 3D tank to navigate a simple obstacle course.
Commands are entered into a text file using a standard text editor and loaded into the application. Fn = Forward n units Bn = Back (reverse) n units Ln = Rotate left n degrees Rn = Rotate right n degrees Points are deducted for entering grid squares with a diamond tile and for leaving the 8 x 8 grid. The challenge is to reach the final destination square with the least penalties, having covered the shortest distance. Additional courses/maps can be designed, very simply, using a text editor. Each grid square is 10 units high and 10 units wide. N W
E S
Fig 1
'Course A.txt'
00000003 00000000 00111111 00000000 00000000 11111100 00000000 20000000 Fig 2
1
Figure 1 shows the 'Course A.txt' graphics created by the contents of the text file (figure 2). 0 (zero) = clear tiles 1 = tile to be avoided 2 = starting position of Big Trak 3 = destination tile Each grid square is 10 units in width and height, so the entire grid is 80 units by 80 units. The image below shows a solution for 'Course A'.
Big Trak starts in the centre of the designated square i.e. 5 units up and 5 units to the right of the bottom left corner. If a map doesn't contain '2' or '3', the start and end positions default to the bottom left and top right tiles, respectively. Points are deducted when the Big Trak's centre moves off the grid or into a grid square with a diamond tile. An additional application is included to calculate the approximate bearing and distance required to move Big Trak by x,y units. (Of use if the student wishes to minimise the distance travelled.)
2
BB4W – Virtual Big Trak REM Prevent resize SYS "GetWindowLong", @hwnd%, -16 TO ws% SYS "SetWindowLong", @hwnd%, -16, ws% AND NOT &40000 AND NOT &10000 MODE 9:OFF *ESC OFF *FONT Arial,16 click=FALSE ON MOUSE:click=TRUE:RETURN ON ERROR:PROCerror:END *REFRESH OFF ORIGIN 640,512 VDU 23,23,2;0;0;0;:REM Line width 2 REM File handling DIM Of% 75,filetype% 40,Fn% 255 !Of%=76:Of%!4=@hwnd%:Of%!28=Fn%:Of%!32=256:Of%!52=6:Of%!12=filetype% $filetype%="Text files"+CHR$0+"*.txt"+CHR$0 DIM btn{(9) sts,x,y,name$}:REM Buttons sptr=0:REM Button pointer DIM nd{(54) xt,yt,zt,xr,yr,zr,x2,y2}:REM Nodes DIM link{(90) type,n1,n2,n3}:REM Links (colours & triangles) DIM td{(3) np,lp,nc,lc}:REM Net pointers FOR a=0 TO 54 READ nd{(a)}.xt,nd{(a)}.yt,nd{(a)}.zt NEXT FOR a=0 TO 90 READ link{(a)}.type,link{(a)}.n1,link{(a)}.n2,link{(a)}.n3 NEXT FOR a=0 TO 3 READ td{(a)}.np,td{(a)}.lp,td{(a)}.nc,td{(a)}.lc NEXT REM Create a unit vector pointing towards a light source lightx=100:lighty=100:lightz=10 lm=SQR(lightx^2+lighty^2+lightz^2) lightx/=lm:lighty/=lm:lightz/=lm vX=0:vY=0:vZ=0:REM View point (calculating distances) vXA=0:REM Viewer's x-axis rotation MAXnav=99 DIM nav{(MAXnav) inst$,units}:REM User's program nptr=-1:REM Program line pointer DIM map(7,7):REM 0=good tile, 1=bad tile DIM omega{(1) x,y}:REM Start & End locations mfile$="":REM Map file name havemap=FALSE:REM Course loaded 3
havenav=FALSE:REM Program loaded status=0:REM 0=need map&pgm, 1=can start, 2=roll scene pause=FALSE nfile$="":REM Nav file name cinst=0:REM Current instruction cunit=0:REM Current unit count cx=0:cy=0:cbear=0:REM Current x,y & bearing gx=0:gy=0:REM Current integer grid co-ordinates score=0:REM Penalties distance=0:REM distance travelled complete=FALSE:REM Destination reached? PROCmakebutton(1,-500,460,"Map") PROCmakebutton(1,-500,380,"Nav") PROCmakebutton(1,300,460,"Start") PROCmakebutton(0,300,460,"Pause") PROCmakebutton(1,500,460,"Reset") REPEAT TIME=0:CLS MOUSE mx,my,mb REM Update status CASE status OF WHEN 0 IF havemap AND havenav status=1 IF NOT havemap THEN GCOL 0,7 *FONT Arial,20 PROCcentre(0,100,"Virtual Big Trak") *FONT Arial,16 vX=0:vY=0:vZ=0:vXA=0 PROCdraw(0,0,-10,-60,0,0,cbear):cbear+=3 ENDIF WHEN 2 IF vXAnptr status=1:REM End of program ENDIF ENDIF IF pause GCOL 0,7:PROCcentre(300,380,"Paused") ENDCASE GCOL 0,7 IF havemap t$=mfile$ ELSE t$="Click to load map" PROCleft(-400,460,t$) IF havenav t$=nfile$ ELSE t$="Click to load navigation program" PROCleft(-400,380,t$) IF havemap PROCquickdraw PROCdrawbuttons REM If board is 'flat' then show score IF vXA=-15 THEN GCOL 0,7 PROCleft(-400,300,"Distance moved: "+STR$(distance)) PROCleft(-400,220,"Bearing: "+FNbearing) PROCleft(-400,140,"Penalties: "+STR$(score)) IF complete PROCleft(-400,60,"Mission Complete!") ENDIF *REFRESH IF havemap WHILE TIME-4 THEN abort=TRUE:REM Node behind viewer ELSE nd{(a)}.x2=f*nd{(a)}.xr/-nd{(a)}.zr:REM 3D to 2D nd{(a)}.y2=f*nd{(a)}.yr/-nd{(a)}.zr ENDIF NEXT IF abort ENDPROC FOR a=td{(net)}.lp TO td{(net)}.lp+td{(net)}.lc-1 CASE link{(a)}.type OF WHEN 1 : col=link{(a)}.n1 WHEN 7 n1=link{(a)}.n1+td{(net)}.np n2=link{(a)}.n2+td{(net)}.np n3=link{(a)}.n3+td{(net)}.np REM Calc two vectors from 3 co-ords (triangle): b-a and c-a v1x=nd{(n2)}.xr-nd{(n1)}.xr v1y=nd{(n2)}.yr-nd{(n1)}.yr 9
v1z=nd{(n2)}.zr-nd{(n1)}.zr v2x=nd{(n3)}.xr-nd{(n1)}.xr v2y=nd{(n3)}.yr-nd{(n1)}.yr v2z=nd{(n3)}.zr-nd{(n1)}.zr REM Find the 'normal' of a triangle, (cross product of two vectors) nx=v1y*v2z-v1z*v2y ny=v1z*v2x-v1x*v2z nz=v1x*v2y-v1y*v2x REM Vector towards viewer v1x=0-nd{(n1)}.xr v1y=0-nd{(n1)}.yr v1z=0-nd{(n1)}.zr REM Triangle faces viewer (normal points towards viewer)? IF (nx*v1x+ny*v1y+nz*v1z)>0 THEN nm=SQR(nx^2+ny^2+nz^2) REM Calc triangle shade from: A.B / |A||B| v=(nx*lightx+ny*lighty+nz*lightz)/nm v=255-ABS(ACS(v))/PI*255 REM Tile in shadow of Big Trak? IF net>0 THEN i=SQR((cx-x)^2+(cy-z)^2) IF i