'Mega Gem Coded by Shockwave (C) 2002.
'
'
'#########################################################

gosub initialise
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
repeat
    setdrawbuf dw
    dw=1-dw
    setdispbuf dw
mm=mm+.05
rr=30*sin(mm)
gg=30*sin(mm/2)
bb=30*sin(mm/3)
    setrgb 1,0+rr,0,60
    setrgb 2,0,70+gg,40
    setrgb 3,140,0,100+bb
    gtriangle 0,0 to 640,490 to 0,490
    gtriangle 0,0 to 640,490 to 640,0
    gosub rotate
    gosub construct
    setrgb 1,255,255,255
    fill rect 0,490 to 640,491
text scx,480,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

'---------------------------------------------------------
'                     Draw The Object;
'---------------------------------------------------------
label construct
for a=1 to faces
gosub draw
next a
for a=2 to faces-1
   line tx(f1(a)),ty(f1(a)) to tx(f2(a)),ty(f2(a))
   line tx(f2(a)),ty(f2(a)) to tx(f3(a)),ty(f3(a))
   line tx(f3(a)),ty(f3(a)) to tx(f4(a)),ty(f4(a))
   line tx(f4(a)),ty(f4(a)) to tx(f1(a)),ty(f1(a))
a=a+.2
next a
return

'---------------------------------------------------------
'              Draw A Face Of The Object;
'---------------------------------------------------------

label draw
  vx1= tx(f1(a))-tx(f2(a))
  vy1= ty(f1(a))-ty(f2(a))
  vx2= tx(f3(a))-tx(f2(a))
  vy2= ty(f3(a))-ty(f2(a))
  n=  vx1*vy2-vx2*vy1
 if n<0 then
       n=-(n/50)
       if n>150 n=150
 setrgb 1,n,n,b(a)+n
 fill triangle tx(f1(a)),ty(f1(a)) to tx(f2(a)),ty(f2(a)) to tx(f3(a)),ty(f3(a))
 fill triangle tx(f1(a)),ty(f1(a)) to tx(f4(a)),ty(f4(a)) to tx(f3(a)),ty(f3(a))
fi

return


label rotate
'###############################################
'## Rotate And Scale Each Point! Store Result ##
'###############################################
 for a=1 to points
  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! ##
'########################
  dv=(zz/60)+1
  xx=size*(xx/dv)+320
  yy=size*(yy/dv)+256
  tx(a)=xx
  ty(a)=yy
  tz(a)=zz
 next a
xr=xr+4
yr=yr+4
zr=zr+1
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
setrgb 0,120,120,190
'---------------------------------------------------------
'            Define the necessary variables;
'---------------------------------------------------------
size=28: rem                       how big do you want it?
dw=1 : Rem                       Double buffering Variable
points=34 : Rem         The amount of points in the object
faces=40 : Rem           The Amount of faces in the object
dim x(points): Rem            Original X co-ordinate store
dim y(points): Rem            Original Y co-ordinate store
dim z(points): Rem            Original Z co-ordinate store
dim tx(points): Rem       Transformed  X co-ordinate store
dim ty(points): Rem        Transformed Y co-ordinate store
dim tz(points): Rem        Transformed Z co-ordinate store
dim f1(faces):rem                   Connections definition
dim f2(faces):rem                   Connections definition
dim f3(faces):rem                   Connections definition
dim f4(faces):rem                   Connections definition
dim r(faces):rem                             Red Component
dim g(faces):rem                           Green Component
dim b(faces):rem                            Blue Component
dim sort(faces):rem                          Drawing order
'---------------------------------------------------------
'   Define Sine Tables for faster matrix calculations;
'---------------------------------------------------------

 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's points;
'---------------------------------------------------------
for a=1 to points
 read x(a),y(a),z(a)
next a
'---------------------------------------------------------
'         Read In Connections and face parameters;
'---------------------------------------------------------
for a=1 to faces
read f1(a)
read f2(a)
read f3(a)
read f4(a)
read r(a),g(a),b(a)
next a

for a=1 to 2
setdrawbuf dw
dw=1-dw
setrgb 1,255,255,255
text 320,508,"THE MEGA GEM DEMO BY SHOCKWAVE","cc"
setrgb 1,135,135,155
text 321,509,"THE MEGA GEM DEMO BY SHOCKWAVE","cc"
setrgb 1,5,5,5
text 322,510,"THE MEGA GEM DEMO BY SHOCKWAVE","cc"
next a
scx=0
p=0
s$="                                                                      "
s$=s$+"WELCOME TO MY LATEST LITTLE DEMO... THIS GEM HAS "
s$=s$+"34 VERTICES AND 40 FACES AT FULL FRAME RATE... "
s$=s$+"THE ROUTINE IS A CONVEX ONE, I WAS THNKING OF "
s$=s$+"XALTHORN'S GEM FETISH WHEN I MADE THIS ONE..  "
s$=s$+"I DESIGNED THE OBJECT WITH MY OBJECT EDITOR, THE "
s$=s$+"DEMO HAS NO SPARE TIME FOR ANY MORE EFFECTS (SORRY"
s$=s$+"!) GREETINGS TO THESE PEOPLE: "
s$=s$+"  XALTHORN, DOCTOR, JIM SHAW, PARABELLUM, JINX, "
s$=s$+"RAFRYER, JOMORROW, DEMONEYE, KYATAAVL, AZ, BALROQ,"
s$=s$+" BONGOTRUMMOR, SEPHIROTH, DREW, ZINGSTER, PYRO, "
s$=s$+"SNAKEDOGG, TONBERRY, JACOB BUSBY, ELL, BRUASET, "
s$=s$+"YALOOPY, COMBATKING AND EVERYONE ELSE AT THE "
s$=s$+"FORUMS AT WWW.YABASIC.CO.UK.    TEXT RESTARTS NOW."


'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
'   The Object Description As Data!
'   The Data Below Describes A Cube.
'^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

'Points definition;
'~~~~~~~~~~~~~~~~~~
'Below are the points of the object defined as x,y,z;

data 0,0,-7,3,-3,-6,3,3,-6,-3,3,-6
data -3,-3,-6,4,0,-6,0,4,-6,-4,0,-6
data 0,-4,-6,0,-7,-4,0,7,-4,-7,0,-4
data 7,0,-4,5,5,-4,-5,5,-4,-5,-5,-4
data 5,-5,-4,5,-5,-2,5,5,-2,-5,5,-2
data -5,-5,-2,-7,0,-2,0,7,-2,7,0,-2
data 0,-7,-2,0,-4,3,0,4,3,4,0,3

data -4,0,3,-3,3,3,3,3,3,3,-3,3
data -3,-3,3,0,0,7
'Connection definition;
'Below are the faces of the object defined as vertice
'numbers, specified in clockwise order. These are followed
'by r,g,b values for the face and finally cell shaded
'parameter (0)=off (1)=on.

data 30,29,22,20,0,0,90
data 29,33,21,22,0,0,90
data 33,26,25,21,0,0,90
data 27,30,20,23,0,0,90
data 31,27,23,19,0,0,90
data 19,24,28,31,0,0,90
data 32,28,24,18,0,0,90
data 18,25,26,32,0,0,90
data 20,22,12,15,0,0,90
data 23,20,15,11,0,0,90
data 21,16,12,22,0,0,90
data 25,10,16,21,0,0,90
data 19,23,11,14,0,0,90
data 13,24,19,14,0,0,90
data 18,24,13,17,0,0,90
data 10,25,18,17,0,0,90

data 33,29,34,34,0,0,90
data 29,30,34,34,0,0,90
data 30,27,34,34,0,0,90
data 27,31,34,34,0,0,90
data 31,28,34,34,0,0,90
data 28,32,34,34,0,0,90
data 32,26,34,34,0,0,90
data 26,33,34,34,0,0,90

data 15,12,8,4,0,0,90
data 12,16,5,8,0,0,90
data 15,4,7,11,0,0,90
data 7,3,14,11,0,0,90
data 3,6,13,14,0,0,90
data 16,10,9,5,0,0,90
data 2,9,10,17,0,0,90
data 6,2,17,13,0,0,90

data 9,2,1,1,0,0,90
data 2,6,1,1,0,0,90
data 6,3,1,1,0,0,90
data 3,7,1,1,0,0,90
data 7,4,1,1,0,0,90
data 5,9,1,1,0,0,90
data 4,8,1,1,0,0,90
data 8,5,1,1,0,0,90

return












