'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Welcome to the listing of the newest demo by Shockwave
'                Fanatix proudly present:
'
'                   A W E S O M E ! ! !
'
'This demo uses some new ideas to create truly incredibly
'fast vectors in Yabasic.. Although they are not practical
'to use in games design, they sure look cool!
'
' If you take code from here and don't credit me then you
' are lame.
'
' I am sorry for the lack of comments in the listing but
' this was thrown together in a hurry!!
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'>>> Open gfx screen
     open window 400,400

'>>>  Display message and precalculate vector object
gosub printupbolox
gosub precalculate


b=0
'## 
'## Variable definitions.. (some of them!)
'##
b=0
p=0
qz=255
a$=""
a$=a$+"          THE AWESOME INTRO          "
a$=a$+" PROGRAMMED BY SHOCKWAVE OF FANATIX! "
a$=a$+" SHOCKWAVE SENDS HANDSHAKES OUT TO : "
a$=a$+"JASON SEEMUNGAL..    ANSEL LAWRENCE.."
a$=a$+"PHILL PACKMAN..         PAUL DUNLOP.."
a$=a$+"JOEL THOMAS.. ADAM LEY.. LEN TUCKER.."
a$=a$+"MASTER TONBERRY..      GERRY SQUIRE.."
a$=a$+"   AND A BIG KISS TO MY GIRL VICKI   "
s$="                                                                   "
s$=s$+"THIS IS SHOCKWAVE OF FANATIX, AND THE INTRO THAT "
s$=s$+"YOU ARE LOOKING AT SHOULDN'T BE POSSIBLE IN "
s$=s$+"YABASIC..  YOU CAN SEE BEFORE YOU: A PLASMA "
s$=s$+"BACKGROUND, A 55 POINT 3D STARFIELD, A SCALLED "
s$=s$+"AND ROTATED 32 POLYGON LIGHT SOURCED VECTOR AND 3 "
s$=s$+"DIFFERENT TEXT DISPLAYS ALL HAPPENING AT ONCE, AND"
s$=s$+" AT FULL FRAME RATE WITH *NO* SLOWDOWN!!   THIS "
s$=s$+"IS ONLY POSSIBLE BECAUSE I AM DOING SOME CHEATING "
s$=s$+"WITH THE VECTOR OBJECT, THE REST OF IT IS PUCKER "
s$=s$+"THOUGH....  I AM STARTING TO GET TO GRIPS WITH "
s$=s$+"YABASIC NOW, SO YOU CAN EXPECT TO SEE MORE DEMOS "
s$=s$+"FROM ME WITH MORE IMPRESSIVE ROUTINES THAN THIS!! "
s$=s$+"   IF YOU LIKE WHAT YOU SEE AND YOU WANT TO LEARN "
s$=s$+"MORE, THE ONLY PLACE TO FIND ME IS WWW.YABASIC.CO."
s$=s$+"UK   IT IS THE ONLY SITE I SUPPORT, AND THERE "
s$=s$+"ARE LOADS OF THINGS LIKE DEMOS, GAMES, TUTORIALS "
s$=s$+"AND ROUTINES, MANY PRINTABLE ALL DOWNLOADABLE!!  "
s$=s$+"THERE'S ALSO A GREAT FORUM TOO WHERE YOU CAN FIND "
s$=s$+"ME MOST EVENINGS...   YOU COULD ALSO EMAIL ME IF "
s$=s$+"YOU WANT, BUT NO WEIRDOS PLEASE, ONLY CODERS: "
s$=s$+"NICKSIMPSON007@AOL.COM      ANYWAY, THAT'S "
s$=s$+"QUITE ENOUGH TEXT I THINK...   TAKE CARE AND I'LL "
s$=s$+"SEE YOU IN MY NEXT DEMO!!! "
scrx=10
tp=0

nstar=55
zm=0
xm=1
ym=1
dim ox(nstar)
dim oy(nstar)
dim oc(nstar)
dim os(nstar)
dim x(nstar)
dim y(nstar)
dim z(nstar)
dw=1

'##
'## Set Star positions..
'##
mmm=1
for a=1 to nstar
  x(a)=-25+ran(50)
  y(a)=-25+ran(50)
  z(a)=mmm
mmm=mmm+100/nstar
next a

open window 400,400

label mloop
'## double buffer draw on logic
   setdrawbuf dw
   clear window
gosub background
       gosub dispstars
if qz<=50 setrgb 1,qz,qz,qz
if qz<=50 text 140,254,mid$(a$,p+1,37)
gosub logo
gosub scroller
       gosub drawprecalcobj
if qz>50 setrgb 1,qz,qz,qz
if qz>50 text 140,254,MID$(a$,p+1,37)

'##double buffer swap logic to physic
   setdispbuf dw
   dw=1-dw
   
