From: Svjatoslav Agejenko Date: Tue, 15 Oct 2024 19:34:12 +0000 (+0300) Subject: Refactoring code for better readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=37f67ea0a42dd000c20750e40e0334d993111b65;p=qbasicapps.git Refactoring code for better readability --- diff --git a/Graphics/3D/tank1.bas b/Graphics/3D/tank1.bas index 2ac540b..fd019bd 100755 --- a/Graphics/3D/tank1.bas +++ b/Graphics/3D/tank1.bas @@ -1,821 +1,824 @@ -' Tank -' made by Svjatoslav Agejenko -' in 2000 -' H-Page: svjatoslav.eu -' E-Mail: svjatoslav@svjatoslav.eu - -' Use keys to move around: -' Left, Right, Up, Down look around -' + move fovard -' - move back -' q quit -' - stop - - -DECLARE SUB start () -DECLARE SUB savepos (x1%, y1%, x2%, y2%) -DECLARE SUB teemaad () -DECLARE SUB setgus () -DECLARE SUB getgus () -DECLARE SUB getgus1 (x1%, y1%, x2%, y2%) -DECLARE SUB kiri () -DECLARE SUB getcor () -DECLARE SUB mulcor () -DECLARE SUB nait3d () -DECLARE SUB calcsin () -DEFINT A-Y -DIM SHARED xn(1000), yn(1000), czn(1000) ' original points -DIM SHARED x(1000), y(1000), cz(1000) ' Rotated points -DIM SHARED Xs1(1000), Ys1(1000), Xe1(1000), Ye1(1000) ' Old rotated points -DIM SHARED pointers1(1000), pointers2(1000) ' Connected points -DIM SHARED cosine&(360), sine&(360) ' SIN & COS table -DIM SHARED np, nl - -DIM SHARED gusx(1 TO 1000) -DIM SHARED gusy(1 TO 1000) -DIM SHARED mitgus -DIM SHARED smes - - -DIM SHARED gusalgp ' segment -DIM SHARED gusalgl -DIM SHARED silalgp ' segment -DIM SHARED silalgl - -DIM SHARED gusxp -DIM SHARED myx, myy, myz -DIM SHARED myxp, myyp, myzp - -DIM SHARED deg1, deg2, deg3 -DIM SHARED speed - -DIM SHARED ssu - - -start - -nait3d - - - - -DATA -10,-30,-20 -DATA 30,-30,-20 -DATA 30,-10,-20 -DATA -10,-10,-20 - -DATA -10,-30,20 -DATA 30,-30,20 -DATA 30,-10,20 -DATA -10,-10,20 - -DATA -10,-40,-15 -DATA 30,-40,-15 -DATA -10,-40,15 -DATA 30,-40,15 - -DATA -20,-30,-15 -DATA -20,-30, 15 - -DATA -70,-10,-50 -DATA 60,-10, -50 -DATA 70, 0, -50 -DATA 70, 20, -50 -DATA 60, 30, -50 -DATA -70,30, -50 -DATA -80,20, -50 -DATA -80, 0, -50 - -DATA -70,-10,-30 -DATA 60,-10, -30 -DATA 70, 0, -30 -DATA 70, 20, -30 -DATA 60, 30, -30 -DATA -70,30, -30 -DATA -80,20, -30 -DATA -80, 0, -30 - -DATA -70,-10, 50 -DATA 60,-10, 50 -DATA 70, 0, 50 -DATA 70, 20, 50 -DATA 60, 30, 50 -DATA -70,30, 50 -DATA -80,20, 50 -DATA -80, 0, 50 - -DATA -70,-10, 30 -DATA 60,-10, 30 -DATA 70, 0, 30 -DATA 70, 20, 30 -DATA 60, 30, 30 -DATA -70,30, 30 -DATA -80,20, 30 -DATA -80, 0, 30 - -DATA -50,-7,-30 -DATA 50,-7,-30 -DATA 50, 15,-30 -DATA -50, 15,-30 - -DATA -50,-7, 30 -DATA 50,-7, 30 -DATA 50, 15,30 -DATA -50, 15,30 - -DATA -20,-20,-5 -DATA -20,-20, 5 -DATA -20,-30, 5 -DATA -20,-30,-5 - -DATA -100,-30,-5 -DATA -100,-30, 5 -DATA -100,-40, 5 -DATA -100,-40,-5 - -DATA 999,999,999 - -DATA 0,1 -DATA 1,2 -DATA 2,3 -DATA 3,0 - -DATA 4,5 -DATA 5,6 -DATA 6,7 -DATA 7,4 - -DATA 0,8 -DATA 1,9 -DATA 4,10 -DATA 5,11 - -DATA 0,12 -DATA 4,13 -DATA 12,8 -DATA 13,10 - -DATA 8,9 -DATA 10,11 -DATA 8,10 -DATA 9,11 - -DATA 12,13 -DATA 12,3 -DATA 13,7 -DATA 3,7 -DATA 1,5 -DATA 2,6 - -DATA 14,15 -DATA 15,16 -DATA 16,17 -DATA 17,18 -DATA 18,19 -DATA 19,20 -DATA 20,21 -DATA 21,14 - -DATA 22,23 -DATA 23,24 -DATA 24,25 -DATA 25,26 -DATA 26,27 -DATA 27,28 -DATA 28,29 -DATA 29,22 - -'DATA 14,22 -'DATA 15,23 -'DATA 16,24 -'DATA 17,25 -'DATA 18,26 -'DATA 19,27 -'DATA 20,28 -'DATA 21,29 - -DATA 30,31 -DATA 31,32 -DATA 32,33 -DATA 33,34 -DATA 34,35 -DATA 35,36 -DATA 36,37 -DATA 37,30 - -DATA 38,39 -DATA 39,40 -DATA 40,41 -DATA 41,42 -DATA 42,43 -DATA 43,44 -DATA 44,45 -DATA 45,38 - -'DATA 30,38 -'DATA 31,39 -'DATA 32,40 -'DATA 33,41 -'DATA 34,42 -'DATA 35,43 -'DATA 36,44 -'DATA 37,45 - -DATA 46,47 -DATA 47,48 -DATA 48,49 -DATA 49,46 - -DATA 50,51 -DATA 51,52 -DATA 52,53 -DATA 53,50 - -DATA 50,46 -DATA 51,47 -DATA 52,48 -DATA 53,49 - -DATA 54,55 -DATA 55,56 -DATA 56,57 -DATA 57,54 - -DATA 54,58 -DATA 55,59 -DATA 56,60 -DATA 57,61 - -DATA 58,59 -DATA 59,60 -DATA 60,61 -DATA 61,58 - -DATA 54,3 -DATA 55,7 - - -'DATA 62,63 - -DATA 999, 999 -' S I L D - - - - - - - - - - - ' parempoolsed k�epided -DATA 100,0,100 -DATA 100,50,100 - -DATA 50,0,100 -DATA 50,50,100 - -DATA 0,0,100 -DATA 0,50,100 - -DATA -50,0,100 -DATA -50,50,100 - -DATA -100,0,100 -DATA -100,50,100 - ' 5 -DATA -150,0,100 -DATA -150,50,100 - -DATA -200,0,100 -DATA -200,50,100 - -DATA -250,0,100 -DATA -250,50,100 - -DATA -300,0,100 -DATA -300,50,100 - -DATA -350,0,100 -DATA -350,50,100 - ' 10 - -DATA -400,0,100 -DATA -400,50,100 - -DATA -450,0,100 -DATA -450,50,100 - -DATA -500,0,100 -DATA -500,50,100 - -DATA -550,0,100 -DATA -550,50,100 - -DATA -600,0,100 -DATA -600,50,100 - -DATA -650,0,100 -DATA -650,50,100 - - ' vasak poolsed k�epided -DATA 100,0,-100 -DATA 100,50,-100 - -DATA 50,0,-100 -DATA 50,50,-100 - -DATA 0,0,-100 -DATA 0,50,-100 - -DATA -50,0,-100 -DATA -50,50,-100 - -DATA -100,0,-100 -DATA -100,50,-100 - ' 5 -DATA -150,0,-100 -DATA -150,50,-100 - -DATA -200,0,-100 -DATA -200,50,-100 - -DATA -250,0,-100 -DATA -250,50,-100 - -DATA -300,0,-100 -DATA -300,50,-100 - -DATA -350,0,-100 -DATA -350,50,-100 - ' 10 - -DATA -400,0,-100 -DATA -400,50,-100 - -DATA -450,0,-100 -DATA -450,50,-100 - -DATA -500,0,-100 -DATA -500,50,-100 - -DATA -550,0,-100 -DATA -550,50,-100 - -DATA -600,0,-100 -DATA -600,50,-100 - -DATA -650,0,-100 -DATA -650,50,-100 - ' alumine joon -DATA 100,75,-100 -DATA -650,75,-100 - -DATA 100,75,100 -DATA -650,75,100 - ' kallas -DATA 75,75,-100 -DATA 75,75,100 - 'parem -DATA -50,200,-100 -DATA -50,200,100 - -DATA 75,200,-190 -DATA 75,200, 190 - 'vasak -DATA -525,200,-100 -DATA -525,200, 100 - -DATA -600,200,-190 -DATA -600,200, 190 - - - - -DATA 999,999,999 - - 'parempoolesd k�epided -'DATA 0,1 -DATA 2,3 -DATA 4,5 -DATA 6,7 -DATA 8,9 - -DATA 10,11 -DATA 12,13 -DATA 14,15 -DATA 16,17 -DATA 18,19 - -DATA 20,21 -DATA 22,23 -DATA 24,25 -DATA 26,27 -DATA 28,29 -'DATA 30,31 - - 'vasakpoolsed k�epided -'DATA 32,33 -DATA 34,35 -DATA 36,37 -DATA 38,39 -DATA 40,41 - -DATA 42,43 -DATA 44,45 -DATA 46,47 -DATA 48,49 -DATA 50,51 - -DATA 52,53 -DATA 54,55 -DATA 56,57 -DATA 58,59 -DATA 60,61 -'DATA 62,63 - ' sild ise -'DATA 0,30 -'DATA 1,31 -'DATA 32,62 -'DATA 33,63 - -' pikad -DATA 0,4 -DATA 4,8 -DATA 8,12 -DATA 12,16 -DATA 16,20 -DATA 20,24 -DATA 24,28 -DATA 28,30 - -DATA 1,5 -DATA 5,9 -DATA 9,13 -DATA 13,17 -DATA 17,21 -DATA 21,25 -DATA 25,29 -DATA 29,31 - -DATA 32,36 -DATA 36,40 -DATA 40,44 -DATA 44,48 -DATA 48,52 -DATA 52,56 -DATA 56,60 -DATA 60,62 - -DATA 33,37 -DATA 37,41 -DATA 41,45 -DATA 45,49 -DATA 49,53 -DATA 53,57 -DATA 57,61 -DATA 61,63 - - - -' l�pp - -DATA 1,33 -DATA 31,63 - -DATA 64,65 -DATA 66,67 -DATA 64,66 -DATA 65,67 - -DATA 0,66 -DATA 32,64 -DATA 30,67 -DATA 62,65 - ' kallas -DATA 68,69 -DATA 70,71 -DATA 68,70 -DATA 69,71 - -DATA 72,70 -DATA 72,68 - -DATA 73,71 -DATA 73,69 - 'vasak -DATA 74,76 -DATA 75,77 -DATA 74,75 - -DATA 74,65 -DATA 76,65 - -DATA 75,67 -DATA 77,67 - - -DATA 999, 999 - -DEFINT Z -SUB calcsin -PRINT "Calculating SIN and COS data..." - -FOR a! = 0 TO 359 / 57.29577951# STEP 1 / 57.29577951# - cosine&(a) = INT(.5 + COS(a!) * 1024) - sine&(a) = INT(.5 + SIN(a!) * 1024) - a = a + 1 -NEXT -CLS -END SUB - -DEFSNG Z -SUB getcor -FOR a = 0 TO 10000 - READ x(a), y(a), cz(a) - IF x(a) = 999 THEN x(a) = 0: y(a) = 0: cz(a) = 0: GOTO 1 -NEXT -1 -np = a -FOR a = 0 TO 10000 - READ pointers1(a), pointers2(a) - IF pointers1(a) = 999 THEN GOTO 2 -NEXT -2 -nl = a - -gusalgp = np -gusalgl = nl - -FOR a = 1 TO 48 -pointers1(nl) = np -np = np + 1 -pointers2(nl) = np -np = np + 1 -nl = nl + 1 -NEXT a - - - -END SUB - -DEFINT Z -SUB getgus - -mitgus = 1 -getgus1 -70, -10, -80, 0 -getgus1 -80, 0, -80, 20 -getgus1 -80, 20, -70, 30 -getgus1 -70, 30, 60, 30 -getgus1 60, 30, 70, 20 -getgus1 70, 20, 70, 0 -getgus1 70, 0, 60, -10 -getgus1 60, -10, -70, -10 -'LOCATE 1, 1 -'PRINT mitgus -'SLEEP - - -END SUB - -DEFSNG Z -SUB getgus1 (x1, y1, x2, y2) -z1 = ABS(x1 - x2) -z2 = ABS(y2 - y1) -mi = SQR(z1 ^ 2 + z2 ^ 2) * 1.017142857# - -zxp = (x1 - x2) / mi -zyp = (y2 - y1) / mi -zx = x1 -zy = y1 - -FOR a = 1 TO mi -zx = zx - zxp -zy = zy + zyp -gusx(mitgus) = zx -gusy(mitgus) = zy -mitgus = mitgus + 1 -NEXT a - -END SUB - -DEFINT Z -SUB moveright -END SUB - -DEFSNG Z -SUB nait3d - -DO - -setgus - - deg1 = deg1 + d1 - deg2 = deg2 + d2 - deg3 = deg3 + d3 -'LOCATE 1, 1 -'PRINT deg1, deg2, deg3, speed - - IF deg1 <= 0 THEN deg1 = deg1 + 360 - IF deg2 <= 0 THEN deg2 = deg2 + 360 - IF deg3 <= 0 THEN deg3 = deg3 + 360 - - IF deg1 >= 360 THEN deg1 = deg1 - 360 - IF deg2 >= 360 THEN deg2 = deg2 - 360 - IF deg3 >= 360 THEN deg3 = deg3 - 360 - - c1& = cosine&(deg1): s1& = sine&(deg1) - c2& = cosine&(deg2): s2& = sine&(deg2) - c3& = cosine&(deg3): S3& = sine&(deg3) - -myx = myx - (s1& * speed / 100) -myy = myy - (c1& * speed / 100) -myz = myz - (s2& * speed / 100) - -FOR a = 0 TO np - 1 -x1 = x(a) + myx -y1 = y(a) + myz -pz1 = cz(a) + myy - -x2 = (x1 * c1& - pz1 * s1&) \ 1024 -pz2 = (x1 * s1& + pz1 * c1&) \ 1024 - -y2 = (y1 * c2& - pz2 * s2&) \ 1024 -pz3 = (y1 * s2& + pz2 * c2&) \ 1024 - -x3 = (y2 * c3& - x2 * S3&) \ 1024 -y3 = (y2 * S3& + x2 * c3&) \ 1024 - -IF pz3 > 10 THEN -xn(a) = 320 + (x3 / pz3 * 500) -yn(a) = 240 + (y3 / pz3 * 500) -ELSE -xn(a) = -1 -END IF - - -NEXT - - -FOR a1 = 0 TO nl - 1 -f1 = pointers1(a1) -s1 = pointers2(a1) - -xn = xn(f1) -yn = yn(f1) - -x1 = xn(s1) -y1 = yn(s1) - -IF Xs1(a1) = -1 OR Xe1(a1) = -1 THEN ELSE LINE (Xs1(a1), Ys1(a1))-(Xe1(a1), Ye1(a1)), 0 -IF x1 = -1 OR xn = -1 THEN ELSE LINE (x1, y1)-(xn, yn), 15 - - -Xs1(a1) = x1: Ys1(a1) = y1 -Xe1(a1) = xn: Ye1(a1) = yn -NEXT - - -k$ = INKEY$ -IF k$ <> "" THEN - -SELECT CASE k$ - -CASE CHR$(0) + "M" -d1 = d1 - 1 - -CASE CHR$(0) + "K" -d1 = d1 + 1 - -CASE CHR$(0) + "P" -d2 = d2 + 1 - -CASE CHR$(0) + "H" -d2 = d2 - 1 - -CASE "w" -d3 = d3 - 1 - -CASE "z" -d3 = d3 + 1 - -CASE "-" -speed = speed - 1 - -CASE "+" -speed = speed + 1 - -CASE " " -d1 = 0 -d2 = 0 -d3 = 0 -speed = 0 - -CASE CHR$(27) -SYSTEM - -END SELECT -k$ = "" -END IF -LOOP -END SUB - -SUB setgus -gusxp = gusxp + ssu -smes = smes + ssu -IF smes > 15 THEN smes = 1 -IF smes < 1 THEN smes = 15 -b = smes - -FOR a = gusalgp TO gusalgp + 48 STEP 2 -x(a) = gusx(b) - gusxp -y(a) = gusy(b) -cz(a) = 50 -x(a + 1) = gusx(b) - gusxp -y(a + 1) = gusy(b) -cz(a + 1) = 30 -b = b + 15 -NEXT a - -b = smes -FOR a = gusalgp + 48 TO gusalgp + 94 STEP 2 -x(a) = gusx(b) - gusxp -y(a) = gusy(b) -cz(a) = -50 -x(a + 1) = gusx(b) - gusxp -y(a + 1) = gusy(b) -cz(a + 1) = -30 -b = b + 15 -NEXT a - -' maa -FOR a = 0 TO 84 -x(a) = x(a) - ssu -NEXT a - -IF x(84) > 0 THEN ssu = 1 -IF x(83) < -400 THEN ssu = -1 - - - - -END SUB - -SUB start -SCREEN 12 -CLS -speed = 0 - -'deg1 = 270 -'deg2 = 0 -'deg3 = 90 - -deg1 = 210 -deg2 = 20 -deg3 = 90 - -smes = 1 -gusxp = 0 - -myxp = 0 -myyp = 0 -myzp = 0 -myx = 0 -myy = -300 -myz = 100 -smes = 1 - -ssu = 1 - -calcsin - -getcor -teemaad -getgus - - -END SUB - -SUB teemaad -silalgl = nl -np = np + 0 -silalgp = np - -5 -READ x(np), y(np), cz(np) -IF x(np) = 999 THEN x(np) = 0: y(np) = 0: cz(np) = 0: GOTO 3 -np = np + 1 -GOTO 5 - -3 -READ pointers1(nl), pointers2(nl) -IF pointers1(nl) = 999 THEN GOTO 4 -pointers1(nl) = pointers1(nl) + silalgp -pointers2(nl) = pointers2(nl) + silalgp -nl = nl + 1 -GOTO 3 -4 - -END SUB - +' Program to render animated 3D tank that drives back and forth on the 3D bridge. +' User can fly around the tank and bridge. +' By Svjatoslav Agejenko. +' Email: svjatoslav@svjatoslav.eu +' Homepage: http://www.svjatoslav.eu +' +' Changelog: +' 2000, Initial version +' 2024, Improved program readability using AI + +' Use keys to move around: +' Left, Right, Up, Down look around +' + move forward +' - move back +' q quit +' - stop + +DECLARE SUB start () +DECLARE SUB savepos (x1%, y1%, x2%, y2%) +DECLARE SUB teemaad () +DECLARE SUB setgus () +DECLARE SUB getgus () +DECLARE SUB getgus1 (x1%, y1%, x2%, y2%) +DECLARE SUB kiri () +DECLARE SUB getcor () +DECLARE SUB mulcor () +DECLARE SUB nait3d () +DECLARE SUB calcsin () +DEFINT A-Y +DIM SHARED xn(1000), yn(1000), czn(1000) ' original points +DIM SHARED x(1000), y(1000), cz(1000) ' Rotated points +DIM SHARED Xs1(1000), Ys1(1000), Xe1(1000), Ye1(1000) ' Old rotated points +DIM SHARED pointers1(1000), pointers2(1000) ' Connected points +DIM SHARED cosine&(360), sine&(360) ' SIN & COS table +DIM SHARED np, nl + +DIM SHARED gusx(1 TO 1000) +DIM SHARED gusy(1 TO 1000) +DIM SHARED mitgus +DIM SHARED smes + +DIM SHARED gusalgp ' segment +DIM SHARED gusalgl +DIM SHARED silalgp ' segment +DIM SHARED silalgl + +DIM SHARED gusxp +DIM SHARED myx, myy, myz +DIM SHARED myxp, myyp, myzp + +DIM SHARED deg1, deg2, deg3 +DIM SHARED speed + +DIM SHARED ssu + +start + +nait3d + +DATA -10,-30,-20 +DATA 30,-30,-20 +DATA 30,-10,-20 +DATA -10,-10,-20 + +DATA -10,-30,20 +DATA 30,-30,20 +DATA 30,-10,20 +DATA -10,-10,20 + +DATA -10,-40,-15 +DATA 30,-40,-15 +DATA -10,-40,15 +DATA 30,-40,15 + +DATA -20,-30,-15 +DATA -20,-30, 15 + +DATA -70,-10,-50 +DATA 60,-10, -50 +DATA 70, 0, -50 +DATA 70, 20, -50 +DATA 60, 30, -50 +DATA -70,30, -50 +DATA -80,20, -50 +DATA -80, 0, -50 + +DATA -70,-10,-30 +DATA 60,-10, -30 +DATA 70, 0, -30 +DATA 70, 20, -30 +DATA 60, 30, -30 +DATA -70,30, -30 +DATA -80,20, -30 +DATA -80, 0, -30 + +DATA -70,-10, 50 +DATA 60,-10, 50 +DATA 70, 0, 50 +DATA 70, 20, 50 +DATA 60, 30, 50 +DATA -70,30, 50 +DATA -80,20, 50 +DATA -80, 0, 50 + +DATA -70,-10, 30 +DATA 60,-10, 30 +DATA 70, 0, 30 +DATA 70, 20, 30 +DATA 60, 30, 30 +DATA -70,30, 30 +DATA -80,20, 30 +DATA -80, 0, 30 + +DATA -50,-7,-30 +DATA 50,-7,-30 +DATA 50, 15,-30 +DATA -50, 15,-30 + +DATA -50,-7, 30 +DATA 50,-7, 30 +DATA 50, 15,30 +DATA -50, 15,30 + +DATA -20,-20,-5 +DATA -20,-20, 5 +DATA -20,-30, 5 +DATA -20,-30,-5 + +DATA -100,-30,-5 +DATA -100,-30, 5 +DATA -100,-40, 5 +DATA -100,-40,-5 + +DATA 999,999,999 + +DATA 0,1 +DATA 1,2 +DATA 2,3 +DATA 3,0 + +DATA 4,5 +DATA 5,6 +DATA 6,7 +DATA 7,4 + +DATA 0,8 +DATA 1,9 +DATA 4,10 +DATA 5,11 + +DATA 0,12 +DATA 4,13 +DATA 12,8 +DATA 13,10 + +DATA 8,9 +DATA 10,11 +DATA 8,10 +DATA 9,11 + +DATA 12,13 +DATA 12,3 +DATA 13,7 +DATA 3,7 +DATA 1,5 +DATA 2,6 + +DATA 14,15 +DATA 15,16 +DATA 16,17 +DATA 17,18 +DATA 18,19 +DATA 19,20 +DATA 20,21 +DATA 21,14 + +DATA 22,23 +DATA 23,24 +DATA 24,25 +DATA 25,26 +DATA 26,27 +DATA 27,28 +DATA 28,29 +DATA 29,22 + +'DATA 14,22 +'DATA 15,23 +'DATA 16,24 +'DATA 17,25 +'DATA 18,26 +'DATA 19,27 +'DATA 20,28 +'DATA 21,29 + +DATA 30,31 +DATA 31,32 +DATA 32,33 +DATA 33,34 +DATA 34,35 +DATA 35,36 +DATA 36,37 +DATA 37,30 + +DATA 38,39 +DATA 39,40 +DATA 40,41 +DATA 41,42 +DATA 42,43 +DATA 43,44 +DATA 44,45 +DATA 45,38 + +'DATA 30,38 +'DATA 31,39 +'DATA 32,40 +'DATA 33,41 +'DATA 34,42 +'DATA 35,43 +'DATA 36,44 +'DATA 37,45 + +DATA 46,47 +DATA 47,48 +DATA 48,49 +DATA 49,46 + +DATA 50,51 +DATA 51,52 +DATA 52,53 +DATA 53,50 + +DATA 50,46 +DATA 51,47 +DATA 52,48 +DATA 53,49 + +DATA 54,55 +DATA 55,56 +DATA 56,57 +DATA 57,54 + +DATA 54,58 +DATA 55,59 +DATA 56,60 +DATA 57,61 + +DATA 58,59 +DATA 59,60 +DATA 60,61 +DATA 61,58 + +DATA 54,3 +DATA 55,7 + +'DATA 62,63 + +DATA 999, 999 +' BRIDGE + +' right handlebars +DATA 100,0,100 +DATA 100,50,100 + +DATA 50,0,100 +DATA 50,50,100 + +DATA 0,0,100 +DATA 0,50,100 + +DATA -50,0,100 +DATA -50,50,100 + +DATA -100,0,100 +DATA -100,50,100 + ' 5 +DATA -150,0,100 +DATA -150,50,100 + +DATA -200,0,100 +DATA -200,50,100 + +DATA -250,0,100 +DATA -250,50,100 + +DATA -300,0,100 +DATA -300,50,100 + +DATA -350,0,100 +DATA -350,50,100 + ' 10 + +DATA -400,0,100 +DATA -400,50,100 + +DATA -450,0,100 +DATA -450,50,100 + +DATA -500,0,100 +DATA -500,50,100 + +DATA -550,0,100 +DATA -550,50,100 + +DATA -600,0,100 +DATA -600,50,100 + +DATA -650,0,100 +DATA -650,50,100 + + ' left handlebars +DATA 100,0,-100 +DATA 100,50,-100 + +DATA 50,0,-100 +DATA 50,50,-100 + +DATA 0,0,-100 +DATA 0,50,-100 + +DATA -50,0,-100 +DATA -50,50,-100 + +DATA -100,0,-100 +DATA -100,50,-100 + ' 5 +DATA -150,0,-100 +DATA -150,50,-100 + +DATA -200,0,-100 +DATA -200,50,-100 + +DATA -250,0,-100 +DATA -250,50,-100 + +DATA -300,0,-100 +DATA -300,50,-100 + +DATA -350,0,-100 +DATA -350,50,-100 + ' 10 + +DATA -400,0,-100 +DATA -400,50,-100 + +DATA -450,0,-100 +DATA -450,50,-100 + +DATA -500,0,-100 +DATA -500,50,-100 + +DATA -550,0,-100 +DATA -550,50,-100 + +DATA -600,0,-100 +DATA -600,50,-100 + +DATA -650,0,-100 +DATA -650,50,-100 + ' alumine joon +DATA 100,75,-100 +DATA -650,75,-100 + +DATA 100,75,100 +DATA -650,75,100 + ' kallas +DATA 75,75,-100 +DATA 75,75,100 + 'parem +DATA -50,200,-100 +DATA -50,200,100 + +DATA 75,200,-190 +DATA 75,200, 190 + 'vasak +DATA -525,200,-100 +DATA -525,200, 100 + +DATA -600,200,-190 +DATA -600,200, 190 + +' + +DATA 999,999,999 + + 'right handlebars +'DATA 0,1 +DATA 2,3 +DATA 4,5 +DATA 6,7 +DATA 8,9 + +DATA 10,11 +DATA 12,13 +DATA 14,15 +DATA 16,17 +DATA 18,19 + +DATA 20,21 +DATA 22,23 +DATA 24,25 +DATA 26,27 +DATA 28,29 +'DATA 30,31 + + 'left handlebars +'DATA 32,33 +DATA 34,35 +DATA 36,37 +DATA 38,39 +DATA 40,41 + +DATA 42,43 +DATA 44,45 +DATA 46,47 +DATA 48,49 +DATA 50,51 + +DATA 52,53 +DATA 54,55 +DATA 56,57 +DATA 58,59 +DATA 60,61 +'DATA 62,63 + ' sild ise +'DATA 0,30 +'DATA 1,31 +'DATA 32,62 +'DATA 33,63 + +' pikad +DATA 0,4 +DATA 4,8 +DATA 8,12 +DATA 12,16 +DATA 16,20 +DATA 20,24 +DATA 24,28 +DATA 28,30 + +DATA 1,5 +DATA 5,9 +DATA 9,13 +DATA 13,17 +DATA 17,21 +DATA 21,25 +DATA 25,29 +DATA 29,31 + +DATA 32,36 +DATA 36,40 +DATA 40,44 +DATA 44,48 +DATA 48,52 +DATA 52,56 +DATA 56,60 +DATA 60,62 + +DATA 33,37 +DATA 37,41 +DATA 41,45 +DATA 45,49 +DATA 49,53 +DATA 53,57 +DATA 57,61 +DATA 61,63 + +' + +' l�pp + +DATA 1,33 +DATA 31,63 + +DATA 64,65 +DATA 66,67 +DATA 64,66 +DATA 65,67 + +DATA 0,66 +DATA 32,64 +DATA 30,67 +DATA 62,65 + ' kallas +DATA 68,69 +DATA 70,71 +DATA 68,70 +DATA 69,71 + +DATA 72,70 +DATA 72,68 + +DATA 73,71 +DATA 73,69 + 'vasak +DATA 74,76 +DATA 75,77 +DATA 74,75 + +DATA 74,65 +DATA 76,65 + +DATA 75,67 +DATA 77,67 + +' + +DATA 999, 999 + +DEFINT Z +SUB calcsin +REM Calculating SIN and COS data... + +FOR a! = 0 TO 359 / 57.29577951# STEP 1 / 57.29577951# + cosine&(a) = INT(.5 + COS(a!) * 1024) + sine&(a) = INT(.5 + SIN(a!) * 1024) + a = a + 1 +NEXT +CLS +END SUB + +DEFSNG Z +SUB getcor +REM Loading original points and connected points +FOR a = 0 TO 10000 + READ x(a), y(a), cz(a) + IF x(a) = 999 THEN x(a) = 0: y(a) = 0: cz(a) = 0: GOTO 1 +NEXT +1 +np = a +FOR a = 0 TO 10000 + READ pointers1(a), pointers2(a) + IF pointers1(a) = 999 THEN GOTO 2 +NEXT +2 +nl = a + +gusalgp = np +gusalgl = nl + +REM Initializing connected points +FOR a = 1 TO 48 +pointers1(nl) = np +np = np + 1 +pointers2(nl) = np +np = np + 1 +nl = nl + 1 +NEXT a + +END SUB + +DEFINT Z +SUB getgus + +REM Initialize the number of segments +mitgus = 1 +getgus1 -70, -10, -80, 0 +getgus1 -80, 0, -80, 20 +getgus1 -80, 20, -70, 30 +getgus1 -70, 30, 60, 30 +getgus1 60, 30, 70, 20 +getgus1 70, 20, 70, 0 +getgus1 70, 0, 60, -10 +getgus1 60, -10, -70, -10 +'LOCATE 1, 1 +'PRINT mitgus +'SLEEP + +END SUB + +DEFSNG Z +SUB getgus1 (x1%, y1%, x2%, y2%) +REM Calculating points for a segment +z1 = ABS(x1 - x2) +z2 = ABS(y2 - y1) +mi = SQR(z1 ^ 2 + z2 ^ 2) * 1.017142857# + +REM Calculating direction vectors +zxp = (x1 - x2) / mi +zyp = (y2 - y1) / mi +zx = x1 +zy = y1 + +FOR a = 1 TO mi + zx = zx - zxp + zy = zy + zyp + gusx(mitgus) = zx + gusy(mitgus) = zy + mitgus = mitgus + 1 +NEXT a + +END SUB + + + +DEFSNG Z +SUB nait3d +REM Main loop to render the scene +DO + + setgus + + REM Updating rotation angles + deg1 = deg1 + d1 + deg2 = deg2 + d2 + deg3 = deg3 + d3 + + REM Normalizing angles + IF deg1 <= 0 THEN deg1 = deg1 + 360 + IF deg2 <= 0 THEN deg2 = deg2 + 360 + IF deg3 <= 0 THEN deg3 = deg3 + 360 + + IF deg1 >= 360 THEN deg1 = deg1 - 360 + IF deg2 >= 360 THEN deg2 = deg2 - 360 + IF deg3 >= 360 THEN deg3 = deg3 - 360 + + REM Calculating sine and cosine values + c1& = cosine&(deg1) + s1& = sine&(deg1) + c2& = cosine&(deg2) + s2& = sine&(deg2) + c3& = cosine&(deg3) + S3& = sine&(deg3) + + REM Updating tank position + myx = myx - (s1& * speed / 100) + myy = myy - (c1& * speed / 100) + myz = myz - (s2& * speed / 100) + + REM Rotating points + FOR a = 0 TO np - 1 + x1 = x(a) + myx + y1 = y(a) + myz + pz1 = cz(a) + myy + + REM Applying rotation matrix + x2 = (x1 * c1& - pz1 * s1&) \ 1024 + pz2 = (x1 * s1& + pz1 * c1&) \ 1024 + + y2 = (y1 * c2& - pz2 * s2&) \ 1024 + pz3 = (y1 * s2& + pz2 * c2&) \ 1024 + + x3 = (y2 * c3& - x2 * S3&) \ 1024 + y3 = (y2 * S3& + x2 * c3&) \ 1024 + + REM Checking if point is within view + IF pz3 > 10 THEN + xn(a) = 320 + (x3 / pz3 * 500) + yn(a) = 240 + (y3 / pz3 * 500) + ELSE + xn(a) = -1 + END IF + NEXT + + REM Drawing lines between connected points + FOR a1 = 0 TO nl - 1 + f1 = pointers1(a1) + s1 = pointers2(a1) + + xn = xn(f1) + yn = yn(f1) + + x1 = xn(s1) + y1 = yn(s1) + + REM Drawing lines + IF Xs1(a1) = -1 OR Xe1(a1) = -1 THEN + ELSE + LINE (Xs1(a1), Ys1(a1))-(Xe1(a1), Ye1(a1)), 0 + END IF + + IF x1 = -1 OR xn = -1 THEN + ELSE + LINE (x1, y1)-(xn, yn), 15 + END IF + + REM Updating old rotated points + Xs1(a1) = x1 + Ys1(a1) = y1 + + Xe1(a1) = xn + Ye1(a1) = yn + NEXT + + REM Handling user input + k$ = INKEY$ + IF k$ <> "" THEN + + SELECT CASE k$ + + CASE CHR$(0) + "M" + d1 = d1 - 1 + + CASE CHR$(0) + "K" + d1 = d1 + 1 + + CASE CHR$(0) + "P" + d2 = d2 + 1 + + CASE CHR$(0) + "H" + d2 = d2 - 1 + + CASE "w" + d3 = d3 - 1 + + CASE "z" + d3 = d3 + 1 + + CASE "-" + speed = speed - 1 + + CASE "+" + speed = speed + 1 + + CASE " " + d1 = 0 + d2 = 0 + d3 = 0 + speed = 0 + + CASE CHR$(27) + SYSTEM + + END SELECT + k$ = "" + END IF +LOOP +END SUB + +SUB setgus +REM Updating tank position +gusxp = gusxp + ssu +smes = smes + ssu +IF smes > 15 THEN smes = 1 +IF smes < 1 THEN smes = 15 +b = smes + +FOR a = gusalgp TO gusalgp + 48 STEP 2 + x(a) = gusx(b) - gusxp + y(a) = gusy(b) + cz(a) = 50 + x(a + 1) = gusx(b) - gusxp + y(a + 1) = gusy(b) + cz(a + 1) = 30 + b = b + 15 +NEXT a + +b = smes +FOR a = gusalgp + 48 TO gusalgp + 94 STEP 2 + x(a) = gusx(b) - gusxp + y(a) = gusy(b) + cz(a) = -50 + x(a + 1) = gusx(b) - gusxp + y(a + 1) = gusy(b) + cz(a + 1) = -30 + b = b + 15 +NEXT a + +REM Moving the tank +FOR a = 0 TO 84 + x(a) = x(a) - ssu +NEXT a + +IF x(84) > 0 THEN ssu = 1 +IF x(83) < -400 THEN ssu = -1 + +END SUB + +SUB start +REM Initializing the program +SCREEN 12 +CLS +speed = 0 + +'deg1 = 270 +'deg2 = 0 +'deg3 = 90 + +deg1 = 210 +deg2 = 20 +deg3 = 90 + +smes = 1 +gusxp = 0 + +myxp = 0 +myyp = 0 +myzp = 0 +myx = 0 +myy = -300 +myz = 100 +smes = 1 + +ssu = 1 + +calcsin + +getcor +teemaad +getgus + +END SUB + +SUB teemaad +REM Adding new points and connected points +silalgl = nl +np = np + 0 +silalgp = np + +5 +READ x(np), y(np), cz(np) +IF x(np) = 999 THEN x(np) = 0: y(np) = 0: cz(np) = 0: GOTO 3 +np = np + 1 +GOTO 5 + +3 +READ pointers1(nl), pointers2(nl) +IF pointers1(nl) = 999 THEN GOTO 4 +pointers1(nl) = pointers1(nl) + silalgp +pointers2(nl) = pointers2(nl) + silalgp +nl = nl + 1 +GOTO 3 +4 + +END SUB