btHeightfieldTerrainShape.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_HEIGHTFIELD_TERRAIN_SHAPE_H
00017 #define BT_HEIGHTFIELD_TERRAIN_SHAPE_H
00018 
00019 #include "btConcaveShape.h"
00020 
00022 
00071 ATTRIBUTE_ALIGNED16(class) btHeightfieldTerrainShape : public btConcaveShape
00072 {
00073 protected:
00074         btVector3       m_localAabbMin;
00075         btVector3       m_localAabbMax;
00076         btVector3       m_localOrigin;
00077 
00079         int     m_heightStickWidth;
00080         int m_heightStickLength;
00081         btScalar        m_minHeight;
00082         btScalar        m_maxHeight;
00083         btScalar m_width;
00084         btScalar m_length;
00085         btScalar m_heightScale;
00086         union
00087         {
00088                 const unsigned char*    m_heightfieldDataUnsignedChar;
00089                 const short*            m_heightfieldDataShort;
00090                 const btScalar*                 m_heightfieldDataFloat;
00091                 const void*     m_heightfieldDataUnknown;
00092         };
00093 
00094         PHY_ScalarType  m_heightDataType;       
00095         bool    m_flipQuadEdges;
00096         bool  m_useDiamondSubdivision;
00097         bool m_useZigzagSubdivision;
00098 
00099         int     m_upAxis;
00100         
00101         btVector3       m_localScaling;
00102 
00103         virtual btScalar        getRawHeightFieldValue(int x,int y) const;
00104         void            quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
00105         void            getVertex(int x,int y,btVector3& vertex) const;
00106 
00107 
00108 
00110 
00114         void initialize(int heightStickWidth, int heightStickLength,
00115                         const void* heightfieldData, btScalar heightScale,
00116                         btScalar minHeight, btScalar maxHeight, int upAxis,
00117                         PHY_ScalarType heightDataType, bool flipQuadEdges);
00118 
00119 public:
00120         
00121         BT_DECLARE_ALIGNED_ALLOCATOR();
00122         
00124 
00129         btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,
00130                                   const void* heightfieldData, btScalar heightScale,
00131                                   btScalar minHeight, btScalar maxHeight,
00132                                   int upAxis, PHY_ScalarType heightDataType,
00133                                   bool flipQuadEdges);
00134 
00136 
00142         btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,const void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
00143 
00144         virtual ~btHeightfieldTerrainShape();
00145 
00146 
00147         void setUseDiamondSubdivision(bool useDiamondSubdivision=true) { m_useDiamondSubdivision = useDiamondSubdivision;}
00148 
00150         void setUseZigzagSubdivision(bool useZigzagSubdivision=true) { m_useZigzagSubdivision = useZigzagSubdivision;}
00151 
00152         virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00153 
00154         virtual void    processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
00155 
00156         virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00157 
00158         virtual void    setLocalScaling(const btVector3& scaling);
00159         
00160         virtual const btVector3& getLocalScaling() const;
00161         
00162         //debugging
00163         virtual const char*     getName()const {return "HEIGHTFIELD";}
00164 
00165 };
00166 
00167 #endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H