CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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 "csgeom/math2d.h"
00032 #include "csgeom/polypool.h"
00033 #include "igeom/clip2d.h"
00034 
00038 class csClipper : public iClipper2D
00039 {
00040 protected:
00042   static csPoly2DPool *polypool;
00043 
00045   uint8 mrClipping;
00046 
00047 public:
00048   static csPoly2DPool *GetSharedPool ();
00049 
00050 public:
00052   csClipper ();
00053 
00055   virtual ~csClipper () { }
00056 
00058   virtual uint8 ClipInPlace (csVector2 *InPolygon, int &InOutCount, csBox2 &BoundingBox);
00059 
00061   uint8 LastClipResult () { return mrClipping; }
00062 
00063   SCF_DECLARE_IBASE;
00064 };
00065 
00070 class csBoxClipper : public csClipper
00071 {
00073   csBox2 region;
00075   csVector2 ClipBox [4];
00076 
00078   inline void InitClipBox ()
00079   {
00080     ClipBox [0].Set (region.MinX (), region.MinY ());
00081     ClipBox [1].Set (region.MinX (), region.MaxY ());
00082     ClipBox [2].Set (region.MaxX (), region.MaxY ());
00083     ClipBox [3].Set (region.MaxX (), region.MinY ());
00084   }
00085 
00086 public:
00088   csBoxClipper (const csBox2& b) : region (b)
00089   { InitClipBox (); }
00091   csBoxClipper (float x1, float y1, float x2, float y2) : region (x1,y1,x2,y2)
00092   { InitClipBox (); }
00093 
00095   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00096     csVector2 *OutPolygon, int &OutCount);
00097 
00099   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00100     csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox);
00101 
00103   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00104     csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus);
00105 
00107   virtual int ClassifyBox (const csBox2 &box);
00108 
00110   virtual bool IsInside (const csVector2& v)
00111   { return region.In (v.x, v.y); }
00112 
00114   virtual int GetVertexCount ()
00115   { return 4; }
00116 
00118   virtual csVector2 *GetClipPoly ()
00119   { return ClipBox; }
00120 };
00121 
00132 class csPolygonClipper : public csClipper
00133 {
00135   csVector2 *ClipData;
00137   csVector2 *ClipPoly;
00139   csPoly2D *ClipPoly2D;
00141   int ClipPolyVertices;
00143   csBox2 ClipBox;
00144 
00146   void Prepare ();
00147 
00148 public:
00150   csPolygonClipper (csPoly2D *Clipper, bool mirror = false,
00151     bool copy = false);
00153   csPolygonClipper (csVector2 *Clipper, int Count, bool mirror = false,
00154     bool copy = false);
00156   virtual ~csPolygonClipper ();
00157 
00159   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00160     csVector2 *OutPolygon, int &OutCount);
00161 
00163   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00164     csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox);
00165 
00167   virtual uint8 Clip (csVector2 *InPolygon, int InCount,
00168     csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus);
00169 
00171   virtual int ClassifyBox (const csBox2 &box);
00172 
00174   virtual bool IsInside (const csVector2& v);
00175 
00177   virtual int GetVertexCount () { return ClipPolyVertices; }
00178 
00180   virtual csVector2 *GetClipPoly ()
00181   { return ClipPoly; }
00182 };
00186 #endif // __CS_POLYCLIP_H__

Generated for Crystal Space by doxygen 1.2.14