'Fast vector Routine (Code Snippet) by Shockwave.
'Please don't include this as a full demo, it's just a
'quick 3D example.
'
'#########################################################

gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
repeat
setdrawbuf dw
dw=1-dw
setdispbuf dw
   setrgb 1,40+(rd/5),30,20
   setrgb 2,0,20+(bl/5),40
   setrgb 3,80,20,gr/5
    gtriangle 0,0 to 640,512 to 0,512
    setrgb 3,40,30,20
    gtriangle 0,0 to 640,512 to 640,0
    mm=mm+.05
    gosub rotate
    r=0 : g=0 : b=200
    f1=1 : f2=2 : f3=3 : f4=4
    gosub draw
    r=0 : g=200 : b=0
    f1=5 : f2=8 : f3=7 : f4=6
    gosub draw
    r=200 : g=0 : b=0
    f1=6 : f2=2 : f3=1 : f4=5
    gosub draw
    r=0 : g=100 : b=100
    f1=8 : f2=4 : f3=3 : f4=7
    gosub draw
    r=100 : g=100 : b=0
    f1=2 : f2=6 : f3=7 : f4=3
    gosub draw
    r=100 : g=100 : b=100
    f1=8 : f2=5 : f3=1 : f4=4
    gosub draw
setrgb 1,255,255,255
for a=1 to polys
 text tx(a),ty(a),str$(a)
next a

until (and(peek("port1"),16384)<>0)
exit
label draw

'##############################
'## Draw A Face Of The Cube! ##
'##############################

  vx1= tx(f1)-tx(f2)
  vy1= ty(f1)-ty(f2)
  vx2= tx(f3)-tx(f2)
  vy2= ty(f3)-ty(f2)
  if  (vx1*vy2-vx2*vy1)<0 then
xc=(tx(f1)+tx(f2)+tx(f3)+tx(f4))/4
yc=(ty(f1)+ty(f2)+ty(f3)+ty(f4))/4
light=-(tz(f1)+tz(f2)+tz(f3)+tz(f4))*5
setrgb 1,r+light,g+light,b+light
fill triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
fill triangle tx(f1),ty(f1) to tx(f4),ty(f4) to tx(f3),ty(f3)
fi
return


label rotate
'###############################################
'## Rotate And Scale Each Point! Store Result ##
'###############################################
 for a=1 to polys
  x1=x(a)
  y1=y(a)
  z1=z(a)
'######################
'## X,Y,Z rotations! ##
'######################
  xx=x1
  yy=y1*cs(xr)+z1*sn(xr)
  zz=z1*cs(xr)-y1*sn(xr)
  y1=yy
  x1=xx*cs(yr)-zz*sn(yr)
  z1=xx*sn(yr)+zz*cs(yr)
  zz=z1
  xx=x1*cs(zr)-y1*sn(zr)
  yy=x1*sn(zr)+y1*cs(zr)
'########################
'## Apply Perspective! ##
'########################
  xx=size*(xx/((zz/50)+1))+320
  yy=size*(yy/((zz/50)+1))+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
xr=xr+3
yr=yr+2
zr=zr+5
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720
return
label initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' This Sub-Routine Initialises The Program.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'######################
'## Open Gfx Screen! ##
'######################
open window 640,512
'#####################################
'## Define the necessary variables! ##
'#####################################
size=16: rem how big do you want it?
dw=1 : Rem            Double buffering Variable
polys=8 : Rem        The amount of polygons in the object
dim x(polys) : Rem  Original X co-ordinate store
dim y(polys) : Rem  Original Y co-ordinate store
dim z(polys) : Rem  Original Z co-ordinate store
dim tx(polys) : Rem Transformed  X co-ordinate store
dim ty(polys) : Rem Transformed Y co-ordinate store
dim tz(polys) : Rem Transformed Z co-ordinate store
'##########################
'## Define Sine Tables!! ##
'##########################
 dim cs(720)
 dim sn(720)
 for ang=0 to 720
  cs(ang)=cos(ang*(pi/360))
  sn(ang)=sin(ang*(pi/360))
 next ang
'#########################
'## Read in the object! ##
'#########################
for a=1 to polys
 read x(a),y(a),z(a)
next a
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   The Object Description As Data!
'   The Data Below Describes A Cube.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data -10,10,10,10,10,10,10,-10,10,-10,-10,10
data -10,10,-10,10,10,-10,10,-10,-10,-10,-10,-10
return








