gosub setup
repeat
sn=sn+5
if sn>359 sn=0
gosub rotate
gosub draw
gosub scroll
until(1=2)
 

'################################'
label rotate
'--------------------------------'
' rotation                       '
'--------------------------------'
rx=rx+1
if rx>359 rx=rx-360
ry=ry+2
if ry>359 ry=ry-360

'--------------------------------'
' move object                    '
'--------------------------------'
zpos=30+sn(sn)*5


'--------------------------------'
' apply rotation to the vertices '
'--------------------------------'
for p=1 to points
  ny=cs(rx)*vy(p)+sn(rx)*vz(p)
  nz=cs(rx)*vz(p)-sn(rx)*vy(p)
  nx=cs(ry)*vx(p)+sn(ry)*nz
  nz=cs(ry)*nz-sn(ry)*vx(p)
  nz=nz+zpos
'--------------------------------'
' add perspective                '
'--------------------------------'
  tx(p)=fov*(nx/nz)+xpos
  ty(p)=fov*(ny/nz)+ypos
  col(p)=255-nz*6
next p
return


'################################'
label draw
'--------------------------------'
' switch buffers                 '
'--------------------------------'
setdispbuf cb
cb=1-cb
setdrawbuf cb
clear window

'--------------------------------'
' draw wire frame                '
'--------------------------------'
for f=1 to faces
  setrgb 1,col(vrtx(f,1)),col(vrtx(f,1)),col(vrtx(f,1))-20
  setrgb 2,col(vrtx(f,2)),col(vrtx(f,2)),col(vrtx(f,2))-20
  setrgb 3,col(vrtx(f,3)),col(vrtx(f,3)),col(vrtx(f,3))-20
  if f>16 and f<19 then
   setrgb 1,col(vrtx(f,1))-20,col(vrtx(f,1))-20,col(vrtx(f,1))-20
   setrgb 2,col(vrtx(f,2))-20,col(vrtx(f,2))-20,col(vrtx(f,2))-20
   setrgb 3,col(vrtx(f,3))-20,col(vrtx(f,3))-20,col(vrtx(f,3))-20
  fi
  if (tx(vrtx(f,1))-tx(vrtx(f,2)))*(ty(vrtx(f,3))-ty(vrtx(f,2)))-(tx(vrtx(f,3))-tx(vrtx(f,2)))*(ty(vrtx(f,1))-ty(vrtx(f,2)))<0 then
   gtriangle tx(vrtx(f,1)),ty(vrtx(f,1)) to tx(vrtx(f,2)),ty(vrtx(f,2)) to tx(vrtx(f,3)),ty(vrtx(f,3))
  fi
next f
return


label scroll
'-----------------------------'
' move letters                '
'-----------------------------'
sx=sx-5
if sx<-10 then
  for l=1 to 64
   l$(l)=l$(l+1)
  next l
  l$(65)=mid$(scroll$,o,1)
  o=o+1
  if o>len(scroll$) o=0
  sx=0
fi

'-----------------------------'
' display scroll              '
'-----------------------------'
setrgb 1,255,255,0
lx=sx
for l=1 to 65
  ly=sinus(lx+10)
  text lx,ly,l$(l)
  lx=lx+10
next l
return


'################################'
label setup
'--------------------------------'
' setup variables                '
'--------------------------------'
points=30:faces=54
xpos=320:ypos=256:zpos=30
fov=700

'--------------------------------'
' dimension arrays               '
'--------------------------------'
dim vx(points),vy(points),vz(points)
dim tx(points),ty(points)
dim vrtx(faces,3),col(points)
dim sn(360),cs(360)
dim l$(65),sinus(650)

'--------------------------------'
' setup vertices                 '
'--------------------------------'
for p=1 to points
  read vx(p),vy(p),vz(p)
next p

'--------------------------------'
' setup faces                    '
'--------------------------------'
for f=1 to faces
  read vrtx(f,1),vrtx(f,2),vrtx(f,3)
next f

'--------------------------------'
' setup sin/cos-LUT              '
'--------------------------------'
for a=0 to 359
  sn(a)=sin(a*pi/180)
  cs(a)=cos(a*pi/180)
next a

