csgeom/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, csBox2 &BoundingBox); 00061 00063 uint8 LastClipResult () { return mrClipping; } 00064 00065 SCF_DECLARE_IBASE; 00066 }; 00067 00072 class CS_CSGEOM_EXPORT csBoxClipper : public csClipper 00073 { 00075 csBox2 region; 00077 csVector2 ClipBox [4]; 00078 00080 inline void InitClipBox () 00081 { 00082 ClipBox [0].Set (region.MinX (), region.MinY ()); 00083 ClipBox [1].Set (region.MinX (), region.MaxY ()); 00084 ClipBox [2].Set (region.MaxX (), region.MaxY ()); 00085 ClipBox [3].Set (region.MaxX (), region.MinY ()); 00086 } 00087 00088 public: 00090 csBoxClipper (const csBox2& b) : region (b) 00091 { InitClipBox (); } 00093 csBoxClipper (float x1, float y1, float x2, float y2) : region (x1,y1,x2,y2) 00094 { InitClipBox (); } 00095 00097 virtual uint8 Clip (csVector2 *InPolygon, int InCount, 00098 csVector2 *OutPolygon, int &OutCount); 00099 00101 virtual uint8 Clip (csVector2 *InPolygon, int InCount, 00102 csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox); 00103 00105 virtual uint8 Clip (csVector2 *InPolygon, int InCount, 00106 csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus); 00107 00109 virtual int ClassifyBox (const csBox2 &box); 00110 00112 virtual bool IsInside (const csVector2& v) 00113 { return region.In (v.x, v.y); } 00114 00116 virtual int GetVertexCount () 00117 { return 4; } 00118 00120 virtual csVector2 *GetClipPoly () 00121 { return ClipBox; } 00122 00123 virtual ClipperType GetClipperType() const { return clipperBox; } 00124 }; 00125 00136 class CS_CSGEOM_EXPORT csPolygonClipper : public csClipper 00137 { 00139 csVector2 *ClipData; 00141 csVector2 *ClipPoly; 00143 csPoly2D *ClipPoly2D; 00145 int ClipPolyVertices; 00147 csBox2 ClipBox; 00148 00150 void Prepare (); 00151 00152 public: 00154 csPolygonClipper (csPoly2D *Clipper, bool mirror = false, 00155 bool copy = false); 00157 csPolygonClipper (csVector2 *Clipper, int Count, bool mirror = false, 00158 bool copy = false); 00160 virtual ~csPolygonClipper (); 00161 00163 virtual uint8 Clip (csVector2 *InPolygon, int InCount, 00164 csVector2 *OutPolygon, int &OutCount); 00165 00167 virtual uint8 Clip (csVector2 *InPolygon, int InCount, 00168 csVector2 *OutPolygon, int &OutCount, csBox2 &BoundingBox); 00169 00171 virtual uint8 Clip (csVector2 *InPolygon, int InCount, 00172 csVector2 *OutPolygon, int &OutCount, csVertexStatus *OutStatus); 00173 00175 virtual int ClassifyBox (const csBox2 &box); 00176 00178 virtual bool IsInside (const csVector2& v); 00179 00181 virtual int GetVertexCount () { return ClipPolyVertices; } 00182 00184 virtual csVector2 *GetClipPoly () 00185 { return ClipPoly; } 00186 00187 virtual ClipperType GetClipperType() const { return clipperPoly; } 00188 }; 00192 #endif // __CS_POLYCLIP_H__
Generated for Crystal Space by doxygen 1.2.18