btTriangleIndexVertexArray.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
00017 #define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
00018 
00019 #include "btStridingMeshInterface.h"
00020 #include "LinearMath/btAlignedObjectArray.h"
00021 #include "LinearMath/btScalar.h"
00022 
00023 
00026 ATTRIBUTE_ALIGNED16( struct)    btIndexedMesh
00027 {
00028         BT_DECLARE_ALIGNED_ALLOCATOR();
00029 
00030    int                     m_numTriangles;
00031    const unsigned char *   m_triangleIndexBase;
00032    // Size in byte of the indices for one triangle (3*sizeof(index_type) if the indices are tightly packed)
00033    int                     m_triangleIndexStride;
00034    int                     m_numVertices;
00035    const unsigned char *   m_vertexBase;
00036    // Size of a vertex, in bytes
00037    int                     m_vertexStride;
00038 
00039    // The index type is set when adding an indexed mesh to the
00040    // btTriangleIndexVertexArray, do not set it manually
00041    PHY_ScalarType m_indexType;
00042 
00043    // The vertex type has a default type similar to Bullet's precision mode (float or double)
00044    // but can be set manually if you for example run Bullet with double precision but have
00045    // mesh data in single precision..
00046    PHY_ScalarType m_vertexType;
00047 
00048 
00049    btIndexedMesh()
00050            :m_indexType(PHY_INTEGER),
00051 #ifdef BT_USE_DOUBLE_PRECISION
00052       m_vertexType(PHY_DOUBLE)
00053 #else // BT_USE_DOUBLE_PRECISION
00054       m_vertexType(PHY_FLOAT)
00055 #endif // BT_USE_DOUBLE_PRECISION
00056       {
00057       }
00058 }
00059 ;
00060 
00061 
00062 typedef btAlignedObjectArray<btIndexedMesh>     IndexedMeshArray;
00063 
00068 ATTRIBUTE_ALIGNED16( class) btTriangleIndexVertexArray : public btStridingMeshInterface
00069 {
00070 protected:
00071         IndexedMeshArray        m_indexedMeshes;
00072         int m_pad[2];
00073         mutable int m_hasAabb; // using int instead of bool to maintain alignment
00074         mutable btVector3 m_aabbMin;
00075         mutable btVector3 m_aabbMax;
00076 
00077 public:
00078 
00079         BT_DECLARE_ALIGNED_ALLOCATOR();
00080 
00081         btTriangleIndexVertexArray() : m_hasAabb(0)
00082         {
00083         }
00084 
00085         virtual ~btTriangleIndexVertexArray();
00086 
00087         //just to be backwards compatible
00088         btTriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride);
00089         
00090         void    addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER)
00091         {
00092                 m_indexedMeshes.push_back(mesh);
00093                 m_indexedMeshes[m_indexedMeshes.size()-1].m_indexType = indexType;
00094         }
00095         
00096         
00097         virtual void    getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
00098 
00099         virtual void    getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
00100 
00103         virtual void    unLockVertexBase(int subpart) {(void)subpart;}
00104 
00105         virtual void    unLockReadOnlyVertexBase(int subpart) const {(void)subpart;}
00106 
00109         virtual int             getNumSubParts() const { 
00110                 return (int)m_indexedMeshes.size();
00111         }
00112 
00113         IndexedMeshArray&       getIndexedMeshArray()
00114         {
00115                 return m_indexedMeshes;
00116         }
00117 
00118         const IndexedMeshArray& getIndexedMeshArray() const
00119         {
00120                 return m_indexedMeshes;
00121         }
00122 
00123         virtual void    preallocateVertices(int numverts){(void) numverts;}
00124         virtual void    preallocateIndices(int numindices){(void) numindices;}
00125 
00126         virtual bool    hasPremadeAabb() const;
00127         virtual void    setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const;
00128         virtual void    getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const;
00129 
00130 }
00131 ;
00132 
00133 #endif //BT_TRIANGLE_INDEX_VERTEX_ARRAY_H