home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 352.lha / IFS_v1.4 / source / vectors.c < prev   
C/C++ Source or Header  |  1990-03-10  |  6KB  |  181 lines

  1. #include "ifs.h"
  2. #include "standard.h"
  3.  
  4. #define JAM1       0
  5. #define JAM2       1
  6. #define COMPLEMENT 2
  7. #define INVERDVID  4
  8.  
  9. void drawonebox();
  10. void checkswitches();
  11. void autoadj();
  12. int  closeby();
  13. void adjust();
  14. void checkswitches();
  15.  
  16. void drawvectors(rp, funs, numoffun, currentfun)
  17.    struct   RastPort      *rp;
  18.    float funs[][6];
  19.    int numoffun, currentfun;
  20. {
  21.   int  i, color;
  22.   
  23.   for (i=0; i<=numoffun; i++) {
  24.      if ((color = (i+2)%MAXCOLORS) < 2)
  25.        color = color+2;        /* paint with correct color */
  26.      SetAPen(rp, color);
  27.      drawonebox(rp,funs[i]);
  28.   }
  29.   SetAPen(rp,1);
  30.   drawonebox(rp,funs[currentfun]);
  31. }
  32.  
  33. void drawonebox(rp, afun)
  34.    struct   RastPort      *rp;
  35.    float afun[6];
  36. {
  37.   short  x[10], j;
  38.  
  39.   Move(rp, (int) (WIDTH/2  + DISPSCALE * afun[4] * WIDTH),
  40.            (int) (HEIGHT/2 - DISPSCALE * afun[5] * HEIGHT));
  41.   j=0;
  42.   x[j++] = WIDTH/2  + DISPSCALE * (afun[0] + afun[4]) * WIDTH;
  43.   x[j++] = HEIGHT/2 - DISPSCALE * (afun[2] + afun[5]) * HEIGHT;
  44.   x[j++] = WIDTH/2  + DISPSCALE * (afun[0] + afun[1] + afun[4]) * WIDTH;
  45.   x[j++] = HEIGHT/2 - DISPSCALE * (afun[2] + afun[3] + afun[5]) * HEIGHT;
  46.   x[j++] = WIDTH/2  + DISPSCALE * (afun[1] + afun[4]) * WIDTH;
  47.   x[j++] = HEIGHT/2 - DISPSCALE * (afun[3] + afun[5]) * HEIGHT;
  48.   x[j++] = WIDTH/2  + DISPSCALE * afun[4] * WIDTH;
  49.   x[j++] = HEIGHT/2 - DISPSCALE * afun[5] * HEIGHT;
  50.   PolyDraw(rp, 4, &x[0]);
  51.   Move(rp, (int) (WIDTH/2  + DISPSCALE * (afun[0]/4 + afun[4]) * WIDTH),
  52.            (int) (HEIGHT/2 - DISPSCALE * (afun[2]/4 + afun[5]) * HEIGHT));
  53.   j=0;            /* draw little box in right hand corner */
  54.   x[j++] = WIDTH/2  + DISPSCALE * (afun[0]/4 + afun[1]/4 + afun[4]) * WIDTH;
  55.   x[j++] = HEIGHT/2 - DISPSCALE * (afun[2]/4 + afun[3]/4 + afun[5]) * HEIGHT;
  56.   x[j++] = WIDTH/2  + DISPSCALE * (afun[1]/4 + afun[4]) * WIDTH;
  57.   x[j++] = HEIGHT/2 - DISPSCALE * (afun[3]/4 + afun[5]) * HEIGHT;
  58.   PolyDraw(rp, 2, &x[0]);  
  59.                              /* and slash in adjacent corner */
  60.   Move(rp, (int) (WIDTH/2  + DISPSCALE * (afun[0]*.75 + afun[4]) * WIDTH),
  61.            (int) (HEIGHT/2 - DISPSCALE * (afun[2]*.75 + afun[5]) * HEIGHT));
  62.   Draw(rp, (int) (WIDTH/2  + DISPSCALE * (afun[0] 
  63.                            + afun[1]/4 + afun[4]) * WIDTH),
  64.            (int) (HEIGHT/2 - DISPSCALE * (afun[2] 
  65.                            + afun[3]/4 + afun[5]) * HEIGHT));
  66. }
  67.  
  68.  
  69. int closeby (funs, currentfun, numoffun, mx, my) 
  70.  
  71. float funs[][6];
  72. int   *currentfun, numoffun;
  73. USHORT mx, my;
  74.  
  75. {
  76.   int xc[4], yc[4], i, j, thecorner = 0, hit=FALSE, thefun;
  77.     
  78.   for (j=0;j<=numoffun;j++) {
  79.      xc[0] = WIDTH/2  + DISPSCALE * funs[j][4] * WIDTH;
  80.      yc[0] = HEIGHT/2 - DISPSCALE * funs[j][5] * HEIGHT;
  81.  
  82.      xc[1] = WIDTH/2  + DISPSCALE * (funs[j][0] + funs[j][4]) * WIDTH;
  83.      yc[1] = HEIGHT/2 - DISPSCALE * (funs[j][2] + funs[j][5]) * HEIGHT;
  84.   
  85.      xc[2] = WIDTH/2  + DISPSCALE 
  86.              * (funs[j][0] + funs[j][1] + funs[j][4]) * WIDTH;
  87.      yc[2] = HEIGHT/2 - DISPSCALE 
  88.              * (funs[j][2] + funs[j][3] + funs[j][5]) * HEIGHT;
  89.      xc[3] = WIDTH/2  + DISPSCALE * (funs[j][1] + funs[j][4]) * WIDTH;
  90.      yc[3] = HEIGHT/2 - DISPSCALE * (funs[j][3] + funs[j][5]) * HEIGHT;
  91.  
  92.      for (i=0;i<4;i++) {
  93.        xc[i] = mx - xc[i];
  94.        yc[i] = my - yc[i];
  95.        if (xc[i] < 0) xc[i] = - xc[i];
  96.        if (yc[i] < 0) yc[i] = - yc[i];
  97.        if (xc[i] < EPSILON && yc[i] < EPSILON) 
  98.           if (hit == FALSE) {
  99.              thecorner = i+1;                /* is closeby */
  100.              thefun = j;
  101.              hit = TRUE;
  102.           }
  103.           else                        /* two at same point */
  104.              if (j == *currentfun) {            /* select currentfun */
  105.                 thecorner = i+1;
  106.                 thefun = j;
  107.          }
  108.           
  109.      }
  110.   }
  111.   if (hit == TRUE) *currentfun = thefun;
  112.   return (thecorner);
  113.   }       /* end closeby */
  114.  
  115. void adjust(corner, rp, funs, currentfun, mx, my) /* returns 1 if moved */
  116.   int corner;
  117.   struct   RastPort      *rp;
  118.   float funs[][6];
  119.   int currentfun;
  120.   USHORT mx, my;
  121.  
  122. {
  123.   float ta, tb, tc, td, te, tf;
  124.  
  125.   ta = funs[currentfun][0];
  126.   tb = funs[currentfun][1];
  127.   tc = funs[currentfun][2];
  128.   td = funs[currentfun][3];
  129.   te = funs[currentfun][4];
  130.   tf = funs[currentfun][5];
  131.  
  132.   switch (corner) {
  133.     case 1:
  134.       te = (mx - WIDTH/2)/(DISPSCALE * WIDTH);
  135.       tf = (HEIGHT/2 - my)/(DISPSCALE * HEIGHT);
  136.       break;
  137.     case 2:
  138.       ta = (mx - WIDTH/2)/(DISPSCALE * WIDTH)   - te; 
  139.       tc = (HEIGHT/2 - my)/(DISPSCALE * HEIGHT) - tf;
  140.       break;
  141.     case 3:
  142.       ta = (mx - WIDTH/2)/(DISPSCALE * WIDTH)   - te - tb; 
  143.       td = (HEIGHT/2 - my)/(DISPSCALE * HEIGHT) - tf - tc;
  144.       break;
  145.     case 4: 
  146.       tb = (mx - WIDTH/2)/(DISPSCALE * WIDTH)   - te;
  147.       td = (HEIGHT/2 - my)/(DISPSCALE * HEIGHT) - tf;
  148.       break;
  149.   }
  150.   if (ta >= MINCOFF && ta <= MAXCOFF &&
  151.       tb >= MINCOFF && tb <= MAXCOFF &&
  152.       tc >= MINCOFF && tc <= MAXCOFF &&
  153.       td >= MINCOFF && td <= MAXCOFF &&
  154.       te >= MINCOFF && te <= MAXCOFF &&
  155.       tf >= MINCOFF && tf <= MAXCOFF) {
  156.    
  157.       funs[currentfun][0] = ta;
  158.       funs[currentfun][1] = tb;
  159.       funs[currentfun][2] = tc;
  160.       funs[currentfun][3] = td;
  161.       funs[currentfun][4] = te;
  162.       funs[currentfun][5] = tf;
  163.       SetDrMd(rp,COMPLEMENT);
  164.       drawonebox(rp, funs[currentfun]);
  165.       drawonebox(rp, funs[currentfun]);
  166.       SetDrMd(rp,JAM1);
  167.       }
  168. }
  169.  
  170. void checkswitches(rp,funs,percent,currentfun,numoffun,vectorsw,displaynumsw)
  171.   struct   RastPort      *rp;
  172.   float funs[][6], percent[];
  173.   int currentfun, numoffun;
  174.   short vectorsw, displaynumsw;
  175. {
  176.   if (vectorsw) 
  177.      drawvectors(rp, funs, numoffun, currentfun);
  178.   if (displaynumsw) 
  179.      displaynums(rp, funs, percent, currentfun, numoffun);
  180. }
  181.