home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsiv / outcode / xf4.c < prev   
Encoding:
C/C++ Source or Header  |  1994-05-16  |  1.5 KB  |  74 lines

  1. /* 2D transform and clip test a vertex list */
  2.  
  3. /* oflo and division traps should be disabled, by the way */
  4.  
  5. #define FI(x)    (*(int *)&x)
  6.  
  7. /********************************************************/
  8. xform_ctp(vc, vpi, vpo, visiz, vosiz, mtx, prj, pf, pa)
  9. int vc    ;    /* vertex count */
  10. int visiz;    /* input vertex array stride */
  11. int vosiz;    /* output vertex array stride */
  12. int *pf;    /* flag array */
  13. int *pa;    /* 2 element - global or_flag, and_flag */
  14. float *vpi, *vpo, *mtx, *prj;
  15. {
  16. register int flag, flag_or, flag_and;
  17.  
  18. /* flpt registers, total 32 */
  19. register float xx, xy, xt;    /* transformation matrix */
  20. register float yx, yy, yt;
  21. register float xo, yo;        /* output vertex */
  22. register float xi, yi;        /* temps */
  23.  
  24. /* load up local transform matrix */
  25. xx = *(mtx+0 ); xy = *(mtx+1 ); xt = *(mtx+2 );
  26. yx = *(mtx+4 ); yy = *(mtx+5 ); yt = *(mtx+6 );
  27.  
  28. /* initialize accumulated flags */
  29. flag_or = 0;
  30. flag_and = -1;
  31.  
  32. do {
  33.     xi = vpi[0];    /* xi */
  34.     yi = vpi[1];    /* yi */
  35.  
  36.     xo = xi * xx + yi * xy + xt;
  37.     yo = xi * yx + yi * yy + yt;
  38.  
  39.     /* let's try branches for comparison purposes */
  40.     flag = 0;
  41.  
  42. #define CXMIN    1
  43. #define CXMAX    2
  44. #define CYMIN    4
  45. #define CYMAX    8
  46.  
  47. #define XMIN    0
  48. #define XMAX    1279
  49. #define YMIN    0
  50. #define YMAX    1023
  51.  
  52.     if (xo < XMIN) flag |= CXMIN;
  53.     if (xo > XMAX) flag |= CXMAX;
  54.     if (yo < YMIN) flag |= CYMIN;
  55.     if (yo > YMAX) flag |= CYMAX;
  56.  
  57.     flag_or |= flag;
  58.     flag_and &= flag;
  59.  
  60.     *(vpo+0) = xo;
  61.     *(vpo+1) = yo;
  62.     *pf = flag;
  63.  
  64.     vpi += visiz;
  65.     vpo += vosiz;
  66.     pf++;
  67. } while (--vc > 0);
  68.  
  69. *(pa+0) = flag_or;
  70. *(pa+1) = flag_and;
  71.  
  72. return;
  73. }
  74.