'MENTAT'S CUBE V.2
'WIREFRAME MANIPULATION
'PRESS Q TO QUIT
'THE KEYS ARE: " 2 4 6 8 , . / * - + R Q" AND ARROW KEYS

'VERSION 2:
'VANISHING POINT IS THE CENTER OF THE SCREEN
'IMPROVED CONTROLS
'ADJUSTED Z COODRINATES
'ADDED VERSION INFO

START:
        PRINT "MENTAT'S WIREFRAME CUBE V.2"
        PRINT "FOR MORE INFO, PRESS I"
        PRINT "THANKS TO RelSoft FOR HIS TUTORIAL ON 2D ROTATIONS."
        PRINT "BLUESHIFT IS TOWARD THE POINT OF VIEW, REDSHIFT IS AWAY"
        PRINT "KEY         | ACTION"
        PRINT "------------+----------------------------"
        PRINT "8           | ROTATES BLUESHIFT DOWN, REDSHIFT UP"
        PRINT "2           | ROTATES BLUESHIFT UP, REDSHIFT DOWN"
        PRINT "4           | ROTATES BLUESHIFT LEFT, REDSHIFT RIGHT"
        PRINT "6           | ROTATES BLUESHIFT RIGHT, REDSHIFT LEFT"
        PRINT ",           | ROTATE CUBE COUNTERCLOCK WISE"
        PRINT ".           | ROTATE CUBE CLOCK WISE"
        PRINT "/           | MOVE CUBE FORWARD"
        PRINT "*           | MOVE CUBE BACKWARD"
        PRINT "-           | ZOOM OUT"
        PRINT "+           | ZOOM IN"
        PRINT "R           | SHOW HELP AND RESET CUBE"
        PRINT "Q           | QUIT"
        PRINT "LEFT ARROW  | MOVE CUBE LEFT"
        PRINT "RIGHT ARROW | MOVE CUBE RIGHT"
        PRINT "UP ARROW    | MOVE CUBE UP"
        PRINT "DOWN ARROW  | MOVE CUBE RIGHT"
        PRINT "PRESS ANY KEY. THE CUBE WILL WON'T SHOW UNTIL A COMMAND IS ENTERED."
       
        DO
                KEY$ = INKEY$
                IF KEY$ = "I" THEN GOSUB INFO
        LOOP WHILE KEY$ = ""

        SCREEN 12
        CLS
        DIM PX(8)       'SCREEN X COORDINATES
        DIM PY(8)       'SCREEN Y COORDINATES
        DIM VX(8)       'X COORDINATES
        DIM VY(8)       'Y COORDINATES
        DIM VZ(8)       'Z COORDINATES
        LET SCALE = 100
        LET OX = 320  'OFSETS, COORDINATES OF THE CENTER OF REVOLUTION
        LET OY = 240
        LET OZ = 1.1
        LET X1 = 270
        LET X2 = 370  'DEFUALT COORDINATES
        LET Y1 = 190  'I HAD THESE SETUP BECUASE OF EASE OF EDITING
        LET Y2 = 290
        LET Z1 = 1
        LET Z2 = 2
                          
        LET VX(1) = X1
        LET VX(4) = X1
        LET VX(5) = X1
        LET VX(8) = X1
        LET VX(2) = X2
        LET VX(3) = X2
        LET VX(6) = X2
        LET VX(7) = X2
        LET VY(1) = Y1
        LET VY(2) = Y1
        LET VY(5) = Y1
        LET VY(6) = Y1
        LET VY(3) = Y2
        LET VY(4) = Y2
        LET VY(7) = Y2
        LET VY(8) = Y2
        FOR I = 1 TO 4           'I HAD TO CHEAT
                LET VZ(I) = Z1
        NEXT I
        FOR I = 5 TO 8
                LET VZ(I) = Z2
        NEXT I

