Differential D8762 Diff 28333 extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
| Show All 11 Lines | |||||
| 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | ||||
| 3. This notice may not be removed or altered from any source distribution. | 3. This notice may not be removed or altered from any source distribution. | ||||
| */ | */ | ||||
| #ifndef BT_HEIGHTFIELD_TERRAIN_SHAPE_H | #ifndef BT_HEIGHTFIELD_TERRAIN_SHAPE_H | ||||
| #define BT_HEIGHTFIELD_TERRAIN_SHAPE_H | #define BT_HEIGHTFIELD_TERRAIN_SHAPE_H | ||||
| #include "btConcaveShape.h" | #include "btConcaveShape.h" | ||||
| #include "LinearMath/btAlignedObjectArray.h" | |||||
| ///btHeightfieldTerrainShape simulates a 2D heightfield terrain | ///btHeightfieldTerrainShape simulates a 2D heightfield terrain | ||||
| /** | /** | ||||
| The caller is responsible for maintaining the heightfield array; this | The caller is responsible for maintaining the heightfield array; this | ||||
| class does not make a copy. | class does not make a copy. | ||||
| The heightfield can be dynamic so long as the min/max height values | The heightfield can be dynamic so long as the min/max height values | ||||
| capture the extremes (heights must always be in that range). | capture the extremes (heights must always be in that range). | ||||
| Show All 35 Lines | /** | ||||
| Whatever the caller specifies as minHeight and maxHeight will be honored. | Whatever the caller specifies as minHeight and maxHeight will be honored. | ||||
| The class will not inspect the heightfield to discover the actual minimum | The class will not inspect the heightfield to discover the actual minimum | ||||
| or maximum heights. These values are used to determine the heightfield's | or maximum heights. These values are used to determine the heightfield's | ||||
| axis-aligned bounding box, multiplied by localScaling. | axis-aligned bounding box, multiplied by localScaling. | ||||
| For usage and testing see the TerrainDemo. | For usage and testing see the TerrainDemo. | ||||
| */ | */ | ||||
| ATTRIBUTE_ALIGNED16(class) btHeightfieldTerrainShape : public btConcaveShape | ATTRIBUTE_ALIGNED16(class) | ||||
| btHeightfieldTerrainShape : public btConcaveShape | |||||
| { | { | ||||
| public: | |||||
| struct Range | |||||
| { | |||||
| btScalar min; | |||||
| btScalar max; | |||||
| }; | |||||
| protected: | protected: | ||||
| btVector3 m_localAabbMin; | btVector3 m_localAabbMin; | ||||
| btVector3 m_localAabbMax; | btVector3 m_localAabbMax; | ||||
| btVector3 m_localOrigin; | btVector3 m_localOrigin; | ||||
| ///terrain data | ///terrain data | ||||
| int m_heightStickWidth; | int m_heightStickWidth; | ||||
| int m_heightStickLength; | int m_heightStickLength; | ||||
| btScalar m_minHeight; | btScalar m_minHeight; | ||||
| btScalar m_maxHeight; | btScalar m_maxHeight; | ||||
| btScalar m_width; | btScalar m_width; | ||||
| btScalar m_length; | btScalar m_length; | ||||
| btScalar m_heightScale; | btScalar m_heightScale; | ||||
| union | union { | ||||
| { | |||||
| const unsigned char* m_heightfieldDataUnsignedChar; | const unsigned char* m_heightfieldDataUnsignedChar; | ||||
| const short* m_heightfieldDataShort; | const short* m_heightfieldDataShort; | ||||
| const btScalar* m_heightfieldDataFloat; | const btScalar* m_heightfieldDataFloat; | ||||
| const void* m_heightfieldDataUnknown; | const void* m_heightfieldDataUnknown; | ||||
| }; | }; | ||||
| PHY_ScalarType m_heightDataType; | PHY_ScalarType m_heightDataType; | ||||
| bool m_flipQuadEdges; | bool m_flipQuadEdges; | ||||
| bool m_useDiamondSubdivision; | bool m_useDiamondSubdivision; | ||||
| bool m_useZigzagSubdivision; | bool m_useZigzagSubdivision; | ||||
| bool m_flipTriangleWinding; | |||||
| int m_upAxis; | int m_upAxis; | ||||
| btVector3 m_localScaling; | btVector3 m_localScaling; | ||||
| virtual btScalar getRawHeightFieldValue(int x,int y) const; | // Accelerator | ||||
| void quantizeWithClamp(int* out, const btVector3& point,int isMax) const; | btAlignedObjectArray<Range> m_vboundsGrid; | ||||
| void getVertex(int x,int y,btVector3& vertex) const; | int m_vboundsGridWidth; | ||||
| int m_vboundsGridLength; | |||||
| int m_vboundsChunkSize; | |||||
| int m_userIndex2; | |||||
| btScalar m_userValue3; | |||||
| struct btTriangleInfoMap* m_triangleInfoMap; | |||||
| virtual btScalar getRawHeightFieldValue(int x, int y) const; | |||||
| void quantizeWithClamp(int* out, const btVector3& point, int isMax) const; | |||||
| /// protected initialization | /// protected initialization | ||||
| /** | /** | ||||
| Handles the work of constructors so that public constructors can be | Handles the work of constructors so that public constructors can be | ||||
| backwards-compatible without a lot of copy/paste. | backwards-compatible without a lot of copy/paste. | ||||
| */ | */ | ||||
| void initialize(int heightStickWidth, int heightStickLength, | void initialize(int heightStickWidth, int heightStickLength, | ||||
| const void* heightfieldData, btScalar heightScale, | const void* heightfieldData, btScalar heightScale, | ||||
| btScalar minHeight, btScalar maxHeight, int upAxis, | btScalar minHeight, btScalar maxHeight, int upAxis, | ||||
| PHY_ScalarType heightDataType, bool flipQuadEdges); | PHY_ScalarType heightDataType, bool flipQuadEdges); | ||||
| public: | public: | ||||
| BT_DECLARE_ALIGNED_ALLOCATOR(); | BT_DECLARE_ALIGNED_ALLOCATOR(); | ||||
| /// preferred constructor | /// preferred constructor | ||||
| /** | /** | ||||
| This constructor supports a range of heightfield | This constructor supports a range of heightfield | ||||
| data types, and allows for a non-zero minimum height value. | data types, and allows for a non-zero minimum height value. | ||||
| heightScale is needed for any integer-based heightfield data types. | heightScale is needed for any integer-based heightfield data types. | ||||
| */ | */ | ||||
| btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength, | btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength, | ||||
| const void* heightfieldData, btScalar heightScale, | const void* heightfieldData, btScalar heightScale, | ||||
| btScalar minHeight, btScalar maxHeight, | btScalar minHeight, btScalar maxHeight, | ||||
| int upAxis, PHY_ScalarType heightDataType, | int upAxis, PHY_ScalarType heightDataType, | ||||
| bool flipQuadEdges); | bool flipQuadEdges); | ||||
| /// legacy constructor | /// legacy constructor | ||||
| /** | /** | ||||
| The legacy constructor assumes the heightfield has a minimum height | The legacy constructor assumes the heightfield has a minimum height | ||||
| of zero. Only unsigned char or floats are supported. For legacy | of zero. Only unsigned char or floats are supported. For legacy | ||||
| compatibility reasons, heightScale is calculated as maxHeight / 65535 | compatibility reasons, heightScale is calculated as maxHeight / 65535 | ||||
| (and is only used when useFloatData = false). | (and is only used when useFloatData = false). | ||||
| */ | */ | ||||
| btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,const void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges); | btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength, const void* heightfieldData, btScalar maxHeight, int upAxis, bool useFloatData, bool flipQuadEdges); | ||||
| virtual ~btHeightfieldTerrainShape(); | virtual ~btHeightfieldTerrainShape(); | ||||
| void setUseDiamondSubdivision(bool useDiamondSubdivision=true) { m_useDiamondSubdivision = useDiamondSubdivision;} | void setUseDiamondSubdivision(bool useDiamondSubdivision = true) { m_useDiamondSubdivision = useDiamondSubdivision; } | ||||
| ///could help compatibility with Ogre heightfields. See https://code.google.com/p/bullet/issues/detail?id=625 | ///could help compatibility with Ogre heightfields. See https://code.google.com/p/bullet/issues/detail?id=625 | ||||
| void setUseZigzagSubdivision(bool useZigzagSubdivision=true) { m_useZigzagSubdivision = useZigzagSubdivision;} | void setUseZigzagSubdivision(bool useZigzagSubdivision = true) { m_useZigzagSubdivision = useZigzagSubdivision; } | ||||
| void setFlipTriangleWinding(bool flipTriangleWinding) | |||||
| { | |||||
| m_flipTriangleWinding = flipTriangleWinding; | |||||
| } | |||||
| virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; | virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const; | ||||
| virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const; | virtual void processAllTriangles(btTriangleCallback * callback, const btVector3& aabbMin, const btVector3& aabbMax) const; | ||||
| virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; | virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const; | ||||
| virtual void setLocalScaling(const btVector3& scaling); | virtual void setLocalScaling(const btVector3& scaling); | ||||
| virtual const btVector3& getLocalScaling() const; | virtual const btVector3& getLocalScaling() const; | ||||
| void getVertex(int x, int y, btVector3& vertex) const; | |||||
| void performRaycast(btTriangleCallback * callback, const btVector3& raySource, const btVector3& rayTarget) const; | |||||
| void buildAccelerator(int chunkSize = 16); | |||||
| void clearAccelerator(); | |||||
| int getUpAxis() const | |||||
| { | |||||
| return m_upAxis; | |||||
| } | |||||
| //debugging | //debugging | ||||
| virtual const char* getName()const {return "HEIGHTFIELD";} | virtual const char* getName() const { return "HEIGHTFIELD"; } | ||||
| void setUserIndex2(int index) | |||||
| { | |||||
| m_userIndex2 = index; | |||||
| } | |||||
| int getUserIndex2() const | |||||
| { | |||||
| return m_userIndex2; | |||||
| } | |||||
| void setUserValue3(btScalar value) | |||||
| { | |||||
| m_userValue3 = value; | |||||
| } | |||||
| btScalar getUserValue3() const | |||||
| { | |||||
| return m_userValue3; | |||||
| } | |||||
| const struct btTriangleInfoMap* getTriangleInfoMap() const | |||||
| { | |||||
| return m_triangleInfoMap; | |||||
| } | |||||
| struct btTriangleInfoMap* getTriangleInfoMap() | |||||
| { | |||||
| return m_triangleInfoMap; | |||||
| } | |||||
| void setTriangleInfoMap(btTriangleInfoMap* map) | |||||
| { | |||||
| m_triangleInfoMap = map; | |||||
| } | |||||
| const unsigned char* getHeightfieldRawData() const | |||||
| { | |||||
| return m_heightfieldDataUnsignedChar; | |||||
| } | |||||
| }; | }; | ||||
| #endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H | #endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H | ||||
| No newline at end of file | |||||