[148] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
| 8 | Copyright (c) 2006 Matthias Fink, netAllied GmbH <matthias.fink@web.de> |
---|
| 9 | |
---|
| 10 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 11 | of this software and associated documentation files (the "Software"), to deal |
---|
| 12 | in the Software without restriction, including without limitation the rights |
---|
| 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 14 | copies of the Software, and to permit persons to whom the Software is |
---|
| 15 | furnished to do so, subject to the following conditions: |
---|
| 16 | |
---|
| 17 | The above copyright notice and this permission notice shall be included in |
---|
| 18 | all copies or substantial portions of the Software. |
---|
| 19 | |
---|
| 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 26 | THE SOFTWARE. |
---|
| 27 | ----------------------------------------------------------------------------- |
---|
| 28 | */ |
---|
| 29 | #ifndef __Polygon_H__ |
---|
| 30 | #define __Polygon_H__ |
---|
| 31 | |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | #include "OgreVector3.h" |
---|
| 34 | #include "OgreHeaderPrefix.h" |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | namespace Ogre |
---|
| 38 | { |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | /** \addtogroup Core |
---|
| 42 | * @{ |
---|
| 43 | */ |
---|
| 44 | /** \addtogroup Math |
---|
| 45 | * @{ |
---|
| 46 | */ |
---|
| 47 | /** The class represents a polygon in 3D space. |
---|
| 48 | @remarks |
---|
| 49 | It is made up of 3 or more vertices in a single plane, listed in |
---|
| 50 | counter-clockwise order. |
---|
| 51 | */ |
---|
| 52 | class _OgreExport Polygon |
---|
| 53 | { |
---|
| 54 | |
---|
| 55 | public: |
---|
| 56 | typedef vector<Vector3>::type VertexList; |
---|
| 57 | |
---|
| 58 | typedef multimap<Vector3, Vector3>::type EdgeMap; |
---|
| 59 | typedef std::pair< Vector3, Vector3> Edge; |
---|
| 60 | |
---|
| 61 | protected: |
---|
| 62 | VertexList mVertexList; |
---|
| 63 | mutable Vector3 mNormal; |
---|
| 64 | mutable bool mIsNormalSet; |
---|
| 65 | /** Updates the normal. |
---|
| 66 | */ |
---|
| 67 | void updateNormal(void) const; |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | public: |
---|
| 71 | Polygon(); |
---|
| 72 | ~Polygon(); |
---|
| 73 | Polygon( const Polygon& cpy ); |
---|
| 74 | |
---|
| 75 | /** Inserts a vertex at a specific position. |
---|
| 76 | @note Vertices must be coplanar. |
---|
| 77 | */ |
---|
| 78 | void insertVertex(const Vector3& vdata, size_t vertexIndex); |
---|
| 79 | /** Inserts a vertex at the end of the polygon. |
---|
| 80 | @note Vertices must be coplanar. |
---|
| 81 | */ |
---|
| 82 | void insertVertex(const Vector3& vdata); |
---|
| 83 | |
---|
| 84 | /** Returns a vertex. |
---|
| 85 | */ |
---|
| 86 | const Vector3& getVertex(size_t vertex) const; |
---|
| 87 | |
---|
| 88 | /** Sets a specific vertex of a polygon. |
---|
| 89 | @note Vertices must be coplanar. |
---|
| 90 | */ |
---|
| 91 | void setVertex(const Vector3& vdata, size_t vertexIndex); |
---|
| 92 | |
---|
| 93 | /** Removes duplicate vertices from a polygon. |
---|
| 94 | */ |
---|
| 95 | void removeDuplicates(void); |
---|
| 96 | |
---|
| 97 | /** Vertex count. |
---|
| 98 | */ |
---|
| 99 | size_t getVertexCount(void) const; |
---|
| 100 | |
---|
| 101 | /** Returns the polygon normal. |
---|
| 102 | */ |
---|
| 103 | const Vector3& getNormal(void) const; |
---|
| 104 | |
---|
| 105 | /** Deletes a specific vertex. |
---|
| 106 | */ |
---|
| 107 | void deleteVertex(size_t vertex); |
---|
| 108 | |
---|
| 109 | /** Determines if a point is inside the polygon. |
---|
| 110 | @remarks |
---|
| 111 | A point is inside a polygon if it is both on the polygon's plane, |
---|
| 112 | and within the polygon's bounds. Polygons are assumed to be convex |
---|
| 113 | and planar. |
---|
| 114 | */ |
---|
| 115 | bool isPointInside(const Vector3& point) const; |
---|
| 116 | |
---|
| 117 | /** Stores the edges of the polygon in ccw order. |
---|
| 118 | The vertices are copied so the user has to take the |
---|
| 119 | deletion into account. |
---|
| 120 | */ |
---|
| 121 | void storeEdges(EdgeMap *edgeMap) const; |
---|
| 122 | |
---|
| 123 | /** Resets the object. |
---|
| 124 | */ |
---|
| 125 | void reset(void); |
---|
| 126 | |
---|
| 127 | /** Determines if the current object is equal to the compared one. |
---|
| 128 | */ |
---|
| 129 | bool operator == (const Polygon& rhs) const; |
---|
| 130 | |
---|
| 131 | /** Determines if the current object is not equal to the compared one. |
---|
| 132 | */ |
---|
| 133 | bool operator != (const Polygon& rhs) const |
---|
| 134 | { return !( *this == rhs ); } |
---|
| 135 | |
---|
| 136 | /** Prints out the polygon data. |
---|
| 137 | */ |
---|
| 138 | _OgreExport friend std::ostream& operator<< ( std::ostream& strm, const Polygon& poly ); |
---|
| 139 | |
---|
| 140 | }; |
---|
| 141 | /** @} */ |
---|
| 142 | /** @} */ |
---|
| 143 | |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | #include "OgreHeaderSuffix.h" |
---|
| 147 | |
---|
| 148 | #endif |
---|