'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'       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!!!!
'
'                    SHOCKWAVE/FANATIX...
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

open window 400,400

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

' ## X+Y rotation values!

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

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

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

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

dw=0
label mloop
str=str+1
size=10*sin(str/65)
size=size+16
   setdrawbuf dw
   clear window
     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

for a=1 to polys
' setrgb 1, tc(b),tc(b+1),tc(b+2)
setrgb 1,150,150,255
triangle tx(b),ty(b) to tx(b+1),ty(b+1) to tx(b+2),ty(b+2)
 b=b+3
next a
setrgb 1,255,255,255
text 88,240,"THIS ROUTINE CAN COPE WITH A MAXIMUM OF 74 LINES"
text 88,260,"AND 222 POINTS AND STILL RUN AT FULL FRAME RATE!"

return

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

label object
' data structure: x,y,z,x,y,z,x,y,z,r,g,b
' flat thing with hole.

data -5,5,1,5,5,1,5,5,1,255,255,255
data 5,5,1,5,5,1,5,-5,1,255,255,255
data 5,-5,1,5,-5,1,-5,-5,1,255,255,255
data -5,-5,1,-5,-5,1,-5,5,1,255,255,255
data -5,-5,1,-5,5,1,-5,5,-1,255,255,255
data -5,-5,1,-5,-5,-1,-5,5,1,255,255,255 
data 5,-5,1,5,5,1,5,5,-1,255,255,255
data 5,-5,1,5,-5,-1,5,5,1,255,255,255 
data 5,-5,1,-5,-5,1,-5,-5,-1,255,255,255
data -5,-5,-1,-5,-5,1,5,-5,-1,255,255,255
data 5,5,1,-5,5,1,-5,5,-1,255,255,255
data -5,5,-1,-5,5,1,5,5,-1,255,255,255
data -4,2,1,4,2,1,0,-4,1,255,255,255
data  0,4,1,4,-2,1,-4,-2,1,255,255,255
data 1,0,-3,5,5,-1,5,-5,-1,255,255,255
data 0,1,-3,5,5,-1,-5,5,-1,255,255,255
data -1,0,-3,-5,-5,-1,-5,5,-1,255,255,255
data 0,-1,-3,-5,-5,-1,5,-5,-1,255,255,255
data -1,0,-3,0,-1,-3,0,1,-3,255,255,255
data 1,0,-3,0,-1,-3,0,1,-3,255,255,255


data -4,2,0,4,2,0,0,-4,0,255,255,255
data  0,4,0,4,-2,0,-4,-2,0,255,255,255
data -4,2,-1,4,2,-1,0,-4,-1,255,255,255
data  0,4,-1,4,-2,-1,-4,-2,-1,255,255,255

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






