home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / prev.tar.gz / prev.tar / box.c < prev    next >
C/C++ Source or Header  |  1991-03-08  |  2KB  |  107 lines

  1. #include <math.h>
  2. #include <stdio.h>
  3. #include "art.h"
  4. #include "macro.h"
  5. #include "gram.h"
  6.  
  7. extern mats    *mstackp;
  8. extern hlist    *fhlist;
  9. extern float    tolerance;
  10.  
  11. extern int    lookatdone;
  12.  
  13. /*
  14.  * boxinit
  15.  *
  16.  *    initialise the function pointers and extra field for a box object
  17.  */
  18. void
  19. boxinit(o, d)
  20.     object    *o;
  21.     details *d;
  22. {
  23.     int    first;
  24.     vector    c1, c2, max, min;
  25.     details    *ld;
  26.  
  27.     c1.x = c1.y = c1.z = 0.0;        /* default box */
  28.     c2.x = c2.y = c2.z = 1.0;
  29.  
  30.     first = 1;
  31.  
  32.     if (!lookatdone)
  33.         deflookat();
  34.  
  35.     while (d != (details *)NULL) {
  36.         switch (d->type) {
  37.         case VERTEX:
  38.             if (first) {
  39.                 c1 = d->u.v;
  40.                 first = 0;
  41.             } else 
  42.                 c2 = d->u.v;
  43.             break;
  44.         default:
  45.             warning("art: illegal field in box ignored.\n");
  46.         }
  47.         ld = d;
  48.         d = d->nxt;
  49.         free(ld);
  50.     }
  51.  
  52.     if (c1.x > c2.x) {
  53.         max.x = c1.x;
  54.         min.x = c2.x;
  55.     } else {
  56.         max.x = c2.x;
  57.         min.x = c1.x;
  58.     }
  59.  
  60.     if (c1.y > c2.y) {
  61.         max.y = c1.y;
  62.         min.y = c2.y;
  63.     } else {
  64.         max.y = c2.y;
  65.         min.y = c1.y;
  66.     }
  67.  
  68.     if (c1.z > c2.z) {
  69.         max.z = c1.z;
  70.         min.z = c2.z;
  71.     } else {
  72.         max.z = c2.z;
  73.         min.z = c1.z;
  74.     }
  75.  
  76.     pushmatrix();
  77.  
  78.         calctransforms(mstackp);
  79.         multmatrix(mstackp->obj2ray);
  80.  
  81.         move(min.x, min.y, min.z);
  82.         draw(max.x, min.y, min.z);
  83.         draw(max.x, max.y, min.z);
  84.         draw(min.x, max.y, min.z);
  85.         draw(min.x, min.y, min.z);
  86.  
  87.         move(min.x, min.y, max.z);
  88.         draw(max.x, min.y, max.z);
  89.         draw(max.x, max.y, max.z);
  90.         draw(min.x, max.y, max.z);
  91.         draw(min.x, min.y, max.z);
  92.  
  93.         move(min.x, min.y, max.z);
  94.         draw(min.x, min.y, min.z);
  95.  
  96.         move(max.x, max.y, max.z);
  97.         draw(max.x, max.y, min.z);
  98.  
  99.         move(min.x, max.y, max.z);
  100.         draw(min.x, max.y, min.z);
  101.  
  102.         move(max.x, min.y, max.z);
  103.         draw(max.x, min.y, min.z);
  104.     
  105.     popmatrix();
  106. }
  107.