home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Educational / RasMol / Source / pixutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-10  |  48.4 KB  |  1,855 lines

  1. /* pixutils.c
  2.  * RasMol2 Molecular Graphics
  3.  * Roger Sayle, August 1995
  4.  * Version 2.6
  5.  */
  6. #include "rasmol.h"
  7.  
  8. #ifdef IBMPC
  9. #include <windows.h>
  10. #include <malloc.h>
  11. #endif
  12. #ifdef APPLEMAC
  13. #include <Types.h>
  14. #include <Errors.h>
  15. #ifdef __CONDITIONALMACROS__
  16. #include <Printing.h>
  17. #else
  18. #include <PrintTraps.h>
  19. #endif
  20. #endif
  21. #ifdef sun386
  22. #include <stdlib.h>
  23. #endif
  24.  
  25. #include <stdio.h>
  26. #include <math.h>
  27.  
  28. #define PIXUTILS
  29. #include "pixutils.h"
  30. #include "graphics.h"
  31. #include "molecule.h"
  32. #include "abstree.h"
  33. #include "transfor.h"
  34. #include "render.h"
  35. #include "font.h"
  36.  
  37. #ifdef INVERT
  38. #define InvertY(y) (y)
  39. #else
  40. #define InvertY(y) (-(y))
  41. #endif
  42.  
  43. /* Sutherland-Cohen Line Clipping Macros */
  44. #define BitAbove    0x01
  45. #define BitBelow    0x02
  46. #define BitRight    0x04
  47. #define BitLeft     0x08
  48. #define BitFront    0x10
  49.  
  50. #define Reject(x,y)   ((x)&(y))
  51. #define Accept(x,y)   (!((x)|(y)))
  52. #define RootSix       2.44948974278
  53.  
  54. #define SETPIXEL(dptr,fptr,d,c)    if( (d) > *(dptr) )              \
  55.                                    {   *(dptr) = (d);               \
  56.                                        *(fptr) = (c);               \
  57.                                    }
  58.  
  59.  
  60. #define MAXVERT 10
  61. typedef struct {
  62.                 Real dx,dz,di;
  63.                 Real x,z,i;
  64.                } Edge;
  65.  
  66. typedef struct {
  67.                 int x, y, z;
  68.                 int inten;
  69.                } Vert;
  70.  
  71. typedef struct {
  72.                 Vert v[MAXVERT];
  73.                 int count;
  74.                } Poly;
  75.  
  76.  
  77. typedef struct {
  78.                 short dx,dy,dz;
  79.                 short inten;
  80.         Long offset;
  81.            } ArcEntry;
  82.  
  83.  
  84. /* Note: DrawCylinderCaps currently employs an
  85.  *       extremely crude hack to avoid stripes
  86.  *       appearing along cylinders.
  87.  */
  88. #define ARCSIZE  2048
  89.  
  90. static ArcEntry __far *ArcAcPtr;
  91. static ArcEntry __far *ArcDnPtr;
  92. #if defined(IBMPC) || defined(APPLEMAC)
  93. static ArcEntry __far *ArcAc;
  94. static ArcEntry __far *ArcDn;
  95. #else
  96. static ArcEntry ArcAc[ARCSIZE];
  97. static ArcEntry ArcDn[ARCSIZE];
  98. #endif
  99.  
  100.  
  101. static char FontDimen[23];
  102. static int ClipStatus;
  103.  
  104.  
  105. static int OutCode(x,y,z)
  106.     register int x,y,z;
  107. {
  108.     register int result;
  109.  
  110.     result=0;
  111.     if( y<0 )
  112.     {   result |= BitAbove;
  113.     } else if( y>=View.ymax )
  114.         result |= BitBelow;
  115.  
  116.     if( x<0 )
  117.     {   result |= BitLeft;
  118.     } else if( x>=View.xmax )
  119.         result |= BitRight;
  120.  
  121.     if( !ZValid(z) )
  122.         result |= BitFront;
  123.     return result;
  124. }
  125.  
  126.  
  127. void PlotPoint(x,y,z,col)
  128.     int x,y,z,col;
  129. {
  130.     register Pixel __huge *fptr;
  131.     register short __huge *dptr;
  132.     register Long offset;
  133.  
  134.     /* SETPIXEL(dptr,fptr,z,Lut[col]); */
  135.  
  136.     offset = (Long)y*View.yskip+x;
  137.     dptr = View.dbuf+offset;
  138.     if( z > *dptr )
  139.     {   fptr = View.fbuf+offset;
  140.         *fptr = Lut[col];
  141.         *dptr = z;
  142.     }
  143. }
  144.  
  145.  
  146. void ClipPoint(x,y,z,col)
  147.     int x,y,z,col;
  148. {
  149.     register Pixel __huge *fptr;
  150.     register short __huge *dptr;
  151.     register Long offset;
  152.  
  153.     if( XValid(x) && YValid(y) && ZValid(z) )
  154.     {   /* PlotPoint(x,y,z,col); */
  155.         offset = (Long)y*View.yskip+x;
  156.         dptr = View.dbuf+offset;
  157.         if( z > *dptr )
  158.         {   fptr = View.fbuf+offset;
  159.             *fptr = Lut[col];
  160.             *dptr = z;
  161.         }
  162.     }
  163. }
  164.  
  165.  
  166. void PlotDeepPoint(x,y,z,col)
  167.     int x,y,z,col;
  168. {
  169.     register Long offset;
  170.     register Pixel __huge *fptr;
  171.     register short __huge *dptr;
  172.     register int inten;
  173.  
  174.     offset = (Long)y*View.yskip+x;
  175.     dptr = View.dbuf+offset;
  176.  
  177.     if( z > *dptr )
  178.     {  fptr = View.fbuf+offset;
  179.        inten = (ColourDepth*(z+ImageRadius-ZOffset))/ImageSize;
  180.        *fptr = Lut[col+inten];
  181.        *dptr = z;
  182.     }
  183. }
  184.  
  185. void ClipDeepPoint(x,y,z,col)
  186.     int x,y,z,col;
  187. {
  188.     register Long offset;
  189.     register Pixel __huge *fptr;
  190.     register short __huge *dptr;
  191.     register int inten;
  192.  
  193.     if( XValid(x) && YValid(y) && ZValid(z) )
  194.     {   /* PlotDeepPoint(x,y,z,col); */
  195.         offset = (Long)y*View.yskip+x;
  196.         dptr = View.dbuf+offset;
  197.  
  198.         if( z > *dptr )
  199.         {  fptr = View.fbuf+offset;
  200.            inten = (ColourDepth*(z+ImageRadius-ZOffset))/ImageSize;
  201.            *fptr = Lut[col+inten];
  202.            *dptr = z;
  203.         }
  204.     }
  205. }
  206.  
  207.  
  208. /* Macros for Bresenhams Line Drawing Algorithm */
  209. #define CommonStep(s)  z1 += zrate; SETPIXEL(dptr,fptr,z1,c);     \
  210.                        if( (zerr+=dz)>0 ) { zerr-=(s); z1+=iz; }
  211.  
  212. #define XStep  { if((err+=dy)>0) { fptr+=ystep; dptr+=ystep; err-=dx; } \
  213.                  fptr+=ix; dptr+=ix; x1+=ix; CommonStep(dx); }
  214.  
  215. #define YStep  { if((err+=dx)>0) { fptr+=ix; dptr+=ix; err-=dy; } \
  216.                  fptr+=ystep; dptr+=ystep; y1+=iy; CommonStep(dy); }
  217.                      
  218.  
  219. void DrawTwinLine(x1,y1,z1,x2,y2,z2,col1,col2)
  220.     int x1,y1,z1,x2,y2,z2,col1,col2;
  221. {
  222.     register Long offset;
  223.     register Pixel __huge *fptr;
  224.     register short __huge *dptr;
  225.     register int zrate, zerr;
  226.     register int ystep,err;
  227.     register int ix,iy,iz;
  228.     register int dx,dy,dz;
  229.     register int mid;
  230.     register Pixel c;
  231.  
  232.     c = Lut[col1];
  233.  
  234.     offset = (Long)y1*View.yskip + x1;
  235.     fptr = View.fbuf+offset;
  236.     dptr = View.dbuf+offset;
  237.  
  238.     SETPIXEL(dptr,fptr,z1,c);
  239.  
  240.     dx = x2-x1;  dy = y2-y1; dz = z2-z1;
  241.     if( !dx && !dy ) return;
  242.  
  243.     ystep = View.yskip;
  244.     ix = iy = iz = 1;
  245.     if( dy<0 ) { dy = -dy; iy = -1; ystep = -ystep; }
  246.     if( dx<0 ) { dx = -dx; ix = -1; }
  247.     if( dz<0 ) { dz = -dz; iz = -1; }
  248.  
  249.     if( dx>dy )
  250.     {   zrate = dz/dx;  
  251.         dz -= dx*zrate;
  252.         err = zerr = -(dx>>1);
  253.  
  254.         if( col1 != col2 )
  255.         {   mid = (x1+x2)>>1;
  256.             while( x1!=mid ) XStep;
  257.             c = Lut[col2];
  258.         }
  259.         while( x1!=x2 ) XStep;
  260.  
  261.     } else
  262.     {   zrate = dz/dy;
  263.         dz -= dy*zrate;
  264.         err = zerr = -(dy>>1);
  265.  
  266.         if( col1 != col2 )
  267.         {   mid = (y1+y2)>>1;
  268.             while( y1!=mid ) YStep;
  269.             c = Lut[col2];
  270.         }
  271.         while( y1!=y2 ) YStep;
  272.     }
  273. }
  274.  
  275.  
  276. static void ClipLine(x1,y1,z1,x2,y2,z2,col)
  277.     int x1,y1,z1,x2,y2,z2,col;
  278. {
  279.     register int code1,code2;
  280.     register int delta,rest;
  281.     register int temp;
  282.  
  283.     while( True )
  284.     {   code1 = OutCode(x1,y1,z2);
  285.         code2 = OutCode(x2,y2,z2);
  286.         if( Reject(code1,code2) ) return;
  287.         if( Accept(code1,code2) ) break;
  288.  
  289.         if( !code1 )
  290.         {   temp=x1; x1=x2; x2=temp;
  291.             temp=y1; y1=y2; y2=temp;
  292.             temp=z1; z1=z2; z2=temp;
  293.             code1 = code2;
  294.         }
  295.  
  296.         if( code1 & BitAbove )
  297.         {   delta = y2-y1;
  298.             x1 += (int)(((Long)y1*(x1-x2))/delta);  
  299.             z1 += (int)(((Long)y1*(z1-z2))/delta);
  300.             y1 = 0;
  301.         } else if( code1 & BitLeft )
  302.         {   delta = x2-x1;
  303.             y1 += (int)(((Long)x1*(y1-y2))/delta);
  304.             z1 += (int)(((Long)x1*(z1-z2))/delta);
  305.             x1 = 0;
  306.         } else if( code1 & BitRight )
  307.         {   delta = x2-x1;
  308.             temp=View.xmax-1; rest=temp-x1;
  309.             y1 += (int)(((Long)rest*(y2-y1))/delta);
  310.             z1 += (int)(((Long)rest*(z2-z1))/delta);
  311.             x1 = temp;
  312.         } else if( code1 & BitBelow )
  313.         {   delta = y2-y1;
  314.             temp=View.ymax-1; rest=temp-y1;
  315.             x1 += (int)(((Long)rest*(x2-x1))/delta);
  316.             z1 += (int)(((Long)rest*(z2-z1))/delta);
  317.             y1 = temp;
  318.         } else /* SLAB */
  319.         {   delta = z2-z1;
  320.             rest = SlabValue-z1;
  321.             x1 += (int)(((Long)rest*(x2-x1))/delta);
  322.             y1 += (int)(((Long)rest*(y2-y1))/delta);
  323.             z1 = SlabValue;
  324.         }
  325.     }
  326.     DrawTwinLine(x1,y1,z1,x2,y2,z2,col,col);
  327. }
  328.  
  329.  
  330. void ClipTwinLine(x1,y1,z1,x2,y2,z2,col1,col2)
  331.     int x1,y1,z1,x2,y2,z2,col1,col2;
  332. {
  333.     register int xmid,ymid,zmid;
  334.     register int code1,code2;
  335.  
  336.  
  337.     if( col1!=col2 )
  338.     {   code1 = OutCode(x1,y1,z1);
  339.         code2 = OutCode(x2,y2,z2);
  340.         if( !Reject(code1,code2) )
  341.         {   if( !Accept(code1,code2) )
  342.             {  xmid = (x1+x2)/2;
  343.                ymid = (y1+y2)/2;
  344.                zmid = (z1+z2)/2;
  345.                ClipLine(x1,y1,z1,xmid,ymid,zmid,col1);
  346.                ClipLine(xmid,ymid,zmid,x2,y2,z2,col2);
  347.             } else
  348.                DrawTwinLine(x1,y1,z1,x2,y2,z2,col1,col2);
  349.         }
  350.     } else
  351.         ClipLine(x1,y1,z1,x2,y2,z2,col1);
  352. }
  353.  
  354.  
  355.  
  356. /* Macros for 3D Bresenhams Vector Algorithm */
  357. #define CommonVectStep(s)  z1 += zrate;   c1 += crate;                    \
  358.                            SETPIXEL(dptr,fptr,z1,Lut[col+c1]);            \
  359.                            if( (zerr+=dz)>0 ) { zerr -= (s); z1 += iz; }  \
  360.                            if( (cerr+=dc)>0 ) { cerr -= (s); c1 += iz; }
  361.  
  362. #define XVectStep  { if((err+=dy)>0) { fptr+=ystep; dptr+=ystep; err-=dx; } \
  363.                      fptr+=ix; dptr+=ix; x1+=ix; CommonVectStep(dx); }
  364.  
  365. #define YVectStep  { if((err+=dx)>0) { fptr+=ix; dptr+=ix; err-=dy; } \
  366.                      fptr+=ystep; dptr+=ystep; y1+=iy; CommonVectStep(dy); }
  367.  
  368.  
  369. void DrawTwinVector(x1,y1,z1,x2,y2,z2,col1,col2)
  370.     int x1,y1,z1,x2,y2,z2,col1,col2;
  371. {
  372.     register Long offset;
  373.     register Pixel __huge *fptr;
  374.     register short __huge *dptr;
  375.     register int dx,dy,dz,dc;
  376.     register int crate, cerr;
  377.     register int zrate, zerr;
  378.     register int ystep,err;
  379.     register int ix,iy,iz;
  380.     register int col, mid;
  381.     register int c1, c2;
  382.  
  383.     c1 = (ColourDepth*(z1+ImageRadius-ZOffset))/ImageSize;
  384.     c2 = (ColourDepth*(z2+ImageRadius-ZOffset))/ImageSize;
  385.  
  386.     offset = (Long)y1*View.yskip + x1;
  387.     fptr = View.fbuf+offset;
  388.     dptr = View.dbuf+offset;
  389.  
  390.     SETPIXEL(dptr,fptr,z1,Lut[col1+c1]);
  391.  
  392.     dx = x2 - x1;  dy = y2 - y1;
  393.     dz = z2 - z1;  dc = c2 - c1;
  394.     if( !dx && !dy ) return;
  395.  
  396.     if( dy<0 ) 
  397.     {   ystep = -View.yskip;
  398.         dy = -dy; 
  399.         iy = -1; 
  400.     } else
  401.     {   ystep = View.yskip;
  402.         iy = 1;
  403.     }
  404.  
  405.     if( dx<0 ) 
  406.     {   dx = -dx; 
  407.         ix = -1; 
  408.     } else ix = 1;
  409.  
  410.     iz = (dz<0)? -1 : 1;
  411.  
  412.     if( dx>dy )
  413.     {   zrate = dz/dx;  dz -= dx*zrate; 
  414.         crate = dc/dx;  dc -= dx*crate;
  415.         err = zerr = cerr = -(dx>>1);
  416.         col = col1;
  417.  
  418.         if( dz<0 )
  419.         {   dz = -dz;
  420.             dc = -dc;
  421.         }
  422.         
  423.         if( col1 != col2 )
  424.         {   mid = (x1+x2)>>1;
  425.             while( x1!=mid ) XVectStep;
  426.             col = col2;
  427.         }
  428.         while( x1!=x2 ) XVectStep;
  429.     } else
  430.     {   zrate = dz/dy;  dz -= dy*zrate;
  431.         crate = dc/dy;  dc -= dy*crate;
  432.         err = zerr = cerr = -(dy>>1);
  433.         col = col1;
  434.  
  435.         if( dz<0 )
  436.         {   dz = -dz;
  437.             dc = -dc;
  438.         }
  439.  
  440.         if( col1 != col2 )
  441.         {   mid = (y1+y2)>>1;
  442.             while( y1!=mid ) YVectStep;
  443.             col=col2;
  444.         }
  445.         while( y1!=y2 ) YVectStep;
  446.     }
  447. }
  448.  
  449. static void ClipVector(x1,y1,z1,x2,y2,z2,col)
  450.     int x1,y1,z1,x2,y2,z2,col;
  451. {
  452.     register int code1,code2;
  453.     register int delta,rest;
  454.     register int temp;
  455.  
  456.     code1 = OutCode(x1,y1,z1);
  457.     code2 = OutCode(x2,y2,z2);
  458.  
  459.     while( True )
  460.     {   if( Accept(code1,code2) ) break;
  461.         if( Reject(code1,code2) ) return;
  462.  
  463.         if( !code1 )
  464.         {   code1 = code2; code2 = 0;
  465.             temp=x1; x1=x2; x2=temp;
  466.             temp=y1; y1=y2; y2=temp;
  467.             temp=z1; z1=z2; z2=temp;
  468.         }
  469.  
  470.         if( code1 & BitAbove )
  471.         {   delta = y2-y1;
  472.             x1 += (int)(((Long)y1*(x1-x2))/delta);  
  473.             z1 += (int)(((Long)y1*(z1-z2))/delta);
  474.             y1 = 0;
  475.         } else if( code1 & BitLeft )
  476.         {   delta = x2-x1;
  477.             y1 += (int)(((Long)x1*(y1-y2))/delta);
  478.             z1 += (int)(((Long)x1*(z1-z2))/delta);
  479.             x1 = 0;
  480.         } else if( code1 & BitRight )
  481.         {   delta = x2-x1;
  482.             temp=View.xmax-1; rest=temp-x1;
  483.             y1 += (int)(((Long)rest*(y2-y1))/delta);
  484.             z1 += (int)(((Long)rest*(z2-z1))/delta);
  485.             x1 = temp;
  486.         } else if( code1 & BitBelow )
  487.         {   delta = y2-y1;
  488.             temp=View.ymax-1; rest=temp-y1;
  489.             x1 += (int)(((Long)rest*(x2-x1))/delta);
  490.             z1 += (int)(((Long)rest*(z2-z1))/delta);
  491.             y1 = temp;
  492.         } else /* SLAB */
  493.         {   delta = z2-z1;
  494.             rest = (SlabValue-1)-z1;
  495.             x1 += (int)(((Long)rest*(x2-x1))/delta);
  496.             y1 += (int)(((Long)rest*(y2-y1))/delta);
  497.             z1 = SlabValue-1;
  498.         }
  499.         code1 = OutCode(x1,y1,z1);
  500.     }
  501.     DrawTwinVector(x1,y1,z1,x2,y2,z2,col,col);
  502. }
  503.  
  504.  
  505. void ClipTwinVector(x1,y1,z1,x2,y2,z2,col1,col2)
  506.     int x1,y1,z1,x2,y2,z2,col1,col2;
  507. {
  508.     register int xmid,ymid,zmid;
  509.     register int code1,code2;
  510.  
  511.     if( col1!=col2 )
  512.     {   code1 = OutCode(x1,y1,z1);
  513.         code2 = OutCode(x2,y2,z2);
  514.         if( !Reject(code1,code2) )
  515.         {   if( !Accept(code1,code2) )
  516.             {  xmid = (x1+x2)/2;
  517.                ymid = (y1+y2)/2;
  518.                zmid = (z1+z2)/2;
  519.                ClipVector(x1,y1,z1,xmid,ymid,zmid,col1);
  520.                ClipVector(xmid,ymid,zmid,x2,y2,z2,col2);
  521.             } else
  522.                DrawTwinVector(x1,y1,z1,x2,y2,z2,col1,col2);
  523.         }
  524.     } else
  525.         ClipVector(x1,y1,z1,x2,y2,z2,col1);
  526. }
  527.  
  528.  
  529. void ClipDashVector(x1,y1,z1,x2,y2,z2,col1,col2)
  530.     int x1,y1,z1,x2,y2,z2,col1,col2;
  531. {
  532.     register Long offset;
  533.     register Pixel __huge *fptr;
  534.     register short __huge *dptr;
  535.     register int ix,iy,iz,ic;
  536.     register int dx,dy,dz,dc;
  537.     register int crate, cerr;
  538.     register int zrate, zerr;
  539.     register int ystep,err;
  540.     register int col, mid;
  541.     register int c1, c2;
  542.     register int count;
  543.  
  544.  
  545.     if( (x1==x2) && (y1==y2) ) return;
  546.     if( Reject(OutCode(x1,y1,z1),OutCode(x2,y2,z2)) )
  547.         return;
  548.  
  549.     c1 = (ColourDepth*(z1+ImageRadius-ZOffset))/ImageSize;
  550.     c2 = (ColourDepth*(z2+ImageRadius-ZOffset))/ImageSize;
  551.  
  552.     dx = x2 - x1;  dy = y2 - y1;
  553.     dz = z2 - z1;  dc = c2 - c1;
  554.  
  555.     offset = (Long)y1*View.yskip + x1;
  556.     fptr = View.fbuf+offset;
  557.     dptr = View.dbuf+offset;
  558.     count = 0;
  559.  
  560.     ystep = View.yskip;
  561.     ix = iy = iz = ic = 1;
  562.     if( dy<0 ) { dy = -dy; iy = -1; ystep = -ystep; }
  563.     if( dx<0 ) { dx = -dx; ix = -1; }
  564.     if( dz<0 ) { dz = -dz; iz = -1; }
  565.     if( dc<0 ) { dc = -dc; ic = -1; }
  566.  
  567.  
  568.     if( dx>dy )
  569.     {   if( x2<x1 )
  570.         {   mid = col1;
  571.             col1 = col2;
  572.             col2 = mid;
  573.         }
  574.         zrate = dz/dx;  dz -= dx*zrate;
  575.         crate = dc/dx;  dc -= dx*crate;
  576.         err = zerr = cerr = -(dx>>1);
  577.         mid = (x1+x2)/2;
  578.  
  579.         while( x1!=x2 )
  580.         {   if( XValid(x1) && YValid(y1) && ZValid(z1) )
  581.             {   if( count<2 )
  582.                 {   col = (x1<mid)? col1 : col2;
  583.                     SETPIXEL(dptr,fptr,z1,Lut[col+c1]);
  584.                     count++;
  585.                 } else if( count==3 )
  586.                 {   count = 0;
  587.                 } else count++;
  588.             }
  589.  
  590.             if( (err+=dy)>0 )
  591.             {   err -= dx;
  592.                 fptr+=ystep;
  593.                 dptr+=ystep;
  594.                 y1+=iy;
  595.             }
  596.  
  597.             if( (zerr+=dz)>0 )
  598.             {   zerr -= dx;
  599.                 z1 += iz;
  600.             }
  601.  
  602.             if( (cerr+=dc)>0 )
  603.             {   cerr -= dx;
  604.                 c1 += ic;
  605.             }
  606.  
  607.             fptr+=ix; dptr+=ix; x1+=ix;
  608.             z1 += zrate;   c1 += crate;
  609.         }
  610.     } else
  611.     {   if( y1>y2 )
  612.         {   mid = col1;
  613.             col1 = col2;
  614.             col2 = mid;
  615.         }
  616.  
  617.         zrate = dz/dy;  dz -= dy*zrate;
  618.         crate = dc/dy;  dc -= dy*crate;
  619.         err = zerr = cerr = -(dy>>1);
  620.         mid = (y1+y2)/2;
  621.  
  622.         
  623.         while( y1!=y2 )
  624.         {   if( XValid(x1) && YValid(y1) && ZValid(z1) )
  625.             {   if( count<2 )
  626.                 {   col = (y1<mid)? col1 : col2;
  627.                     SETPIXEL(dptr,fptr,z1,Lut[col+c1]);
  628.                     count++;
  629.                 } else if( count==3 )
  630.                 {   count = 0;
  631.                 } else count++;
  632.             }
  633.  
  634.             if( (err+=dx)>0 )
  635.             {   err-=dy;
  636.                 fptr+=ix;
  637.                 dptr+=ix;
  638.                 x1+=ix;
  639.             }
  640.  
  641.             if( (zerr+=dz)>0 )
  642.             {   zerr -= dy;
  643.                 z1 += iz;
  644.             }
  645.  
  646.             if( (cerr+=dc)>0 )
  647.             {   cerr -= dy;
  648.                 c1 += ic;
  649.             }
  650.  
  651.             fptr+=ystep; dptr+=ystep; y1+=iy;
  652.             z1 += zrate;   c1 += crate;
  653.         }
  654.     }
  655. }
  656.  
  657.  
  658. /* SplineCount is either 1, 2, 3, 4, 5 or 9! */
  659.  
  660. void StrandRibbon( src, dst, col1, col2 )
  661.     Knot __far *src, __far *dst;  
  662.     int col1, col2;
  663. {
  664.     register int hsx, hsy, hsz;
  665.     register int hdx, hdy, hdz;
  666.     register int qsx, qsy, qsz;
  667.     register int qdx, qdy, qdz;
  668.     register int col;
  669.  
  670.     if( SplineCount != 4 )
  671.     {   if( SplineCount == 1 ) 
  672.         {   ClipVector( src->px, src->py, src->pz,
  673.                         dst->px, dst->py, dst->pz, col2 );
  674.             return;
  675.         } else if( SplineCount != 2 )
  676.             ClipVector( src->px, src->py, src->pz,
  677.                         dst->px, dst->py, dst->pz, col1 );
  678.  
  679.         ClipVector( src->px+src->wx, src->py+src->wy, src->pz+src->wz,
  680.                     dst->px+dst->wx, dst->py+dst->wy, dst->pz+dst->wz, col2 );
  681.         ClipVector( src->px-src->wx, src->py-src->wy, src->pz-src->wz,
  682.                     dst->px-dst->wx, dst->py-dst->wy, dst->pz-dst->wz, col2 );
  683.         if( SplineCount<=3 ) return;
  684.  
  685.         hsx = src->wx/2;  hsy = src->wy/2;  hsz = src->wz/2;
  686.         hdx = dst->wx/2;  hdy = dst->wy/2;  hdz = dst->wz/2;
  687.  
  688.         ClipVector( src->px+hsx, src->py+hsy, src->pz+hsz,
  689.                     dst->px+hdx, dst->py+hdy, dst->pz+hdz, col1 );
  690.         ClipVector( src->px-hsx, src->py-hsy, src->pz-hsz,
  691.                     dst->px-hdx, dst->py-hdy, dst->pz-hdz, col1 );
  692.         if( SplineCount==5 ) 
  693.             return;
  694.         col = col1;
  695.     } else /* SplineCount == 4 */
  696.     {   hsx = src->wx/2;  hsy = src->wy/2;  hsz = src->wz/2;
  697.         hdx = dst->wx/2;  hdy = dst->wy/2;  hdz = dst->wz/2;
  698.         col = col2;
  699.     }
  700.  
  701.     qsx = hsx/2;  qsy = hsy/2;  qsz = hsz/2;
  702.     qdx = hdx/2;  qdy = hdy/2;  qdz = hdz/2;
  703.  
  704.     ClipVector( src->px+hsx+qsx, src->py+hsy+qsy, src->pz+hsz+qsz,
  705.                 dst->px+hdx+qdx, dst->py+hdy+qdy, dst->pz+hdz+qdz, col );
  706.     ClipVector( src->px+hsx-qsx, src->py+hsy-qsy, src->pz+hsz-qsz,
  707.                 dst->px+hdx-qdx, dst->py+hdy-qdy, dst->pz+hdz-qdz, col1 );
  708.     ClipVector( src->px-hsx+qsx, src->py-hsy+qsy, src->pz-hsz+qsz,
  709.                 dst->px-hdx+qdx, dst->py-hdy+qdy, dst->pz-hdz+qdz, col1 );
  710.     ClipVector( src->px-hsx-qsx, src->py-hsy-qsy, src->pz-hsz-qsz,
  711.                 dst->px-hdx-qdx, dst->py-hdy-qdy, dst->pz-hdz-qdz, col );
  712. }
  713.  
  714.  
  715. void DashRibbon( src, dst, col1, col2 )
  716.     Knot __far *src, __far *dst;  
  717.     int col1, col2;
  718. {
  719.     register int hsx, hsy, hsz;
  720.     register int hdx, hdy, hdz;
  721.     register int qsx, qsy, qsz;
  722.     register int qdx, qdy, qdz;
  723.     register int col;
  724.  
  725.     if( SplineCount != 4 )
  726.     {   if( SplineCount == 1 ) 
  727.         {   ClipDashVector( src->px, src->py, src->pz,
  728.                             dst->px, dst->py, dst->pz, col2, col2 );
  729.             return;
  730.         } else if( SplineCount != 2 )
  731.             ClipDashVector( src->px, src->py, src->pz,
  732.                             dst->px, dst->py, dst->pz, col1, col1 );
  733.  
  734.         ClipDashVector(src->px+src->wx,src->py+src->wy,src->pz+src->wz,
  735.                        dst->px+dst->wx,dst->py+dst->wy,dst->pz+dst->wz,
  736.                        col2,col2);
  737.         ClipDashVector(src->px-src->wx,src->py-src->wy,src->pz-src->wz,
  738.                        dst->px-dst->wx,dst->py-dst->wy,dst->pz-dst->wz,
  739.                        col2,col2);
  740.         if( SplineCount<=3 ) return;
  741.  
  742.         hsx = src->wx/2;  hsy = src->wy/2;  hsz = src->wz/2;
  743.         hdx = dst->wx/2;  hdy = dst->wy/2;  hdz = dst->wz/2;
  744.  
  745.         ClipDashVector( src->px+hsx, src->py+hsy, src->pz+hsz,
  746.                         dst->px+hdx, dst->py+hdy, dst->pz+hdz, col1, col1 );
  747.         ClipDashVector( src->px-hsx, src->py-hsy, src->pz-hsz,
  748.                         dst->px-hdx, dst->py-hdy, dst->pz-hdz, col1, col1 );
  749.         if( SplineCount==5 ) 
  750.             return;
  751.         col = col1;
  752.     } else /* SplineCount == 4 */
  753.     {   hsx = src->wx/2;  hsy = src->wy/2;  hsz = src->wz/2;
  754.         hdx = dst->wx/2;  hdy = dst->wy/2;  hdz = dst->wz/2;
  755.         col = col2;
  756.     }
  757.  
  758.     qsx = hsx/2;  qsy = hsy/2;  qsz = hsz/2;
  759.     qdx = hdx/2;  qdy = hdy/2;  qdz = hdz/2;
  760.  
  761.     ClipDashVector(src->px+hsx+qsx,src->py+hsy+qsy,src->pz+hsz+qsz,
  762.                    dst->px+hdx+qdx,dst->py+hdy+qdy,dst->pz+hdz+qdz,col,col);
  763.     ClipDashVector(src->px+hsx-qsx,src->py+hsy-qsy,src->pz+hsz-qsz,
  764.                    dst->px+hdx-qdx,dst->py+hdy-qdy,dst->pz+hdz-qdz,col1,col1);
  765.     ClipDashVector(src->px-hsx+qsx,src->py-hsy+qsy,src->pz-hsz+qsz,
  766.                    dst->px-hdx+qdx,dst->py-hdy+qdy,dst->pz-hdz+qdz,col1,col1);
  767.     ClipDashVector(src->px-hsx-qsx,src->py-hsy-qsy,src->pz-hsz-qsz,
  768.                    dst->px-hdx-qdx,dst->py-hdy-qdy,dst->pz-hdz-qdz,col,col);
  769. }
  770.  
  771.  
  772. #ifndef PIXUTILS  /* Unused Function */
  773. static void OutLinePolygon( p )
  774.     Poly *p;
  775. {
  776.     register int i;
  777.  
  778.     for( i=0; i<p->count-1; i++ )
  779.          ClipLine( p->v[i].x, p->v[i].y, p->v[i].z, 
  780.                    p->v[i+1].x, p->v[i+1].y, p->v[i+1].z,
  781.                    p->v[i].inten);
  782.     ClipLine( p->v[i].x, p->v[i].y, p->v[i].z,
  783.               p->v[0].x, p->v[0].y, p->v[0].z,
  784.               p->v[i].inten);
  785. }
  786. #endif
  787.  
  788.  
  789. static void RenderPolygon( p )
  790.     Poly *p;
  791. {
  792.     static Edge lft, rgt;
  793.     register Edge *pmin, *pmax;
  794.     register Pixel __huge *fbase;
  795.     register short __huge *dbase;
  796.     register short __huge *dptr;
  797.     register Long offset;
  798.  
  799.     register Real z,inten;
  800.     register Real dy,dz,di;
  801.     register int ri,li,ry,ly;
  802.     register int xmin,xmax;
  803.     register int ymin;
  804.     register int top,rem;
  805.     register int x,y,i;
  806.  
  807.  
  808.     /* Reject Clip Polygon */
  809.     if( UseSlabPlane )
  810.         for( i=0; i<p->count; i++ )
  811.             if( p->v[i].z >= SlabValue )
  812.                 return;
  813.  
  814.     /* Find top vertex */
  815.     top = 0;  
  816.     ymin = p->v[0].y;
  817.     for( i=1; i<p->count; i++ )
  818.        if( p->v[i].y < ymin )
  819.        {   ymin = p->v[i].y;
  820.            top = i;
  821.        }
  822.  
  823.     rem = p->count;
  824.     ly = ry = y = ymin;
  825.     li = ri = top;
  826.  
  827.     if( y<0 )
  828.     {   rem--;
  829.  
  830.         while( ly<=0 && rem )
  831.         {   i = li-1; if( i<0 ) i=p->count-1;
  832.             if( p->v[i].y > 0 )
  833.             {   dy = 1.0/(p->v[i].y - ly);
  834.                 lft.di = dy*(p->v[i].inten - p->v[li].inten);
  835.                 lft.dx = dy*(p->v[i].x - p->v[li].x);
  836.                 lft.dz = dy*(p->v[i].z - p->v[li].z);
  837.  
  838.                 lft.i = p->v[li].inten - ly*lft.di;
  839.                 lft.x = p->v[li].x - ly*lft.dx;
  840.                 lft.z = p->v[li].z - ly*lft.dz;
  841.             } else rem--;
  842.             ly = p->v[i].y;
  843.             li = i;
  844.         }
  845.  
  846.         while( ry<=0 && rem )
  847.         {   i = ri+1; if( i>=p->count ) i = 0;
  848.             if( p->v[i].y > 0 )
  849.             {   dy = 1.0/(p->v[i].y - ry);
  850.                 rgt.di = dy*(p->v[i].inten - p->v[ri].inten);
  851.                 rgt.dx = dy*(p->v[i].x - p->v[ri].x);
  852.                 rgt.dz = dy*(p->v[i].z - p->v[ri].z);
  853.  
  854.                 rgt.i = p->v[ri].inten - ry*rgt.di;
  855.                 rgt.x = p->v[ri].x - ry*rgt.dx;
  856.                 rgt.z = p->v[ri].z - ry*rgt.dz;
  857.             } else rem--;
  858.             ry = p->v[i].y;
  859.             ri = i;
  860.         }
  861.  
  862.         fbase = View.fbuf;
  863.         dbase = View.dbuf;
  864.         y = 0;
  865.     } else /* y >= 0 */
  866.     {   offset = (Long)y*View.yskip;
  867.         fbase = View.fbuf+offset;
  868.         dbase = View.dbuf+offset;
  869.     }
  870.  
  871.     while( rem )
  872.     {   while( ly<=y && rem )
  873.         {   i = li-1; if( i<0 ) i=p->count-1;
  874.             if( p->v[i].y > y )
  875.             {   dy = 1.0/(p->v[i].y - ly);
  876.                 lft.di = dy*(p->v[i].inten - p->v[li].inten);
  877.                 lft.dx = dy*(p->v[i].x - p->v[li].x);
  878.                 lft.dz = dy*(p->v[i].z - p->v[li].z);
  879.  
  880.                 lft.i = p->v[li].inten;
  881.                 lft.x = p->v[li].x;
  882.                 lft.z = p->v[li].z;
  883.             }
  884.             ly = p->v[i].y;
  885.             rem--;  li = i;
  886.         }
  887.  
  888.         while( ry<=y && rem )
  889.         {   i = ri+1; if( i>=p->count ) i = 0;
  890.             if( p->v[i].y > y )
  891.             {   dy = 1.0/(p->v[i].y - ry);
  892.                 rgt.di = dy*(p->v[i].inten - p->v[ri].inten);
  893.                 rgt.dx = dy*(p->v[i].x - p->v[ri].x);
  894.                 rgt.dz = dy*(p->v[i].z - p->v[ri].z);
  895.  
  896.                 rgt.i = p->v[ri].inten;
  897.                 rgt.x = p->v[ri].x;
  898.                 rgt.z = p->v[ri].z;
  899.             }
  900.             ry = p->v[i].y;
  901.             rem--; ri = i;
  902.         }
  903.  
  904.  
  905.         ymin = MinFun(ly,ry);
  906.         if( ymin>View.ymax )
  907.         {   ymin = View.ymax;
  908.             rem = 0;
  909.         }
  910.         
  911.         while( y<ymin )
  912.         {   if( lft.x < rgt.x )
  913.             {   pmin = &lft;
  914.                 pmax = &rgt;
  915.             } else
  916.             {   pmin = &rgt;
  917.                 pmax = &lft;
  918.             }
  919.  
  920.             xmax = (int)(pmax->x)+1;
  921.             xmin = (int)(pmin->x);
  922.  
  923.             if( (xmin<View.xmax) && (xmax>=0) )
  924.             {   di = (pmax->i-pmin->i)/(xmax-xmin);
  925.                 dz = (pmax->z-pmin->z)/(xmax-xmin);
  926.                 if( xmin<0 )
  927.                 {   inten = pmin->i - xmin*di;
  928.                     z = pmin->z - xmin*dz;
  929.                     xmin = 0;
  930.                 } else /* xmin >= 0 */
  931.                 {   inten = pmin->i;  
  932.                     z = pmin->z;
  933.                 }
  934.  
  935.                 if( xmax>=View.xmax )
  936.                     xmax = View.xmax;
  937.  
  938.                 dptr = dbase+xmin;
  939.                 for( x=xmin; x<xmax; x++ )
  940.                 {   if( (int)z > *dptr )
  941.                     {   fbase[x] = Lut[(int)inten];
  942.                         *dptr = (int)z;
  943.                     }
  944.                     inten += di;
  945.                     z += dz;
  946.                     dptr++;
  947.                 }
  948.             }
  949.  
  950.             lft.x += lft.dx;  rgt.x += rgt.dx;
  951.             lft.z += lft.dz;  rgt.z += rgt.dz;
  952.             lft.i += lft.di;  rgt.i += rgt.di;
  953.             dbase += View.yskip;
  954.             fbase += View.yskip;
  955.             y++;
  956.         }
  957.     }
  958. }
  959.  
  960.  
  961. void SolidRibbon( src, dst, col )
  962.     Knot __far *src, __far *dst;  
  963.     int col;
  964. {
  965.     static Poly p;
  966.  
  967.     p.v[0].x = src->px+src->wx;  
  968.     p.v[0].y = src->py+src->wy;  
  969.     p.v[0].z = src->pz+src->wz;
  970.     p.v[0].inten = src->vinten+col;
  971.  
  972.     p.v[1].x = dst->px+dst->wx;  
  973.     p.v[1].y = dst->py+dst->wy;  
  974.     p.v[1].z = dst->pz+dst->wz;
  975.     p.v[1].inten = dst->vinten+col;
  976.  
  977.     p.v[2].x = dst->px-dst->wx;
  978.     p.v[2].y = dst->py-dst->wy;  
  979.     p.v[2].z = dst->pz-dst->wz;
  980.     p.v[2].inten = dst->vinten+col;
  981.  
  982.     p.v[3].x = src->px-src->wx;  
  983.     p.v[3].y = src->py-src->wy;  
  984.     p.v[3].z = src->pz-src->wz;
  985.     p.v[3].inten = src->vinten+col;
  986.  
  987.     p.count = 4;
  988.     /* OutLinePolygon( &p ); */
  989.     RenderPolygon( &p );
  990. }
  991.  
  992.  
  993. void RectRibbon( src, dst, col )
  994.     Knot __far *src, __far *dst;  
  995.     int col;
  996. {
  997.     static Poly p;
  998.  
  999.     p.count = 4;
  1000.  
  1001.     p.v[0].inten = src->vinten+col;
  1002.     p.v[1].inten = dst->vinten+col;
  1003.     p.v[2].inten = dst->vinten+col;
  1004.     p.v[3].inten = src->vinten+col;
  1005.  
  1006.     /* Top Surface */
  1007.     p.v[0].x = src->px+src->wx+src->hx;  
  1008.     p.v[0].y = src->py+src->wy+src->hy;  
  1009.     p.v[0].z = src->pz+src->wz+src->hz;
  1010.  
  1011.     p.v[1].x = dst->px+dst->wx+dst->hx;  
  1012.     p.v[1].y = dst->py+dst->wy+dst->hy;  
  1013.     p.v[1].z = dst->pz+dst->wz+dst->hz;
  1014.  
  1015.     p.v[2].x = dst->px-dst->wx+dst->hx;
  1016.     p.v[2].y = dst->py-dst->wy+dst->hy;  
  1017.     p.v[2].z = dst->pz-dst->wz+dst->hz;
  1018.  
  1019.     p.v[3].x = src->px-src->wx+src->hx;  
  1020.     p.v[3].y = src->py-src->wy+src->hy;  
  1021.     p.v[3].z = src->pz-src->wz+src->hz;
  1022.     RenderPolygon( &p );
  1023.  
  1024.     /* Bottom Surface */
  1025.     p.v[0].x = src->px+src->wx-src->hx;  
  1026.     p.v[0].y = src->py+src->wy-src->hy;  
  1027.     p.v[0].z = src->pz+src->wz-src->hz;
  1028.  
  1029.     p.v[1].x = dst->px+dst->wx-dst->hx;  
  1030.     p.v[1].y = dst->py+dst->wy-dst->hy;  
  1031.     p.v[1].z = dst->pz+dst->wz-dst->hz;
  1032.  
  1033.     p.v[2].x = dst->px-dst->wx-dst->hx;
  1034.     p.v[2].y = dst->py-dst->wy-dst->hy;  
  1035.     p.v[2].z = dst->pz-dst->wz-dst->hz;
  1036.  
  1037.     p.v[3].x = src->px-src->wx-src->hx;  
  1038.     p.v[3].y = src->py-src->wy-src->hy;  
  1039.     p.v[3].z = src->pz-src->wz-src->hz;
  1040.     RenderPolygon( &p );
  1041.  
  1042.     p.v[0].inten = src->hinten+col;
  1043.     p.v[1].inten = dst->hinten+col;
  1044.     p.v[2].inten = dst->hinten+col;
  1045.     p.v[3].inten = src->hinten+col;
  1046.  
  1047.     /* Left Surface */
  1048.     p.v[0].x = src->px+src->wx+src->hx;  
  1049.     p.v[0].y = src->py+src->wy+src->hy;  
  1050.     p.v[0].z = src->pz+src->wz+src->hz;
  1051.  
  1052.     p.v[1].x = dst->px+dst->wx+dst->hx;  
  1053.     p.v[1].y = dst->py+dst->wy+dst->hy;  
  1054.     p.v[1].z = dst->pz+dst->wz+dst->hz;
  1055.  
  1056.     p.v[2].x = dst->px+dst->wx-dst->hx;
  1057.     p.v[2].y = dst->py+dst->wy-dst->hy;  
  1058.     p.v[2].z = dst->pz+dst->wz-dst->hz;
  1059.  
  1060.     p.v[3].x = src->px+src->wx-src->hx;  
  1061.     p.v[3].y = src->py+src->wy-src->hy;  
  1062.     p.v[3].z = src->pz+src->wz-src->hz;
  1063.     RenderPolygon( &p );
  1064.  
  1065.     /* Right Surface */
  1066.     p.v[0].x = src->px-src->wx+src->hx;  
  1067.     p.v[0].y = src->py-src->wy+src->hy;  
  1068.     p.v[0].z = src->pz-src->wz+src->hz;
  1069.  
  1070.     p.v[1].x = dst->px-dst->wx+dst->hx;  
  1071.     p.v[1].y = dst->py-dst->wy+dst->hy;  
  1072.     p.v[1].z = dst->pz-dst->wz+dst->hz;
  1073.  
  1074.     p.v[2].x = dst->px-dst->wx-dst->hx;
  1075.     p.v[2].y = dst->py-dst->wy-dst->hy;  
  1076.     p.v[2].z = dst->pz-dst->wz-dst->hz;
  1077.  
  1078.     p.v[3].x = src->px-src->wx-src->hx;  
  1079.     p.v[3].y = src->py-src->wy-src->hy;  
  1080.     p.v[3].z = src->pz-src->wz-src->hz;
  1081.     RenderPolygon( &p );
  1082. }
  1083.  
  1084.  
  1085. static int TestSphere( x, y, z, rad )
  1086.     register int x, y, z, rad;
  1087. {
  1088.     register int temp;
  1089.  
  1090.     ClipStatus = 0;
  1091.  
  1092.     if( UseSlabPlane )
  1093.     {   if( z-rad>=SlabValue )
  1094.             return( False );
  1095.  
  1096.         if( z+rad>=SlabValue )
  1097.         {   if( SlabMode )
  1098.             {   ClipStatus |= BitFront;
  1099.             } else return( False );
  1100.         } else if( SlabMode==SlabSection )
  1101.             return( False );
  1102.     }
  1103.  
  1104.     temp = x+rad;
  1105.     if( temp<0 ) return( False );
  1106.     if( temp>=View.xmax ) ClipStatus |= BitRight;
  1107.  
  1108.     temp = x-rad;
  1109.     if( temp>=View.xmax ) return( False );
  1110.     if( temp<0 ) ClipStatus |= BitLeft;
  1111.  
  1112.     temp = y+rad;
  1113.     if( temp<0 ) return( False );
  1114.     if( temp>=View.ymax ) ClipStatus |= BitBelow;
  1115.  
  1116.     temp = y-rad;
  1117.     if( temp>=View.ymax ) return( False );
  1118.     if( temp<0 ) ClipStatus |= BitAbove;
  1119.  
  1120.     return True;
  1121. }
  1122.  
  1123.  
  1124. #ifdef INVERT
  1125. #define CalcInten(dz)    inten = (dz)+(dz)+dx+dy
  1126. #else
  1127. #define CalcInten(dz)    inten = (dz)+(dz)+dx-dy
  1128. #endif
  1129.  
  1130. #define UpdateAcross(dz)    \
  1131.         depth = (dz)+z;                    \
  1132.         if( depth > *dptr )                \
  1133.         {   *dptr = depth;                 \
  1134.             fptr = fold+dx;                \
  1135.             CalcInten((dz));               \
  1136.             if( inten>0 )                  \
  1137.             {      inten = (int)((inten*ColConst[rad])>>ColBits); \
  1138.                    *fptr = Lut[col+inten]; \
  1139.             } else *fptr = Lut[col];       \
  1140.         }                                  \
  1141.         dptr++;  dx++;
  1142.  
  1143.  
  1144. #define UpdateLine  \
  1145.         dx = -wide;                   \
  1146.         dptr = dold-wide;             \
  1147.         tptr = LookUp[wide]+wide;     \
  1148.         while( dx<0 ) { UpdateAcross(*tptr); tptr--; }       \
  1149.         do { UpdateAcross(*tptr); tptr++; } while(dx<=wide); \
  1150.         dold += View.yskip;  fold += View.yskip;             \
  1151.         dy++;
  1152.  
  1153.  
  1154. void DrawSphere(x,y,z,rad,col)
  1155.     int x,y,z,rad,col;
  1156. {
  1157.     register Pixel __huge *fptr, __huge *fold;
  1158.     register short __huge *dptr, __huge *dold;
  1159.     register Byte __far *tptr;
  1160.  
  1161.     register Long offset;
  1162.     register int depth,wide,inten;
  1163.     register int dx,dy;
  1164.  
  1165.     offset = (Long)(y-rad)*View.yskip + x;
  1166.     fold=View.fbuf+offset;  
  1167.     dold=View.dbuf+offset;
  1168.  
  1169.     dy = -rad;
  1170.     while( dy<0 ) 
  1171.     {   wide = LookUp[rad][-dy]; 
  1172.         UpdateLine; 
  1173.     }
  1174.  
  1175.     do { 
  1176.         wide = LookUp[rad][dy];  
  1177.         UpdateLine; 
  1178.     } while( dy<=rad );
  1179. }
  1180.  
  1181.  
  1182. void ClipSphere(x,y,z,rad,col)
  1183.     int x,y,z,rad,col;
  1184. {
  1185.     register Pixel __huge *fptr, __huge *fold;
  1186.     register short __huge *dptr, __huge *dold;
  1187.  
  1188.     register int lastx,lasty,dx,dy,dz;
  1189.     register int depth,wide,inten,side;
  1190.     register int crad,cwide,temp;
  1191.     register Long offset;
  1192.  
  1193.  
  1194.     /* Visibility Tests */
  1195.     if( !TestSphere(x,y,z,rad) )
  1196.         return;
  1197.  
  1198.     if( !ClipStatus )
  1199.     {   DrawSphere(x,y,z,rad,col);
  1200.         return;
  1201.     }
  1202.  
  1203.     if( ClipStatus&BitAbove )
  1204.     {   dy = -y;
  1205.         fold = View.fbuf + x;
  1206.         dold = View.dbuf + x;
  1207.     } else
  1208.     {   dy = -rad;
  1209.         offset = (Long)(y+dy)*View.yskip+x;
  1210.         fold = View.fbuf + offset;
  1211.         dold = View.dbuf + offset;
  1212.     }
  1213.  
  1214.     if( ClipStatus&BitBelow )
  1215.     {   lasty = (View.ymax-1)-y;
  1216.     } else lasty = rad;
  1217.  
  1218.  
  1219.     side = (View.xmax-1)-x;
  1220.     /* No Slab Plane Clipping */
  1221.     if( !(ClipStatus&BitFront) )
  1222.     {   while( dy<=lasty )
  1223.         {   wide = LookUp[rad][AbsFun(dy)];
  1224.             lastx = MinFun(wide,side);
  1225.             dx = - MinFun(wide,x);
  1226.             dptr = dold + dx;
  1227.  
  1228.             while( dx<=lastx )
  1229.             {   dz = LookUp[wide][AbsFun(dx)];
  1230.                 UpdateAcross(dz);
  1231.             }
  1232.             dold += View.yskip;
  1233.             fold += View.yskip;
  1234.             dy++;
  1235.         }
  1236.         return;
  1237.     }
  1238.  
  1239.  
  1240.     dz = SlabValue-z;
  1241.     crad = LookUp[rad][AbsFun(dz)];
  1242.  
  1243.    
  1244.     if( (z>SlabValue) || (SlabMode==SlabSection) )
  1245.     {   if( crad<lasty ) lasty = crad;
  1246.         if( -crad>dy ) 
  1247.         {   dy = -crad;
  1248.             offset = (Long)(y+dy)*View.yskip+x;
  1249.             fold = View.fbuf + offset;
  1250.             dold = View.dbuf + offset;
  1251.         }
  1252.     }
  1253.  
  1254.     while( dy<=lasty )
  1255.     {   temp = AbsFun(dy);
  1256.         wide = LookUp[rad][temp];
  1257.         lastx = MinFun(wide,side);
  1258.         dx = - MinFun(x,wide);
  1259.         dptr = dold + dx;
  1260.  
  1261.         if( temp<=crad )
  1262.         {   cwide = LookUp[crad][temp];
  1263.             while( dx<=lastx )
  1264.             {   temp = AbsFun(dx);
  1265.                 if( temp<=cwide )
  1266.                 {    /* Slab Plane Clipping Modes */
  1267.                     switch( SlabMode )
  1268.                     {   case( SlabFinal ):
  1269.                                 fold[dx] = Lut[col+SlabInten];
  1270.                                 *dptr = SliceValue;
  1271.                                 break;
  1272.  
  1273.                         case( SlabHollow ):
  1274.                                 dz = LookUp[wide][temp];
  1275.                                 depth = z - dz;
  1276.                                 if( depth>*dptr )
  1277.                                 {   *dptr = depth;
  1278. #ifdef INVERT
  1279.                                     inten = dz+dz-dx-dy;
  1280. #else
  1281.                                     inten = dz+dz-dx+dy;
  1282. #endif
  1283.                                     if( inten>0 )
  1284.                                     {   inten=(int)( (inten*ColConst[rad])
  1285.                                                      >>(ColBits+1));
  1286.                                         fold[dx] = Lut[col+inten];
  1287.                                     } else fold[dx] = Lut[col];
  1288.                                 }
  1289.                                 break;
  1290.  
  1291.                         case( SlabSection ):
  1292.                         case( SlabClose ):
  1293.                                 dz = SlabValue-z;
  1294.                                 depth = dx*dx+dy*dy+dz*dz+SliceValue;
  1295.                                 if( (*dptr<SliceValue) || (depth<*dptr) )
  1296.                                 {   fold[dx] = Lut[col+SlabInten];
  1297.                                     *dptr = depth;
  1298.                                 }
  1299.                                 break;
  1300.                     }
  1301.                     dptr++;  dx++;
  1302.                 } else if( (z<SlabValue) && (SlabMode!=SlabSection) )
  1303.                 {    dz = LookUp[wide][temp];
  1304.                      UpdateAcross(dz);
  1305.                 } else
  1306.                 {   dptr++;  dx++;
  1307.                 }
  1308.             }
  1309.         } else /* Slabless ScanLine */
  1310.             while( dx<=lastx )
  1311.             {   dz = LookUp[wide][AbsFun(dx)];
  1312.                 UpdateAcross(dz);
  1313.             }
  1314.  
  1315.         dold += View.yskip;
  1316.         fold += View.yskip;
  1317.         dy++;
  1318.     }
  1319. }
  1320.  
  1321.  
  1322. #ifdef FUNCPROTO
  1323. /* Function Prototypes */
  1324. static void DrawArcDn( short __huge*, Pixel __huge*, int, int );
  1325. static void DrawArcAc( short __huge*, Pixel __huge*, int, int );
  1326. static void ClipArcDn( short __huge*, Pixel __huge*, int, int, int, int );
  1327. static void ClipArcAc( short __huge*, Pixel __huge*, int, int, int, int );
  1328. #endif
  1329.  
  1330.  
  1331. static void DrawArcAc(dbase,fbase,z,c)
  1332.     register short __huge *dbase;
  1333.     register Pixel __huge *fbase;
  1334.     register int z,c;
  1335. {
  1336.     register ArcEntry __far *ptr;
  1337.     register short __huge *dptr;
  1338.     register short depth;
  1339.  
  1340.     for( ptr=ArcAc; ptr<ArcAcPtr; ptr++ )
  1341.     {   dptr = dbase+ptr->offset;  depth = ptr->dz+z;
  1342.         SETPIXEL(dptr,fbase+ptr->offset,depth,Lut[ptr->inten+c]);
  1343.     }
  1344. }
  1345.  
  1346. static void DrawArcDn(dbase,fbase,z,c)
  1347.     register short __huge *dbase;
  1348.     register Pixel __huge *fbase;
  1349.     register int z,c;
  1350. {
  1351.     register ArcEntry __far *ptr;
  1352.     register short __huge *dptr;
  1353.     register short depth;
  1354.  
  1355.     for( ptr=ArcDn; ptr<ArcDnPtr; ptr++ )
  1356.     {   dptr = dbase+ptr->offset;  depth = ptr->dz+z;
  1357.         SETPIXEL(dptr,fbase+ptr->offset,depth,Lut[ptr->inten+c]);
  1358.     }
  1359. }
  1360.  
  1361.  
  1362. static void DrawCylinderCaps( x1,y1,z1,x2,y2,z2,c1,c2,rad )
  1363.     int x1,y1,z1, x2,y2,z2, c1,c2,rad;
  1364. {
  1365.     register short __huge *dold, __huge *dptr;
  1366.     register Pixel __huge *fold;
  1367. #ifndef PIXUTILS
  1368.     register int ax,ay,ix,iy;
  1369.     register int zrate,lz;
  1370. #endif
  1371.     register Long offset,temp,end;
  1372.     register int inten,absx;
  1373.     register int wide,depth;
  1374.     register int dx,dy,dz;
  1375.     register int lx,ly;
  1376.  
  1377.     lx = x2-x1;
  1378.     ly = y2-y1;
  1379.  
  1380. #ifndef PIXUTILS
  1381.     lz = z2-z1;
  1382.     if( ly>0 ) { ay = ly; iy = 1; }
  1383.     else { ay = -ly; iy = -1; }
  1384.     if( lx>0 ) { ax = lx; ix = 1; }
  1385.     else { ax = -lx; ix = -1; }
  1386.     zrate = lz/MaxFun(ax,ay);
  1387. #endif
  1388.  
  1389.     end = (Long)ly*View.yskip+lx;
  1390.     temp = (Long)y1*View.yskip+x1;
  1391.     fold = View.fbuf+temp;
  1392.     dold = View.dbuf+temp;
  1393.  
  1394.     ArcAcPtr = ArcAc;
  1395.     ArcDnPtr = ArcDn;
  1396.  
  1397.     temp = (Long)-(rad*View.yskip);
  1398.     for( dy= -rad; dy<=rad; dy++ )
  1399.     {   wide = LookUp[rad][AbsFun(dy)];
  1400.  
  1401.         for( dx= -wide; dx<=wide; dx++ )
  1402.         {   absx = AbsFun(dx);
  1403.             dz = LookUp[wide][absx];
  1404.             CalcInten(dz);
  1405.             if( inten>0 )
  1406.             {   inten = (int)((inten*ColConst[rad])>>ColBits);
  1407.             } else inten = 0;
  1408.             offset = temp+dx;
  1409.  
  1410.             if( XValid(x1+dx) && YValid(y1+dy) )
  1411.             {   dptr = dold+offset; depth = z1+dz;
  1412.                 SETPIXEL(dptr,fold+offset,depth,Lut[c1+inten]);
  1413.             }
  1414.  
  1415.             if( XValid(x2+dx) && YValid(y2+dy) )
  1416.             {   dptr = dold+(offset+end); depth = z2+dz;
  1417.                 SETPIXEL(dptr,fold+(offset+end),depth,Lut[c2+inten]);
  1418.             }
  1419.  
  1420. #ifndef PIXUTILS
  1421.             k1 = AbsFun(dx+ix); 
  1422.             k2 = AbsFun(dx-ix);
  1423.  
  1424.             if( ((k1>wide)||(dz>=LookUp[wide][k1]-zrate)) &&
  1425.                 ((k2>wide)||(dz>LookUp[wide][k2]+zrate)) )
  1426. #endif
  1427.             {   ArcAcPtr->offset = offset; ArcAcPtr->inten = inten;
  1428.                 ArcAcPtr->dx=dx; ArcAcPtr->dy=dy; ArcAcPtr->dz=dz;
  1429.                 ArcAcPtr++;
  1430.             }
  1431.  
  1432. #ifndef PIXUTILS
  1433.             k1 = AbsFun(dy+iy);
  1434.             k2 = AbsFun(dy-iy);
  1435.  
  1436.             high = LookUp[rad][absx];
  1437.             if( ((k1>high)||(dz>=LookUp[LookUp[rad][k1]][absx]-zrate)) &&
  1438.                 ((k2>high)||(dz>LookUp[LookUp[rad][k2]][absx]+zrate)) )
  1439. #endif
  1440.             {   ArcDnPtr->offset = offset; ArcDnPtr->inten = inten;
  1441.                 ArcDnPtr->dx=dx; ArcDnPtr->dy=dy; ArcDnPtr->dz=dz;
  1442.                 ArcDnPtr++;
  1443.             }
  1444.         }
  1445.         temp += View.yskip;
  1446.     }
  1447. }
  1448.  
  1449.  
  1450. void DrawCylinder( x1,y1,z1,x2,y2,z2,c1,c2,rad )
  1451.     int x1,y1,z1, x2,y2,z2, c1,c2,rad;
  1452. {
  1453.     register short __huge *dbase;
  1454.     register Pixel __huge *fbase;
  1455.  
  1456.     register int zrate,zerr,ystep,err;
  1457.     register int ix,iy,ax,ay;
  1458.     register int lx,ly,lz;
  1459.     register int mid,tmp;
  1460.     register Long temp;
  1461.  
  1462.  
  1463.     /* Trivial Case */
  1464.     if( (x1==x2) && (y1==y2) )
  1465.     {   if( z1>z2 )
  1466.         {      DrawSphere(x1,y1,z1,rad,c1);
  1467.         } else DrawSphere(x2,y2,z2,rad,c2);
  1468.         return;
  1469.     }
  1470.  
  1471.     if( z1<z2 )
  1472.     {   tmp=x1; x1=x2; x2=tmp;
  1473.         tmp=y1; y1=y2; y2=tmp;
  1474.         tmp=z1; z1=z2; z2=tmp;
  1475.         tmp=c1; c1=c2; c2=tmp;
  1476.     }
  1477.  
  1478.     DrawCylinderCaps(x1,y1,z1,x2,y2,z2,c1,c2,rad);
  1479.  
  1480.     lx = x2-x1;
  1481.     ly = y2-y1;
  1482.     lz = z2-z1;
  1483.  
  1484.     if( ly>0 ) { ystep = View.yskip; ay = ly; iy = 1; }
  1485.     else {   ystep = -View.yskip; ay = -ly; iy = -1; }
  1486.     if( lx>0 ) { ax = lx; ix = 1; }
  1487.     else { ax = -lx; ix = -1; }
  1488.     zrate = lz/MaxFun(ax,ay);
  1489.  
  1490.     temp = (Long)y1*View.yskip+x1;
  1491.     fbase = View.fbuf+temp;
  1492.     dbase = View.dbuf+temp;
  1493.  
  1494.     if( ax>ay )
  1495.     {   lz -= ax*zrate;
  1496.         zerr = err = -(ax>>1);
  1497.  
  1498.         if( c1 != c2 )
  1499.         {   mid = (x1+x2)>>1;
  1500.             while( x1!=mid )
  1501.             {   z1 += zrate;  if( (zerr-=lz)>0 ) { zerr-=ax; z1--; }
  1502.                 fbase+=ix; dbase+=ix; x1+=ix;
  1503.                 if( (err+=ay)>0 )
  1504.                 {   fbase+=ystep; dbase+=ystep; err-=ax;
  1505.                        DrawArcDn(dbase,fbase,z1,c1);
  1506.                 } else DrawArcAc(dbase,fbase,z1,c1);
  1507.             }
  1508.         }
  1509.  
  1510.         while( x1!=x2 )
  1511.         {   z1 += zrate;  if( (zerr-=lz)>0 ) { zerr-=ax; z1--; }
  1512.             fbase+=ix; dbase+=ix; x1+=ix;
  1513.             if( (err+=ay)>0 )
  1514.             {   fbase+=ystep; dbase+=ystep; err-=ax;
  1515.                    DrawArcDn(dbase,fbase,z1,c2);
  1516.             } else DrawArcAc(dbase,fbase,z1,c2);
  1517.         }
  1518.     } else /*ay>=ax*/
  1519.     {   lz -= ay*zrate;
  1520.         zerr = err = -(ay>>1);
  1521.  
  1522.         if( c1 != c2 )
  1523.         {   mid = (y1+y2)>>1;
  1524.             while( y1!=mid )
  1525.             {   z1 += zrate;  if( (zerr-=lz)>0 ) { zerr-=ay; z1--; }
  1526.                 fbase+=ystep; dbase+=ystep; y1+=iy;
  1527.                 if( (err+=ax)>0 )
  1528.                 {   fbase+=ix; dbase+=ix; err-=ay; 
  1529.                        DrawArcAc(dbase,fbase,z1,c1);
  1530.                 } else DrawArcDn(dbase,fbase,z1,c1);
  1531.             }
  1532.         }
  1533.  
  1534.         while( y1!=y2 )
  1535.         {   z1 += zrate;  if( (zerr-=lz)>0 ) { zerr-=ay; z1--; }
  1536.             fbase+=ystep; dbase+=ystep; y1+=iy;
  1537.             if( (err+=ax)>0 )
  1538.             {   fbase+=ix; dbase+=ix; err-=ay; 
  1539.                    DrawArcAc(dbase,fbase,z1,c2);
  1540.             } else DrawArcDn(dbase,fbase,z1,c2);
  1541.         }
  1542.     }
  1543. }
  1544.  
  1545.  
  1546. static int TestCylinder( x1,y1,z1,x2,y2,z2,rad )
  1547.     int x1,y1,z1,x2,y2,z2,rad;
  1548. {
  1549.     register int tmp1, tmp2;
  1550.  
  1551.     if( UseSlabPlane )
  1552.         if( (z1+rad>SlabValue) || (z2+rad>SlabValue) )
  1553.             return(False);
  1554.  
  1555.     ClipStatus = False;
  1556.  
  1557.     tmp1 = x1+rad;  tmp2 = x2+rad;
  1558.     if( (tmp1<0) && (tmp2<0) )
  1559.         return( False );
  1560.     if( (tmp1>=View.xmax) || (tmp2>=View.xmax) )
  1561.         ClipStatus = True;
  1562.  
  1563.     tmp1 = x1-rad;  tmp2 = x2-rad;
  1564.     if( (tmp1>=View.xmax) && (tmp2>=View.xmax) )
  1565.         return( False );
  1566.     if( (tmp1<0) || (tmp2<0) )
  1567.         ClipStatus = True;
  1568.  
  1569.     tmp1 = y1+rad;  tmp2 = y2+rad;
  1570.     if( (tmp1<0) && (tmp2<0) )
  1571.         return( False );
  1572.     if( (tmp1>=View.ymax) || (tmp2>=View.ymax) )
  1573.         ClipStatus = True;
  1574.  
  1575.     tmp1 = y1-rad;  tmp2 = y2-rad;
  1576.     if( (tmp1>=View.ymax) && (tmp2>=View.ymax) )
  1577.         return( False );
  1578.     if( (tmp1<0) || (tmp2<0) )
  1579.         ClipStatus = True;
  1580.  
  1581.     return( True );
  1582. }
  1583.  
  1584.  
  1585.  
  1586. static void ClipArcAc(dbase,fbase,x,y,z,c)
  1587.     register short __huge *dbase;
  1588.     register Pixel __huge *fbase;
  1589.     register int x,y,z,c;
  1590. {
  1591.     register ArcEntry __far *ptr;
  1592.     register short __huge *dptr;
  1593.     register short depth;
  1594.     register int temp;
  1595.  
  1596.     ptr = ArcAc;
  1597.     while( (temp=y+ptr->dy) < 0 )
  1598.         if( ++ptr == ArcAcPtr )
  1599.             return;
  1600.  
  1601.     while( (temp<View.ymax) && (ptr<ArcAcPtr) )
  1602.     {   temp = x+ptr->dx;
  1603.         if( XValid(temp) )
  1604.         {   dptr = dbase+ptr->offset;  depth = ptr->dz+z;
  1605.             SETPIXEL(dptr,fbase+ptr->offset,depth,Lut[ptr->inten+c]);
  1606.         }
  1607.         ptr++;
  1608.         temp = y+ptr->dy;
  1609.     }
  1610. }
  1611.  
  1612. static void ClipArcDn(dbase,fbase,x,y,z,c)
  1613.     register short __huge *dbase;
  1614.     register Pixel __huge *fbase;
  1615.     register int x,y,z,c;
  1616. {
  1617.     register ArcEntry __far *ptr;
  1618.     register short __huge *dptr;
  1619.     register short depth;
  1620.     register int temp;
  1621.  
  1622.     ptr = ArcDn;
  1623.     while( (temp=y+ptr->dy) < 0 )
  1624.         if( ++ptr == ArcDnPtr )
  1625.             return;
  1626.  
  1627.     while( (temp<View.ymax) && (ptr<ArcDnPtr) )
  1628.     {   temp = x+ptr->dx;
  1629.         if( XValid(temp) )
  1630.         {   dptr = dbase+ptr->offset;  depth = ptr->dz+z;
  1631.             SETPIXEL(dptr,fbase+ptr->offset,depth,Lut[ptr->inten+c]);
  1632.         }
  1633.         ptr++;
  1634.         temp = y+ptr->dy;
  1635.     }
  1636. }
  1637.  
  1638.  
  1639. void ClipCylinder( x1,y1,z1,x2,y2,z2,c1,c2,rad )
  1640.     int x1,y1,z1, x2,y2,z2, c1,c2,rad;
  1641. {
  1642.     register short __huge *dbase;
  1643.     register Pixel __huge *fbase;
  1644.  
  1645.     register int zrate,zerr,ystep,err;
  1646.     register int ix,iy,ax,ay;
  1647.     register int lx,ly,lz;
  1648.     register int mid,tmp;
  1649.     register Long temp;
  1650.  
  1651.     /* Visibility Tests */
  1652.     if( !TestCylinder(x1,y1,z1,x2,y2,z2,rad) )
  1653.         return;
  1654.  
  1655.     if( !ClipStatus )
  1656.     {   DrawCylinder(x1,y1,z1,x2,y2,z2,c1,c2,rad);
  1657.         return;
  1658.     }
  1659.  
  1660.     /* Trivial Case */
  1661.     if( (x1==x2) && (y1==y2) )
  1662.     {   if( z1>z2 )
  1663.         {      ClipSphere(x1,y1,z1,rad,c1);
  1664.         } else ClipSphere(x2,y2,z2,rad,c2);
  1665.         return;
  1666.     }
  1667.  
  1668.     if( z1<z2 )
  1669.     {   tmp=x1; x1=x2; x2=tmp;
  1670.         tmp=y1; y1=y2; y2=tmp;
  1671.         tmp=z1; z1=z2; z2=tmp;
  1672.         tmp=c1; c1=c2; c2=tmp;
  1673.     }
  1674.  
  1675.     DrawCylinderCaps(x1,y1,z1,x2,y2,z2,c1,c2,rad);
  1676.  
  1677.     lx = x2-x1;
  1678.     ly = y2-y1;
  1679.     lz = z2-z1;
  1680.  
  1681.     if( ly>0 ) { ystep = View.yskip; ay = ly; iy = 1; }
  1682.     else {   ystep = -View.yskip; ay = -ly; iy = -1; }
  1683.     if( lx>0 ) { ax = lx; ix = 1; }
  1684.     else { ax = -lx; ix = -1; }
  1685.     zrate = lz/MaxFun(ax,ay);
  1686.  
  1687.     temp = (Long)y1*View.yskip+x1;
  1688.     fbase = View.fbuf+temp;
  1689.     dbase = View.dbuf+temp;
  1690.  
  1691.     if( ax>ay )
  1692.     {   if( x2<x1 )
  1693.         {   tmp = c1;
  1694.             c1 = c2;
  1695.             c2 = tmp;
  1696.         }
  1697.         lz -= ax*zrate;
  1698.         zerr = err = -(ax>>1);
  1699.         mid = (x1+x2)/2;
  1700.  
  1701.         while( x1!=x2 )
  1702.         {   z1 += zrate;  if( (zerr-=lz)>0 ) { zerr-=ax; z1--; }
  1703.             fbase+=ix; dbase+=ix; x1+=ix;
  1704.             if( (err+=ay)>0 )
  1705.             {   fbase += ystep;  err -= ax;
  1706.                 dbase += ystep;  y1 += iy;
  1707.                    ClipArcDn(dbase,fbase,x1,y1,z1,(x1<mid?c1:c2));
  1708.             } else ClipArcAc(dbase,fbase,x1,y1,z1,(x1<mid?c1:c2));
  1709.         }
  1710.     } else /*ay>=ax*/
  1711.     {   if( y2<y1 )
  1712.         {   tmp = c1;
  1713.             c1 = c2;
  1714.             c2 = tmp;
  1715.         }
  1716.         lz -= ay*zrate;
  1717.         zerr = err = -(ay>>1);
  1718.         mid = (y1+y2)/2;
  1719.  
  1720.         while( y1!=y2 )
  1721.         {   z1 += zrate;  if( (zerr-=lz)>0 ) { zerr-=ay; z1--; }
  1722.             fbase+=ystep; dbase+=ystep; y1+=iy;
  1723.             if( (err+=ax)>0 )
  1724.             {   fbase += ix;  err -= ay;
  1725.                 dbase += ix;  x1 += ix; 
  1726.                    ClipArcAc(dbase,fbase,x1,y1,z1,(y1<mid?c1:c2));
  1727.             } else ClipArcDn(dbase,fbase,x1,y1,z1,(y1<mid?c1:c2));
  1728.         }
  1729.     }
  1730. }
  1731.  
  1732.  
  1733. void SetFontSize( size )
  1734.     int size;
  1735. {
  1736.     register int count;
  1737.     register int i;
  1738.  
  1739.     count = 0;
  1740.     for( i=0; i<23; i++ )
  1741.     {   FontDimen[i] = count>>4;
  1742.         count += size;
  1743.     }
  1744.     FontSize = size;
  1745. }
  1746.  
  1747.  
  1748. static void ClipCharacter( x, y, z, glyph, col )
  1749.     int x, y, z, glyph, col;
  1750. {
  1751.     register char *ptr;
  1752.     register int sx,sy;
  1753.     register int ex,ey;
  1754.  
  1755.     ptr = VectFont[glyph];
  1756.     while( *ptr )
  1757.     {   /* Uppercase test */
  1758.         if( ptr[0] < 'a' )
  1759.         {   sx = x + FontDimen[ptr[0]-'A'];
  1760.             sy = y + InvertY(FontDimen[ptr[1]-'a']);
  1761.             ptr += 2;
  1762.         } else
  1763.         {   sx = ex;
  1764.             sy = ey;
  1765.         }
  1766.  
  1767.         ex = x + FontDimen[ptr[0]-'a'];
  1768.         ey = y + InvertY(FontDimen[ptr[1]-'a']);
  1769.         if( (ex!=sx) || (ey!=sy) )
  1770.         {   ClipLine(sx,sy,z,ex,ey,z,col);
  1771.         } else ClipPoint(ex,ey,z,col);
  1772.         ptr += 2;
  1773.     }
  1774. }
  1775.  
  1776.  
  1777. void DisplayString( x, y, z, label, col )
  1778.     int x, y, z;  char *label;  int col;
  1779. {
  1780.     register int clip,high,max;
  1781.     register char *ptr;
  1782.     register int sx,sy;
  1783.     register int ex,ey;
  1784.  
  1785.  
  1786.     high = (FontSize*3)>>1;
  1787. #ifdef INVERT
  1788.     if( ((y+high)<0) || (y>=View.ymax) ) return;
  1789.     clip = (y<0) || (y+high>=View.ymax);
  1790. #else
  1791.     if( (y<0) || ((y-high)>=View.ymax) ) return;
  1792.     clip = (y-high<0) || (y>=View.ymax);
  1793. #endif
  1794.  
  1795.     if( x < 0 )
  1796.     {   while( *label && (x<=-FontSize) )
  1797.         {   x += FontSize;  label++;
  1798.         }
  1799.  
  1800.         if( *label )
  1801.         {   ClipCharacter(x,y,z,(*label-32),col);
  1802.             x += FontSize;
  1803.             label++;
  1804.         } else return;
  1805.     }
  1806.  
  1807.     if( !clip )
  1808.     {   max = View.xmax-FontSize;
  1809.         while( *label && (x<max) )
  1810.         {  ptr = VectFont[*label-32];
  1811.            while( *ptr )
  1812.            {   /* Uppercase test */
  1813.                if( ptr[0] < 'a' )
  1814.                {   sx = x + FontDimen[ptr[0]-'A'];
  1815.                    sy = y + InvertY(FontDimen[ptr[1]-'a']);
  1816.                    ptr += 2;
  1817.                } else
  1818.                {   sx = ex;
  1819.                    sy = ey;
  1820.                }
  1821.  
  1822.                ex = x + FontDimen[ptr[0]-'a'];
  1823.                ey = y + InvertY(FontDimen[ptr[1]-'a']);
  1824.                if( (ex!=sx) || (ey!=sy) )
  1825.                {   DrawTwinLine(sx,sy,z,ex,ey,z,col,col);
  1826.                } else PlotPoint(ex,ey,z,col);
  1827.                ptr += 2;
  1828.            }
  1829.            x += FontSize;
  1830.            label++;
  1831.         }
  1832.  
  1833.         if( *label )
  1834.             ClipCharacter(x,y,z,(*label-32),col);
  1835.     } else /* Always Clip! */
  1836.         while( *label && (x<View.xmax) )
  1837.         {   ClipCharacter(x,y,z,(*label-32),col);
  1838.             x += FontSize;
  1839.             label++;
  1840.         }
  1841. }
  1842.  
  1843.  
  1844.  
  1845. void InitialisePixUtils()
  1846. {
  1847. #if defined(IBMPC) || defined(APPLEMAC)
  1848.     ArcAc = (ArcEntry __far*)_fmalloc(ARCSIZE*sizeof(ArcEntry));
  1849.     ArcDn = (ArcEntry __far*)_fmalloc(ARCSIZE*sizeof(ArcEntry));
  1850. #endif
  1851.     SplineCount = 5;
  1852.     SetFontSize(8);
  1853. }
  1854.  
  1855.