Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | 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 00025 00026 #include "csextern.h" 00027 00028 #include "csgeom/box.h" 00029 00030 #include "igeom/clip2d.h" 00031 00032 #include "csutil/scf_implementation.h" 00033 00034 class csPoly2DPool; 00035 00045 class CS_CRYSTALSPACE_EXPORT csClipper : 00046 public scfImplementation1<csClipper,iClipper2D> 00047 { 00048 protected: 00050 static csPoly2DPool *polypool; 00051 00053 uint8 mrClipping; 00054 00055 public: 00056 static csPoly2DPool *GetSharedPool (); 00057 00058 public: 00060 csClipper (); 00061 00063 virtual ~csClipper (); 00064 00066 virtual uint8 ClipInPlace (csVector2 *InPolygon, size_t &InOutCount, 00067 csBox2 &BoundingBox); 00068 00070 uint8 LastClipResult () { return mrClipping; } 00071 }; 00072 00077 class CS_CRYSTALSPACE_EXPORT csBoxClipper : public csClipper 00078 { 00080 csBox2 region; 00082 csVector2 ClipBox [4]; 00083 00085 inline void InitClipBox () 00086 { 00087 ClipBox [0].Set (region.MinX (), region.MinY ()); 00088 ClipBox [1].Set (region.MinX (), region.MaxY ()); 00089 ClipBox [2].Set (region.MaxX (), region.MaxY ()); 00090 ClipBox [3].Set (region.MaxX (), region.MinY ()); 00091 } 00092 00093 public: 00095 csBoxClipper (const csBox2& b) : region (b) 00096 { InitClipBox (); } 00098 csBoxClipper (float x1, float y1, float x2, float y2) : region (x1,y1,x2,y2) 00099 { InitClipBox (); } 00100 00102 virtual uint8 Clip (csVector2 *InPolygon, size_t InCount, 00103 csVector2 *OutPolygon, size_t &OutCount); 00104 00106 virtual uint8 Clip (csVector2 *InPolygon, size_t InCount, 00107 csVector2 *OutPolygon, size_t &OutCount, csBox2 &BoundingBox); 00108 00110 virtual uint8 Clip (csVector2 *InPolygon, size_t InCount, 00111 csVector2 *OutPolygon, size_t &OutCount, csVertexStatus *OutStatus); 00112 00114 virtual int ClassifyBox (const csBox2 &box); 00115 00117 virtual bool IsInside (const csVector2& v) 00118 { return region.In (v.x, v.y); } 00119 00121 virtual size_t GetVertexCount () 00122 { return 4; } 00123 00125 virtual csVector2 *GetClipPoly () 00126 { return ClipBox; } 00127 00128 virtual ClipperType GetClipperType() const { return clipperBox; } 00129 }; 00130 00141 class CS_CRYSTALSPACE_EXPORT csPolygonClipper : public csClipper 00142 { 00144 csVector2 *ClipData; 00146 csVector2 *ClipPoly; 00148 csPoly2D *ClipPoly2D; 00150 size_t ClipPolyVertices; 00152 csBox2 ClipBox; 00153 00155 void Prepare (); 00156 00157 public: 00159 csPolygonClipper (csPoly2D *Clipper, bool mirror = false, 00160 bool copy = false); 00162 csPolygonClipper (csVector2 *Clipper, size_t Count, bool mirror = false, 00163 bool copy = false); 00165 virtual ~csPolygonClipper (); 00166 00168 virtual uint8 Clip (csVector2 *InPolygon, size_t InCount, 00169 csVector2 *OutPolygon, size_t &OutCount); 00170 00172 virtual uint8 Clip (csVector2 *InPolygon, size_t InCount, 00173 csVector2 *OutPolygon, size_t &OutCount, csBox2 &BoundingBox); 00174 00176 virtual uint8 Clip (csVector2 *InPolygon, size_t InCount, 00177 csVector2 *OutPolygon, size_t &OutCount, csVertexStatus *OutStatus); 00178 00180 virtual int ClassifyBox (const csBox2 &box); 00181 00183 virtual bool IsInside (const csVector2& v); 00184 00186 virtual size_t GetVertexCount () { return ClipPolyVertices; } 00187 00189 virtual csVector2 *GetClipPoly () 00190 { return ClipPoly; } 00191 00192 virtual ClipperType GetClipperType() const { return clipperPoly; } 00193 }; 00197 #endif // __CS_POLYCLIP_H__
Generated for Crystal Space by doxygen 1.4.4