goto mloop


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label printupbolox
dim boll$(11)
 boll$(1)="           FANATIX PROUDLY PRESENT:   "
 boll$(2)="          THE  A W E S O M E  INTRO.          "
 boll$(3)="=============================================="
 boll$(4)="= ALL PROGRAMMING AND DESIGN : SHOCKWAVE/FTX ="
 boll$(5)="= RELEASED IN AUGUST 2001 ON THE ACE WEBSITE ="
 boll$(6)="= WWW.YABASIC.CO.UK ( GIVE THEM A LOOK!!!!!) ="
 boll$(7)="= CONTACT ME VIA THE FORUM PAGE ON THAT SITE ="
 boll$(8)="= OR IF YOU'RE REALLY  COOL YOU CAN EMAIL ME ="
 boll$(9)="= ON : NICKSIMPSON007@AOL.COM (CODERS ONLY!) ="
boll$(10)="= NOW BE PREPARED FOR A SHOCK ANY SECOND NOW ="
boll$(11)="=============================================="
for b=1 to 250
setdrawbuf dw
clear window
y=185
for a=1 to 11
scalc=(b+(a*13))*sin(b/17)
setrgb 1,scalc,scalc,scalc
 text 100,y,boll$(a)
   y=y+13
next a
setdispbuf dw
dw=1-dw
next b
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label scroller
setrgb 1,0,0,0
text scrx,500,mid$(s$,tp,64)
setrgb 1,200,255,255
text scrx,496,mid$(s$,tp,64)

scrx=scrx-2
if scrx<0 tp=tp+1
if scrx<0 scrx=scrx+10
if tp>len(s$) tp=0
return

label logo
setrgb 1,0,0,50
fill rectangle 50,10 to 590,40
setrgb 1,0,0,0
text 74,32,"FANATIX PRESENT THE AWESOME INTRO BY SHOCKWAVE :)"
setrgb 1,250,250,250
text 74,30,"FANATIX PRESENT THE AWESOME INTRO BY SHOCKWAVE :)"
return

'## Draw stars

'### This subroutine draws the plasma and blue border ###
label background
'>>>>Cycle colours
     backcount=backcount+1
     red=20+20*sin(backcount/14)
     grn=20+20*sin(backcount/15)
     blu=20+20*sin(backcount/16)

'>>>>Set poly palette
     setrgb 1,red,20,20
     setrgb 2,20,grn,20
     setrgb 3,20,20,blu

'>>>>draw plasma
     gtriangle 0,0 to 640,510 to 0,510
     gtriangle 0,0 to 640,510 to 640,0

'>>>>Draw blue border lines
     setrgb 1,15,15,255
     rectangle -1,1 to 642,510
     setrgb 1,15,15,155
     rectangle -1,2 to 642,509
return


label dispstars
mm=mm+.1
sz=2*sin(mm/23)


for a=1 to nstar

qt=200-z(a)*2
setrgb 1,qt,qt,qt+20
xx=x(a)*25
yy=y(a)*25
xx=xx/z(a)*30
yy=yy/z(a)*30
   xx=xx+320
   yy=yy+250
zz=10-z(a)/14

     fill rectangle xx,yy to xx+zz,yy+zz
z(a)=z(a)+sz

if z(a)<1 z(a)=z(a)+100
if z(a)>100 z(a)=z(a)-100
next a

qz=qz-1
if qz<=0 p=p+37 : if p>len(a$) p=0
if qz<=0 qz=255
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'     Draw the diamond from out software memory bank!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label drawprecalcobj
for a=1 to polys
'setrgb 1,rstore(b/3)*a,gstore(b/3)*(a*2),bstore(b/3)*(a*3)
setrgb 1,a*2,a*3,a*4
   fill triangle xstore(b),ystore(b) to xstore(b+1),ystore(b+1) to xstore(b+2),ystore(b+2)
b=b+3 
next a
if b>=(polys*3)*175 b=0
return






'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'The rest of the listing is the precalculation routine!!!!
'This code will work out the screen co-ordinates for the
'32 polygon diamond!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label precalculate
'## Number of faces in object:

polys=32

dim xstore((polys*3)*179)
dim ystore((polys*3)*179)
dim rstore(polys*179)
dim gstore(polys*179)
dim bstore(polys*179)

'## X and Y screen offset positions to centre object:
xff=335
yff=255

' ## X+Y rotation values!

rotx=0.036
roty=0.036
rtx=0
rty=0

' ## How big do you want it???
size=14

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'      Permanent and temporary storage definition!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'## Define arrays to store data:

dim x(polys*3)
dim y(polys*3)
dim z(polys*3)
dim c(polys*3)

'## Define arrays to hold transformed data:

dim tx(polys*3)
dim ty(polys*3)
dim tz(polys*3)
dim tc(polys*3)

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Read in the object data and place into storage arrays:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=1
for a=1 to polys

   read x(b),y(b),z(b),x(b+1),y(b+1),z(b+1),x(b+2),y(b+2),z(b+2),c(b),c(b+1),c(b+2)
   b=b+3

next a

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                      Make movement!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dw=0
for frames=1 to 179

'   setdrawbuf dw
'   clear window
     gosub transform
     gosub rotate
     gosub sort
     gosub draw
'   setdispbuf dw
'dw= 1-dw


next frames

return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                 End of precalculation                   
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Sort Faces, colours and z co-ords according to depth!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label sort

