Main Page   Class Hierarchy   Compound List   File List   Compound Members  

polyclip.h

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 
00025 #include "csgeom/math2d.h"
00026 #include "csgeom/polypool.h"
00027 #include "igeom/clip2d.h"
00028 
00032 class csClipper : public iClipper2D
00033 {
00034 protected:
00036   static csPoly2DPool polypool;
00037 
00039   UByte mrClipping;
00040   
00041 public:
00043   csClipper ();
00044 
00046   virtual ~csClipper () { }
00047 
00049   virtual UByte ClipInPlace (csVector2 *InPolygon, int &InOutCount, csBox2 &BoundingBox);
00050   
00052   UByte LastClipResult () { return mrClipping; }
00053 
00054   SCF_DECLARE_IBASE;
00055 };
00056 
00061 class csBoxClipper : public csClipper
00062 {
00064   csBox2 region;
00066   csVector2 ClipBox [4];
00067 
00069   inline void InitClipBox ()
00070   {
00071     ClipBox [0].Set (region.MinX (), region.MinY ());
00072     ClipBox [1].Set (region.MinX (), region.MaxY ());
00073     ClipBox [2].Set (region.MaxX (), region.MaxY ());
00074     ClipBox [3].Set (region.MaxX (), region.MinY ());
00075   }
00076 
00077 public:
00079   csBoxClipper (const csBox2& b) : region (b)
00080   { InitClipBox (); }
00082   csBoxClipper (float x1, float y1, float x2, float y2) : region (x1,y1,x2,y2)
00083   { InitClipBox (); }
00084 
00086   virtual UByte Clip (csVector2 *InPolygon, int InCount,
00087     csVector2 *OutPolygon, int &OutCount);
00088 
00090   virtual UByte Clip (csVector2 *InPolygon, int InCount,
00091     csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox);
00092 
00094   virtual UByte Clip (csVector2 *InPolygon, int InCount,
00095     csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus);
00096 
00098   virtual int ClassifyBox (const csBox2 &box);
00099 
00101   virtual bool IsInside (const csVector2& v)
00102   { return region.In (v.x, v.y); }
00103 
00105   virtual int GetVertexCount ()
00106   { return 4; }
00107 
00109   virtual csVector2 *GetClipPoly ()
00110   { return ClipBox; }
00111 };
00112 
00123 class csPolygonClipper : public csClipper
00124 {
00126   csVector2 *ClipData;
00128   csVector2 *ClipPoly;
00130   csPoly2D *ClipPoly2D;
00132   int ClipPolyVertices;
00134   csBox2 ClipBox;
00135 
00137   void Prepare ();
00138 
00139 public:
00141   csPolygonClipper (csPoly2D *Clipper, bool mirror = false,
00142     bool copy = false);
00144   csPolygonClipper (csVector2 *Clipper, int Count, bool mirror = false,
00145     bool copy = false);
00147   virtual ~csPolygonClipper ();
00148 
00150   virtual UByte Clip (csVector2 *InPolygon, int InCount,
00151     csVector2 *OutPolygon, int &OutCount);
00152 
00154   virtual UByte Clip (csVector2 *InPolygon, int InCount,
00155     csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox);
00156 
00158   virtual UByte Clip (csVector2 *InPolygon, int InCount,
00159     csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus);
00160 
00162   virtual int ClassifyBox (const csBox2 &box);
00163 
00165   virtual bool IsInside (const csVector2& v);
00166 
00168   virtual int GetVertexCount () { return ClipPolyVertices; }
00169 
00171   virtual csVector2 *GetClipPoly ()
00172   { return ClipPoly; }
00173 };
00174 
00175 #endif // __CS_POLYCLIP_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000