Bullet Collision Detection & Physics Library
btHeightfieldTerrainShape.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_HEIGHTFIELD_TERRAIN_SHAPE_H
17 #define BT_HEIGHTFIELD_TERRAIN_SHAPE_H
18 
19 #include "btConcaveShape.h"
21 
23 
74 {
75 public:
76  struct Range
77  {
80  };
81 
82 protected:
86 
95  union {
96  const unsigned char* m_heightfieldDataUnsignedChar;
97  const short* m_heightfieldDataShort;
100  };
101 
107  int m_upAxis;
108 
110 
111  // Accelerator
116 
119 
121 
122  virtual btScalar getRawHeightFieldValue(int x, int y) const;
123  void quantizeWithClamp(int* out, const btVector3& point, int isMax) const;
124 
126 
130  void initialize(int heightStickWidth, int heightStickLength,
131  const void* heightfieldData, btScalar heightScale,
132  btScalar minHeight, btScalar maxHeight, int upAxis,
133  PHY_ScalarType heightDataType, bool flipQuadEdges);
134 
135 public:
137 
139 
144  btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,
145  const void* heightfieldData, btScalar heightScale,
146  btScalar minHeight, btScalar maxHeight,
147  int upAxis, PHY_ScalarType heightDataType,
148  bool flipQuadEdges);
149 
151 
157  btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength, const void* heightfieldData, btScalar maxHeight, int upAxis, bool useFloatData, bool flipQuadEdges);
158 
159  virtual ~btHeightfieldTerrainShape();
160 
161  void setUseDiamondSubdivision(bool useDiamondSubdivision = true) { m_useDiamondSubdivision = useDiamondSubdivision; }
162 
164  void setUseZigzagSubdivision(bool useZigzagSubdivision = true) { m_useZigzagSubdivision = useZigzagSubdivision; }
165 
166  void setFlipTriangleWinding(bool flipTriangleWinding)
167  {
168  m_flipTriangleWinding = flipTriangleWinding;
169  }
170  virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
171 
172  virtual void processAllTriangles(btTriangleCallback * callback, const btVector3& aabbMin, const btVector3& aabbMax) const;
173 
174  virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
175 
176  virtual void setLocalScaling(const btVector3& scaling);
177 
178  virtual const btVector3& getLocalScaling() const;
179 
180  void getVertex(int x, int y, btVector3& vertex) const;
181 
182  void performRaycast(btTriangleCallback * callback, const btVector3& raySource, const btVector3& rayTarget) const;
183 
184  void buildAccelerator(int chunkSize = 16);
185  void clearAccelerator();
186 
187  int getUpAxis() const
188  {
189  return m_upAxis;
190  }
191  //debugging
192  virtual const char* getName() const { return "HEIGHTFIELD"; }
193 
194 
195  void setUserIndex2(int index)
196  {
197  m_userIndex2 = index;
198  }
199  int getUserIndex2() const
200  {
201  return m_userIndex2;
202  }
204  {
205  m_userValue3 = value;
206  }
208  {
209  return m_userValue3;
210  }
211  const struct btTriangleInfoMap* getTriangleInfoMap() const
212  {
213  return m_triangleInfoMap;
214  }
216  {
217  return m_triangleInfoMap;
218  }
220  {
221  m_triangleInfoMap = map;
222  }
223  const unsigned char* getHeightfieldRawData() const
224  {
225  return m_heightfieldDataUnsignedChar;
226  }
227 };
228 
229 #endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H
btHeightfieldTerrainShape::m_localAabbMin
btVector3 m_localAabbMin
Definition: btHeightfieldTerrainShape.h:83
btHeightfieldTerrainShape::m_heightStickLength
int m_heightStickLength
Definition: btHeightfieldTerrainShape.h:89
btHeightfieldTerrainShape::setUseZigzagSubdivision
void setUseZigzagSubdivision(bool useZigzagSubdivision=true)
could help compatibility with Ogre heightfields. See https://code.google.com/p/bullet/issues/detail?...
Definition: btHeightfieldTerrainShape.h:164
btHeightfieldTerrainShape::m_heightDataType
PHY_ScalarType m_heightDataType
Definition: btHeightfieldTerrainShape.h:102
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btHeightfieldTerrainShape::getTriangleInfoMap
struct btTriangleInfoMap * getTriangleInfoMap()
Definition: btHeightfieldTerrainShape.h:215
btConcaveShape
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
Definition: btConcaveShape.h:37
btHeightfieldTerrainShape::m_vboundsGridLength
int m_vboundsGridLength
Definition: btHeightfieldTerrainShape.h:114
btHeightfieldTerrainShape::getUserIndex2
int getUserIndex2() const
Definition: btHeightfieldTerrainShape.h:199
btHeightfieldTerrainShape::m_userIndex2
int m_userIndex2
Definition: btHeightfieldTerrainShape.h:117
btHeightfieldTerrainShape::setTriangleInfoMap
void setTriangleInfoMap(btTriangleInfoMap *map)
Definition: btHeightfieldTerrainShape.h:219
btConcaveShape.h
btHeightfieldTerrainShape::getUpAxis
int getUpAxis() const
Definition: btHeightfieldTerrainShape.h:187
btHeightfieldTerrainShape
btHeightfieldTerrainShape simulates a 2D heightfield terrain
Definition: btHeightfieldTerrainShape.h:72
btHeightfieldTerrainShape::Range
Definition: btHeightfieldTerrainShape.h:76
btHeightfieldTerrainShape::m_localAabbMax
btVector3 m_localAabbMax
Definition: btHeightfieldTerrainShape.h:84
btHeightfieldTerrainShape::m_useDiamondSubdivision
bool m_useDiamondSubdivision
Definition: btHeightfieldTerrainShape.h:104
btHeightfieldTerrainShape::m_width
btScalar m_width
Definition: btHeightfieldTerrainShape.h:92
btHeightfieldTerrainShape::Range::min
btScalar min
Definition: btHeightfieldTerrainShape.h:78
btHeightfieldTerrainShape::m_heightfieldDataFloat
const btScalar * m_heightfieldDataFloat
Definition: btHeightfieldTerrainShape.h:98
btHeightfieldTerrainShape::m_triangleInfoMap
struct btTriangleInfoMap * m_triangleInfoMap
Definition: btHeightfieldTerrainShape.h:120
btHeightfieldTerrainShape::setUseDiamondSubdivision
void setUseDiamondSubdivision(bool useDiamondSubdivision=true)
Definition: btHeightfieldTerrainShape.h:161
btHeightfieldTerrainShape::m_upAxis
int m_upAxis
Definition: btHeightfieldTerrainShape.h:107
btHeightfieldTerrainShape::m_heightfieldDataUnknown
const void * m_heightfieldDataUnknown
Definition: btHeightfieldTerrainShape.h:99
btHeightfieldTerrainShape::getHeightfieldRawData
const unsigned char * getHeightfieldRawData() const
Definition: btHeightfieldTerrainShape.h:223
btTriangleInfoMap
The btTriangleInfoMap stores edge angle information for some triangles. You can compute this informat...
Definition: btTriangleInfoMap.h:53
PHY_ScalarType
PHY_ScalarType
PHY_ScalarType enumerates possible scalar types.
Definition: btConcaveShape.h:25
btHeightfieldTerrainShape::getUserValue3
btScalar getUserValue3() const
Definition: btHeightfieldTerrainShape.h:207
btHeightfieldTerrainShape::m_flipQuadEdges
bool m_flipQuadEdges
Definition: btHeightfieldTerrainShape.h:103
btHeightfieldTerrainShape::setFlipTriangleWinding
void setFlipTriangleWinding(bool flipTriangleWinding)
Definition: btHeightfieldTerrainShape.h:166
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition: btTriangleCallback.h:23
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:28
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:425
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
btHeightfieldTerrainShape::m_length
btScalar m_length
Definition: btHeightfieldTerrainShape.h:93
btHeightfieldTerrainShape::Range::max
btScalar max
Definition: btHeightfieldTerrainShape.h:79
btHeightfieldTerrainShape::m_minHeight
btScalar m_minHeight
Definition: btHeightfieldTerrainShape.h:90
btHeightfieldTerrainShape::m_useZigzagSubdivision
bool m_useZigzagSubdivision
Definition: btHeightfieldTerrainShape.h:105
btHeightfieldTerrainShape::m_heightfieldDataUnsignedChar
const unsigned char * m_heightfieldDataUnsignedChar
Definition: btHeightfieldTerrainShape.h:96
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:99
btHeightfieldTerrainShape::m_heightStickWidth
int m_heightStickWidth
terrain data
Definition: btHeightfieldTerrainShape.h:88
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:45
btHeightfieldTerrainShape::m_vboundsChunkSize
int m_vboundsChunkSize
Definition: btHeightfieldTerrainShape.h:115
btHeightfieldTerrainShape::setUserValue3
void setUserValue3(btScalar value)
Definition: btHeightfieldTerrainShape.h:203
btHeightfieldTerrainShape::m_vboundsGrid
btAlignedObjectArray< Range > m_vboundsGrid
Definition: btHeightfieldTerrainShape.h:112
btHeightfieldTerrainShape::m_heightfieldDataShort
const short * m_heightfieldDataShort
Definition: btHeightfieldTerrainShape.h:97
btHeightfieldTerrainShape::m_vboundsGridWidth
int m_vboundsGridWidth
Definition: btHeightfieldTerrainShape.h:113
btAlignedObjectArray.h
btHeightfieldTerrainShape::m_flipTriangleWinding
bool m_flipTriangleWinding
Definition: btHeightfieldTerrainShape.h:106
btHeightfieldTerrainShape::m_localOrigin
btVector3 m_localOrigin
Definition: btHeightfieldTerrainShape.h:85
btHeightfieldTerrainShape::m_localScaling
btVector3 m_localScaling
Definition: btHeightfieldTerrainShape.h:109
btHeightfieldTerrainShape::getTriangleInfoMap
const struct btTriangleInfoMap * getTriangleInfoMap() const
Definition: btHeightfieldTerrainShape.h:211
btHeightfieldTerrainShape::m_maxHeight
btScalar m_maxHeight
Definition: btHeightfieldTerrainShape.h:91
btHeightfieldTerrainShape::setUserIndex2
void setUserIndex2(int index)
Definition: btHeightfieldTerrainShape.h:195
btHeightfieldTerrainShape::getName
virtual const char * getName() const
Definition: btHeightfieldTerrainShape.h:192
btHeightfieldTerrainShape::m_userValue3
btScalar m_userValue3
Definition: btHeightfieldTerrainShape.h:118
btHeightfieldTerrainShape::m_heightScale
btScalar m_heightScale
Definition: btHeightfieldTerrainShape.h:94