OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreConvexBody.h
Go to the documentation of this file.
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-2014 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 __ConvexBody_H__
30 #define __ConvexBody_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgrePolygon.h"
34 #include "OgreHeaderPrefix.h"
35 
36 
37 namespace Ogre
38 {
39 
53  {
54  public:
56 
57  protected:
59 
60  // Static 'free list' of polygons to save reallocation, shared between all bodies
62 #if OGRE_THREAD_SUPPORT
63  OGRE_STATIC_MUTEX(msFreePolygonsMutex);
64 #endif
65 
66  public:
67  ConvexBody();
68  ~ConvexBody();
69  ConvexBody( const ConvexBody& cpy );
70 
73  void define(const Frustum& frustum);
74 
77  void define(const AxisAlignedBox& aab);
78 
81  void define( const Vector3 corners[8] );
82 
86  void clip( const Frustum& frustum );
87 
91  void clip( const AxisAlignedBox& aab );
92 
95  void clip(const ConvexBody& body);
96 
99  void clip(const Plane& pl, bool keepNegative = true);
100 
107  void extend(const Vector3& pt);
108 
111  void reset( void );
112 
115  size_t getPolygonCount( void ) const;
116 
119  size_t getVertexCount( size_t poly ) const;
120 
123  const Polygon& getPolygon( size_t poly ) const;
124 
127  const Vector3& getVertex( size_t poly, size_t vertex ) const;
128 
131  const Vector3& getNormal( size_t poly );
132 
135  AxisAlignedBox getAABB( void ) const;
136 
139  bool hasClosedHull( void ) const;
140 
144  void mergePolygons( void );
145 
148  bool operator == ( const ConvexBody& rhs ) const;
149 
152  bool operator != ( const ConvexBody& rhs ) const
153  { return !( *this == rhs ); }
154 
157  _OgreExport friend std::ostream& operator<< ( std::ostream& strm, const ConvexBody& body );
158 
160  void logInfo() const;
161 
163  static void _initialisePool();
165  static void _destroyPool();
166 
167 
168  protected:
171  static Polygon* allocatePolygon();
173  static void freePolygon(Polygon* poly);
179  void insertPolygon(Polygon* pdata, size_t poly);
185  void insertPolygon(Polygon* pdata);
186 
192  void insertVertex(size_t poly, const Vector3& vdata, size_t vertex);
198  void insertVertex(size_t poly, const Vector3& vdata);
201  void deletePolygon(size_t poly);
202 
207  Polygon* unlinkPolygon(size_t poly);
208 
212  void moveDataFromBody(ConvexBody& body);
213 
216  void deleteVertex(size_t poly, size_t vertex);
217 
222  void setPolygon(Polygon* pdata, size_t poly );
223 
229  void setVertex( size_t poly, const Vector3& vdata, size_t vertex );
230 
234  Polygon::EdgeMap getSingleEdges() const;
235 
238  void storeEdgesOfPolygon(size_t poly, Polygon::EdgeMap *edgeMap) const;
239 
245  void allocateSpace(size_t numPolygons, size_t numVertices);
246 
255  bool findAndEraseEdgePair(const Vector3& vec,
256  Polygon::EdgeMap& intersectionEdges, Vector3& vNext ) const;
257 
258  };
262 }
263 
264 #include "OgreHeaderSuffix.h"
265 
266 #endif
267 
#define _OgreExport
Definition: OgrePlatform.h:255
Defines a plane in 3D space.
Definition: OgrePlane.h:61
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
Holds a solid representation of a convex body.
A 3D box aligned with the x/y/z axes.
static PolygonList msFreePolygons
The class represents a polygon in 3D space.
Definition: OgrePolygon.h:52
multimap< Vector3, Vector3 >::type EdgeMap
Definition: OgrePolygon.h:58
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:666
#define OGRE_STATIC_MUTEX(name)
vector< Polygon * >::type PolygonList
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
PolygonList mPolygons
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)