Created
January 1, 2026 11:16
-
-
Save samizzo/a665fecf39ad6914d5282e64f721d2f2 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 INTEGER | |
| DIM pointsy(1 TO nbPoints) AS INTEGER | |
| DIM pointsz(1 TO nbPoints) AS INTEGER | |
| DIM trigTableSize AS INTEGER | |
| trigTableSize = 512 | |
| DIM sintab(0 TO trigTableSize - 1) AS INTEGER | |
| DIM costab(0 TO trigTableSize - 1) AS INTEGER | |
| FOR i = 0 TO trigTableSize - 1 | |
| ang! = i * 2 * 3.1415 / trigTableSize | |
| sintab(i) = INT(SIN(ang!) * 256) | |
| costab(i) = INT(COS(ang!) * 256) | |
| pct% = (i * 100) / trigTableSize | |
| LOCATE 1, 1 | |
| PRINT "Initialising.. "; pct%; "%"; | |
| NEXT i | |
| SCREEN 1 | |
| CLS | |
| 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 x! | |
| pointsx(i) = INT(x! * 256) | |
| READ y! | |
| pointsy(i) = INT(y! * 256) | |
| READ z! | |
| pointsz(i) = INT(z! * 256) | |
| NEXT i | |
| TYPE point2 | |
| x AS INTEGER | |
| y AS INTEGER | |
| END TYPE | |
| TYPE Point3 | |
| x AS INTEGER | |
| y AS INTEGER | |
| z AS INTEGER | |
| 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 | |
| dz% = INT(.75 * 256) | |
| dangle% = INT(trigTableSize / (2 * 60)) | |
| angle% = 0 | |
| DO | |
| IF INKEY$ = CHR$(27) THEN EXIT DO | |
| angle% = angle% + dangle% | |
| IF angle% >= trigTableSize THEN angle% = 0 | |
| mcos% = costab(angle%) | |
| msin% = sintab(angle%) | |
| CLS | |
| PRINT "Qbasic 1.1 - 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 | |
| REM 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 * 256) / p.z | |
| p.y = (p.y * 256) / p.z | |
| END SUB | |
| SUB RotateXZ (p AS Point3, mcos%, msin%) | |
| x% = p.x | |
| y% = p.y | |
| z% = p.z | |
| p.x = (x% * mcos% - z% * msin%) / 256 | |
| p.y = y% | |
| p.z = (x% * msin% + z% * mcos%) / 256 | |
| 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 + 256) / 2) * W%) / 256 | |
| p.y = ((256 - (p.y + 256) / 2) * H%) / 256 | |
| 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