OgreConvexBody.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8Copyright (c) 2006 Matthias Fink, netAllied GmbH <matthias.fink@web.de>
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE 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
40namespace 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
255 Polygon::EdgeMap& intersectionEdges, Vector3& vNext ) const;
256
257 };
261}
262
263#include "OgreHeaderSuffix.h"
264
265#endif
266
#define _OgreExport
Definition: OgrePlatform.h:257
#define OGRE_STATIC_MUTEX(name)
A 3D box aligned with the x/y/z axes.
Holds a solid representation of a convex body.
static void _destroyPool()
Tear down the internal polygon pool used to minimise allocations.
void setVertex(size_t poly, const Vector3 &vdata, size_t vertex)
Replace a specific vertex of a polygon.
void clip(const ConvexBody &body)
Clips the body with another body.
void reset(void)
Resets the object.
static void freePolygon(Polygon *poly)
Release a polygon back tot he pool.
void insertVertex(size_t poly, const Vector3 &vdata)
Inserts a vertex for a polygon at the end.
void setPolygon(Polygon *pdata, size_t poly)
Replace a polygon at a particular index.
Polygon * unlinkPolygon(size_t poly)
Removes a specific polygon from the body without deleting it.
Polygon::EdgeMap getSingleEdges() const
Returns the single edges in an EdgeMap (= edges where one side is a vertex and the other is empty spa...
PolygonList mPolygons
void mergePolygons(void)
Merges all neighboring polygons into one single polygon if they are lay in the same plane.
static void _initialisePool()
Initialise the internal polygon pool used to minimise allocations.
void insertPolygon(Polygon *pdata)
Inserts a polygon at the end.
static Polygon * allocatePolygon()
Get a new polygon from the pool.
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...
size_t getPolygonCount(void) const
Returns the current number of polygons.
const Polygon & getPolygon(size_t poly) const
Returns a polygon.
void deleteVertex(size_t poly, size_t vertex)
Deletes a specific vertex of a specific polygon.
static PolygonList msFreePolygons
AxisAlignedBox getAABB(void) const
Returns an AABB representation.
void deletePolygon(size_t poly)
Deletes a specific polygon.
void insertPolygon(Polygon *pdata, size_t poly)
Inserts a polygon at a particular point in the body.
void define(const Frustum &frustum)
Build a new polygon representation from a frustum.
void insertVertex(size_t poly, const Vector3 &vdata, size_t vertex)
Inserts a vertex for a polygon at a particular point.
void logInfo() const
Log details of this body.
bool hasClosedHull(void) const
Checks if the body has a closed hull.
void extend(const Vector3 &pt)
Extends the existing body to incorporate the passed in point as a convex hull.
void clip(const Plane &pl, bool keepNegative=true)
Clips the object by the positive half space of a plane.
void moveDataFromBody(ConvexBody &body)
Moves all polygons from the parameter body to this instance.
void clip(const AxisAlignedBox &aab)
Clips the body with an AAB.
vector< Polygon * >::type PolygonList
size_t getVertexCount(size_t poly) const
Returns the number of vertices for a polygon.
const Vector3 & getNormal(size_t poly)
Returns the normal of a specified polygon.
const Vector3 & getVertex(size_t poly, size_t vertex) const
Returns a specific vertex of a polygon.
ConvexBody(const ConvexBody &cpy)
void storeEdgesOfPolygon(size_t poly, Polygon::EdgeMap *edgeMap) const
Stores the edges of a specific polygon in a passed in structure.
void define(const AxisAlignedBox &aab)
Build a new polygon representation from an AAB.
void clip(const Frustum &frustum)
Clips the body with a frustum.
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,...
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:86
Defines a plane in 3D space.
Definition: OgrePlane.h:62
The class represents a polygon in 3D space.
Definition: OgrePolygon.h:53
multimap< Vector3, Vector3 >::type EdgeMap
Definition: OgrePolygon.h:58
Standard 3-dimensional vector.
Definition: OgreVector3.h:52
std::ostream & operator<<(std::ostream &o, const TRect< T > &r)
Definition: OgreCommon.h:636
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator,...

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