5     screen 1,4
10    dim  sp1%(100),sp2%(100),mp(2,50)
20    gosub 2500
30    scnclr
40    print "Use cursor keys to move cube forward, backward, and sideways."
50    print "Use 'l' and 'r' for left and right rotation respectively."
60    print "Press 'q' to quit."
100   rem main loop
110   get a$: if a$="" then 110
115   if a$="l" then theta=10 : gosub 1000
116   if a$="r" then theta=-10 : gosub 1000
117   if a$="q" then chain "menu"
118   if asc(a$)<>155 goto 110
119   get a$:a%=asc(a$)
120   if a%=65 then theta=10 : gosub 1200
130   if a%=66 then theta=-10 : gosub 1200
140   if a%=68 then theta=10 : gosub 1100
150   if a%=67 then theta=-10  : gosub 1100
160   goto 110
1000  rem do a 3-d rotation around x-axis,m(aster)=0 or 1,np=number points
1005  gosub 1480
1010  for ip=0 to np-1
1020  gosub 1500
1030  x2=x*costh-y*sinth:y2=x*sinth+y*costh:z2=z
1040  gosub 1600
1045  next ip
1049  gosub 2000
1050  return
1100  rem do a 3-d rotation around y-axis,m(aster)=0 or 1,np=number points
1105  gosub 1480
1110  for ip=0 to np-1
1120  gosub 1500
1130  x2=x*costh+z*sinth:y2=y:z2=-x*sinth+z*costh
1140  gosub 1600
1145  next ip
1149  gosub 2000
1150  return
1200  rem do a 3-d rotation around z-axis,m(aster)=0 or 1,np=number points
1205  gosub 1480
1210  for ip=0 to np-1
1220  gosub 1500
1230  x2=x:y2=y*costh-z*sinth:z2=y*sinth+z*costh
1240  gosub 1600
1245  next ip
1249  gosub 2000
1250  return
1480  costh=cos(theta/180*pi):sinth=sin(theta/180*pi)
1490  return
1500  rem get x,y,x from mp%()
1510  x=mp(0,ip):y=mp(1,ip):z=mp(2,ip)
1520  return
1600  rem to save point and also update the sp array
1610  mp(0,ip)=x2:mp(1,ip)=y2:mp(2,ip)=z2
1620  if m=1 then sp2%(ip*2)=x2*90+320:sp2%(ip*2+1)=100-40*y2 else sp1%(ip*2)=x2*90+320:sp1%(ip*2+1)=100-40*y2
1630  return
2000  rem plot object
2010  pena 0
2020  if m=1 then mat draw np,sp1%() else mat draw np,sp2%()
2030  m=3-m:pena 1
2040  if m=1 then mat draw np,sp1%() else mat draw np,sp2%()
2050  return
2500  rem readin the object and init vars and display object
2510  read np
2520  m=1
2530  for ip=0 to np-1
2540  read x2,y2,z2
2550  gosub 1600: rem save points
2560  next ip
2570  gosub 2000
2580  return
3000  rem data for object
3010  data 16
3020  data -1,1,1,   -1,-1,1,   1,-1,1,   1,1,1,   -1,1,1,  -1,1,-1
3030  data 1,1,-1,  1,1,1,   1,-1,1,   1,-1,-1,   -1,-1,-1,   -1,1,-1
3040  data 1,1,-1,  1,-1,-1,  -1,-1,-1,  -1,-1,1
5000  rem test
5005  scnclr
5010  locate (sp1%(0),sp1%(1))
5020  for i=1 to np-1
5025  ? i
5030  draw (to sp1%(i*2),sp1%(i*2+1))
5040  sleep 4*10^6
5050  next i
5070  end