for lame=1 to polys-1
b=1
for a=1 to polys-1

  dck1=tz(b)+tz(b+1)+tz(b+2)
  dck2=tz(b+3)+tz(b+4)+tz(b+5)
  if dck2>dck1 gosub swap
  b=b+3
next a
next lame

return

label swap

  for in=0 to 2
    tmpx=tx(b+in)
    tmpy=ty(b+in)
    tmpz=tz(b+in)
    tmpc=tc(b+in)
      tx(b+in)=tx(b+in+3)
      ty(b+in)=ty(b+in+3)
      tz(b+in)=tz(b+in+3)
      tc(b+in)=tc(b+in+3)
        tx(b+in+3)=tmpx
        ty(b+in+3)=tmpy
        tz(b+in+3)=tmpz
        tc(b+in+3)=tmpc
  next in

return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'           Rotate Object and apply perspective:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label rotate
'## New angles:

rtx=rtx+rotx
rty=rty+roty
'## For tidyness
crx=cos(rtx)
srx=sin(rtx)
cry=cos(rty)
sry=sin(rty)
'## spin `em!!
b=1
for p=1 to polys
for inner=1 to 3

 nwy= crx*ty(b) + srx*tz(b)
 nwz= crx*tz(b) - srx*ty(b)

 nwx= cry*tx(b) + sry*nwz
 nwz= cry*nwz - sry*tx(b)

'##  Perspective+offset
 nwz=nwz+700
 tx(b)=xff+nwx*1300 /nwz
 ty(b)=yff+nwy*1300 /nwz
 tz(b)=nwz

 b=b+1
next inner
next p

return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Pull Object into temporary storage for manipulation!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label transform
b=1


size=25*sin(frames/55.01)

for a=1 to polys
for inner=1 to 3
 tx(b)=x(b)*size
 ty(b)=y(b)*size
 tz(b)=z(b)*size
 tc(b)=c(b)
 b=b+1
next inner
next a
 
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Draw the object held in the temporary array!!!!!!!!!!!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label draw
b=1

for a=1 to polys
xstore(mp)=tx(b)
xstore(mp+1)=tx(b+1)
xstore(mp+2)=tx(b+2)

ystore(mp)=ty(b)
ystore(mp+1)=ty(b+1)
ystore(mp+2)=ty(b+2)
rstore(cp)=tc(b)+(size*4) -100
gstore(cp)=tc(b+1)+(size*4) -100
bstore(cp)=tc(b+2)+(size*4) -100

' setrgb 1, tc(b),tc(b+1),tc(b+2)
'fill triangle tx(b),ty(b) to tx(b+1),ty(b+1) to tx(b+2),ty(b+2)
 b=b+3
cp=cp+1
mp=mp+3
next a

return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' 3D Object Description As Numerical Data...
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label object
' data structure: x,y,z,x,y,z,x,y,z,r,g,b
' (diamond object, 32 polygons)

data -1,6,0,1,6,0,0,0,4,97,7,7
data -1,-6,0,1,-6,0,0,0,4,97,7,7
data  6,1,0,6,-1,0,0,0,4,97,7,7
data -6,1,0,-6,-1,0,0,0,4,97,7,7
data  3,5,0,1,6,0,0,0,4,57,7,7
data  3,5,0,5,3,0,0,0,4,67,7,7
data  5,3,0,6,1,0,0,0,4,77,7,7
data  -3,5,0,-1,6,0,0,0,4,87,7,7
data  -3,5,0,-5,3,0,0,0,4,97,7,7
data  -5,3,0,-6,1,0,0,0,4,107,7,7
data  3,-5,0,1,-6,0,0,0,4,117,7,7
data  3,-5,0,5,-3,0,0,0,4,127,7,7
data  5,-3,0,6,-1,0,0,0,4,137,7,7
data  -3,-5,0,-1,-6,0,0,0,4,147,7,7
data  -3,-5,0,-5,-3,0,0,0,4,157,7,7
data  -5,-3,0,-6,-1,0,0,0,4,167,7,7
data -1,6,0,1,6,0,0,0,-4,7,7,97
data -1,-6,0,1,-6,0,0,0,-4,7,7,97
data  6,1,0,6,-1,0,0,0,-4,7,7,97
data -6,1,0,-6,-1,0,0,0,-4,7,7,97
data  3,5,0,1,6,0,0,0,-4,7,7,57
data  3,5,0,5,3,0,0,0,-4,7,7,67
data  5,3,0,6,1,0,0,0,-4,7,7,77
data  -3,5,0,-1,6,0,0,0,-4,7,7,87
data  -3,5,0,-5,3,0,0,0,-4,7,7,97
data  -5,3,0,-6,1,0,0,0,-4,7,7,107
data  3,-5,0,1,-6,0,0,0,-4,7,7,117
data  3,-5,0,5,-3,0,0,0,-4,7,7,127
data  5,-3,0,6,-1,0,0,0,-4,7,7,137
data  -3,-5,0,-1,-6,0,0,0,-4,7,7,147
data  -3,-5,0,-5,-3,0,0,0,-4,7,7,157
data  -5,-3,0,-6,-1,0,0,0,-4,7,7,167

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                    End of routine!!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




