Created
December 31, 2025 14:13
-
-
Save kevingosse/d05eca4434ed621f5a736ddced957865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE SUB RotateXZ (p AS ANY, mcos!, msin!) | |
| DECLARE SUB ToScreen (p AS ANY) | |
| DECLARE SUB TranslateZ (p AS ANY, dz!) | |
| DECLARE SUB DrawLine (p1 AS ANY, p2 AS ANY) | |
| DECLARE SUB Project (p AS ANY) | |
| DECLARE SUB SleepMS (ms!) | |
| CONST W% = 320 | |
| CONST H% = 200 | |
| SCREEN 1 | |
| CLS | |
| DIM lines(1 TO 6, 1 TO 4) | |
| DIM LineLen(1 TO 6) | |
| DIM nbPoints AS INTEGER | |
| nbPoints = 8 | |
| DIM pointsx(1 TO nbPoints) AS SINGLE | |
| DIM pointsy(1 TO nbPoints) AS SINGLE | |
| DIM pointsz(1 TO nbPoints) AS SINGLE | |
| DATA 0.25, 0.25, 0.25 | |
| DATA -0.25, 0.25, 0.25 | |
| DATA -0.25, -0.25, 0.25 | |
| DATA 0.25, -0.25, 0.25 | |
| DATA 0.25, 0.25, -0.25 | |
| DATA -0.25, 0.25, -0.25 | |
| DATA -0.25, -0.25, -0.25 | |
| DATA 0.25, -0.25, -0.25 | |
| FOR i = 1 TO nbPoints | |
| READ pointsx(i) | |
| READ pointsy(i) | |
| READ pointsz(i) | |
| NEXT i | |
| TYPE point2 | |
| x AS SINGLE | |
| y AS SINGLE | |
| END TYPE | |
| TYPE Point3 | |
| x AS SINGLE | |
| y AS SINGLE | |
| z AS SINGLE | |
| END TYPE | |
| DATA 4, 0,1,2,3 | |
| DATA 4, 4,5,6,7 | |
| DATA 2, 0,4 | |
| DATA 2, 1,5 | |
| DATA 2, 2,6 | |
| DATA 2, 3,7 | |
| FOR i = 1 TO 6 | |
| READ LineLen(i) | |
| FOR j = 1 TO LineLen(i) | |
| READ lines(i, j) | |
| lines(i, j) = lines(i, j) + 1 | |
| NEXT j | |
| NEXT i | |
| dt! = 1 / 60 | |
| dz! = .75 | |
| angle! = 0 | |
| DO | |
| IF INKEY$ = CHR$(27) THEN EXIT DO | |
| angle! = angle! + 3.1415 * dt! | |
| mcos! = COS(angle) | |
| msin! = SIN(angle) | |
| CLS | |
| PRINT "QuickBasic 4.5 - CGA" | |
| FOR i = 1 TO 6 ' for each line | |
| FOR j = 1 TO LineLen(i) | |
| l = lines(i, j) | |
| ax! = pointsx(l) | |
| ay! = pointsy(l) | |
| az! = pointsz(l) | |
| modj = (j + 1) MOD (LineLen(i) + 1) | |
| IF modj = 0 THEN modj = 1 | |
| bx = pointsx(lines(i, modj)) | |
| by = pointsy(lines(i, modj)) | |
| bz = pointsz(lines(i, modj)) | |
| DIM a AS Point3 | |
| a.x = ax! | |
| a.y = ay! | |
| a.z = az! | |
| DIM b AS Point3 | |
| b.x = bx! | |
| b.y = by! | |
| b.z = bz! | |
| RotateXZ a, mcos!, msin! | |
| TranslateZ a, dz | |
| Project a | |
| ToScreen a | |
| RotateXZ b, mcos!, msin! | |
| TranslateZ b, dz | |
| Project b | |
| ToScreen b | |
| DrawLine a, b | |
| NEXT j | |
| NEXT i | |
| SleepMS (20) | |
| LOOP | |
| quit: | |
| SUB DrawLine (p1 AS Point3, p2 AS Point3) | |
| LINE (p1.x, p1.y)-(p2.x, p2.y), 3 | |
| END SUB | |
| SUB Project (p AS Point3) | |
| p.x = p.x / p.z | |
| p.y = p.y / p.z | |
| END SUB | |
| SUB RotateXZ (p AS Point3, mcos!, msin!) | |
| 'mcos = COS(angle) | |
| 'msin = SIN(angle) | |
| x! = p.x | |
| y! = p.y | |
| z! = p.z | |
| p.x = x! * mcos! - z! * msin! | |
| p.y = y! | |
| p.z = x! * msin! + z! * mcos! | |
| END SUB | |
| SUB SleepMS (ms!) | |
| t! = TIMER | |
| DO | |
| LOOP WHILE TIMER < t! + ms! / 1000! | |
| END SUB | |
| SUB ToScreen (p AS Point3) | |
| p.x = ((p.x + 1) / 2) * W% | |
| p.y = (1 - (p.y + 1) / 2) * H% | |
| END SUB | |
| SUB TranslateZ (p AS Point3, dz!) | |
| p.z = p.z + dz! | |
| END SUB | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment