home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / E / TFF-A32R.LZX / AmigaE3.2a / Src / Tools / FilledVector / examples / wb1200.e < prev    next >
Encoding:
Text File  |  1994-07-06  |  9.5 KB  |  445 lines

  1.  
  2. /*
  3.  
  4.     Complex Workbench2.0+ Example of FilledVector.m
  5.  
  6.     This program creates a spinning "A1200" logo that spins
  7.     around on the back of Workbench.  On a 1200 without
  8.     fastmem, it can hapily be run in the background without
  9.     causing noticeable delays.
  10.  
  11.     On the command line, specify the number of columns,
  12.     followed by the number of rows of images you want,
  13.     it defaults to 2x2.
  14.  
  15.     Run it with Workbench NOT inbackdrop mode, and to
  16.     remove it, run it again.
  17.  
  18.     Michael Zucchi, 1994.  Program in public domain.
  19.  
  20. */
  21.  
  22.  
  23.  
  24. OPT OSVERSION=37
  25.  
  26. MODULE 'tools/filledvector', 'tools/filledvdefs',
  27.     'exec/lists', 'exec/ports', 'exec/nodes', 'exec/libraries',
  28.     'intuition/screens', 'intuition/intuition', 'intuition/intuitionbase',
  29.     'graphics/gfx', 'graphics/rastport', 'graphics/layers'
  30.  
  31. DEF list:PTR TO mlh,pc,
  32.     let_0:PTR TO vobject,
  33.     let_1:PTR TO vobject,
  34.     let_2:PTR TO vobject,
  35.     let_A:PTR TO vobject,
  36.     scr:PTR TO screen,abitm:PTR TO bitmap,
  37.     win:PTR TO window,
  38.     myrast:rastport,
  39.     mport:PTR TO mp,
  40.     width,height,depth,
  41.     rows,cols
  42.  
  43. DEF dx,dy,dz
  44.  
  45. /********************************************************************
  46.  
  47.     main
  48.  
  49.  */
  50.  
  51. PROC main()
  52. DEF rdargs, args:PTR TO LONG,p:PTR TO LONG, i, gfx:PTR TO lib
  53.  
  54. cols:=2;
  55. rows:=2;
  56.  
  57. -> check arguments
  58. args:=[0,0];
  59. IF rdargs:=ReadArgs('cols/N,rows/N', args, 0)
  60.   IF p:=args[0] THEN cols:=p[0]
  61.   IF p:=args[1] THEN rows:=p[0]
  62.   FreeArgs(rdargs);
  63. ENDIF  
  64.  
  65. -> see if we're already running, if yes, signal the other version
  66. Forbid();
  67. mport:=FindPort('backdrop');
  68. IF mport
  69.   Signal(mport.sigtask, Shl(1,mport.sigbit))
  70. ENDIF
  71. Permit();
  72.  
  73. -> if we are not already running, start doing our thing
  74. IF mport=0
  75.  
  76.   -> create a public port where we can be found later
  77.   mport:=CreateMsgPort();
  78.   mport::ln.name:='backdrop';
  79.   mport::ln.pri:=-128;
  80.   AddPort(mport);
  81.  
  82.   -> open the backdrop window
  83.   win:=OpenWindowTagList(0, [WA_FLAGS, WFLG_BACKDROP OR WFLG_BORDERLESS OR WFLG_SIMPLE_REFRESH OR WFLG_NOCAREREFRESH,
  84.     WA_BACKFILL, LAYERS_NOBACKFILL, 0]);
  85.  
  86.   -> calculate size of each tile
  87.   width:=win.width/cols
  88.   height:=win.height/rows
  89.   IF height AND 1 THEN height++
  90.   IF width AND 31 THEN width:=width+(32-(width AND 31))
  91.  
  92.   -> find the depth of workbench, and open our rendering bitmap
  93.   scr:=LockPubScreen(0);
  94.  
  95.   depth:=scr.rastport::rastport.bitmap::bitmap.depth
  96.   gfx:=gfxbase;
  97.  
  98.   IF gfx.version<39
  99.     abitm:=New(SIZEOF bitmap+(8*4));
  100.     p:=abitm.planes
  101.     FOR i:=0 TO depth-1 DO p[i]:=AllocRaster(width,height);
  102.     InitBitMap(abitm,depth,width,height);
  103.   ELSE
  104.     abitm:=AllocBitMap(width,height,depth,
  105.       BMF_CLEAR+BMF_INTERLEAVED,0);
  106.   ENDIF
  107.  
  108.   UnlockPubScreen(0, scr);
  109.  
  110.   -> finish of setting up, then goto the main loop
  111.   SetTaskPri(FindTask(0), -128);
  112.   InitRastPort(myrast);
  113.   myrast.bitmap:=abitm;
  114.  
  115.   IF win
  116.     IF createobjects()
  117.       IF pc:=newPolyContext(abitm,50)
  118.         demo()
  119.         freePolyContext(pc)
  120.       ENDIF
  121.       freeobjects()
  122.     ENDIF
  123.     CloseWindow(win);
  124.   ENDIF
  125.  
  126.   IF gfx.version<39
  127.     p:=abitm.planes
  128.     FOR i:=0 TO depth-1 DO FreeRaster(p[i], width,height);
  129.     InitBitMap(abitm,depth,width,height);
  130.   ELSE
  131.     FreeBitMap(abitm);
  132.   ENDIF
  133.  
  134.   RemPort(mport);
  135.   DeleteMsgPort(mport);
  136.  
  137. ENDIF -> IF mport=0
  138.  
  139. ENDPROC
  140.  
  141. /********************************************************************
  142.  
  143.   Main loop.  Render/move the object until we get told to stop
  144.  
  145.  */
  146.  
  147. PROC demo()
  148.   DEF p:position,x,y,c, sigbit, destz
  149.  
  150.   c:=0;
  151.   p.ax:=0;p.ay:=0;p.az:=0;p.px:=0;p.py:=0;p.pz:=750;
  152.  
  153.   destz:=Rnd(1000)+400;
  154.   sigbit:=Shl(1, mport.sigbit);
  155.   setPolyFlags(pc,1,1)
  156.  
  157.   -> main loop
  158.   WHILE (SetSignal(0, sigbit) AND sigbit)=0    -> see if we've been told to stop?
  159.  
  160.     cls()
  161.     setPolyBitMap(pc, abitm)
  162.  
  163.     IF c--<0
  164.       setangles()
  165.       c:=60;
  166.     ENDIF
  167.  
  168.     -> pri back to 0, this will stop us losing cpu while blitter owned (hang!)
  169.     SetTaskPri(FindTask(0), 0);
  170.  
  171.     moveDrawVList(pc, list, p)
  172.     FOR x:=0 TO cols-1
  173.     FOR y:=0 TO rows-1
  174.       BltBitMapRastPort(abitm, 0,0, win.rport, x*width,y*height,width,height,$c0);
  175.     ENDFOR
  176.     ENDFOR
  177.  
  178.     -> its safe to go back to low pri again
  179.     SetTaskPri(FindTask(0), -128);
  180.  
  181.     -> move object
  182.     p.pz:=p.pz+((destz-p.pz)/6)
  183.     IF Abs(p.pz-destz)<6 THEN destz:=Rnd(4000)+200
  184.     p.az:=p.az+dz;
  185.     p.ax:=p.ax-dx;
  186.     p.ay:=p.ay+dy;
  187.  
  188.   ENDWHILE
  189. ENDPROC
  190.  
  191. PROC setangles()
  192. dx:=Rnd(9)-4
  193. dy:=Rnd(9)-4
  194. dz:=Rnd(9)-4
  195. ENDPROC
  196.  
  197.  
  198. /********************************************************************
  199.  
  200.  Clears the bitmap we're rendering into, then fills it with the
  201.  stipple pattern
  202.  
  203.  */
  204.  
  205. PROC cls()
  206.  SetRast(myrast, 0);
  207.  WaitBlit()
  208.  
  209.  MOVE.L abitm,A2
  210.  MOVE.L 8(A2),A1
  211.  MOVE.L    height,D3
  212.  LSR.L    #1,D3
  213.  SUBQ.L    #1,D3
  214.  MOVE.L #$55555555,D0
  215.  MOVE.L #$AAAAAAAA,D1
  216. d_lp0:
  217.  MOVE.L A1,A0
  218.  ADDA.W (A2),A1
  219.  MOVE.L width,D2
  220.  LSR.W    #5,D2
  221.  SUBQ.W    #1,D2
  222. d_lp1:
  223.  MOVE.L D0,(A0)+
  224.  DBF    D2,d_lp1
  225.  MOVE.L A1,A0
  226.  ADDA.W (A2),A1
  227.  MOVE.L    width,D2
  228.  LSR.W    #5,D2
  229.  SUBQ.W    #1,D2
  230. d_lp2:
  231.  MOVE.L D1,(A0)+
  232.  DBF    D2,d_lp2
  233.  DBF    D3,d_lp0
  234. ENDPROC
  235.  
  236. /********************************************************************
  237.  
  238.      Create all of the objects
  239.  
  240.  */ 
  241.  
  242. PROC createobjects()
  243.   DEF stat=-1,
  244.       tmp:PTR TO vobject
  245.  
  246.   /* allocate a list, and add them to it */
  247.   list:=newVList()
  248.  
  249.   let_0:=newVectorObject(0,16,10,
  250.     [8*3,126*3,-20*4,
  251.     37*3,30*3,-20*4,
  252.     83*3,0*3,-20*4,
  253.     134*3,0*3,-20*4,
  254.     153*3,31*3,-20*4,
  255.     111*3,144*3,-20*4,
  256.     79*3,165*3,-20*4,
  257.     20*3,165*3,-20*4,
  258.     8*3,126*3,20*4,
  259.     37*3,30*3,20*4,
  260.     83*3,0*3,20*4,
  261.     134*3,0*3,20*4,
  262.     153*3,31*3,20*4,
  263.     111*3,144*3,20*4,
  264.     79*3,165*3,20*4,
  265.     20*3,165*3,20*4]:INT,
  266.     [0,1,9,1,
  267.         [4,0,1,1,9,9,8,8,0]:INT,0,
  268.     0+1,1+1,9+1,2,
  269.         [4,0+1,1+1,1+1,9+1,9+1,8+1,8+1,0+1]:INT,0,
  270.     0+2,1+2,9+2,3,
  271.         [4,0+2,1+2,1+2,9+2,9+2,8+2,8+2,0+2]:INT,0,
  272.     0+3,1+3,9+3,4,
  273.         [4,0+3,1+3,1+3,9+3,9+3,8+3,8+3,0+3]:INT,0,
  274.     0+4,1+4,9+4,5,
  275.         [4,0+4,1+4,1+4,9+4,9+4,8+4,8+4,0+4]:INT,0,
  276.     0+5,1+5,9+5,6,
  277.         [4,0+5,1+5,1+5,9+5,9+5,8+5,8+5,0+5]:INT,0,
  278.     0+6,1+6,9+6,7,
  279.         [4,0+6,1+6,1+6,9+6,9+6,8+6,8+6,0+6]:INT,0,
  280.     7,0,8,8,
  281.         [4,7,0,0,8,8,15,15,7]:INT,0,
  282.     -> front/back
  283.     4,1,0,9,
  284.         [8,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,0]:INT,0,
  285.     8,9,12,10,
  286.         [8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,8]:INT,0]:face);
  287.  
  288.  
  289.  
  290.   let_1:=newVectorObject(0,8,6,
  291.     [1*3,165*3,-20*4,
  292.     22*3,165*3,-20*4,
  293.     105*3,0*3,-20*4,
  294.     84*3,0*3,-20*4,
  295.     1*3,165*3,20*4,
  296.     22*3,165*3,20*4,
  297.     105*3,0*3,20*4,
  298.     84*3,0*3,20*4]:INT,
  299.       [0,1,2,1,
  300.           [4,1,2,2,3,3,0,0,1]:INT,0,
  301.       6,5,4,2,
  302.         [4,7,6,6,5,5,4,4,7]:INT,0,
  303.       5,6,2,3,
  304.         [4,6,2,6,5,5,1,1,2]:INT,0,
  305.       7,4,0,4,
  306.         [4,3,7,7,4,4,0,0,3]:INT,0,
  307.       5,1,0,5,
  308.         [4,4,5,5,1,1,0,0,4]:INT,0,
  309.       6,7,3,6,
  310.         [4,6,7,7,3,3,2,2,6]:INT,0]:face);
  311.  
  312.   let_A:=newVectorObject(0,22,13,
  313.     [2*3,165*3,-20*4,
  314.     128*3,0*3,-20*4,
  315.     148*3,0*3,-20*4,
  316.     148*3,165*3,-20*4,
  317.     127*3,165*3,-20*4,
  318.     127*3,100*3,-20*4,
  319.     76*3,100*3,-20*4,
  320.     27*3,165*3,-20*4,
  321.     127*3,84*3,-20*4,
  322.     127*3,33*3,-20*4,
  323.     88*3,84*3,-20*4,
  324.     2*3,165*3,20*4,
  325.     128*3,0*3,20*4,
  326.     148*3,0*3,20*4,
  327.     148*3,165*3,20*4,
  328.     127*3,165*3,20*4,
  329.     127*3,100*3,20*4,
  330.     76*3,100*3,20*4,
  331.     27*3,165*3,20*4,
  332.     127*3,84*3,20*4,
  333.     127*3,33*3,20*4,
  334.     88*3,84*3,20*4]:INT,
  335.     [
  336.     9,10,21,2,    -> left inside A
  337.         [4,9,10,10,21,21,20,20,9]:INT,0,
  338.     8,9,20,1,    -> inside right A
  339.         [4,8,9,9,20,20,19,19,8]:INT,0,
  340.     4,5,16,4,    -> right inside A
  341.         [4,4,5,5,16,16,15,15,4]:INT,0,
  342.     5,6,17,5,    -> inside top leg
  343.         [4,5,6,6,17,17,16,16,5]:INT,0,
  344.     6,7,18,6,    -> left inside leg
  345.         [4,6,7,7,18,18,17,17,6]:INT,0,
  346.     10,8,19,3,    -> bottom inside A
  347.         [4,10,8,8,19,19,21,21,10]:INT,0,
  348.     0,1,12,7,    -> left out
  349.         [4,0,1,1,12,12,11,11,0]:INT,0,
  350.     1,2,13,8,    -> top
  351.         [4,1,2,2,13,13,12,12,1]:INT,0,
  352.     2,3,14,9,    -> right out
  353.         [4,2,3,3,14,14,13,13,2]:INT,0,
  354.     3,4,15,10,    -> bottom leg right
  355.         [4,3,4,4,15,15,14,14,3]:INT,0,
  356.     7,0,11,11,    -> bottom leg left
  357.         [4,7,0,0,11,11,18,18,7]:INT,0,
  358.     3,2,0,12,    -> front
  359.         [11,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,0,8,9,9,10,10,8]:INT,0,
  360.     11,13,14,13,    -> back
  361.         [11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,11,19,20,20,21,21,19]:INT,0]:face);
  362.  
  363.  
  364.   let_2:=newVectorObject(0,24,14,
  365.     [54*3,40*3,-20*4,
  366.     27*3,34*3,-20*4,
  367.     92*3,-2*3,-20*4,
  368.     159*3,22*3,-20*4,
  369.     141*3,74*3,-20*4,
  370.     52*3,149*3,-20*4,
  371.     137*3,149*3,-20*4,
  372.     137*3,165*3,-20*4,
  373.     2*3,165*3,-20*4,
  374.     119*3,63*3,-20*4,
  375.     125*3,31*3,-20*4,
  376.     93*3,21*3,-20*4,
  377.  
  378.     54*3,40*3,20*4,
  379.     27*3,34*3,20*4,
  380.     92*3,-2*3,20*4,
  381.     159*3,22*3,20*4,
  382.     141*3,74*3,20*4,
  383.     52*3,149*3,20*4,
  384.     137*3,149*3,20*4,
  385.     137*3,165*3,20*4,
  386.     2*3,165*3,20*4,
  387.     119*3,63*3,20*4,
  388.     125*3,31*3,20*4,
  389.     93*3,21*3,20*4]:INT,
  390.  
  391.     /* since no 'depth' sorting is done - ensure innermost surfaces drawn first */
  392.     [
  393.     5,6,18,19,    -> top of base
  394.         [4,5,6,6,18,18,17,17,5]:INT,0,
  395.     9,10,22,21,    -> inside top left
  396.         [4,9,10,10,22,22,21,21,9]:INT,0,
  397.     10,11,23,23,    -> inside top mid
  398.         [4,10,11,11,23,23,22,22,10]:INT,0,
  399.     11,0,12,24,    -> inside top left
  400.         [4,11,0,0,12,12,23,23,11]:INT,0,
  401.     8,9,21,16,    -> top of rasier
  402.         [4,8,9,9,21,21,20,20,8]:INT,0,
  403.     0,1,13,22,    -> front edge
  404.         [4,0,1,1,13,13,12,12,0]:INT,0,
  405.     4,5,17,17,    -> bottom of raiser
  406.         [4,4,5,5,17,17,16,16,4]:INT,0,
  407.     3,4,16,13,    -> right side
  408.         [4,3,4,4,16,16,15,15,3]:INT,0,
  409.     6,7,19,18,    -> right side of base
  410.         [4,6,7,7,19,19,18,18,6]:INT,0,
  411.     7,8,20,14,    -> base
  412.         [4,7,8,8,20,20,19,19,7]:INT,0,
  413.     2,3,15,15,    -> top right
  414.         [4,2,3,3,15,15,14,14,2]:INT,0,
  415.     1,2,14,20,    -> top left
  416.         [4,1,2,2,14,14,13,13,1]:INT,0,
  417.  
  418.     2,1,0,25,    /* front face */
  419.         [12,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,0]:INT,0,
  420.     12,13,14,26,    /* rear face */
  421.         [12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,12]:INT,0]:face);
  422.  
  423.  
  424.   /* add objects to the list, and position them accordingly */
  425.   addVObject(list,let_A)
  426.   let_A.px:=-1275-100
  427.   addVObject(list,let_1)
  428.   let_1.px:=-735-100
  429.   addVObject(list,let_2)
  430.   let_2.px:=-345-100
  431.   tmp:=cloneVectorObject(let_0);
  432.   addVObject(list,let_0)
  433.   let_0.px:=195-100
  434.   addVObject(list,tmp);
  435.   tmp.px:=735-100
  436.  
  437. ENDPROC stat
  438.  
  439. PROC freeobjects()
  440.   freeVList(list,1)       /* also free nodes */
  441. ENDPROC
  442.  
  443.  
  444.  
  445.