home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / outcode / xcc2d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  2.2 KB  |  113 lines

  1. /* Time xform, clip checking, lighting only */
  2.  
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <fcntl.h>
  6. #include <sys/time.h>
  7.  
  8. /* BSD timer macros -- replace with your own */
  9. struct timeval start, stop;
  10.  
  11. #define START    gettimeofday(&start, NULL)
  12. #define STOP    gettimeofday(&stop, NULL)
  13. #define DELTAT    ((float)(stop.tv_sec - start.tv_sec)+1.0e-6*    \
  14.          (float)(stop.tv_usec-start.tv_usec))
  15.  
  16. #define LOOPCOUNT 10000
  17.  
  18. #define VSIZ 2 /* vertex size */
  19.  
  20. #define XSIZ 1280
  21. #define YSIZ 1024
  22. #define ZSIZ 32768
  23.  
  24. /* clip test bit flags */
  25. #define CXMAX 1
  26. #define CXMIN 2
  27. #define CYMAX 4
  28. #define CYMIN 8
  29. #define CZMAX 16
  30. #define CZMIN 32
  31.  
  32. #define VERTS 12    /* number of points in primitive */
  33.  
  34. typedef float verttype[VSIZ];
  35.  
  36. /* 100 pixel triangles in a triangle strip */
  37. #define X    14.0
  38. verttype vtxm[] = {    /* model triangle strip points */
  39.     { 0.0, 0.0 + X*0},
  40.     { X,   X/2 + X*0},
  41.     { 0.0, 0.0 + X*1},
  42.     { X,   X/2 + X*1},
  43.     { 0.0, 0.0 + X*2},
  44.     { X,   X/2 + X*2},
  45.     { 0.0, 0.0 + X*3},
  46.     { X,   X/2 + X*3},
  47.     { 0.0, 0.0 + X*4},
  48.     { X,   X/2 + X*4},
  49.     { 0.0, 0.0 + X*5},
  50.     { X,   X/2 + X*5}, };
  51.  
  52. /*
  53.  * Transform/clip check test program
  54.  *
  55.  * takes the following command line options:
  56.  *
  57.  *    -m MHz     : set MHz for clock calculation
  58.  *    -c count : loop counter (defaults to 10000)
  59.  *
  60.  */
  61.  
  62. main( argc, argv)
  63. int argc; char *argv[];
  64. {
  65. int MHz = 40;
  66. int i;
  67. float mtx[16], proj[6];
  68. float vtxw[VERTS+1][VSIZ-1];    /* output xyz device coords */
  69. int vflg[VERTS];
  70. int tflg[2];
  71. int loopcount = LOOPCOUNT;
  72.  
  73. /* read command line options */
  74.     while (--argc){
  75.       if ((*++argv)[0] == '-'){
  76.         switch((*argv)[1]){
  77.           case 'm': MHz = atoi((*++argv));
  78.                 --argc;
  79.                 break;
  80.           case 'c': loopcount = atoi((*++argv));
  81.                 --argc;
  82.                 break;
  83.         }
  84.       }
  85.     }
  86.  
  87. /* set up transform and projection matrices */
  88.  
  89.     /* identity matrix */
  90.     for (i=0; i<16; i++) mtx[i] = 0;
  91.     mtx[0] = mtx[5] = mtx[10] = mtx[15] =  1.0;
  92.  
  93.     /* projection values */
  94.     proj[0] = 100.0;
  95.     proj[1] = 0.0;
  96.     proj[2] = 100.0;
  97.     proj[3] = 0.0;
  98.     proj[4] = 100.0;
  99.     proj[5] = 0.0;
  100.  
  101. /* start the operation */
  102.     START;
  103.  
  104.     for (i=0; i < loopcount; i++) {
  105.         xform_ctp(VERTS,vtxm,vtxw,VSIZ,VSIZ-1,mtx,proj,vflg,tflg);
  106.     }
  107.  
  108.     STOP;
  109.  
  110.     printf("%d points in %g seconds\n", i*VERTS, DELTAT);
  111.     printf("%g clocks/point at %d MHz\n", DELTAT/(i*VERTS)*MHz*1.0e6, MHz);
  112. }
  113.