Bullet Collision Detection & Physics Library: btHeightfieldTerrainShape.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btHeightfieldTerrainShape.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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 BT_HEIGHTFIELD_TERRAIN_SHAPE_H
17#define BT_HEIGHTFIELD_TERRAIN_SHAPE_H
18
19#include "btConcaveShape.h"
20#include "LinearMath/btAlignedObjectArray.h"
21
23
70 ATTRIBUTE_ALIGNED16(class)
71 btHeightfieldTerrainShape : public btConcaveShape
72{
73public:
74 struct Range
75 {
76 Range() {}
77 Range(btScalar min, btScalar max) : min(min), max(max) {}
78
79 bool overlaps(const Range& other) const
80 {
81 return !(min > other.max || max < other.min);
82 }
83
84 btScalar min;
85 btScalar max;
86 };
87
88protected:
89 btVector3 m_localAabbMin;
90 btVector3 m_localAabbMax;
91 btVector3 m_localOrigin;
92
94 int m_heightStickWidth;
95 int m_heightStickLength;
96 btScalar m_minHeight;
97 btScalar m_maxHeight;
98 btScalar m_width;
99 btScalar m_length;
100 btScalar m_heightScale;
101 union {
102 const unsigned char* m_heightfieldDataUnsignedChar;
103 const short* m_heightfieldDataShort;
104 const float* m_heightfieldDataFloat;
105 const double* m_heightfieldDataDouble;
106 const void* m_heightfieldDataUnknown;
107 };
108
109 PHY_ScalarType m_heightDataType;
110 bool m_flipQuadEdges;
111 bool m_useDiamondSubdivision;
112 bool m_useZigzagSubdivision;
113 bool m_flipTriangleWinding;
114 int m_upAxis;
115
116 btVector3 m_localScaling;
117
118 // Accelerator
119 btAlignedObjectArray<Range> m_vboundsGrid;
120 int m_vboundsGridWidth;
121 int m_vboundsGridLength;
122 int m_vboundsChunkSize;
123
124
125 btScalar m_userValue3;
126
127 struct btTriangleInfoMap* m_triangleInfoMap;
128
129 virtual btScalar getRawHeightFieldValue(int x, int y) const;
130 void quantizeWithClamp(int* out, const btVector3& point, int isMax) const;
131
133
137 void initialize(int heightStickWidth, int heightStickLength,
138 const void* heightfieldData, btScalar heightScale,
139 btScalar minHeight, btScalar maxHeight, int upAxis,
140 PHY_ScalarType heightDataType, bool flipQuadEdges);
141
142public:
143 BT_DECLARE_ALIGNED_ALLOCATOR();
144
146 btHeightfieldTerrainShape(
147 int heightStickWidth, int heightStickLength,
148 const float* heightfieldData, btScalar minHeight, btScalar maxHeight,
149 int upAxis, bool flipQuadEdges);
150 btHeightfieldTerrainShape(
151 int heightStickWidth, int heightStickLength,
152 const double* heightfieldData, btScalar minHeight, btScalar maxHeight,
153 int upAxis, bool flipQuadEdges);
154 btHeightfieldTerrainShape(
155 int heightStickWidth, int heightStickLength,
156 const short* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight,
157 int upAxis, bool flipQuadEdges);
158 btHeightfieldTerrainShape(
159 int heightStickWidth, int heightStickLength,
160 const unsigned char* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight,
161 int upAxis, bool flipQuadEdges);
162
164
173 btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,
174 const void* heightfieldData, btScalar heightScale,
175 btScalar minHeight, btScalar maxHeight,
176 int upAxis, PHY_ScalarType heightDataType,
177 bool flipQuadEdges);
178
180
186 btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength, const void* heightfieldData, btScalar maxHeight, int upAxis, bool useFloatData, bool flipQuadEdges);
187
188 virtual ~btHeightfieldTerrainShape();
189
190 void setUseDiamondSubdivision(bool useDiamondSubdivision = true) { m_useDiamondSubdivision = useDiamondSubdivision; }
191
193 void setUseZigzagSubdivision(bool useZigzagSubdivision = true) { m_useZigzagSubdivision = useZigzagSubdivision; }
194
195 void setFlipTriangleWinding(bool flipTriangleWinding)
196 {
197 m_flipTriangleWinding = flipTriangleWinding;
198 }
199 virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
200
201 virtual void processAllTriangles(btTriangleCallback * callback, const btVector3& aabbMin, const btVector3& aabbMax) const;
202
203 virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
204
205 virtual void setLocalScaling(const btVector3& scaling);
206
207 virtual const btVector3& getLocalScaling() const;
208
209 void getVertex(int x, int y, btVector3& vertex) const;
210
211 void performRaycast(btTriangleCallback * callback, const btVector3& raySource, const btVector3& rayTarget) const;
212
213 void buildAccelerator(int chunkSize = 16);
214 void clearAccelerator();
215
216 int getUpAxis() const
217 {
218 return m_upAxis;
219 }
220 //debugging
221 virtual const char* getName() const { return "HEIGHTFIELD"; }
222
223
224 void setUserValue3(btScalar value)
225 {
226 m_userValue3 = value;
227 }
228 btScalar getUserValue3() const
229 {
230 return m_userValue3;
231 }
232 const struct btTriangleInfoMap* getTriangleInfoMap() const
233 {
234 return m_triangleInfoMap;
235 }
236 struct btTriangleInfoMap* getTriangleInfoMap()
237 {
238 return m_triangleInfoMap;
239 }
240 void setTriangleInfoMap(btTriangleInfoMap* map)
241 {
242 m_triangleInfoMap = map;
243 }
244 const unsigned char* getHeightfieldRawData() const
245 {
246 return m_heightfieldDataUnsignedChar;
247 }
248};
249
250#endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H
btAlignedObjectArray.h
btConcaveShape.h
PHY_ScalarType
PHY_ScalarType
PHY_ScalarType enumerates possible scalar types.
Definition btConcaveShape.h:26
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition btAlignedObjectArray.h:46
btConcaveShape
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
Definition btConcaveShape.h:39
btHeightfieldTerrainShape
btHeightfieldTerrainShape simulates a 2D heightfield terrain
Definition btHeightfieldTerrainShape.h:72
btHeightfieldTerrainShape::m_vboundsGridWidth
int m_vboundsGridWidth
Definition btHeightfieldTerrainShape.h:120
btHeightfieldTerrainShape::m_flipTriangleWinding
bool m_flipTriangleWinding
Definition btHeightfieldTerrainShape.h:113
btHeightfieldTerrainShape::setFlipTriangleWinding
void setFlipTriangleWinding(bool flipTriangleWinding)
Definition btHeightfieldTerrainShape.h:195
btHeightfieldTerrainShape::m_localOrigin
btVector3 m_localOrigin
Definition btHeightfieldTerrainShape.h:91
btHeightfieldTerrainShape::m_minHeight
btScalar m_minHeight
Definition btHeightfieldTerrainShape.h:96
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:193
btHeightfieldTerrainShape::m_heightScale
btScalar m_heightScale
Definition btHeightfieldTerrainShape.h:100
btHeightfieldTerrainShape::m_heightDataType
PHY_ScalarType m_heightDataType
Definition btHeightfieldTerrainShape.h:109
btHeightfieldTerrainShape::m_useZigzagSubdivision
bool m_useZigzagSubdivision
Definition btHeightfieldTerrainShape.h:112
btHeightfieldTerrainShape::setUseDiamondSubdivision
void setUseDiamondSubdivision(bool useDiamondSubdivision=true)
Definition btHeightfieldTerrainShape.h:190
btHeightfieldTerrainShape::getTriangleInfoMap
struct btTriangleInfoMap * getTriangleInfoMap()
Definition btHeightfieldTerrainShape.h:236
btHeightfieldTerrainShape::m_useDiamondSubdivision
bool m_useDiamondSubdivision
Definition btHeightfieldTerrainShape.h:111
btHeightfieldTerrainShape::m_localAabbMin
btVector3 m_localAabbMin
Definition btHeightfieldTerrainShape.h:89
btHeightfieldTerrainShape::setUserValue3
void setUserValue3(btScalar value)
Definition btHeightfieldTerrainShape.h:224
btHeightfieldTerrainShape::m_heightfieldDataShort
const short * m_heightfieldDataShort
Definition btHeightfieldTerrainShape.h:103
btHeightfieldTerrainShape::m_heightfieldDataDouble
const double * m_heightfieldDataDouble
Definition btHeightfieldTerrainShape.h:105
btHeightfieldTerrainShape::m_flipQuadEdges
bool m_flipQuadEdges
Definition btHeightfieldTerrainShape.h:110
btHeightfieldTerrainShape::getTriangleInfoMap
const struct btTriangleInfoMap * getTriangleInfoMap() const
Definition btHeightfieldTerrainShape.h:232
btHeightfieldTerrainShape::m_vboundsGridLength
int m_vboundsGridLength
Definition btHeightfieldTerrainShape.h:121
btHeightfieldTerrainShape::m_userValue3
btScalar m_userValue3
Definition btHeightfieldTerrainShape.h:125
btHeightfieldTerrainShape::m_localScaling
btVector3 m_localScaling
Definition btHeightfieldTerrainShape.h:116
btHeightfieldTerrainShape::getUserValue3
btScalar getUserValue3() const
Definition btHeightfieldTerrainShape.h:228
btHeightfieldTerrainShape::m_heightfieldDataUnknown
const void * m_heightfieldDataUnknown
Definition btHeightfieldTerrainShape.h:106
btHeightfieldTerrainShape::getHeightfieldRawData
const unsigned char * getHeightfieldRawData() const
Definition btHeightfieldTerrainShape.h:244
btHeightfieldTerrainShape::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btHeightfieldTerrainShape::m_heightfieldDataUnsignedChar
const unsigned char * m_heightfieldDataUnsignedChar
Definition btHeightfieldTerrainShape.h:102
btHeightfieldTerrainShape::getName
virtual const char * getName() const
Definition btHeightfieldTerrainShape.h:221
btHeightfieldTerrainShape::m_heightStickLength
int m_heightStickLength
Definition btHeightfieldTerrainShape.h:95
btHeightfieldTerrainShape::m_maxHeight
btScalar m_maxHeight
Definition btHeightfieldTerrainShape.h:97
btHeightfieldTerrainShape::m_vboundsChunkSize
int m_vboundsChunkSize
Definition btHeightfieldTerrainShape.h:122
btHeightfieldTerrainShape::m_width
btScalar m_width
Definition btHeightfieldTerrainShape.h:98
btHeightfieldTerrainShape::m_heightfieldDataFloat
const float * m_heightfieldDataFloat
Definition btHeightfieldTerrainShape.h:104
btHeightfieldTerrainShape::m_upAxis
int m_upAxis
Definition btHeightfieldTerrainShape.h:114
btHeightfieldTerrainShape::m_heightStickWidth
int m_heightStickWidth
terrain data
Definition btHeightfieldTerrainShape.h:94
btHeightfieldTerrainShape::m_vboundsGrid
btAlignedObjectArray< Range > m_vboundsGrid
Definition btHeightfieldTerrainShape.h:119
btHeightfieldTerrainShape::setTriangleInfoMap
void setTriangleInfoMap(btTriangleInfoMap *map)
Definition btHeightfieldTerrainShape.h:240
btHeightfieldTerrainShape::getUpAxis
int getUpAxis() const
Definition btHeightfieldTerrainShape.h:216
btHeightfieldTerrainShape::m_length
btScalar m_length
Definition btHeightfieldTerrainShape.h:99
btHeightfieldTerrainShape::m_triangleInfoMap
struct btTriangleInfoMap * m_triangleInfoMap
Definition btHeightfieldTerrainShape.h:127
btHeightfieldTerrainShape::m_localAabbMax
btVector3 m_localAabbMax
Definition btHeightfieldTerrainShape.h:90
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition btTriangleCallback.h:24
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btHeightfieldTerrainShape::Range
Definition btHeightfieldTerrainShape.h:75
btHeightfieldTerrainShape::Range::Range
Range()
Definition btHeightfieldTerrainShape.h:76
btHeightfieldTerrainShape::Range::min
btScalar min
Definition btHeightfieldTerrainShape.h:84
btHeightfieldTerrainShape::Range::max
btScalar max
Definition btHeightfieldTerrainShape.h:85
btHeightfieldTerrainShape::Range::overlaps
bool overlaps(const Range &other) const
Definition btHeightfieldTerrainShape.h:79
btHeightfieldTerrainShape::Range::Range
Range(btScalar min, btScalar max)
Definition btHeightfieldTerrainShape.h:77
btTriangleInfoMap
The btTriangleInfoMap stores edge angle information for some triangles. You can compute this informat...
Definition btTriangleInfoMap.h:54