<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>Crystal Space 1.2.1: csgeom/poly2d.h Source File (Crystal Space 1.2.1 Public API Reference)</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="head"> <tr height="59"> <td class="head" width="202" valign="bottom" style="padding-left:0;"><a href="http://www.crystalspace3d.org/"><img src="csblur.png" width="236" height="59" alt="CrystalSpace" border="0"></a></td> <td class="head"><h2>Public API Reference</h2></td> </tr> <tr height="11"> <td colspan="2" class="headshadow" valign="top" style="padding-left:0;"><img src="csblurb.png" width="236" height="11" alt="" border="0"></td> </tr> </table> <div class="content"> <!-- Generated by Doxygen 1.5.3 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul> </div> <h1>csgeom/poly2d.h</h1><a href="poly2d_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> Copyright (C) 1998,2000 by Jorrit Tyberghein</span> <a name="l00003"></a>00003 <span class="comment"></span> <a name="l00004"></a>00004 <span class="comment"> This library is free software; you can redistribute it and/or</span> <a name="l00005"></a>00005 <span class="comment"> modify it under the terms of the GNU Library General Public</span> <a name="l00006"></a>00006 <span class="comment"> License as published by the Free Software Foundation; either</span> <a name="l00007"></a>00007 <span class="comment"> version 2 of the License, or (at your option) any later version.</span> <a name="l00008"></a>00008 <span class="comment"></span> <a name="l00009"></a>00009 <span class="comment"> This library is distributed in the hope that it will be useful,</span> <a name="l00010"></a>00010 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00011"></a>00011 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00012"></a>00012 <span class="comment"> Library General Public License for more details.</span> <a name="l00013"></a>00013 <span class="comment"></span> <a name="l00014"></a>00014 <span class="comment"> You should have received a copy of the GNU Library General Public</span> <a name="l00015"></a>00015 <span class="comment"> License along with this library; if not, write to the Free</span> <a name="l00016"></a>00016 <span class="comment"> Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00017"></a>00017 <span class="comment">*/</span> <a name="l00018"></a>00018 <a name="l00019"></a>00019 <span class="preprocessor">#ifndef __CS_POLY2D_H__</span> <a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define __CS_POLY2D_H__</span> <a name="l00021"></a>00021 <span class="preprocessor"></span> <a name="l00022"></a>00022 <span class="preprocessor">#include "csextern.h"</span> <a name="l00023"></a>00023 <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="vector2_8h.html" title="2D vector.">csgeom/vector2.h</a>"</span> <a name="l00032"></a>00032 <span class="keyword">class </span><a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a>; <a name="l00033"></a>00033 <span class="keyword">class </span><a class="code" href="classcsPlane2.html" title="A plane in 2D space.">csPlane2</a>; <a name="l00034"></a>00034 <a name="l00035"></a>00035 <span class="keyword">struct </span><a class="code" href="structiClipper2D.html" title="This interfaces represents a 2D clipper for polygons.">iClipper2D</a>; <a name="l00036"></a>00036 <a name="l00040"></a><a class="code" href="classcsPoly2D.html">00040</a> <span class="keyword">class </span>CS_CRYSTALSPACE_EXPORT <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> <a name="l00041"></a>00041 { <a name="l00042"></a>00042 <span class="keyword">protected</span>: <a name="l00044"></a><a class="code" href="classcsPoly2D.html#3833701bac9174d48c39ed8233680b97">00044</a> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* vertices; <a name="l00046"></a><a class="code" href="classcsPoly2D.html#7d72568063b523accb2732e30b27408c">00046</a> <span class="keywordtype">size_t</span> num_vertices; <a name="l00048"></a><a class="code" href="classcsPoly2D.html#a05d23cec1236c42e43876e2532030f8">00048</a> <span class="keywordtype">size_t</span> max_vertices; <a name="l00049"></a>00049 <span class="keyword">public</span>: <a name="l00053"></a>00053 <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> (<span class="keywordtype">size_t</span> start_size = 10); <a name="l00054"></a>00054 <a name="l00056"></a>00056 <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> (<span class="keyword">const</span> <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& copy); <a name="l00057"></a>00057 <a name="l00059"></a>00059 ~<a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> (); <a name="l00060"></a>00060 <a name="l00062"></a>00062 <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& operator= (<span class="keyword">const</span> <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& other); <a name="l00063"></a>00063 <a name="l00067"></a>00067 <span class="keywordtype">void</span> MakeEmpty (); <a name="l00068"></a>00068 <a name="l00072"></a><a class="code" href="classcsPoly2D.html#f3d6ca0f05b72f629361b97d286fb656">00072</a> <span class="keywordtype">size_t</span> GetVertexCount ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> num_vertices; } <a name="l00073"></a>00073 <a name="l00077"></a><a class="code" href="classcsPoly2D.html#12979aa411170a6caecc1d552bca8ee1">00077</a> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* GetVertices () { <span class="keywordflow">return</span> vertices; } <a name="l00078"></a>00078 <a name="l00082"></a><a class="code" href="classcsPoly2D.html#27676cea69af1dcb97f9889284f2ecda">00082</a> <span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* GetVertices ()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> vertices; } <a name="l00083"></a>00083 <a name="l00087"></a><a class="code" href="classcsPoly2D.html#3844412270470722fb1e4215cd245bec">00087</a> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* GetVertex (<span class="keywordtype">size_t</span> i) <a name="l00088"></a>00088 { <a name="l00089"></a>00089 <span class="keywordflow">if</span> (i>=num_vertices) <span class="keywordflow">return</span> 0; <a name="l00090"></a>00090 <span class="keywordflow">return</span> &vertices[i]; <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <a name="l00096"></a><a class="code" href="classcsPoly2D.html#44123805a6de0d28f0e4934d47d07bd0">00096</a> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& operator[] (<span class="keywordtype">size_t</span> i) <a name="l00097"></a>00097 { <a name="l00098"></a>00098 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a> (i < num_vertices); <a name="l00099"></a>00099 <span class="keywordflow">return</span> vertices[i]; <a name="l00100"></a>00100 } <a name="l00101"></a>00101 <a name="l00105"></a><a class="code" href="classcsPoly2D.html#68ff77fd33fd243945faeba74a11aec4">00105</a> <span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& operator[] (<span class="keywordtype">size_t</span> i)<span class="keyword"> const</span> <a name="l00106"></a>00106 <span class="keyword"> </span>{ <a name="l00107"></a>00107 <a class="code" href="cssysdef_8h.html#c380bd47888ecfe73e7b7a40b6f827a1" title="Assertion.">CS_ASSERT</a> (i < num_vertices); <a name="l00108"></a>00108 <span class="keywordflow">return</span> vertices[i]; <a name="l00109"></a>00109 } <a name="l00110"></a>00110 <a name="l00114"></a><a class="code" href="classcsPoly2D.html#65d0b7a6d47fb3e1b2b4203424f9e40f">00114</a> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* GetFirst () <a name="l00115"></a>00115 { <span class="keywordflow">if</span> (num_vertices<=0) <span class="keywordflow">return</span> 0; <span class="keywordflow">else</span> <span class="keywordflow">return</span> vertices; } <a name="l00116"></a>00116 <a name="l00120"></a><a class="code" href="classcsPoly2D.html#fc1653a837adc98567e675ebff74c491">00120</a> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* GetLast () <a name="l00121"></a>00121 { <span class="keywordflow">if</span> (num_vertices<=0) <span class="keywordflow">return</span> 0; <span class="keywordflow">else</span> <span class="keywordflow">return</span> &vertices[num_vertices-1]; } <a name="l00122"></a>00122 <a name="l00126"></a>00126 <span class="keywordtype">bool</span> In (<span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& v); <a name="l00127"></a>00127 <a name="l00131"></a>00131 <span class="keyword">static</span> <span class="keywordtype">bool</span> In (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>* poly, <span class="keywordtype">size_t</span> num_poly, <span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& v); <a name="l00132"></a>00132 <a name="l00136"></a>00136 <span class="keywordtype">void</span> MakeRoom (<span class="keywordtype">size_t</span> new_max); <a name="l00137"></a>00137 <a name="l00141"></a><a class="code" href="classcsPoly2D.html#02bde73de458cfa18118343da83bc6c3">00141</a> <span class="keywordtype">void</span> SetVertexCount (<span class="keywordtype">size_t</span> n) <a name="l00142"></a>00142 { <a name="l00143"></a>00143 MakeRoom (n); <a name="l00144"></a>00144 num_vertices = n; <a name="l00145"></a>00145 } <a name="l00146"></a>00146 <a name="l00151"></a><a class="code" href="classcsPoly2D.html#48fc3a012a4273e512621b13b972662d">00151</a> <span class="keywordtype">size_t</span> AddVertex (<span class="keyword">const</span> <a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>& v) { <span class="keywordflow">return</span> AddVertex (v.<a class="code" href="classcsVector2.html#cf4ee25489c98e6b7b7a460c4edd4ac6" title="X component of vector.">x</a>, v.<a class="code" href="classcsVector2.html#f736730a67b9ee807f1455da3d2be188" title="Y component of vector.">y</a>); } <a name="l00152"></a>00152 <a name="l00157"></a>00157 <span class="keywordtype">size_t</span> AddVertex (<span class="keywordtype">float</span> x, <span class="keywordtype">float</span> y); <a name="l00158"></a>00158 <a name="l00163"></a><a class="code" href="classcsPoly2D.html#4b8e659bfd5690c6ee29b4d41fc51c45">00163</a> <span class="keywordtype">void</span> SetVertices (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a> <span class="keyword">const</span>* v, <span class="keywordtype">size_t</span> num) <a name="l00164"></a>00164 { <a name="l00165"></a>00165 MakeRoom (num); <a name="l00166"></a>00166 memcpy (vertices, v, (num_vertices = num) * <span class="keyword">sizeof</span> (<a class="code" href="classcsVector2.html" title="A 2D vector.">csVector2</a>)); <a name="l00167"></a>00167 } <a name="l00168"></a>00168 <a name="l00177"></a>00177 <span class="keywordtype">bool</span> ClipAgainst (<a class="code" href="structiClipper2D.html" title="This interfaces represents a 2D clipper for polygons.">iClipper2D</a>* view); <a name="l00178"></a>00178 <a name="l00187"></a>00187 <span class="keywordtype">void</span> Intersect (<span class="keyword">const</span> <a class="code" href="classcsPlane2.html" title="A plane in 2D space.">csPlane2</a>& plane, <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& left, <a name="l00188"></a>00188 <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& right) <span class="keyword">const</span>; <a name="l00189"></a>00189 <a name="l00194"></a>00194 <span class="keywordtype">void</span> ClipPlane (<span class="keyword">const</span> <a class="code" href="classcsPlane2.html" title="A plane in 2D space.">csPlane2</a>& plane, <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& right) <span class="keyword">const</span>; <a name="l00195"></a>00195 <a name="l00204"></a>00204 <span class="keywordtype">void</span> ExtendConvex (<span class="keyword">const</span> <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>& other, <span class="keywordtype">size_t</span> this_edge); <a name="l00205"></a>00205 <a name="l00209"></a>00209 <span class="keywordtype">float</span> GetSignedArea(); <a name="l00210"></a>00210 <a name="l00216"></a>00216 <span class="keywordtype">void</span> Random (<span class="keywordtype">size_t</span> num, <span class="keyword">const</span> <a class="code" href="classcsBox2.html" title="A bounding box in 2D space.">csBox2</a>& max_bbox); <a name="l00217"></a>00217 }; <a name="l00218"></a>00218 <a name="l00224"></a><a class="code" href="classcsPoly2DFactory.html">00224</a> <span class="keyword">class </span><a class="code" href="classcsPoly2DFactory.html" title="This factory is responsible for creating csPoly2D objects or subclasses of csPoly2D...">csPoly2DFactory</a> <a name="l00225"></a>00225 { <a name="l00226"></a>00226 <span class="keyword">public</span>: <a name="l00227"></a>00227 <span class="comment">// Needed for GCC4. Otherwise emits a flood of "virtual functions but</span> <a name="l00228"></a>00228 <span class="comment">// non-virtual destructor" warnings.</span> <a name="l00229"></a><a class="code" href="classcsPoly2DFactory.html#903949b189803ad19beca856a2efa873">00229</a> <span class="keyword">virtual</span> <a class="code" href="classcsPoly2DFactory.html#903949b189803ad19beca856a2efa873">~csPoly2DFactory</a>() {} <a name="l00230"></a>00230 <a name="l00232"></a>00232 <a class="code" href="cssysdef_8h.html#9e3fbfaf27ee31f36c4f994e232e11a8" title="Declare a static variable inside a class.">CS_DECLARE_STATIC_CLASSVAR</a>(sharedFactory,SharedFactory,<a class="code" href="classcsPoly2DFactory.html" title="This factory is responsible for creating csPoly2D objects or subclasses of csPoly2D...">csPoly2DFactory</a>) <a name="l00233"></a>00233 <a name="l00234"></a>00234 <a name="l00235"></a><a class="code" href="classcsPoly2DFactory.html#a8a9045d12c3a5e9ac0718d61313f3f4">00235</a> virtual <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>* <a class="code" href="classcsPoly2DFactory.html#a8a9045d12c3a5e9ac0718d61313f3f4" title="A shared factory that you can use.">Create</a> () <a name="l00236"></a>00236 { <a name="l00237"></a>00237 <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a>* p = <span class="keyword">new</span> <a class="code" href="classcsPoly2D.html" title="The following class represents a general 2D polygon.">csPoly2D</a> (); <a name="l00238"></a>00238 <span class="keywordflow">return</span> p; <a name="l00239"></a>00239 } <a name="l00240"></a>00240 }; <a name="l00241"></a>00241 <a name="l00244"></a>00244 <span class="preprocessor">#endif // __CS_POLY2D_H__</span> </pre></div><hr size="1"><address><small>Generated for Crystal Space 1.2.1 by <a href="http://www.doxygen.org/index.html">doxygen</a> 1.5.3 </small></address> </div></body> </html>