home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vogle / prev.lha / super.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  2.5 KB  |  145 lines

  1. #include <math.h>
  2. #include <stdio.h>
  3. #include "art.h"
  4. #include "macro.h"
  5. #include "gram.h"
  6. #include "poly.h"
  7.  
  8. extern mats    *mstackp;
  9. extern hlist    *fhlist;
  10. extern float    tolerance;
  11.  
  12. extern double    power();
  13.  
  14. /*
  15.  * bounding box for all superquadrics
  16.  */
  17. static bbox sqbox = {
  18.     { 1.0, 1.0, 1.0 },
  19.     { -1.0, -1.0, -1.0 }
  20. };
  21.  
  22. /*
  23.  * superinit
  24.  *
  25.  *    initialise the function pointers and fields for a superquadric object,
  26.  *     returning its pointer.
  27.  */
  28. void
  29. superinit(o, d)
  30.     object    *o;
  31.     details *d;
  32. {
  33.     superquadric    *sprq;
  34.     int        first, order;
  35.     vector        c1, c2, cent;
  36.     float        xlen, ylen, zlen;
  37.     details        *ld;
  38.  
  39.     first = 1;
  40.  
  41.     order = 1;
  42.     c1.x = c1.y = c1.z = -1.0;
  43.     c2.x = c2.y = c2.z = 1.0;
  44.  
  45.     while (d != (details *)NULL) {
  46.         switch (d->type) {
  47.         case VERTEX:
  48.             if (first) {
  49.                 c1 = d->u.v;
  50.                 first = 0;
  51.             } else
  52.                 c2 = d->u.v;
  53.             break;
  54.         case ORDER:
  55.             order = d->u.i;
  56.             break;
  57.         default:
  58.             warning("art: illegal field in superquadric ignored.\n");
  59.         }
  60.         ld = d;
  61.         d = d->nxt;
  62.         free(ld);
  63.     }
  64.  
  65.     xlen = fabs((c1.x - c2.x)) / 2;
  66.     ylen = fabs((c1.y - c2.y)) / 2;
  67.     zlen = fabs((c1.z - c2.z)) / 2;
  68.  
  69.     cent.x = (c1.x + c2.x) / 2.0;
  70.     cent.y = (c1.y + c2.y) / 2.0;
  71.     cent.z = (c1.z + c2.z) / 2.0;
  72.  
  73.     if (order == 1) {        /* a diamond */
  74.         pushmatrix();
  75.  
  76.             calctransforms(mstackp);
  77.             multmatrix(mstackp->obj2ray);
  78.  
  79.             translate(cent.x, cent.y, cent.z);
  80.  
  81.             move(xlen, 0.0, 0.0);    /* "equator" */
  82.             draw(0.0, ylen, 0.0);
  83.             draw(-xlen, 0.0, 0.0);
  84.             draw(0.0, -ylen, 0.0);
  85.             draw(xlen, 0.0, 0.0);
  86.  
  87.             move(0.0, 0.0, zlen);    /* upper latitude */
  88.             draw(0.0, ylen, 0.0);
  89.  
  90.             move(0.0, 0.0, zlen);
  91.             draw(-xlen, 0.0, 0.0);
  92.  
  93.             move(0.0, 0.0, zlen);
  94.             draw(0.0, -ylen, 0.0);
  95.  
  96.             move(0.0, 0.0, zlen);
  97.             draw(xlen, 0.0, 0.0);
  98.  
  99.             move(0.0, 0.0, -zlen);    /* lower latitude */
  100.             draw(0.0, ylen, 0.0);
  101.  
  102.             move(0.0, 0.0, -zlen);
  103.             draw(-xlen, 0.0, 0.0);
  104.  
  105.             move(0.0, 0.0, -zlen);
  106.             draw(0.0, -ylen, 0.0);
  107.  
  108.             move(0.0, 0.0, -zlen);
  109.             draw(xlen, 0.0, 0.0);
  110.  
  111.         popmatrix();
  112.     } else {            /* just do a box for now */
  113.         pushmatrix();
  114.  
  115.             calctransforms(mstackp);
  116.             multmatrix(mstackp->obj2ray);
  117.  
  118.             move(c1.x, c1.y, c1.z);
  119.             draw(c2.x, c1.y, c1.z);
  120.             draw(c2.x, c2.y, c1.z);
  121.             draw(c1.x, c2.y, c1.z);
  122.             draw(c1.x, c1.y, c1.z);
  123.  
  124.             move(c1.x, c1.y, c2.z);
  125.             draw(c2.x, c1.y, c2.z);
  126.             draw(c2.x, c2.y, c2.z);
  127.             draw(c1.x, c2.y, c2.z);
  128.             draw(c1.x, c1.y, c2.z);
  129.  
  130.             move(c1.x, c1.y, c2.z);
  131.             draw(c1.x, c1.y, c1.z);
  132.  
  133.             move(c2.x, c2.y, c2.z);
  134.             draw(c2.x, c2.y, c1.z);
  135.  
  136.             move(c1.x, c2.y, c2.z);
  137.             draw(c1.x, c2.y, c1.z);
  138.  
  139.             move(c2.x, c1.y, c2.z);
  140.             draw(c2.x, c1.y, c1.z);
  141.         
  142.         popmatrix();
  143.     }
  144. }
  145.