OgreConvexBody.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 Copyright (c) 2006 Matthias Fink, netAllied GmbH <matthias.fink@web.de>                             
00009 
00010 Permission is hereby granted, free of charge, to any person obtaining a copy
00011 of this software and associated documentation files (the "Software"), to deal
00012 in the Software without restriction, including without limitation the rights
00013 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00014 copies of the Software, and to permit persons to whom the Software is
00015 furnished to do so, subject to the following conditions:
00016 
00017 The above copyright notice and this permission notice shall be included in
00018 all copies or substantial portions of the Software.
00019 
00020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00023 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00026 THE SOFTWARE.
00027 -----------------------------------------------------------------------------
00028 */
00029 #ifndef __ConvexBody_H__
00030 #define __ConvexBody_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 #include "OgrePolygon.h"
00034 
00035 
00036 namespace Ogre
00037 {
00038 
00051     class _OgreExport ConvexBody
00052     {
00053     public:
00054         typedef vector< Polygon* >::type    PolygonList;
00055 
00056     protected:
00057         PolygonList mPolygons;
00058 
00059         // Static 'free list' of polygons to save reallocation, shared between all bodies
00060         static PolygonList msFreePolygons;
00061 #if OGRE_THREAD_SUPPORT
00062         OGRE_STATIC_MUTEX(msFreePolygonsMutex)
00063 #endif
00064 
00065     public:
00066         ConvexBody();
00067         ~ConvexBody();
00068         ConvexBody( const ConvexBody& cpy );
00069 
00072         void define(const Frustum& frustum);
00073 
00076         void define(const AxisAlignedBox& aab);
00077 
00081         void clip( const Frustum& frustum );
00082 
00086         void clip( const AxisAlignedBox& aab );
00087 
00090         void clip(const ConvexBody& body);
00091 
00094         void clip(const Plane& pl, bool keepNegative = true);
00095 
00102         void extend(const Vector3& pt);
00103 
00106         void reset( void );
00107 
00110         size_t getPolygonCount( void ) const;
00111 
00114         size_t getVertexCount( size_t poly ) const;
00115 
00118         const Polygon& getPolygon( size_t poly ) const;
00119 
00122         const Vector3& getVertex( size_t poly, size_t vertex ) const;
00123 
00126         const Vector3& getNormal( size_t poly );
00127 
00130         AxisAlignedBox getAABB( void ) const;
00131 
00134         bool hasClosedHull( void ) const;
00135 
00139         void mergePolygons( void );
00140 
00143         bool operator == ( const ConvexBody& rhs ) const;
00144 
00147         bool operator != ( const ConvexBody& rhs ) const
00148         { return !( *this == rhs ); }
00149 
00152         _OgreExport friend std::ostream& operator<< ( std::ostream& strm, const ConvexBody& body );
00153 
00155         void logInfo() const;
00156 
00158         static void _initialisePool();
00160         static void _destroyPool();
00161 
00162 
00163     protected:
00166         static Polygon* allocatePolygon();
00168         static void freePolygon(Polygon* poly);
00174         void insertPolygon(Polygon* pdata, size_t poly);
00180         void insertPolygon(Polygon* pdata);
00181 
00187         void insertVertex(size_t poly, const Vector3& vdata, size_t vertex);
00193         void insertVertex(size_t poly, const Vector3& vdata);
00196         void deletePolygon(size_t poly);
00197 
00202         Polygon* unlinkPolygon(size_t poly);
00203 
00207         void moveDataFromBody(ConvexBody& body);
00208 
00211         void deleteVertex(size_t poly, size_t vertex);
00212 
00217         void setPolygon(Polygon* pdata, size_t poly );
00218 
00224         void setVertex( size_t poly, const Vector3& vdata, size_t vertex );
00225 
00229         Polygon::EdgeMap getSingleEdges() const;
00230 
00233         void storeEdgesOfPolygon(size_t poly, Polygon::EdgeMap *edgeMap) const;
00234             
00240         void allocateSpace(size_t numPolygons, size_t numVertices);
00241 
00250         bool findAndEraseEdgePair(const Vector3& vec, 
00251             Polygon::EdgeMap& intersectionEdges, Vector3& vNext ) const;
00252 
00253     };
00257 }
00258 
00259 #endif 
00260 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:23 2012