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-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 __ConvexBody_H__
30 #define __ConvexBody_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgrePolygon.h"
34 #if OGRE_THREAD_SUPPORT
36 #endif
37 #include "OgreHeaderPrefix.h"
38 
39 
40 namespace Ogre
41 {
42 
56  {
57  public:
59 
60  protected:
62 
63  // Static 'free list' of polygons to save reallocation, shared between all bodies
65 #if OGRE_THREAD_SUPPORT
66  OGRE_STATIC_MUTEX(msFreePolygonsMutex);
67 #endif
68 
69  public:
72  ConvexBody( const ConvexBody& cpy );
73 
76  void define(const Frustum& frustum);
77 
80  void define(const AxisAlignedBox& aab);
81 
85  void clip( const Frustum& frustum );
86 
90  void clip( const AxisAlignedBox& aab );
91 
94  void clip(const ConvexBody& body);
95 
98  void clip(const Plane& pl, bool keepNegative = true);
99 
106  void extend(const Vector3& pt);
107 
110  void reset( void );
111 
114  size_t getPolygonCount( void ) const;
115 
118  size_t getVertexCount( size_t poly ) const;
119 
122  const Polygon& getPolygon( size_t poly ) const;
123 
126  const Vector3& getVertex( size_t poly, size_t vertex ) const;
127 
130  const Vector3& getNormal( size_t poly );
131 
134  AxisAlignedBox getAABB( void ) const;
135 
138  bool hasClosedHull( void ) const;
139 
143  void mergePolygons( void );
144 
147  bool operator == ( const ConvexBody& rhs ) const;
148 
151  bool operator != ( const ConvexBody& rhs ) const
152  { return !( *this == rhs ); }
153 
156  _OgreExport friend std::ostream& operator<< ( std::ostream& strm, const ConvexBody& body );
157 
159  void logInfo() const;
160 
162  static void _initialisePool();
164  static void _destroyPool();
165 
166 
167  protected:
172  static void freePolygon(Polygon* poly);
178  void insertPolygon(Polygon* pdata, size_t poly);
184  void insertPolygon(Polygon* pdata);
185 
191  void insertVertex(size_t poly, const Vector3& vdata, size_t vertex);
197  void insertVertex(size_t poly, const Vector3& vdata);
200  void deletePolygon(size_t poly);
201 
206  Polygon* unlinkPolygon(size_t poly);
207 
212 
215  void deleteVertex(size_t poly, size_t vertex);
216 
221  void setPolygon(Polygon* pdata, size_t poly );
222 
228  void setVertex( size_t poly, const Vector3& vdata, size_t vertex );
229 
234 
237  void storeEdgesOfPolygon(size_t poly, Polygon::EdgeMap *edgeMap) const;
238 
244  void allocateSpace(size_t numPolygons, size_t numVertices);
245 
254  bool findAndEraseEdgePair(const Vector3& vec,
255  Polygon::EdgeMap& intersectionEdges, Vector3& vNext ) const;
256 
257  };
261 }
262 
263 #include "OgreHeaderSuffix.h"
264 
265 #endif
266 
OgreHeaderSuffix.h
Ogre::ConvexBody::logInfo
void logInfo() const
Log details of this body.
Ogre::ConvexBody::deleteVertex
void deleteVertex(size_t poly, size_t vertex)
Deletes a specific vertex of a specific polygon.
Ogre::ConvexBody::define
void define(const AxisAlignedBox &aab)
Build a new polygon representation from an AAB.
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::Plane
Defines a plane in 3D space.
Definition: OgrePlane.h:62
Ogre::ConvexBody::mergePolygons
void mergePolygons(void)
Merges all neighboring polygons into one single polygon if they are lay in the same plane.
OgrePolygon.h
Ogre::ConvexBody::getPolygonCount
size_t getPolygonCount(void) const
Returns the current number of polygons.
Ogre::ConvexBody::getVertex
const Vector3 & getVertex(size_t poly, size_t vertex) const
Returns a specific vertex of a polygon.
Ogre::Polygon::EdgeMap
multimap< Vector3, Vector3 >::type EdgeMap
Definition: OgrePolygon.h:58
Ogre::ConvexBody::extend
void extend(const Vector3 &pt)
Extends the existing body to incorporate the passed in point as a convex hull.
Ogre::ConvexBody::define
void define(const Frustum &frustum)
Build a new polygon representation from a frustum.
Ogre::ConvexBody::getSingleEdges
Polygon::EdgeMap getSingleEdges() const
Returns the single edges in an EdgeMap (= edges where one side is a vertex and the other is empty spa...
Ogre::ConvexBody::msFreePolygons
static PolygonList msFreePolygons
Definition: OgreConvexBody.h:64
Ogre::ConvexBody::clip
void clip(const AxisAlignedBox &aab)
Clips the body with an AAB.
Ogre::ConvexBody::insertPolygon
void insertPolygon(Polygon *pdata, size_t poly)
Inserts a polygon at a particular point in the body.
Ogre::ConvexBody::clip
void clip(const Plane &pl, bool keepNegative=true)
Clips the object by the positive half space of a plane.
Ogre::ConvexBody::moveDataFromBody
void moveDataFromBody(ConvexBody &body)
Moves all polygons from the parameter body to this instance.
Ogre::ConvexBody::insertVertex
void insertVertex(size_t poly, const Vector3 &vdata, size_t vertex)
Inserts a vertex for a polygon at a particular point.
Ogre::ConvexBody::getVertexCount
size_t getVertexCount(size_t poly) const
Returns the number of vertices for a polygon.
Ogre::ConvexBody::allocatePolygon
static Polygon * allocatePolygon()
Get a new polygon from the pool.
Ogre::operator!=
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
Definition: OgreMemorySTLAllocator.h:202
Ogre::ConvexBody::hasClosedHull
bool hasClosedHull(void) const
Checks if the body has a closed hull.
Ogre::ConvexBody::deletePolygon
void deletePolygon(size_t poly)
Deletes a specific polygon.
Ogre::ConvexBody::unlinkPolygon
Polygon * unlinkPolygon(size_t poly)
Removes a specific polygon from the body without deleting it.
Ogre::ConvexBody::freePolygon
static void freePolygon(Polygon *poly)
Release a polygon back tot he pool.
Ogre::operator<<
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
OgreHeaderPrefix.h
Ogre::ConvexBody::mPolygons
PolygonList mPolygons
Definition: OgreConvexBody.h:61
OgrePrerequisites.h
OGRE_STATIC_MUTEX
#define OGRE_STATIC_MUTEX(name)
Definition: OgreThreadDefinesBoost.h:48
Ogre::ConvexBody
Holds a solid representation of a convex body.
Definition: OgreConvexBody.h:56
OgreThreadHeaders.h
Ogre::ConvexBody::setVertex
void setVertex(size_t poly, const Vector3 &vdata, size_t vertex)
Replace a specific vertex of a polygon.
Ogre::ConvexBody::getAABB
AxisAlignedBox getAABB(void) const
Returns an AABB representation.
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:55
Ogre::ConvexBody::PolygonList
vector< Polygon * >::type PolygonList
Definition: OgreConvexBody.h:58
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::ConvexBody::setPolygon
void setPolygon(Polygon *pdata, size_t poly)
Replace a polygon at a particular index.
Ogre::ConvexBody::reset
void reset(void)
Resets the object.
Ogre::ConvexBody::getNormal
const Vector3 & getNormal(size_t poly)
Returns the normal of a specified polygon.
Ogre::Frustum
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:86
Ogre::ConvexBody::clip
void clip(const Frustum &frustum)
Clips the body with a frustum.
Ogre::ConvexBody::clip
void clip(const ConvexBody &body)
Clips the body with another body.
Ogre::ConvexBody::getPolygon
const Polygon & getPolygon(size_t poly) const
Returns a polygon.
Ogre::ConvexBody::insertPolygon
void insertPolygon(Polygon *pdata)
Inserts a polygon at the end.
Ogre::ConvexBody::_destroyPool
static void _destroyPool()
Tear down the internal polygon pool used to minimise allocations.
Ogre::ConvexBody::~ConvexBody
~ConvexBody()
Ogre::ConvexBody::ConvexBody
ConvexBody(const ConvexBody &cpy)
Ogre::ConvexBody::allocateSpace
void allocateSpace(size_t numPolygons, size_t numVertices)
Allocates space for an specified amount of polygons with each of them having a specified number of ve...
Ogre::ConvexBody::_initialisePool
static void _initialisePool()
Initialise the internal polygon pool used to minimise allocations.
Ogre::operator==
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
Definition: OgreMemorySTLAllocator.h:184
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::ConvexBody::insertVertex
void insertVertex(size_t poly, const Vector3 &vdata)
Inserts a vertex for a polygon at the end.
Ogre::ConvexBody::findAndEraseEdgePair
bool findAndEraseEdgePair(const Vector3 &vec, Polygon::EdgeMap &intersectionEdges, Vector3 &vNext) const
Searches for a pair (an edge) in the intersectionList with an entry that equals vec,...
Ogre::ConvexBody::storeEdgesOfPolygon
void storeEdgesOfPolygon(size_t poly, Polygon::EdgeMap *edgeMap) const
Stores the edges of a specific polygon in a passed in structure.
Ogre::Polygon
The class represents a polygon in 3D space.
Definition: OgrePolygon.h:53
Ogre::ConvexBody::ConvexBody
ConvexBody()
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:52

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.