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

  1.  
  2. /*
  3.  
  4.     Complex Workbench2.0+ Example of FilledVector.m
  5.  
  6.     This program creates a spinning Torus 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.  This object is a bit
  10.     more 'chunky'  than the a1200 logo in wb1200, and
  11.     it can make the system feel a bit jerky.
  12.  
  13.     On the command line, specify the number of columns,
  14.     followed by the number of rows of images you want,
  15.     it defaults to 2x2.
  16.  
  17.     Run it with Workbench NOT inbackdrop mode, and to
  18.     remove it, run it again (it will interact with
  19.     the other wbbackdrop code in this archive)
  20.  
  21.  
  22.     The Torus was created in Imagine 2.0, and then saved.
  23.     The program tddd2nff (from t3dlib) was then used to
  24.     decompose the object into NFF.  ReadNFF was then
  25.     used to convert the object to FilledVector.m format,
  26.     and following this, some hand editing (quite a lot ...)
  27.     was used to create a useable object.
  28.  
  29.  
  30.     Michael Zucchi, 1994.  Program in public domain.
  31.  
  32.     (this is identical to wb1200.e, but has a different
  33.     object)
  34. */
  35.  
  36.  
  37.  
  38. OPT OSVERSION=37
  39.  
  40. MODULE 'tools/filledvector', 'tools/filledvdefs',
  41.     'exec/lists', 'exec/ports', 'exec/nodes', 'exec/libraries',
  42.     'intuition/screens', 'intuition/intuition', 'intuition/intuitionbase',
  43.     'graphics/gfx', 'graphics/rastport', 'graphics/layers'
  44.  
  45. DEF list:PTR TO mlh,pc,
  46.     ball:PTR TO vobject,
  47.     scr:PTR TO screen,abitm:PTR TO bitmap,
  48.     win:PTR TO window,
  49.     myrast:rastport,
  50.     mport:PTR TO mp,
  51.     width,height,depth,
  52.     rows,cols
  53.  
  54. DEF dx,dy,dz
  55.  
  56. /********************************************************************
  57.  
  58.     main
  59.  
  60.  */
  61.  
  62. PROC main()
  63. DEF rdargs, args:PTR TO LONG,p:PTR TO LONG, i, gfx:PTR TO lib
  64.  
  65. cols:=2;
  66. rows:=2;
  67.  
  68. -> check arguments
  69. args:=[0,0];
  70. IF rdargs:=ReadArgs('cols/N,rows/N', args, 0)
  71.   IF p:=args[0] THEN cols:=p[0]
  72.   IF p:=args[1] THEN rows:=p[0]
  73.   FreeArgs(rdargs);
  74. ENDIF  
  75.  
  76. -> see if we're already running, if yes, signal the other version
  77. Forbid();
  78. mport:=FindPort('backdrop');
  79. IF mport
  80.   Signal(mport.sigtask, Shl(1,mport.sigbit))
  81. ENDIF
  82. Permit();
  83.  
  84. -> if we are not already running, start doing our thing
  85. IF mport=0
  86.  
  87.   -> create a public port where we can be found later
  88.   mport:=CreateMsgPort();
  89.   mport::ln.name:='backdrop';
  90.   mport::ln.pri:=-128;
  91.   AddPort(mport);
  92.  
  93.   -> open the backdrop window
  94.   win:=OpenWindowTagList(0, [WA_FLAGS, WFLG_BACKDROP OR WFLG_BORDERLESS OR WFLG_SIMPLE_REFRESH OR WFLG_NOCAREREFRESH,
  95.     WA_BACKFILL, LAYERS_NOBACKFILL, 0]);
  96.  
  97.   -> calculate size of each tile
  98.   width:=win.width/cols
  99.   height:=win.height/rows
  100.   IF height AND 1 THEN height++
  101.   IF width AND 31 THEN width:=width+(32-(width AND 31))
  102.  
  103.   -> find the depth of workbench, and open our rendering bitmap
  104.   scr:=LockPubScreen(0);
  105.  
  106.   depth:=scr.rastport::rastport.bitmap::bitmap.depth
  107.   gfx:=gfxbase;
  108.  
  109.   IF gfx.version<39
  110.     abitm:=New(SIZEOF bitmap+(8*4));
  111.     p:=abitm.planes
  112.     FOR i:=0 TO depth-1 DO p[i]:=AllocRaster(width,height);
  113.     InitBitMap(abitm,depth,width,height);
  114.   ELSE
  115.     abitm:=AllocBitMap(width,height,depth,
  116.       BMF_CLEAR+BMF_INTERLEAVED,0);
  117.   ENDIF
  118.  
  119.   UnlockPubScreen(0, scr);
  120.  
  121.   -> finish of setting up, then goto the main loop
  122.   SetTaskPri(FindTask(0), -128);
  123.   InitRastPort(myrast);
  124.   myrast.bitmap:=abitm;
  125.  
  126.   IF win
  127.     IF createobjects()
  128.       IF pc:=newPolyContext(abitm,50)
  129.         demo()
  130.         freePolyContext(pc)
  131.       ENDIF
  132.       freeobjects()
  133.     ENDIF
  134.     CloseWindow(win);
  135.   ENDIF
  136.  
  137.   IF gfx.version<39
  138.     p:=abitm.planes
  139.     FOR i:=0 TO depth-1 DO FreeRaster(p[i], width,height);
  140.     InitBitMap(abitm,depth,width,height);
  141.   ELSE
  142.     FreeBitMap(abitm);
  143.   ENDIF
  144.  
  145.   RemPort(mport);
  146.   DeleteMsgPort(mport);
  147.  
  148. ENDIF -> IF mport=0
  149.  
  150. ENDPROC
  151.  
  152. /********************************************************************
  153.  
  154.   Main loop.  Render/move the object until we get told to stop
  155.  
  156.  */
  157.  
  158. PROC demo()
  159.   DEF p:position,x,y,c, sigbit, destz
  160.  
  161.   c:=0;
  162.   p.ax:=0;p.ay:=0;p.az:=0;p.px:=0;p.py:=0;p.pz:=750;
  163.  
  164.   destz:=Rnd(1000)+400;
  165.   sigbit:=Shl(1, mport.sigbit);
  166.   setPolyFlags(pc,1,1)
  167.  
  168.   -> main loop
  169.   WHILE (SetSignal(0, sigbit) AND sigbit)=0    -> see if we've been told to stop?
  170.  
  171.     cls()
  172.     setPolyBitMap(pc, abitm)
  173.  
  174.     IF c--<0
  175.       setangles()
  176.       c:=60;
  177.     ENDIF
  178.  
  179.     -> pri back to 0, this will stop us losing cpu while blitter owned (hang!)
  180.     SetTaskPri(FindTask(0), 0);
  181.  
  182.     moveDrawVList(pc, list, p)
  183.     FOR x:=0 TO cols-1
  184.     FOR y:=0 TO rows-1
  185.       BltBitMapRastPort(abitm, 0,0, win.rport, x*width,y*height,width,height,$c0);
  186.     ENDFOR
  187.     ENDFOR
  188.  
  189.     -> its safe to go back to low pri again
  190.     SetTaskPri(FindTask(0), -128);
  191.  
  192.     -> move object
  193.     p.pz:=p.pz+((destz-p.pz)/6)
  194.     IF Abs(p.pz-destz)<6 THEN destz:=Rnd(4000)+200
  195.     p.az:=p.az+dz;
  196.     p.ax:=p.ax-dx;
  197.     p.ay:=p.ay+dy;
  198.  
  199.   ENDWHILE
  200. ENDPROC
  201.  
  202. PROC setangles()
  203. dx:=Rnd(9)-4
  204. dy:=Rnd(9)-4
  205. dz:=Rnd(9)-4
  206. ENDPROC
  207.  
  208.  
  209. /********************************************************************
  210.  
  211.  Clears the bitmap we're rendering into, then fills it with the
  212.  stipple pattern
  213.  
  214.  */
  215.  
  216. PROC cls()
  217.  SetRast(myrast, 0);
  218.  WaitBlit()
  219.  
  220.  MOVE.L abitm,A2
  221.  MOVE.L 8(A2),A1
  222.  MOVE.L    height,D3
  223.  LSR.L    #1,D3
  224.  SUBQ.L    #1,D3
  225.  MOVE.L #$55555555,D0
  226.  MOVE.L #$AAAAAAAA,D1
  227. d_lp0:
  228.  MOVE.L A1,A0
  229.  ADDA.W (A2),A1
  230.  MOVE.L width,D2
  231.  LSR.W    #5,D2
  232.  SUBQ.W    #1,D2
  233. d_lp1:
  234.  MOVE.L D0,(A0)+
  235.  DBF    D2,d_lp1
  236.  MOVE.L A1,A0
  237.  ADDA.W (A2),A1
  238.  MOVE.L    width,D2
  239.  LSR.W    #5,D2
  240.  SUBQ.W    #1,D2
  241. d_lp2:
  242.  MOVE.L D1,(A0)+
  243.  DBF    D2,d_lp2
  244.  DBF    D3,d_lp0
  245. ENDPROC
  246.  
  247. /********************************************************************
  248.  
  249.      Create all of the objects
  250.  
  251.  */ 
  252.  
  253. PROC createobjects()
  254.   DEF stat=-1,
  255.       tmp:PTR TO vobject
  256.  
  257.   /* allocate a list, and add them to it */
  258.   list:=newVList()
  259.  
  260.  ball:=newVectorObject(0,32,64, ->64,
  261.     [141,-142,100,
  262.     200,0,100,
  263.     277,-115,0,
  264.     277,114,0,
  265.     141,141,100,
  266.     114,277,0,
  267.     0,200,100,
  268.     -115,277,0,
  269.     -142,141,100,
  270.     -278,114,0,
  271.     -200,0,100,
  272.     -278,-115,0,
  273.     -142,-142,100,
  274.     -115,-278,0,
  275.     0,-200,100,
  276.     114,-278,0,
  277.     200,0,-100,
  278.     141,141,-100,
  279.     0,200,-100,
  280.     -142,141,-100,
  281.     -200,0,-100,
  282.     -142,-142,-100,
  283.     0,-200,-100,
  284.     141,-142,-100,
  285.     92,38,0,
  286.     38,92,0,
  287.     -39,92,0,
  288.     -93,38,0,
  289.     -93,-39,0,
  290.     -39,-93,0,
  291.     38,-93,0,
  292.     92,-39,0,
  293.     0,0,0]:INT,
  294. [24,17,16,32,[3,16,17,17,24,24,16]:INT,0,    ->  all of these lines had their 
  295. 24,25,17,33,[3,24,25,25,17,17,24]:INT,0,
  296. 25,18,17,34,[3,17,18,18,25,25,17]:INT,0,    ->  cross product numbers swapped
  297. 25,26,18,35,[3,25,26,26,18,18,25]:INT,0,
  298. 26,19,18,36,[3,18,19,19,26,26,18]:INT,0,    ->
  299. 26,27,19,37,[3,26,27,27,19,19,26]:INT,0,
  300. 27,20,19,38,[3,19,20,20,27,27,19]:INT,0,    ->
  301. 27,28,20,39,[3,27,28,28,20,20,27]:INT,0,
  302. 28,21,20,40,[3,20,21,21,28,28,20]:INT,0,    ->
  303. 28,29,21,41,[3,28,29,29,21,21,28]:INT,0,
  304. 29,22,21,42,[3,21,22,22,29,29,21]:INT,0,    ->
  305. 29,30,22,43,[3,29,30,30,22,22,29]:INT,0,
  306. 30,23,22,44,[3,22,23,23,30,30,22]:INT,0,    ->
  307. 30,31,23,45,[3,30,31,31,23,23,30]:INT,0,
  308. 31,16,23,46,[3,23,16,16,31,31,23]:INT,0,    ->
  309. 31,24,16,47,[3,31,24,24,16,16,31]:INT,0,
  310. 4,25,24,48,[3,24,25,25,4,4,24]:INT,0,    ->
  311. 4,6,25,49,[3,4,6,6,25,25,4]:INT,0,
  312. 6,26,25,50,[3,25,26,26,6,6,25]:INT,0,    ->
  313. 6,8,26,51,[3,6,8,8,26,26,6]:INT,0,
  314. 8,27,26,52,[3,26,27,27,8,8,26]:INT,0,    ->
  315. 8,10,27,53,[3,8,10,10,27,27,8]:INT,0,
  316. 10,28,27,54,[3,27,28,28,10,10,27]:INT,0,    ->
  317. 10,12,28,55,[3,10,12,12,28,28,10]:INT,0,
  318. 12,29,28,56,[3,28,29,29,12,12,28]:INT,0,    ->
  319. 12,14,29,57,[3,12,14,14,29,29,12]:INT,0,
  320. 14,30,29,58,[3,29,30,30,14,14,29]:INT,0,    ->
  321. 14,0,30,59,[3,14,0,0,30,30,14]:INT,0,
  322. 0,31,30,60,[3,30,31,31,0,0,30]:INT,0,    ->
  323. 0,1,31,61,[3,0,1,1,31,31,0]:INT,0,
  324. 1,24,31,62,[3,31,24,24,1,1,31]:INT,0,    ->
  325. 1,4,24,63,[3,1,4,4,24,24,1]:INT,0,
  326.  
  327. 16,3,2,16,[3,2,3,3,16,16,2]:INT,0,    ->
  328. 16,17,3,17,[3,16,17,17,3,3,16]:INT,0,
  329. 17,5,3,18,[3,3,5,5,17,17,3]:INT,0,    ->
  330. 17,18,5,19,[3,17,18,18,5,5,17]:INT,0,
  331. 18,7,5,20,[3,5,7,7,18,18,5]:INT,0,    ->
  332. 18,19,7,21,[3,18,19,19,7,7,18]:INT,0,
  333. 19,9,7,22,[3,7,9,9,19,19,7]:INT,0,    ->
  334. 19,20,9,23,[3,19,20,20,9,9,19]:INT,0,
  335. 20,11,9,24,[3,9,11,11,20,20,9]:INT,0,    ->
  336. 20,21,11,25,[3,20,21,21,11,11,20]:INT,0,
  337. 21,13,11,26,[3,11,13,13,21,21,11]:INT,0,    ->
  338. 21,22,13,27,[3,21,22,22,13,13,21]:INT,0,
  339. 22,15,13,28,[3,13,15,15,22,22,13]:INT,0,    ->
  340. 22,23,15,29,[3,22,23,23,15,15,22]:INT,0,
  341. 23,2,15,30,[3,15,2,2,23,23,15]:INT,0,    ->
  342. 23,16,2,31,[3,23,16,16,2,2,23]:INT,0,
  343.  
  344. 2,1,0,0,[3,0,1,1,2,2,0]:INT,0,    ->
  345. 2,3,1,1,[3,2,3,3,1,1,2]:INT,0,
  346. 3,4,1,2,[3,1,4,4,3,3,1]:INT,0,    ->
  347. 3,5,4,3,[3,3,5,5,4,4,3]:INT,0,
  348. 5,6,4,4,[3,4,6,6,5,5,4]:INT,0,    ->
  349. 5,7,6,5,[3,5,7,7,6,6,5]:INT,0,
  350. 7,8,6,6,[3,6,8,8,7,7,6]:INT,0,    ->
  351. 7,9,8,7,[3,7,9,9,8,8,7]:INT,0,
  352. 9,10,8,8,[3,8,10,10,9,9,8]:INT,0,    ->
  353. 9,11,10,9,[3,9,11,11,10,10,9]:INT,0,
  354. 11,12,10,10,[3,10,12,12,11,11,10]:INT,0,    ->
  355. 11,13,12,11,[3,11,13,13,12,12,11]:INT,0,
  356. 13,14,12,12,[3,12,14,14,13,13,12]:INT,0,    ->
  357. 13,15,14,13,[3,13,15,15,14,14,13]:INT,0,
  358. 15,0,14,14,[3,14,0,0,15,15,14]:INT,0,    ->
  359. 15,2,0,15,[3,15,2,2,0,0,15]:INT,0]:face)
  360.  
  361.  
  362.   ball.pz:=0
  363.   addVObject(list,ball)
  364.  
  365.  
  366. ENDPROC stat
  367.  
  368. PROC freeobjects()
  369.   freeVList(list,1)       /* also free nodes */
  370. ENDPROC
  371.  
  372.  
  373.  
  374.