'                %%%%%%%%%%%%%%%%%%%%%%%%%%
'                %% The In A Spin Demo!! %%
'                %%%%%%%%%%%%%%%%%%%%%%%%%%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'%%     Programmed In May 2002 (c) By Mr. Shockwave     %%
'%%     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     %%
'%%           You can Contact Me Via Email On:          %%
'%%             SHOCKWAVE@PS2-YABASIC.CO.UK             %%
'%%                Or On The Forums At:                 %%
'%%                 WWW.Yabasic.co.uk                   %%
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'            My Back Catalogue Is Available On:
'            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'               +---------------------------+
'               |WWW.PS2-YABASIC.CO.UK (all)|
'               |WWW.YABASIC.CO.UK    (most)|
'               |WWW.EVILSOFT.S5.COM  (some)|
'               |WWW.CODEJUNKIES.COM  (some)|
'               +---------------------------+
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
repeat
setdrawbuf dw
dw=1-dw
setdispbuf dw
gosub dpad
gosub background

    if c=0 mm=mm+.05
    size=32+19*sin(mm/2)
    r=100:b=0:g=0
    gosub rotate
    gosub object
setrgb 1,0,0,0
text 323,59,"-= IN A SPIN DEMO BY SHOCKWAVE =-","cc"


text scx+3,453,mid$(s$,p,67)

setrgb 1,250,250,100
text 320,56,"-= IN A SPIN DEMO BY SHOCKWAVE =-","cc"


text scx,450,mid$(s$,p,67)
scx=scx-1
if scx<-10 then
scx=scx+10
p=p+1
if p>len(s$) p=0
fi

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


label dpad
c=peek("port1")
if and(c,16)<>0 yr=yr-5
if and(c,64)<>0 yr=yr+5
if and(c,32)<>0 xr=xr+5
if and(c,128)<>0 xr=xr-5
if and(c,1024)<>0 zr=zr-5
if and(c,2048)<>0 zr=zr+5
if and(c,512)<>0 mm=mm+.1
if and(c,256)<>0 mm=mm-.1


if xr<0 xr=xr+720
if yr<0 yr=yr+720
if zr<0 zr=zr+720

if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720

return


label background
setrgb 2,0,0,0
setrgb 3,0,0,0
ang=ang+1
lm=lm+.03
rd=40+40*sin(lm)
gn=40+40*sin(lm/4)
bl=40+40*sin(lm/7)

if ang>360 ang=ang-360
for a=0 to 360 step 30
cv=20*sin(a+ang*pi/180)

setrgb 1,cv+rd,cv+gn,cv+bl

x1=(560*(sin((ang+a)*pi/180)))
y1=(560*(cos((ang+a)*pi/180)))
x2=(560*(sin((30+ang+a)*pi/180)))
y2=(560*(cos((30+ang+a)*pi/180)))
gtriangle 320,256 to x1+320,y1+256 to x2+320,y2+256
setrgb 1,0,0,0
triangle 320,256 to x1+320,y1+256 to x2+320,y2+256

next a

return

label object
'insides;
r=0:g=0:b=100
f1=1 : f2=2 : f3=3 : f4=4
gosub quadb
f1=8 : f2=7 : f3=6 : f4=5
gosub quadb
f1=8 : f2=9 : f3=4 : f4=12
gosub quadb
f1=7 : f2=12 : f3=3 : f4=11
gosub quadb
f1=6 : f2=11 : f3=2 : f4=10
gosub quadb
f1=9 : f2=5 : f3=10 : f4=1
gosub quadb
f1=1 : f2=4 : f3=9 
gosub trib
f1=4 : f2=3 : f3=12 
gosub trib
f1=9 : f2=8 : f3=5 
gosub trib
f1=8 : f2=12 : f3=7 
gosub trib
f1=3 : f2=2 : f3=11 
gosub trib
f1=6 : f2=7 : f3=11 
gosub trib
f1=2 : f2=1 : f3=10 
gosub trib
f1=6 : f2=10 : f3=5 
gosub trib
r=100:g=0:b=0
'Fronts;
'f1=1 : f2=2 : f3=3 : f4=4
'gosub quad
f1=8 : f2=7 : f3=6 : f4=5
gosub quad
f1=8 : f2=9 : f3=4 : f4=12
gosub quad
f1=7 : f2=12 : f3=3 : f4=11
gosub quad
f1=6 : f2=11 : f3=2 : f4=10
gosub quad
f1=9 : f2=5 : f3=10 : f4=1
gosub quad
f1=1 : f2=4 : f3=9 
gosub tri
f1=4 : f2=3 : f3=12 
gosub tri
f1=9 : f2=8 : f3=5 
gosub tri
f1=8 : f2=12 : f3=7 
gosub tri
f1=3 : f2=2 : f3=11 
gosub tri
f1=6 : f2=7 : f3=11 
gosub tri
f1=2 : f2=1 : f3=10 
gosub tri
f1=6 : f2=10 : f3=5 
gosub tri
return


label tri
'#####################################
'## Draw Triangle Face (1 Triangle) ##
'#####################################
  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
light=-(tz(f1)+tz(f2)+tz(f3))*10
setrgb 1,r+light,g+light,b+light
fill triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
setrgb 1,0,0,0
line tx(f1),ty(f1) to tx(f2),ty(f2)
line tx(f2),ty(f2) to tx(f3),ty(f3)
line tx(f3),ty(f3) to tx(f1),ty(f1)