'--------------------------------'
' setup scrolltext               '
'--------------------------------'
scroll$="PLAY >      "
scroll$=scroll$+"Hello everyone!      This is Bongotrummor "
scroll$=scroll$+"here with his latest creation, a 3D-model "
scroll$=scroll$+"of his Macintosh SE.      I didn't do "
scroll$=scroll$+"any proper z-sorting 'cause I'm a lazy bum. "
scroll$=scroll$+"There are no major overlaps anyway, and the "
scroll$=scroll$+"sorting would have caused serious speed issues"
scroll$=scroll$+". I think it's slow enough as it is, and it's "
scroll$=scroll$+"this scroll that slows it down...   anyways.."
scroll$=scroll$+"      Greetings to everyone at the PS2-Yabasic"
scroll$=scroll$+" forum, and thanks to everyone who helped me "
scroll$=scroll$+"understand at least some of this 3D-business..."
scroll$=scroll$+"      << REWIND"
scroll$=scroll$+"                                     "
scroll$=scroll$+"                        "

'--------------------------------'
' setup sin table for scroll     '
'--------------------------------'
for x=0 to 650
  sinus(x)=500+sin(x/20)*10
next x

'--------------------------------'
' setup scroll start             '
'--------------------------------'
for l=1 to 65
  l$(l)=" "
next l

'--------------------------------'
' open graphics window           '
'--------------------------------'
open window 640,512
return

'--------------------------------'
' vertex coord data              '
'--------------------------------'
data -5,-6,-5           rem front (1,2,3,4)
data  5,-6,-5           rem ---------------
data  5, 4,-5.5
data -5, 4,-5.5

data -5, 4,-4           rem front/bottom (5,6,7,8)
data  5, 4,-4           rem ----------------------
data  5, 7,-4
data -5, 7,-4

data -5,-4, 5           rem back (9,10,11,12)
data  5,-4, 5           rem -----------------
data  5, 7, 5.2
data -5, 7, 5.2

data -5,-5.5, 4         rem back/top (13,14,15)
data -2,-5.5, 4         rem ----------
data -2,-4, 5

data  5,-5.5, 4         rem back/top (16,17,18)
data  2,-5.5, 4         rem -------------------
data  2,-4, 5

data -2,-5.8, 0         rem back/top indent(19,20,21,22)
data  2,-5.8, 0         rem ----------------------------
data  2,-4, 0
data -2,-4, 0

data -4,-5,-5           rem screen frame (23,24,25,26)
data  4,-5,-5           rem --------------------------
data  4, 1,-5.3
data -4, 1,-5.3

data -3.5,-4.5,-4.5     rem screen surface (27,28,29,30)
data  3.5,-4.5,-4.5     rem ----------------------------
data  3.5, .5,-4.5
data -3.5, .5,-4.5

'--------------------------------'
' face connection data           '
'--------------------------------'

data 20,19,22           rem back/top faces
data 22,21,20           rem ----------
data 17,20,21
data 21,18,17
data 19,14,15
data 15,22,19
data 21,22,15
data 15,18,21

data 23,24,28           rem screen faces
data 28,27,23           rem ------------
data 28,24,25
data 25,29,28
data 30,29,25
data 25,26,30
data 23,27,30
data 30,26,23
data 27,28,29
data 29,30,27

data 4,3,6              rem front/bottom
data 6,5,4              rem ------------
data 5,6,7
data 7,8,5

data 1,2,24             rem front faces
data 24,23,1            rem -----------
data 24,2,3
data 3,25,24
data 26,25,3
data 3,4,26
data 1,23,26
data 26,4,1

data 19,20,2            rem top faces
data 2,1,19             rem ---------
data 13,14,19
data 19,1,13
data 17,16,2
data 2,20,17

data 16,17,18           rem back faces
data 18,10,16           rem ----------
data 14,13,9
data 9,15,14
data 10,9,12
data 12,11,10

data 13,1,4             rem left faces
data 4,5,13             rem ----------
data 9,13,5
data 12,5,8
data 5,12,9

data 2,16,3             rem right faces
data 16,10,3            rem -----------
data 3,10,6
data 6,10,11
data 6,11,7

data 8,7,11             rem bottom faces
data 11,12,8            rem ------------



