§ Скриншот


§ Исходный код

SCREEN 13

' Vertex
DATA -1, 1, 1
DATA  1, 1, 1
DATA  1,-1, 1
DATA -1,-1, 1
DATA -1, 1,-1
DATA  1, 1,-1
DATA  1,-1,-1
DATA -1,-1,-1

' Faces
DATA 1,0,3,2
DATA 4,5,6,7
DATA 0,1,5,4
DATA 2,3,7,6
DATA 5,1,2,6
DATA 0,4,7,3

TYPE vec2
  x AS SINGLE
  y AS SINGLE
END TYPE

TYPE vec3
  x AS SINGLE
  y AS SINGLE
  z AS SINGLE
END TYPE

DIM v(0 TO 7) AS vec3
DIM f(0 TO 5, 0 TO 3) AS INTEGER
DIM p(0 TO 3) AS vec2
DIM c AS vec3, t AS vec3, r AS vec3, cam AS vec3

' Set camera position
cam.x = 0: r.x = 0
cam.y = 0: r.y = 1
cam.z = 3: r.z = 0

' Read vertex and face cube data
FOR i = 0 TO 7: READ v(i).x, v(i).y, v(i).z: NEXT
FOR i = 0 TO 5: READ f(i, 0), f(i, 1), f(i, 2), f(i, 3): NEXT

DO

' List faces
FOR i = 0 TO 5

  ' List face items
  FOR j = 0 TO 3

    ' Get vertex id from face `i`, point on face `j`
    c = v(f(i, j))

    ' Rotate X Axis
    ' -----------------------------------------
    t.x = c.x
    t.y = c.y * COS(r.x) + c.z * SIN(r.x)
    t.z = c.z * COS(r.x) - c.y * SIN(r.x)
    c = t

    ' Rotate Y Axis
    ' -----------------------------------------
    t.x = c.x * COS(r.y) + c.z * SIN(r.y)
    t.y = c.y
    t.z = c.z * COS(r.y) - c.x * SIN(r.y)
    c = t

    ' Add camera
    c.x = c.x + cam.x
    c.y = c.y + cam.y
    c.z = c.z + cam.z

    ' Save to p(j)
    p(j).x = 160 + 100 * c.x / c.z
    p(j).y = 100 - 100 * c.y / c.z

  NEXT

  ' Draw lines
  FOR j = 0 TO 3

    ' Calculate face direction
    ABx = p(1).x - p(0).x: ABy = p(1).y - p(0).y
    ACx = p(2).x - p(0).x: ACy = p(2).y - p(0).y

    ' Face is front
    IF ACx * ABy < ACy * ABx THEN

      n = (j + 1) MOD 4
      LINE (p(j).x, p(j).y)-(p(n).x, p(n).y)

    END IF

  NEXT

NEXT

' Wait key
DO: i$ = INKEY$: LOOP WHILE i$ = ""

CLS

st = .05

' Control keys
IF i$ = "w" THEN r.x = r.x + st
IF i$ = "s" THEN r.x = r.x - st
IF i$ = "a" THEN r.y = r.y + st
IF i$ = "d" THEN r.y = r.y - st
IF i$ = "q" THEN r.x = r.x + st: r.y = r.y + st
IF i$ = "e" THEN r.x = r.x - st: r.y = r.y - st

LOCATE 2, 2: PRINT i$

LOOP WHILE i$ <> CHR$(27)