home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / vect / vectdraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-02  |  3.5 KB  |  147 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12.  /*
  13.   * Geometry Routines
  14.   * 
  15.   * Geometry Supercomputer Project
  16.   * 
  17.   * ROUTINE DESCRIPTION:
  18.   *    Draw a Vect (collection of vectors).
  19.   * 
  20.   */
  21.  
  22. #include "mgP.h"
  23. #include "vectP.h"
  24. #include "hpointn.h"
  25. #include "transformn.h"
  26.  
  27. #include <stdlib.h>
  28. #ifndef alloca
  29. #include <alloca.h>
  30. #endif
  31.  
  32. static void
  33. draw_projected_vect(mgmapfunc NDmap, void *NDinfo, Vect *v, int flags, int penultimate)
  34. {
  35.     HPointN *h = HPtNCreate(5, NULL);
  36.     HPoint3 *p, *op, *np, *newp;
  37.     ColorA *lastcolor, *c, *newc;
  38.     int i, nc, hascolor, colored = 0;
  39.  
  40.     newp = (HPoint3 *)alloca(v->nvert*sizeof(HPoint3));
  41.     newc = (ColorA *)alloca(v->nvert*sizeof(ColorA));
  42.  
  43.     for(i = 0, op = v->p, np = newp; i < v->nvert; i++, op++, np++) {
  44.     *(HPoint3 *)h->v = *op;
  45.     colored = (*NDmap)(NDinfo, h, np, &newc[i]);
  46.     }
  47.  
  48.     for(i = 0, p = newp, c = colored ? newc : v->c; i < v->nvec; i++) {
  49.     register int nv;
  50.  
  51.     nv = vcount(v->vnvert[i]);
  52.     if(colored) nc = nv;
  53.     else if (hascolor) nc = v->vncolor[i];
  54.  
  55.     flags |= vwrapped(v->vnvert[i]);
  56.  
  57.     if(nc==0)
  58.         if(lastcolor)
  59.         mgpolyline(nv,p,1,lastcolor, flags);
  60.         else
  61.         mgpolyline(nv,p,nc,c,flags);
  62.     else
  63.         mgpolyline(nv,p,nc, lastcolor=c, flags);
  64.  
  65.     p += nv;
  66.     if (hascolor) c += nc;
  67.     flags = (i < penultimate) ? 6 : 2;    /* 2: not first batch member */
  68.     }
  69.     HPtNDelete(h);
  70. }
  71.  
  72. Vect *
  73. VectDraw(v)
  74.      register Vect *v;
  75. {
  76.     register HPoint3 *p;
  77.     register ColorA *c, edgecolor;
  78.     register int n, hascolor, nc;
  79.     int flags, penultimate;
  80.     ColorA *lastcolor=NULL;
  81.     register Appearance *ap = mggetappearance();
  82.  
  83.     /* Don't draw if vect-drawing is off. */
  84.     if (v == NULL || (ap->flag & APF_VECTDRAW) == 0)
  85.         return NULL;
  86.     
  87.     /* draw in conformal model if necessary */
  88.     if (_mgc->space & TM_CONFORMAL_BALL) {
  89.             cmodel_clear(_mgc->space);
  90.             cm_read_vect(v);
  91.             cmodel_draw(0);
  92.         return v;
  93.     }
  94.  
  95.     p = v->p;
  96.     c = v->c;
  97.     hascolor = (v->ncolor > 0) &&
  98.         !(ap->mat && (ap->mat->override & MTF_EDGECOLOR));
  99.  
  100.     if (!hascolor && ap->mat) {
  101.       *(Color *)&edgecolor = ap->mat->edgecolor;
  102.       edgecolor.a = 1;
  103.       c = &edgecolor;
  104.       nc = 1;
  105.     }
  106.  
  107.     flags = v->nvec > 1 ? 4 : 0;     /* 4: not last mbr of batch of lines */
  108.     penultimate = v->nvec - 2;
  109.  
  110.     if(_mgc->NDinfo) {
  111.         Transform T;
  112.         float focallen;
  113.         mgpushtransform();
  114.         CamGet(_mgc->cam, CAM_FOCUS, &focallen);
  115.         TmTranslate(T, 0., 0., -focallen);
  116.         TmConcat(T, _mgc->C2W, T);
  117.         mgsettransform(T);
  118.         draw_projected_vect(_mgc->NDmap, _mgc->NDinfo, v, flags, penultimate);
  119.         mgpoptransform();
  120.         return v;
  121.     }
  122.  
  123.     for(n = 0; n < v->nvec; n++) {
  124.         register int nv;
  125.  
  126.         nv = vcount(v->vnvert[n]);
  127.         if (hascolor) nc = v->vncolor[n];
  128.  
  129.  
  130.         flags |= vwrapped(v->vnvert[n]);
  131.  
  132.         if(nc == 0)
  133.         if(lastcolor)
  134.             mgpolyline(nv, p, 1, lastcolor, flags);
  135.         else
  136.             mgpolyline(nv, p, nc, c, flags);
  137.         else
  138.         mgpolyline(nv,p,nc,lastcolor=c, flags);
  139.  
  140.         p += nv;
  141.         if (hascolor) c += nc;
  142.         flags = (n < penultimate) ? 6 : 2;    /* 2: not first batch member */
  143.     }
  144.     return v;
  145. }
  146.  
  147.