add raycast accelerator for btHeightfieldTerrainShape, thanks to Marc Zylann, see https://github.com/bulletphysics/bullet3/pull/2062
it can be disabled by setting the flag cb.m_flags |= btTriangleRaycastCallback::kF_DisableHeightfieldAccelerator; acceleration is disabled for z axis up. add btHeightfieldTerrainShape example to example browser
This commit is contained in:
@@ -17,6 +17,7 @@ subject to the following restrictions:
|
||||
#define BT_HEIGHTFIELD_TERRAIN_SHAPE_H
|
||||
|
||||
#include "btConcaveShape.h"
|
||||
#include "LinearMath/btAlignedObjectArray.h"
|
||||
|
||||
///btHeightfieldTerrainShape simulates a 2D heightfield terrain
|
||||
/**
|
||||
@@ -71,6 +72,13 @@ subject to the following restrictions:
|
||||
ATTRIBUTE_ALIGNED16(class)
|
||||
btHeightfieldTerrainShape : public btConcaveShape
|
||||
{
|
||||
public:
|
||||
struct Range
|
||||
{
|
||||
btScalar min;
|
||||
btScalar max;
|
||||
};
|
||||
|
||||
protected:
|
||||
btVector3 m_localAabbMin;
|
||||
btVector3 m_localAabbMax;
|
||||
@@ -100,9 +108,14 @@ protected:
|
||||
|
||||
btVector3 m_localScaling;
|
||||
|
||||
// Accelerator
|
||||
btAlignedObjectArray<Range> m_vboundsGrid;
|
||||
int m_vboundsGridWidth;
|
||||
int m_vboundsGridLength;
|
||||
int m_vboundsChunkSize;
|
||||
|
||||
virtual btScalar getRawHeightFieldValue(int x, int y) const;
|
||||
void quantizeWithClamp(int* out, const btVector3& point, int isMax) const;
|
||||
void getVertex(int x, int y, btVector3& vertex) const;
|
||||
|
||||
/// protected initialization
|
||||
/**
|
||||
@@ -155,8 +168,19 @@ public:
|
||||
|
||||
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
|
||||
virtual const char* getName() const { return "HEIGHTFIELD"; }
|
||||
};
|
||||
|
||||
#endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H
|
||||
#endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H
|
||||
Reference in New Issue
Block a user