' Morphing Dots routine.
' ~~~~~~~~~~~~~~~~~~~~~~
' This one uses Dots and lines to show how an animated
' 3D object can be created. X,Y,Z rotation and at full
' frame rate.
' This one's for the forums.
' Coded by Shockwave (C) 2001.
'#########################################################

gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
setrgb 0,30,30,20
repeat
setdrawbuf dw
dw=1-dw
setdispbuf dw
clear window
zz=(-q*(polys/2))
for a=1 to polys
z(a)=zz
zz=zz+q
next a
q=.6+.5*sin(mm/.8)
mm=mm+.1
gosub rotate
gosub draw
'#######################################################
'## The Main Loop. These Calls Are Repeated Until (X) ##
'#######################################################
until (and(peek("port1"),16384)<>0)
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
exit

label draw
'########################
'## Draw The object!!! ##
'########################
b=1
for a=1 to polys-1
c=-tz(a)*10
c=c+140
setrgb 1,c,c,c+50
line tx(a),ty(a) to tx(a+1),ty(a+1)
fill rectangle tx(a)-2,ty(a)-2 to tx(a)+2,ty(a)+2
next a
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/70)+1))+320
  yy=size*(yy/((zz/70)+1))+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
xr=xr+1
yr=yr+1
zr=zr+3
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=8: rem how big do you want it?
dw=1 : Rem            Double buffering Variable
polys=57 : 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! ##
'#########################
zz=-((polys/2)*.5)
for a=1 to polys
x(a)=10*sin(a*(pi/10))
y(a)=10*cos(a*(pi/10))
z(a)=zz
zz=zz+.5
next a
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   The Object Description As Data!
'   (uses 3 points per polygon!)
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

return

