'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'       NICE LINE VECTOR ROUTINE BY NICK (C) 2001!
' AS THIS IS AN ADAPTION OF EARLIER CODE, IT STILL NEEDS
' TO HAVE DUMMY COLOUR VALUES IN THE OBJECT DESIGN......
' LAME I KNOW, BUT I CANT BE BOTHERED TO TAKE IT OUT AS 
' IT RUNS FAST ENOUGH ANYHOW!!!!
'

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t$="                                                                 "
t$=t$+"WELCOME TO SHOCKWAVES STUPID NEWEST DEMO.... THIS"
t$=t$+" SUCKS AND IT IS LAME BUT I DONT CARE....   2D "
t$=t$+"VECTORS WENT OUT WITH THE ARC!!   EMAIL ME ON "
t$=t$+"NICKSIMPSON007@AOL.COM OR CATCH ME IN THE FORUMS "
t$=t$+"AT WWW.YABASIC.CO.UK....    THAT'S ALL FOR NOW "
t$=t$+"EXCEPT TO SAY HI TO ALL YABASIC CODERS AND ALL "
t$=t$+"WHO KNOW ME....    "

tp=0
sxp=10

open window 400,400

'## Number of faces in object:
polys=18
'## X and Y screen offset positions to centre object:
xff=330
yff=250

' ## X+Y rotation values!

rotx=0.02
roty=0.02
rtx=0
rty=0

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

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'      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)

dim x2(polys*3)
dim y2(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),x(b+1),y(b+1),x(b+2),y(b+2)
   b=b+3

next a

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                       Main Loop!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dw=0
label mloop
   setdrawbuf dw
   clear window
gosub colours
m=m+.1
size=6+4*sin(m/8)

     gosub transform
     gosub rotate
     gosub draw
   setdispbuf dw
dw= 1-dw


goto mloop


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                     Main Loop Ends!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'           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
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

setrgb 1,5,5,5
cut$=mid$(t$,tp,65)

text sxp,247,cut$
setrgb 1,255,255,155
text sxp,252,cut$
sxp=sxp-1
if sxp=0 tp=tp+1
if sxp=0 sxp=10
if tp>len(t$) tp=0

setrgb 1,0,0,0
for a=1 to polys

 fill triangle x2(b),y2(b) to x2(b+1),y2(b+1) to x2(b+2),y2(b+2)
b=b+3
next a
b=1
setrgb 1,size*15,size*15,size*15

for a=1 to polys
  fill triangle tx(b),ty(b) to tx(b+1),ty(b+1) to tx(b+2),ty(b+2)

x2(b)=tx(b)
y2(b)=ty(b)
x2(b+1)=tx(b+1)
y2(b+1)=ty(b+1)
x2(b+2)=tx(b+2)
y2(b+2)=ty(b+2)
 b=b+3
next a
return

'              ###########################
'              ### Bacground colours!! ###
'              ### Using 2 Polygons!!! ###
'              ###########################
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
label colours
cvl=cvl+.1    
    col1=50+49*sin(cvl/3)
    col2=50+49*sin(cvl/4)
    col3=50+49*sin(cvl/5)
      ypl=300+299*cos(cvl/4)
      setrgb 1,col1,0,0
      setrgb 2,0,col2,0
      setrgb 3,0,0,col3
       gtriangle 0-ypl,0-ypl to 640,512 to 0-ypl,512+ypl
       gtriangle 0-ypl,0-ypl to 640,512 to 640+ypl,0-ypl
return
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

label object
' data structure: x,y,z,x,y,z,x,y,z,r,g,b
' fanatix!!


data -39,-9,-25,-15,-24,-8
data -31,-15,-35,15,-28,15
data -38,0,-27,-4,-26,5
data -25,15,-20,-15,-21,18
data -21,-15,-15,15,-18,15
data -25,3,-18,-4,-16,4
data -15,14,-13,-14,-13,17
data -16,-14,-9,15,-5,18
data -11,-7,-8,-10,-6,19
data -3,-12,-5,15,-3,18
data -6,-13,5,15,2,16
data -6,3,-5,-2,4,4
data -2,-10,0,-6,15,-12
data 6,17,10,15,3,-13
data 12,15,20,15,15,-4
data 15,-4,17,-7,10,-8
data 15,-11,35,15,27,13
data 35,-15,29,-13,21,19

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












