Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h @ 1963

Last change on this file since 1963 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef HEIGHTFIELD_TERRAIN_SHAPE_H
17#define HEIGHTFIELD_TERRAIN_SHAPE_H
18
19#include "btConcaveShape.h"
20
21///The btHeightfieldTerrainShape simulates a 2D heightfield terrain collision shape. You can also use the more general btBvhTriangleMeshShape instead.
22///An example implementation of btHeightfieldTerrainShape is provided in Demos/VehicleDemo/VehicleDemo.cpp
23class btHeightfieldTerrainShape : public btConcaveShape
24{
25protected:
26        btVector3       m_localAabbMin;
27        btVector3       m_localAabbMax;
28       
29        ///terrain data
30        int     m_heightStickWidth;
31        int m_heightStickLength;
32        btScalar        m_maxHeight;
33        btScalar m_width;
34        btScalar m_length;
35        union
36        {
37                unsigned char*  m_heightfieldDataUnsignedChar;
38                btScalar*                       m_heightfieldDataFloat;
39                void*                   m_heightfieldDataUnknown;
40        };
41       
42        bool    m_useFloatData;
43        bool    m_flipQuadEdges;
44  bool  m_useDiamondSubdivision;
45
46        int     m_upAxis;
47       
48        btVector3       m_localScaling;
49
50        virtual btScalar        getHeightFieldValue(int x,int y) const;
51        void            quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
52        void            getVertex(int x,int y,btVector3& vertex) const;
53
54        inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const  int* aabbMin2,const  int* aabbMax2) const
55        {
56                bool overlap = true;
57                overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
58                overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
59                overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
60                return overlap;
61        }
62
63public:
64        btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
65
66        virtual ~btHeightfieldTerrainShape();
67
68
69        void setUseDiamondSubdivision(bool useDiamondSubdivision=true) { m_useDiamondSubdivision = useDiamondSubdivision;}
70
71
72        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
73
74        virtual void    processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
75
76        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
77
78        virtual void    setLocalScaling(const btVector3& scaling);
79       
80        virtual const btVector3& getLocalScaling() const;
81       
82        //debugging
83        virtual const char*     getName()const {return "HEIGHTFIELD";}
84
85};
86
87#endif //HEIGHTFIELD_TERRAIN_SHAPE_H
Note: See TracBrowser for help on using the repository browser.