' Program to render animated 3D tank that drives back and forth on the 3D bridge.
-' User can fly around the tank and bridge.
+' Notably, tracks on the tank are properly synchronized with the tank movement.
+' User can freely look and fly around in the space.
+'
' By Svjatoslav Agejenko.
' Email: svjatoslav@svjatoslav.eu
' Homepage: http://www.svjatoslav.eu
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 setTracks ()
+DECLARE SUB getTracks ()
+DECLARE SUB getTracks1 (x1%, y1%, x2%, y2%)
DECLARE SUB kiri ()
DECLARE SUB getcor ()
DECLARE SUB mulcor ()
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 Tracksx(1 TO 1000)
+DIM SHARED Tracksy(1 TO 1000)
+DIM SHARED mitTracks
DIM SHARED smes
-DIM SHARED gusalgp ' segment
-DIM SHARED gusalgl
-DIM SHARED silalgp ' segment
-DIM SHARED silalgl
+' Pointers to the beginning of the tank tracks, this is needed to animate tank tracks
+DIM SHARED TracksBeginp ' point index
+DIM SHARED TracksBeginl ' line index
+
+' Pointers to the beginning of the bridge
+DIM SHARED BridgeBeginp ' point index
+DIM SHARED BridgeBeginl ' line index
-DIM SHARED gusxp
+DIM SHARED Tracksxp
DIM SHARED myx, myy, myz
DIM SHARED myxp, myyp, myzp
2
nl = a
-gusalgp = np
-gusalgl = nl
+TracksBeginp = np
+TracksBeginl = nl
-REM Initializing connected points
+' Initializing connected points
FOR a = 1 TO 48
pointers1(nl) = np
np = np + 1
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
+SUB getTracks
+
+' Initialize the number of segments
+mitTracks = 1
+getTracks1 -70, -10, -80, 0
+getTracks1 -80, 0, -80, 20
+getTracks1 -80, 20, -70, 30
+getTracks1 -70, 30, 60, 30
+getTracks1 60, 30, 70, 20
+getTracks1 70, 20, 70, 0
+getTracks1 70, 0, 60, -10
+getTracks1 60, -10, -70, -10
END SUB
DEFSNG Z
-SUB getgus1 (x1%, y1%, x2%, y2%)
+SUB getTracks1 (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
+' Calculating direction vectors
zxp = (x1 - x2) / mi
zyp = (y2 - y1) / mi
zx = x1
FOR a = 1 TO mi
zx = zx - zxp
zy = zy + zyp
- gusx(mitgus) = zx
- gusy(mitgus) = zy
- mitgus = mitgus + 1
+ Tracksx(mitTracks) = zx
+ Tracksy(mitTracks) = zy
+ mitTracks = mitTracks + 1
NEXT a
END SUB
DEFSNG Z
SUB nait3d
-REM Main loop to render the scene
+' Main loop to render the scene
DO
- setgus
+ setTracks
- REM Updating rotation angles
+ ' Updating rotation angles
deg1 = deg1 + d1
deg2 = deg2 + d2
deg3 = deg3 + d3
- REM Normalizing angles
+ ' Normalizing angles
IF deg1 <= 0 THEN deg1 = deg1 + 360
IF deg2 <= 0 THEN deg2 = deg2 + 360
IF deg3 <= 0 THEN deg3 = deg3 + 360
IF deg2 >= 360 THEN deg2 = deg2 - 360
IF deg3 >= 360 THEN deg3 = deg3 - 360
- REM Calculating sine and cosine values
+ ' sine and cosine values lookup
c1& = cosine&(deg1)
s1& = sine&(deg1)
c2& = cosine&(deg2)
c3& = cosine&(deg3)
S3& = sine&(deg3)
- REM Updating tank position
+ ' Updating tank position
myx = myx - (s1& * speed / 100)
myy = myy - (c1& * speed / 100)
myz = myz - (s2& * speed / 100)
- REM Rotating points
+ ' Rotating points
FOR a = 0 TO np - 1
x1 = x(a) + myx
y1 = y(a) + myz
pz1 = cz(a) + myy
- REM Applying rotation matrix
+ ' Applying rotation matrix
x2 = (x1 * c1& - pz1 * s1&) \ 1024
pz2 = (x1 * s1& + pz1 * c1&) \ 1024
x3 = (y2 * c3& - x2 * S3&) \ 1024
y3 = (y2 * S3& + x2 * c3&) \ 1024
- REM Checking if point is within view
+ ' Checking if point is within view
IF pz3 > 10 THEN
xn(a) = 320 + (x3 / pz3 * 500)
yn(a) = 240 + (y3 / pz3 * 500)
END IF
NEXT
- REM Drawing lines between connected points
+ ' Drawing lines between connected points
FOR a1 = 0 TO nl - 1
f1 = pointers1(a1)
s1 = pointers2(a1)
x1 = xn(s1)
y1 = yn(s1)
- REM Drawing lines
+ ' Drawing lines
IF Xs1(a1) = -1 OR Xe1(a1) = -1 THEN
ELSE
LINE (Xs1(a1), Ys1(a1))-(Xe1(a1), Ye1(a1)), 0
LINE (x1, y1)-(xn, yn), 15
END IF
- REM Updating old rotated points
+ ' Updating old rotated points
Xs1(a1) = x1
Ys1(a1) = y1
Ye1(a1) = yn
NEXT
- REM Handling user input
+ ' Handling user input
k$ = INKEY$
IF k$ <> "" THEN
LOOP
END SUB
-SUB setgus
+SUB setTracks
' Updating tank position
-gusxp = gusxp + ssu
+Tracksxp = Tracksxp + 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)
+FOR a = TracksBeginp TO TracksBeginp + 48 STEP 2
+ x(a) = Tracksx(b) - Tracksxp
+ y(a) = Tracksy(b)
cz(a) = 50
- x(a + 1) = gusx(b) - gusxp
- y(a + 1) = gusy(b)
+ x(a + 1) = Tracksx(b) - Tracksxp
+ y(a + 1) = Tracksy(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)
+FOR a = TracksBeginp + 48 TO TracksBeginp + 94 STEP 2
+ x(a) = Tracksx(b) - Tracksxp
+ y(a) = Tracksy(b)
cz(a) = -50
- x(a + 1) = gusx(b) - gusxp
- y(a + 1) = gusy(b)
+ x(a + 1) = Tracksx(b) - Tracksxp
+ y(a + 1) = Tracksy(b)
cz(a + 1) = -30
b = b + 15
NEXT a
END SUB
SUB start
-REM Initializing the program
+' Initializing the program
SCREEN 12
CLS
speed = 0
deg3 = 90
smes = 1
-gusxp = 0
+Tracksxp = 0
myxp = 0
myyp = 0
getcor
teemaad
-getgus
+getTracks
END SUB
SUB teemaad
-REM Adding new points and connected points
-silalgl = nl
+' Adding new points and connected points
+BridgeBeginl = nl
np = np + 0
-silalgp = np
+BridgeBeginp = np
5
READ x(np), y(np), cz(np)
3
READ pointers1(nl), pointers2(nl)
IF pointers1(nl) = 999 THEN GOTO 4
-pointers1(nl) = pointers1(nl) + silalgp
-pointers2(nl) = pointers2(nl) + silalgp
+pointers1(nl) = pointers1(nl) + BridgeBeginp
+pointers2(nl) = pointers2(nl) + BridgeBeginp
nl = nl + 1
GOTO 3
4