home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / pointlist / ptlInst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-12  |  2.9 KB  |  115 lines

  1. #include "ooglutil.h"
  2. #include "geom.h"
  3. #include "instP.h"
  4. #include "pointlistP.h"
  5.  
  6. void *inst_PointList_get(int sel, Geom *geom, va_list args);
  7. void *inst_PointList_fillin(int sel, Geom *geom, va_list args);
  8. void *inst_PointList_set(int sel, Geom *geom, va_list args);
  9. void *inst_PointList_length(int sel, Geom *geom, va_list args);
  10.  
  11. #define MAX_METHODS 4
  12.  
  13. static SpecFunc methods[] = {
  14.   "PointList_get", inst_PointList_get,
  15.   "PointList_fillin", inst_PointList_fillin,
  16.   "PointList_set", inst_PointList_set,
  17.   "PointList_length", inst_PointList_length
  18. };
  19.  
  20. static char msg[] = "ptlInst.c";
  21.  
  22. ptlInst_init() {
  23.   pointlist_initspec(methods, MAX_METHODS, GeomClassLookup("inst"));
  24. }
  25.  
  26. void *inst_PointList_get(int sel, Geom *geom, va_list args) {
  27.   Inst *i = (Inst *)geom;
  28.   HPoint3 *plist;
  29.   int n_points;
  30.   float **t;
  31.   int coordsys;
  32.  
  33.   n_points = (int)GeomCall(GeomMethodSel("PointList_length"), geom);
  34.   plist = OOGLNewNE(HPoint3, n_points, msg);
  35.  
  36.   t = va_arg(args, float **);
  37.   coordsys = va_arg(args, int);
  38.  
  39.   return GeomCall(GeomMethodSel("PointList_fillin"), geom, t, 
  40.           coordsys, plist);
  41.  
  42. }
  43.  
  44. void *inst_PointList_fillin(int sel, Geom *geom, va_list args) {
  45.   Inst *inst = (Inst *)geom;
  46.   HPoint3 *plist;
  47.   int coordsys;
  48.   GeomIter *it;
  49.   Transform Tnew;
  50.   int i, n_points;
  51.   float **t;
  52.  
  53.   t = va_arg(args, float **);
  54.   coordsys = va_arg(args, int);
  55.   plist = va_arg(args, HPoint3 *);
  56.  
  57.   n_points = (int)GeomCall(GeomMethodSel("PointList_length"), inst->geom);
  58.  
  59.   it = GeomIterate(geom, DEEP);
  60.   for (i = 0; NextTransform(it, Tnew); i += n_points) 
  61.     if (coordsys == POINTLIST_SELF) {
  62.       TmConcat(Tnew, t, Tnew);
  63.       GeomCall(GeomMethodSel("PointList_fillin"), inst->geom, &Tnew[0][0],
  64.            coordsys, &plist[i]);
  65.     } else if (coordsys == POINTLIST_PRIMITIVE) 
  66.       GeomCall(GeomMethodSel("PointList_fillin"), inst->geom, t, coordsys,
  67.            &plist[i]);
  68.     else {
  69.       OOGLError(1, "Unrecognized coordinate system in inst_PointList_fillin");
  70.       return NULL;
  71.     }
  72.  
  73.   return plist;
  74.  
  75. }
  76.  
  77.  
  78. void *inst_PointList_set(int sel, Geom *geom, va_list args) {
  79.   Inst *inst = (Inst *)geom;
  80.   HPoint3 *plist;
  81.   Transform T, TInv;
  82.   int coordsys;
  83.   GeomIter *it;
  84.  
  85.   coordsys = va_arg(args, int);
  86.   plist = va_arg(args, HPoint3 *);
  87.  
  88.   /* If the point list has more than one copy of the points 
  89.    * of the geom in it, just use the first set */
  90.   it = GeomIterate(geom, DEEP);
  91.   if (NextTransform(it, T) && coordsys == POINTLIST_SELF) {
  92.     Tm3Invert(T, TInv);
  93.     HPt3TransformN(TInv, plist, plist, 
  94.            GeomCall(GeomMethodSel("PointList_length"), inst->geom));
  95.   }
  96.   GeomCall(GeomMethodSel("PointList_set"), inst->geom, coordsys, plist);
  97.   return NULL;
  98.  
  99. }
  100.  
  101.  
  102. void *inst_PointList_length(int sel, Geom *geom, va_list args) {
  103.   Inst *inst = (Inst *)geom;
  104.   int i, n_points;
  105.   Transform T;
  106.   GeomIter *it;
  107.  
  108.   n_points = 
  109.     (int)GeomCall(GeomMethodSel("PointList_length"), inst->geom);
  110.   it = GeomIterate(geom, DEEP);
  111.   for (i = 0; NextTransform(it, T); i += n_points);
  112.   return (void *)i;
  113.  
  114. }
  115.