CrystalSpace

Public API Reference

Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

polyclip.h

Go to the documentation of this file.
00001 /*
00002     Crystal Space polygon clipping routines
00003     Copyright (C) 1998 by Jorrit Tyberghein
00004     Contributed by Ivan Avramovic <ivan@avramovic.com> and
00005                    Andrew Zabolotny <bit@eltech.ru>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public
00018     License along with this library; if not, write to the Free
00019     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 
00022 #ifndef __CS_POLYCLIP_H__
00023 #define __CS_POLYCLIP_H__
00024 
00031 #include "csextern.h"
00032 
00033 #include "csgeom/math2d.h"
00034 #include "csgeom/polypool.h"
00035 #include "igeom/clip2d.h"
00036 
00040 class CS_CSGEOM_EXPORT csClipper : public iClipper2D
00041 {
00042 protected:
00044   static csPoly2DPool *polypool;
00045 
00047   uint8 mrClipping;
00048 
00049 public:
00050   static csPoly2DPool *GetSharedPool ();
00051 
00052 public:
00054   csClipper ();
00055 
00057   virtual ~csClipper ();
00058 
00060   virtual uint8 ClipInPlace (csVector2 *InPolygon, int &InOutCount,
00061         csBox2 &BoundingBox);
00062 
00064   uint8 LastClipResult () { return mrClipping; }
00065 
00066   SCF_DECLARE_IBASE;
00067 };
00068 
00073 class CS_CSGEOM_EXPORT csBoxClipper : public csClipper
00074 {
00076   csBox2 region;
00078   csVector2 ClipBox [4];
00079 
00081   inline void InitClipBox ()
00082   {
00083     ClipBox [0].Set (region.MinX (), region.MinY ());
00084     ClipBox [1].Set (region.MinX (), region.MaxY ());
00085     ClipBox [2].Set (region.MaxX (), region.MaxY ());
00086     ClipBox [3].Set (region.MaxX (), region.MinY ());
00087   }
00088 
00089 public:
00091   csBoxClipper (const csBox2& b) : region (b)
00092   { InitClipBox (); }
00094   csBoxClipper (float x1, float y1, float x2, float y2) : region (x1,y1,x2,y2)
00095   { InitClipBox (); }
00096 
00098   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00099     csVector2 *OutPolygon, int &OutCount);
00100 
00102   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00103     csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox);
00104 
00106   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00107     csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus);
00108 
00110   virtual int ClassifyBox (const csBox2 &box);
00111 
00113   virtual bool IsInside (const csVector2& v)
00114   { return region.In (v.x, v.y); }
00115 
00117   virtual int GetVertexCount ()
00118   { return 4; }
00119 
00121   virtual csVector2 *GetClipPoly ()
00122   { return ClipBox; }
00123 
00124   virtual ClipperType GetClipperType() const { return clipperBox; }
00125 };
00126 
00137 class CS_CSGEOM_EXPORT csPolygonClipper : public csClipper
00138 {
00140   csVector2 *ClipData;
00142   csVector2 *ClipPoly;
00144   csPoly2D *ClipPoly2D;
00146   int ClipPolyVertices;
00148   csBox2 ClipBox;
00149 
00151   void Prepare ();
00152 
00153 public:
00155   csPolygonClipper (csPoly2D *Clipper, bool mirror = false,
00156     bool copy = false);
00158   csPolygonClipper (csVector2 *Clipper, int Count, bool mirror = false,
00159     bool copy = false);
00161   virtual ~csPolygonClipper ();
00162 
00164   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00165     csVector2 *OutPolygon, int &OutCount);
00166 
00168   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00169     csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox);
00170 
00172   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00173     csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus);
00174 
00176   virtual int ClassifyBox (const csBox2 &box);
00177 
00179   virtual bool IsInside (const csVector2& v);
00180 
00182   virtual int GetVertexCount () { return ClipPolyVertices; }
00183 
00185   virtual csVector2 *GetClipPoly ()
00186   { return ClipPoly; }
00187 
00188   virtual ClipperType GetClipperType() const { return clipperPoly; }
00189 };
00193 #endif // __CS_POLYCLIP_H__

Generated for Crystal Space by doxygen 1.3.9.1