home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d056 / mcad.lha / mCAD / tdp / source / plot3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-02  |  3.4 KB  |  96 lines

  1. /* plot3d.c */
  2. #include "tdp.h"
  3. void plot3d()
  4. {
  5.    register short i;
  6.    short pdir, ystart, yinc, xstart, xinc;
  7.    short pass, color, color_start, color_inc;
  8.    short nhpts, nvpts, hinc, vinc;
  9.    int *xthis, *ythis, *xlast, *ylast;
  10.    short i_phi, i_theta, ycross;
  11.    
  12.    calc();
  13.  
  14.    /*** SET PLOTTING ORDER, DIRECTION SO THAT HIDDEN LINE ALGORITHM WORKS ***/
  15.    i_phi = (int)(phi/d2r); if (debug) printf("i_phi=%d\n",i_phi);
  16.       /* assume, for the moment, that abs(theta) <= 90 degrees */
  17.    if (i_phi < -135)
  18.       {xstart=0; ystart=nypts-1; pdir=-1; ycross=TRUE;}
  19.    else if (i_phi < -90)
  20.       {xstart=0; ystart=nypts-1; pdir=1; ycross=FALSE;}
  21.    else if (i_phi < -45)
  22.       {xstart=0; ystart=0; pdir=-1; ycross=FALSE;}
  23.    else if (i_phi <   0)
  24.       {xstart=0; ystart=0; pdir=1; ycross=TRUE;}
  25.    else if (i_phi <  45)
  26.       {xstart=nxpts-1; ystart=0; pdir=-1; ycross=TRUE;}
  27.    else if (i_phi <  90)
  28.       {xstart=nxpts-1; ystart=0; pdir=1; ycross=FALSE;}
  29.    else if (i_phi < 135)
  30.       {xstart=nxpts-1; ystart=nypts-1; pdir=-1; ycross=FALSE;}
  31.    else
  32.       {xstart=nxpts-1; ystart=nypts-1; pdir=1; ycross=TRUE;}
  33.    color_start = 0;
  34.  
  35.       /* handle abs(theta) > 90 degrees */
  36.    i_theta = (int)(theta/d2r); if (debug) printf("i_theta=%d\n",i_theta);
  37.    if (abs(i_theta) > 90) {
  38.       color_start = nsides-1;
  39.       ystart = ((ystart) ? 0 : nypts-1);
  40.       xstart = ((xstart) ? 0 : nxpts-1);
  41.       pdir = -pdir;
  42.    }
  43.  
  44.    color_inc = ((color_start) ? -1 : 1);
  45.    xinc = ((xstart) ? -1 : 1); yinc = ((ystart) ? -1 : 1);
  46.    xthis = &x[ystart][xstart]; ythis = &y[ystart][xstart];
  47.    if (ycross)
  48.       {nhpts=nxpts; nvpts=nypts; hinc=xinc; vinc=yinc*MAXCHAN;}
  49.    else
  50.       {nhpts=nypts; nvpts=nxpts; hinc=yinc*MAXCHAN; vinc=xinc;}
  51.    
  52.    /*** PLOT ***/
  53.    for (i = 0; i < MAXHORIZ; i++) {vhicum[i] = 0; vlocum[i] = 400;}
  54.  
  55.    if (debug) {printf("hit return for plot\n"); while (!gets(str));}
  56.    initwind();
  57.    if (PlotFile) {
  58.       fprintf(pfp,"IN; SC 0 %d 0 %d;\n",MAXHORIZ+2,MAXVERT+2);
  59.       /* fprintf(pfp,"VS 30.0;\n"); */ /* VELOCITY cm/s */
  60.       fprintf(pfp,"\033.N;19:\033.I81;;17:\n"); /* xON/xOFF handshake */
  61.       fprintf(pfp,"SP;\n");
  62.    }
  63.    if (inverse_vid)
  64.       {SetRGB4(vp,BACKGND_COLOR,0,0,0); SetRGB4(vp,PASS_0_COLOR,15,15,15);}
  65.  
  66.    for (pass=0, color=color_start; pass<nsides; pass++, color+=color_inc) {
  67.       SetAPen(rp, ((color) ? PASS_1_COLOR : PASS_0_COLOR) );
  68.       if (PlotFile) fprintf(pfp,"SP %d;\n",pass+1);
  69.       if (To_mCAD) fprintf(mfp,"*C %d\n",pass+1);
  70.       Move(rp, *xthis, TOPVERT-*ythis);
  71.       if (PlotFile) fprintf(pfp,"PU %d %d;\n",*xthis+1, 1+TOPVERT-*ythis);
  72. /*      if (To_mCAD) fprintf(mfp,"\n%d %d\n", *xthis, *ythis); */
  73.       for (i=0; i < nvpts-1; i++) {
  74.          hlplot(xthis, ythis, nhpts, hinc, pdir, pass);
  75.          xlast=xthis; ylast=ythis;
  76.          xthis += vinc; ythis += vinc;
  77.          if ((netplot=='y') || (netplot=='Y'))
  78.             hlcross(xlast, ylast, xthis, ythis, nhpts, hinc, -pdir, pass);
  79.       }
  80.       hlplot(xthis, ythis, nhpts, hinc, pdir, pass);
  81.       xthis = &x[ystart][xstart]; ythis = &y[ystart][xstart];
  82.    }
  83.  
  84.    if ((axes == 'y') || (axes == 'Y')) {
  85.       SetAPen(rp, AXIS_COLOR);
  86.       Move(rp, xA_i[0], TOPVERT - yA_i[0]);
  87.       Draw(rp, xA_i[1], TOPVERT - yA_i[1]);
  88.       Move(rp, xA_i[0], TOPVERT - yA_i[0]);
  89.       Draw(rp, xA_i[2], TOPVERT - yA_i[2]);
  90.       Move(rp, xA_i[0], TOPVERT - yA_i[0]);
  91.       Draw(rp, xA_i[3], TOPVERT - yA_i[3]);
  92.    }
  93.    if (PlotFile) {fprintf(pfp,"SP;\n"); (void) fclose(pfp);}
  94.    if (To_mCAD) (void) fclose(mfp);
  95. }
  96.