home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / grapdrvs / drawpoly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-14  |  4.0 KB  |  134 lines

  1. /*****************************************************************************
  2. *   Default polyline/gon drawing routine common to graphics drivers.         *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "iritprsr.h"
  9. #include "cagd_lib.h"
  10. #include "symb_lib.h"
  11. #include "iritgrap.h"
  12.  
  13. /*****************************************************************************
  14. * DESCRIPTION:                                                               M
  15. * Draw a single Poly object using current modes and transformations.         M
  16. *                                                                            *
  17. * PARAMETERS:                                                                M
  18. *   PObj:     A poly object to draw.                                         M
  19. *                                                                            *
  20. * RETURN VALUE:                                                              M
  21. *   void                                                                     M
  22. *                                                                            *
  23. * KEYWORDS:                                                                  M
  24. *   IGDrawPoly                                                               M
  25. *****************************************************************************/
  26. void IGDrawPoly(IPObjectStruct *PObj)
  27. {
  28.     IPVertexStruct *V;
  29.     IPPolygonStruct
  30.     *Pl = PObj -> U.Pl;
  31.  
  32.     if (IGGlblAbortKeyPressed)
  33.     return;
  34.  
  35.     if (IP_IS_POLYLINE_OBJ(PObj)) {
  36.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  37.         if (Pl -> PVertex != NULL && Pl -> PVertex -> Pnext != NULL) {
  38.         IGMoveTo3D(Pl -> PVertex -> Coord);
  39.         for (V = Pl -> PVertex -> Pnext; V != NULL; V = V -> Pnext)
  40.             IGLineTo3D(V -> Coord);
  41.         }
  42.     }
  43.     }
  44.     else if (IP_IS_POINTLIST_OBJ(PObj)) {
  45.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  46.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  47.         int i;
  48.         PointType Ends[6];
  49.         RealType
  50.             *Pt = V -> Coord;
  51.  
  52.         for (i = 0; i < 6; i++)
  53.             PT_COPY(Ends[i], Pt);
  54.  
  55.         Ends[0][0] -= IG_POINT_WIDTH;
  56.         Ends[1][0] += IG_POINT_WIDTH;
  57.         Ends[2][1] -= IG_POINT_WIDTH;
  58.         Ends[3][1] += IG_POINT_WIDTH;
  59.         Ends[4][2] -= IG_POINT_WIDTH;
  60.         Ends[5][2] += IG_POINT_WIDTH;
  61.  
  62.         for (i = 0; i < 6; i += 2) {
  63.             IGMoveTo3D(Ends[i]);
  64.             IGLineTo3D(Ends[i+1]);
  65.         }
  66.         }
  67.     }
  68.     }
  69.     else if (IP_IS_POLYGON_OBJ(PObj)) {
  70.     int i, j,
  71.         NumOfVertices = 0;
  72.     PointType PNormal, VNormal;
  73.  
  74.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  75.         IPVertexStruct *PrevV;
  76.  
  77.         if (IGGlblBackFaceCull) {
  78.             RealType P1[3], P2[3];
  79.  
  80.         MatMultVecby4by4(P1, Pl -> PVertex -> Coord,
  81.                  IGGlblCrntViewMat);
  82.         PT_ADD(PNormal, Pl -> PVertex -> Coord, Pl -> Plane);
  83.         MatMultVecby4by4(P2, PNormal, IGGlblCrntViewMat);
  84.         if (P2[2] - P1[2] > 0.0)
  85.             continue;
  86.         }
  87.  
  88.         if (IGGlblDrawPNormal) {
  89.         NumOfVertices = 0;
  90.         PNormal[0] = PNormal[1] = PNormal[2] = 0.0;
  91.         }
  92.  
  93.         IGMoveTo3D(Pl -> PVertex -> Coord);
  94.         for (PrevV = Pl -> PVertex, V = PrevV -> Pnext;
  95.          V != NULL;
  96.          PrevV = V, V = V -> Pnext) {
  97.         if (IP_IS_INTERNAL_VRTX(PrevV) && !IGGlblDrawInternal)
  98.             IGMoveTo3D(V -> Coord);
  99.         else
  100.             IGLineTo3D(V -> Coord);
  101.  
  102.         if (IGGlblDrawPNormal) {
  103.             for (j = 0; j < 3; j++)
  104.             PNormal[j] += V -> Coord[j];
  105.             NumOfVertices++;
  106.         }
  107.         }
  108.         if (!IP_IS_INTERNAL_VRTX(PrevV) || IGGlblDrawInternal)
  109.         IGLineTo3D(Pl -> PVertex -> Coord);
  110.  
  111.         if (IGGlblDrawPNormal && IP_HAS_PLANE_POLY(Pl)) {
  112.         for (i = 0; i < 3; i++)
  113.             PNormal[i] /= NumOfVertices;
  114.         IGMoveTo3D(PNormal);
  115.         for (i = 0; i < 3; i++)
  116.             PNormal[i] += Pl -> Plane[i] * IGGlblNormalLen;
  117.         IGLineTo3D(PNormal);
  118.         }
  119.  
  120.         if (IGGlblDrawVNormal) {
  121.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  122.             if (IP_HAS_NORMAL_VRTX(V)) {
  123.             for (j = 0; j < 3; j++)
  124.                 VNormal[j] = V -> Coord[j] +
  125.                          V -> Normal[j] * IGGlblNormalLen;
  126.             IGMoveTo3D(V ->Coord);
  127.             IGLineTo3D(VNormal);
  128.             }
  129.         }
  130.         }
  131.     }
  132.     }
  133. }
  134.