Back to index

supertuxkart  0.5+dfsg1
btHeightfieldTerrainShape.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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 HEIGHTFIELD_TERRAIN_SHAPE_H
00017 #define HEIGHTFIELD_TERRAIN_SHAPE_H
00018 
00019 #include "btConcaveShape.h"
00020 
00022 class btHeightfieldTerrainShape : public btConcaveShape
00023 {
00024 protected:
00025        btVector3     m_localAabbMin;
00026        btVector3     m_localAabbMax;
00027        
00029        int    m_heightStickWidth;
00030        int m_heightStickLength;
00031        btScalar      m_maxHeight;
00032        btScalar m_width;
00033        btScalar m_length;
00034        union
00035        {
00036               unsigned char*       m_heightfieldDataUnsignedChar;
00037               btScalar*                   m_heightfieldDataFloat;
00038               void*                m_heightfieldDataUnknown;
00039        };
00040        
00041        bool   m_useFloatData;
00042        bool   m_flipQuadEdges;
00043   bool  m_useDiamondSubdivision;
00044 
00045        int    m_upAxis;
00046        
00047        btVector3     m_localScaling;
00048 
00049        virtual btScalar     getHeightFieldValue(int x,int y) const;
00050        void          quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
00051        void          getVertex(int x,int y,btVector3& vertex) const;
00052 
00053        inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const  int* aabbMin2,const  int* aabbMax2) const
00054        {
00055               bool overlap = true;
00056               overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
00057               overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
00058               overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
00059               return overlap;
00060        }
00061 
00062 public:
00063        btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
00064 
00065        virtual ~btHeightfieldTerrainShape();
00066 
00067 
00068        void setUseDiamondSubdivision(bool useDiamondSubdivision=true) { m_useDiamondSubdivision = useDiamondSubdivision;}
00069 
00070        virtual int   getShapeType() const
00071        {
00072               return TERRAIN_SHAPE_PROXYTYPE;
00073        }
00074 
00075        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00076 
00077        virtual void  processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
00078 
00079        virtual void  calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00080 
00081        virtual void  setLocalScaling(const btVector3& scaling);
00082        
00083        virtual const btVector3& getLocalScaling() const;
00084        
00085        //debugging
00086        virtual const char*  getName()const {return "HEIGHTFIELD";}
00087 
00088 };
00089 
00090 #endif //HEIGHTFIELD_TERRAIN_SHAPE_H