fi
return
label quad
'##################################
'## Draw Quad Face (2 Triangles) ##
'##################################
  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
light=-(tz(f1)+tz(f2)+tz(f3))*10
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)
setrgb 1,0,0,0
line tx(f1),ty(f1) to tx(f2),ty(f2)
line tx(f2),ty(f2) to tx(f3),ty(f3)
line tx(f3),ty(f3) to tx(f4),ty(f4)
line tx(f4),ty(f4) to tx(f1),ty(f1)

fi
return

label trib
'#####################################
'## Draw Triangle Face (1 Triangle) ##
'#####################################
  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
light=-(tz(f1)+tz(f2)+tz(f3))*4
setrgb 1,r+light,g+light,b+light
fill triangle tx(f1),ty(f1) to tx(f2),ty(f2) to tx(f3),ty(f3)
fi
return
label quadb
'##################################
'## Draw Quad Face (2 Triangles) ##
'##################################
  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
light=-(tz(f1)+tz(f2)+tz(f3))*4
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/100)+1))+320
  yy=size*(yy/((zz/100)+1))+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
if peek("port1")=0 then
xr=xr+1
yr=yr+2
zr=zr+3
if xr>720 xr=xr-720
if yr>720 yr=yr-720
if zr>720 zr=zr-720
fi
return
label initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
' This Sub-Routine Initialises The Program.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'######################
'## Open Gfx Screen! ##
'######################
open window 640,512
'#####################################
'## Define the necessary variables! ##
'#####################################
size=50: rem how big do you want it?
dw=1 : Rem            Double buffering Variable
polys=12 : 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

s$="                                                                 "
s$=s$+"WELCOME TO MY LATEST DEMO CALLED 'IN A SPIN'     "
s$=s$+"NOT THE MOST ORIGINAL NAME I KNOW, I HAD THOUGHT "
s$=s$+"ABOUT CALING IT 'HOW TO CHEAT AT VECTORS' BUT I "
s$=s$+"GUESS THAT I LIKE THE SPIN ONE BETTER....      "
s$=s$+"IT'S BASICALLY COME ABOUT BECAUSE I'M HAVING A "
s$=s$+"LITTLE BREAK FROM BATTLEZONE AT THE MOMENT.    "
s$=s$+"I AM DOING A LITTLE CHEATING TO GET THIS OBJECT "
s$=s$+"RUNNING SMOOTHLY.. IT SHOULD BE A NON CONVEX "
s$=s$+"OBJECT BUT I'VE MANAGED TO DO IT USING A CONVEX "
s$=s$+"3D ROUTINE WHICH IS MUCH FASTER AS NO SORTING IS "
s$=s$+"NEEDED..  THE OBJECT IS KIND OF STRANGE TOO, IT "
s$=s$+"IS A CUBE WITH TRIANGULAR WEDGES TAKEN OUT OF THE "
s$=s$+"CORNERS... I TRIED SOME SPHERES IN HERE BUT IT "
s$=s$+"SLOWED RIGHT DOWN... THIS OBJECT IS A GOOD "
s$=s$+"COMPROMISE. THERE'S PROBABLY A PROPER NAME FOR THE"
s$=s$+" OBJECT AS I'VE SEEN IT IN LOTS OF DEMOS IN THE "
s$=s$+"PAST BUT THE NAME ESCAPES ME AT THE MOMENT...   "
s$=s$+"THERE'S A USER CONTROL MODE IN THIS DEMO;       "
s$=s$+"(X) QUITS DEMO , DPAD CHANGES X AND Y ROTATION "
s$=s$+"[L1] AND [R1] ALTER Z ROTATION [L2] AND [R2] "
s$=s$+"CHANGE ZOOM, ANY OTHER BUTTON PAUSES ROTATION. "
s$=s$+"I'D LIKE TO SAY HELLO TO THE FOLLOWING PEOPLE "
s$=s$+"BEFORE I GO, SO IN RANDOM ORDER, HANDSHAKES GO "
s$=s$+"OUT TO: "
s$=s$+"DOCTOR   XALTHORN   JOMORROW   SNAKEDOGG   "
s$=s$+"DEMONEYE   JINX   RAFRYER   JIM SHAW   JACOB "
s$=s$+"BUSBY   ZINGSTER   DREW   YALOOPY   GOTHI   "
s$=s$+"COMBATKING   MASTER TONBERRY   STATICGERBIL   "
s$=s$+"PS2YABASIC   SEPHIROTH   AND ALL THE REST OF YOU "
s$=s$+"(YOU KNOW WHO YOU ARE) AND I'LL EVEN SAY HELLO "
s$=s$+"TO KYATAVL (YABASIC GURUS) WHO'LL PROBABLY RIP "
s$=s$+"OFF THIS CODE AND TELL HIS FRIENDS THAT HE MADE IT"
s$=s$+"... GRRR.. ANYHOW, GOT TO GO. ENJOY THE DEMO <8O):::...   "


p=0
scx=0

'##########################
'## 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 0,5,5,5,0,5,0,-5,5,-5,0,5
data 0,5,-5,5,0,-5,0,-5,-5,-5,0,-5
data -5,5,0,5,5,0,5,-5,0,-5,-5,0

return











