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

  1. /* transform, clip test, and project 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, xz, xw;        /* transformation matrix */
  20. register float yx, yy, yz, yw;
  21. register float zx, zy, zz, zw;
  22. register float wx, wy, wz, ww;
  23. register float xo, yo, zo, wo;        /* output vertex */
  24. register float xs, xt, ys, yt, zs /*zt*/;    /* projection scale and translate */
  25. register float t0, t1, t2, t3, t4, t5;    /* temps */
  26. register float one = 1.0;
  27.  
  28. /* load up local projection matrix */
  29. xs = *(prj+0); xt = *(prj+1);
  30. ys = *(prj+2); yt = *(prj+3);
  31. zs = *(prj+4); /* zt = *(prj+5); later */
  32.  
  33. /* load up local transform matrix */
  34. xx = *(mtx+0 ); xy = *(mtx+1 ); xz = *(mtx+2 ); xw = *(mtx+3 );
  35. yx = *(mtx+4 ); yy = *(mtx+5 ); yz = *(mtx+6 ); yw = *(mtx+7 );
  36. zx = *(mtx+8 ); zy = *(mtx+9 ); zz = *(mtx+10); zw = *(mtx+11);
  37. wx = *(mtx+12); wy = *(mtx+13); wz = *(mtx+14); ww = *(mtx+15);
  38.  
  39. /* initialize accumulated flags */
  40. flag_or = 0;
  41. flag_and = -1;
  42.  
  43. do {
  44. #define wi    t4
  45.     wi = vpi[3];    /* wi */
  46. #define xi    t5
  47.     xi = vpi[0];    /* xi */
  48.  
  49.     /* calculate 4x4 transform, use as few regs as possible */
  50.     wo = wi*ww; xo = wi*wx; yo = wi*wy; zo = wi*wz;
  51. #define yi    t4
  52.     yi = vpi[1];    /* yi */
  53.  
  54.     t0 = xi*xw; t1 = xi*xx; t2 = xi*xy; t3 = xi*xz;
  55. #define zi    t5
  56.     zi = vpi[2];    /* zi */
  57.     wo += t0; xo += t1; yo += t2; zo += t3;
  58.  
  59.     t0 = yi*yw; t1 = yi*yx; t2 = yi*yy; t3 = yi*yz;
  60.     wo += t0; xo += t1; yo += t2; zo += t3;
  61.  
  62.     t0 = zi*zw; t1 = zi*zx; t2 = zi*zy; t3 = zi*zz;
  63.     wo += t0; xo += t1; yo += t2; zo += t3;
  64.  
  65. #define winv    t0
  66.     winv = one / wo;
  67.  
  68. #define zt    t1
  69.     /* ready for this now */
  70.     zt =    prj[5];
  71.  
  72.     /* let's try branches for comparison purposes */
  73.     flag = 0;
  74.  
  75. #define CXMAX    1
  76. #define CXMIN    2
  77. #define CYMAX    4
  78. #define CYMIN    8
  79. #define CZMAX    16
  80. #define CZMIN 32
  81.  
  82.     if (xo >  wo) flag |= CXMAX;
  83.     if (xo < -wo) flag |= CXMIN;
  84.     if (yo >  wo) flag |= CYMAX;
  85.     if (yo < -wo) flag |= CYMIN;
  86.     if (zo >  wo) flag |= CZMAX;
  87.     if (zo < -wo) flag |= CZMIN;
  88.  
  89.     flag_or |= flag;
  90.     flag_and &= flag;
  91.  
  92.     xo *= xs;
  93.     yo *= ys;
  94.     zo *= zs;
  95.  
  96.     xo *= winv;
  97.     yo *= winv;
  98.     zo *= winv;
  99.  
  100.     xo += xt;
  101.     yo += yt;
  102.     zo += zt;
  103.  
  104.     *(vpo+0) = xo;
  105.     *(vpo+1) = yo;
  106.     *(vpo+2) = zo;
  107.     *pf = flag;
  108.  
  109.     vpi += visiz;
  110.     vpo += vosiz;
  111.     pf++;
  112. } while (--vc > 0);
  113.  
  114. *(pa+0) = flag_or;
  115. *(pa+1) = flag_and;
  116.  
  117. return;
  118. }
  119.