MAIN:
        DO
                COLOR 14
                PSET (320, 240) 'CENTER DOT
                PSET (320, 239)
                PSET (321, 240)
                PSET (320, 241)
                PSET (319, 240)
                COLOR 15
                DO
                        LET KEY$ = INKEY$
                LOOP WHILE KEY$ = ""

                SELECT CASE KEY$
                        CASE "2"                  'ROTATE YZ AXIS FRONTWARDS
                                FOR I = 1 TO 8
                                        LET VZ(I) = OZ + (VZ(I) - OZ) * COS(-.01) - ((VY(I) - OY) / 100) * SIN(-.01)
                                        LET VY(I) = OY + (VY(I) - OY) * COS(-.01) + 100 * (VZ(I) - OZ) * SIN(-.01)
                                NEXT I
                        CASE "6"                  'ROTATE XZ AXIS
                                FOR I = 1 TO 8
                                        LET VX(I) = OX + (VX(I) - OX) * COS(.01) - 100 * (VZ(I) - OZ) * SIN(.01)
                                        LET VZ(I) = OZ + (VZ(I) - OZ) * COS(.01) + ((VX(I) - OX) / 100) * SIN(.01)
                                NEXT I
                        CASE "4"                  'ROTATE XZ AXIS
                                FOR I = 1 TO 8
                                        LET VX(I) = OX + (VX(I) - OX) * COS(-.01) - 100 * (VZ(I) - OZ) * SIN(-.01)
                                        LET VZ(I) = OZ + (VZ(I) - OZ) * COS(-.01) + ((VX(I) - OX) / 100) * SIN(-.01)
                                NEXT I
                        CASE "8"                  'ROTATE YZ AXIS BACKWARDS
                                FOR I = 1 TO 8
                                        LET VZ(I) = OZ + (VZ(I) - OZ) * COS(.01) - (100 / (VY(I) - OY)) * SIN(.01)
                                        LET VY(I) = OY + (VY(I) - OY) * COS(.01) + 100 * (VZ(I) - OZ) * SIN(.01)
                                NEXT I
                        CASE "."   'ROTATE XY AXIS COUNTERCLOCK WISE
                                FOR I = 1 TO 8
                                        LET VX(I) = 320 + (VX(I) - 320) * COS(.01) - (VY(I) - 240) * SIN(.01)
                                        LET VY(I) = 240 + (VY(I) - 240) * COS(.01) + (VX(I) - 320) * SIN(.01)
                                NEXT I
                        CASE ","   'ROTATE XY AXIS CLOCK WISE
                                FOR I = 1 TO 8
                                        LET VX(I) = 320 + (VX(I) - 320) * COS(-.01) - (VY(I) - 240) * SIN(-.01)
                                        LET VY(I) = 240 + (VY(I) - 240) * COS(-.01) + (VX(I) - 320) * SIN(-.01)
                                NEXT I
                        CASE CHR$(0) + CHR$(72)   'MOVE UP
                                FOR I = 1 TO 8
                                        LET VY(I) = VY(I) - 1
                                NEXT I
                        CASE CHR$(0) + CHR$(80)   'MOVE DOWN
                                FOR I = 1 TO 8
                                        LET VY(I) = VY(I) + 1
                                NEXT I
                        CASE CHR$(0) + CHR$(75)                'MOVE LEFT
                                FOR I = 1 TO 8
                                        LET VX(I) = VX(I) - 1
                                NEXT I
                        CASE CHR$(0) + CHR$(77)                'MOVE RIGHT
                                FOR I = 1 TO 8
                                        LET VX(I) = VX(I) + 1
                                NEXT I
                        CASE "+"                  'DECREASE SCALE, ZOOM IN
                                LET SCALE = SCALE - .1
                        CASE "-"                  'INCREASE SCALE, ZOOM OUT
                                LET SCALE = SCALE + .1
                        CASE "/"                  'DECREASES Z
                                FOR I = 1 TO 8
                                        LET VZ(I) = VZ(I) - .02
                                NEXT I
                        CASE "*"                  'INCREASES Z
                                FOR I = 1 TO 8
                                        LET VZ(I) = VZ(I) + .02
                                NEXT I
                        CASE "R"                  'RESTARTS
                                GOTO START
                        CASE "r"
                                GOTO START
                END SELECT

                FOR I = 1 TO 8
                                IF VZ(I) <> 0 THEN
                                LET PX(I) = 320 + (SCALE * (VX(I) - 320)) / VZ(I)
                                LET PY(I) = 240 + (SCALE * (VY(I) - 240)) / VZ(I)
                                END IF
                NEXT I

                CLS
                LINE (PX(1), PY(1))-(PX(2), PY(2)) 'FRONT LINES
                LINE (PX(2), PY(2))-(PX(3), PY(3))
                LINE (PX(3), PY(3))-(PX(4), PY(4))
                LINE (PX(4), PY(4))-(PX(1), PY(1))
                LINE (PX(1), PY(1))-(PX(5), PY(5)) 'SIDE LINES
                LINE (PX(2), PY(2))-(PX(6), PY(6))
                LINE (PX(3), PY(3))-(PX(7), PY(7))
                LINE (PX(4), PY(4))-(PX(8), PY(8))
                LINE (PX(5), PY(5))-(PX(6), PY(6)) 'BACK LINES
                LINE (PX(6), PY(6))-(PX(7), PY(7))
                LINE (PX(7), PY(7))-(PX(8), PY(8))
                LINE (PX(8), PY(8))-(PX(5), PY(5))

        LOOP UNTIL KEY$ = "Q" OR KEY$ = "q"
       
        STOP

INFO:
        CLS
        PRINT "V.2:"
        PRINT "         MOVED VANISHING POINT TO THE CENTER OF THE SCREEN"
        PRINT "         REVERSED AND IMPROVED CONTROLS"
        PRINT "         RESET Z COORDINATES"
        PRINT "         "
RETURN

