1 ' 3D Wireframe Exclamation mark
2 ' Author: Svjatoslav Agejenko
4 ' Up, Down, Left, Right, w, z - rotate
8 DECLARE SUB GetCoordinates ()
9 DECLARE SUB ScaleCoordinates ()
10 DECLARE SUB Render3D ()
11 DECLARE SUB CalculateSineCosine ()
14 Dim Shared Xn(100), Yn(100), Zn(100)
15 Dim Shared Xs1(100), Ys1(100), Xe1(100), Ye1(100)
16 Dim Shared x(100), y(100), z(100), pointers1(100), pointers2(100)
17 Dim Shared Cosine&(360), Sine&(360)
18 Dim Shared numPoints, numLines
19 Dim Shared rotationX, rotationY
116 Sub CalculateSineCosine
117 ' Precalculate sine and cosine values for faster computation
118 For angle! = 0 To 359 / 57.29577951# Step 1 / 57.29577951#
119 Cosine&(angle) = Int(.5 + Cos(angle!) * 1024)
120 Sine&(angle) = Int(.5 + Sin(angle!) * 1024)
126 ' Read vertex coordinates from DATA statements
128 Read x(i), y(i), z(i)
129 If x(i) = 999 Then x(i) = 0: y(i) = 0: z(i) = 0: GoTo EndVertexData
134 ' Read line data from DATA statements
136 Read pointers1(i), pointers2(i)
137 If pointers1(i) = 999 Then GoTo EndLineData
144 ' Scale coordinates to fit the screen
146 For i = 0 To numPoints
147 If Abs(x(i)) > maxValue Then maxValue = Abs(x(i))
148 If Abs(y(i)) > maxValue Then maxValue = Abs(y(i))
149 If Abs(z(i)) > maxValue Then maxValue = Abs(z(i))
151 scaleFactor = 100 / maxValue
152 For i = 0 To numPoints
153 x(i) = x(i) * scaleFactor
154 y(i) = y(i) * scaleFactor
155 z(i) = z(i) * scaleFactor
161 ' Update rotation angles
162 rotationX = rotationX + dx
163 rotationY = rotationY + dy
164 rotationZ = rotationZ + dz
167 ' Wrap rotation angles within 0 to 359 degrees
168 If rotationX <= 0 Then rotationX = rotationX + 360
169 If rotationY <= 0 Then rotationY = rotationY + 360
170 If rotationZ <= 0 Then rotationZ = rotationZ + 360
171 If rotationX >= 360 Then rotationX = rotationX - 360
172 If rotationY >= 360 Then rotationY = rotationY - 360
173 If rotationZ >= 360 Then rotationZ = rotationZ - 360
175 ' Get sine and cosine values for rotation angles
176 cosX& = Cosine&(rotationX): sinX& = Sine&(rotationX)
177 cosY& = Cosine&(rotationY): sinY& = Sine&(rotationY)
178 cosZ& = Cosine&(rotationZ): sinZ& = Sine&(rotationZ)
180 ' Rotate and project vertices
181 For i = 0 To numPoints - 1
182 Xo = x(i): Yo = y(i): Zo = z(i)
183 X1 = (Xo * cosX& - Yo * sinX&) \ 1024
184 Y1 = (Xo * sinX& + Yo * cosX&) \ 1024
185 X2& = (X1 * cosY& - Zo * sinY&) \ 1024
186 Z1 = (X1 * sinY& + Zo * cosY&) \ 1024
187 Y2& = (Y1 * cosZ& - Z1 * sinZ&) \ 1024
188 Z2 = (Y1 * sinZ& + Z1 * cosZ&) \ 1024
190 Xn(i) = 320 + (X2& / Z2 * 500)
191 Yn(i) = 240 + (Y2& / Z2 * 500)
194 ' Draw lines between vertices
195 For i = 0 To numLines - 1
196 startVertex = pointers1(i)
197 endVertex = pointers2(i)
202 Line (Xs1(i), Ys1(i))-(Xe1(i), Ye1(i)), 0
203 Line (X1, Y1)-(Xn, Yn), 15
204 Xs1(i) = X1: Ys1(i) = Y1
205 Xe1(i) = Xn: Ye1(i) = Yn
212 Case Chr$(0) + Chr$(72) ' Up arrow
214 Case Chr$(0) + Chr$(80) ' Down arrow
216 Case Chr$(0) + Chr$(75) ' Left arrow
218 Case Chr$(0) + Chr$(77) ' Right arrow
228 Case Chr$(27) ' Escape key