Blender V4.3
btHeightfieldTerrainShape.h File Reference

Go to the source code of this file.

Functions

virtual btScalar getRawHeightFieldValue (int x, int y) const
 
void quantizeWithClamp (int *out, const btVector3 &point, int isMax) const
 given input vector, return quantized version
 
void initialize (int heightStickWidth, int heightStickLength, const void *heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, PHY_ScalarType heightDataType, bool flipQuadEdges)
 protected initialization
 
 BT_DECLARE_ALIGNED_ALLOCATOR ()
 
 btHeightfieldTerrainShape (int heightStickWidth, int heightStickLength, const void *heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, PHY_ScalarType heightDataType, bool flipQuadEdges)
 preferred constructor
 
 btHeightfieldTerrainShape (int heightStickWidth, int heightStickLength, const void *heightfieldData, btScalar maxHeight, int upAxis, bool useFloatData, bool flipQuadEdges)
 legacy constructor
 
virtual ~btHeightfieldTerrainShape ()
 
void setUseDiamondSubdivision (bool useDiamondSubdivision=true)
 
void setUseZigzagSubdivision (bool useZigzagSubdivision=true)
 could help compatibility with Ogre heightfields. See https://code.google.com/p/bullet/issues/detail?id=625
 
void setFlipTriangleWinding (bool flipTriangleWinding)
 
virtual void getAabb (const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
 getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
 
virtual void processAllTriangles (btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const
 
virtual void calculateLocalInertia (btScalar mass, btVector3 &inertia) const
 CollisionShape Interface.
 
virtual void setLocalScaling (const btVector3 &scaling)
 in case we receive negative scaling
 
virtual const btVector3getLocalScaling () 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
 
virtual const char * getName () const
 
void setUserIndex2 (int index)
 
int getUserIndex2 () const
 
void setUserValue3 (btScalar value)
 
btScalar getUserValue3 () const
 
const struct btTriangleInfoMapgetTriangleInfoMap () const
 
void setTriangleInfoMap (btTriangleInfoMap *map)
 
const unsigned char * getHeightfieldRawData () const
 

Variables

btHeightfieldTerrainShape __pad0__
 btHeightfieldTerrainShape simulates a 2D heightfield terrain
 
btScalar max
 
btVector3 m_localAabbMin
 
btVector3 m_localAabbMax
 
btVector3 m_localOrigin
 
int m_heightStickWidth
 terrain data
 
int m_heightStickLength
 
btScalar m_minHeight
 
btScalar m_maxHeight
 
btScalar m_width
 
btScalar m_length
 
btScalar m_heightScale
 
union { 
 
   const unsigned char *   m_heightfieldDataUnsignedChar 
 
   const short *   m_heightfieldDataShort 
 
   const btScalar *   m_heightfieldDataFloat 
 
   const void *   m_heightfieldDataUnknown 
 
};  
 
PHY_ScalarType m_heightDataType
 
bool m_flipQuadEdges
 
bool m_useDiamondSubdivision
 
bool m_useZigzagSubdivision
 
bool m_flipTriangleWinding
 
int m_upAxis
 
btVector3 m_localScaling
 
btAlignedObjectArray< Range > m_vboundsGrid
 
int m_vboundsGridWidth
 
int m_vboundsGridLength
 
int m_vboundsChunkSize
 
int m_userIndex2
 
btScalar m_userValue3
 
struct btTriangleInfoMapm_triangleInfoMap
 

Function Documentation

◆ BT_DECLARE_ALIGNED_ALLOCATOR()

BT_DECLARE_ALIGNED_ALLOCATOR ( )

◆ btHeightfieldTerrainShape() [1/2]

btHeightfieldTerrainShape::btHeightfieldTerrainShape ( int heightStickWidth,
int heightStickLength,
const void * heightfieldData,
btScalar heightScale,
btScalar minHeight,
btScalar maxHeight,
int upAxis,
PHY_ScalarType heightDataType,
bool flipQuadEdges )

preferred constructor

This constructor supports a range of heightfield data types, and allows for a non-zero minimum height value. heightScale is needed for any integer-based heightfield data types.

Definition at line 20 of file btHeightfieldTerrainShape.cpp.

References initialize().

Referenced by btAdjustInternalEdgeContacts(), and btCollisionWorld::rayTestSingleInternal().

◆ btHeightfieldTerrainShape() [2/2]

btHeightfieldTerrainShape::btHeightfieldTerrainShape ( int heightStickWidth,
int heightStickLength,
const void * heightfieldData,
btScalar maxHeight,
int upAxis,
bool useFloatData,
bool flipQuadEdges )

legacy constructor

The legacy constructor assumes the heightfield has a minimum height of zero. Only unsigned char or floats are supported. For legacy compatibility reasons, heightScale is calculated as maxHeight / 65535 (and is only used when useFloatData = false).

Definition at line 33 of file btHeightfieldTerrainShape.cpp.

References initialize(), PHY_FLOAT, and PHY_UCHAR.

◆ buildAccelerator()

void btHeightfieldTerrainShape::buildAccelerator ( int chunkSize = 16)

Builds a grid data structure storing the min and max heights of the terrain in chunks. if chunkSize is zero, that accelerator is removed. If you modify the heights, you need to rebuild this accelerator.

Definition at line 750 of file btHeightfieldTerrainShape.cpp.

References clearAccelerator(), getRawHeightFieldValue(), m_heightStickLength, m_heightStickWidth, m_vboundsChunkSize, m_vboundsGrid, m_vboundsGridLength, m_vboundsGridWidth, x, and z().

◆ calculateLocalInertia()

virtual void calculateLocalInertia ( btScalar mass,
btVector3 & inertia ) const
virtual

CollisionShape Interface.

Definition at line 54 of file btConeShape.h.

◆ clearAccelerator()

void btHeightfieldTerrainShape::clearAccelerator ( )

Definition at line 848 of file btHeightfieldTerrainShape.cpp.

References m_vboundsGrid.

Referenced by buildAccelerator(), and ~btHeightfieldTerrainShape().

◆ getAabb()

virtual void getAabb ( const btTransform & t,
btVector3 & aabbMin,
btVector3 & aabbMax ) const
virtual

getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.

getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version

getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.

Definition at line 54 of file btCapsuleShape.h.

◆ getHeightfieldRawData()

const unsigned char * getHeightfieldRawData ( ) const

Definition at line 223 of file btHeightfieldTerrainShape.h.

References m_heightfieldDataUnsignedChar.

◆ getLocalScaling()

virtual const btVector3 & getLocalScaling ( ) const
virtual

Definition at line 126 of file btCompoundShape.h.

◆ getName()

virtual const char * getName ( ) const
virtual

Definition at line 192 of file btHeightfieldTerrainShape.h.

◆ getRawHeightFieldValue()

btScalar btHeightfieldTerrainShape::getRawHeightFieldValue ( int x,
int y ) const
protectedvirtual

This returns the "raw" (user's initial) height, not the actual height. The actual height needs to be adjusted to be relative to the center of the heightfield's AABB.

Definition at line 146 of file btHeightfieldTerrainShape.cpp.

References btAssert, m_heightDataType, m_heightfieldDataFloat, m_heightfieldDataShort, m_heightfieldDataUnsignedChar, m_heightScale, m_heightStickWidth, PHY_FLOAT, PHY_SHORT, and PHY_UCHAR.

Referenced by buildAccelerator().

◆ getTriangleInfoMap()

const struct btTriangleInfoMap * getTriangleInfoMap ( ) const

Definition at line 211 of file btHeightfieldTerrainShape.h.

References m_triangleInfoMap.

◆ getUpAxis()

int getUpAxis ( ) const

Definition at line 187 of file btHeightfieldTerrainShape.h.

References m_upAxis.

◆ getUserIndex2()

int getUserIndex2 ( ) const

Definition at line 199 of file btHeightfieldTerrainShape.h.

References m_userIndex2.

◆ getUserValue3()

btScalar getUserValue3 ( ) const

Definition at line 207 of file btHeightfieldTerrainShape.h.

References m_userValue3.

◆ getVertex()

void getVertex ( int x,
int y,
btVector3 & vertex ) const

◆ initialize()

void initialize ( int heightStickWidth,
int heightStickLength,
const void * heightfieldData,
btScalar heightScale,
btScalar minHeight,
btScalar maxHeight,
int upAxis,
PHY_ScalarType heightDataType,
bool flipQuadEdges )
protected

protected initialization

Handles the work of constructors so that public constructors can be backwards-compatible without a lot of copy/paste.

◆ performRaycast()

void performRaycast ( btTriangleCallback * callback,
const btVector3 & raySource,
const btVector3 & rayTarget ) const

◆ processAllTriangles()

virtual void processAllTriangles ( btTriangleCallback * callback,
const btVector3 & aabbMin,
const btVector3 & aabbMax ) const
virtual

Definition at line 57 of file btEmptyShape.h.

◆ quantizeWithClamp()

void btHeightfieldTerrainShape::quantizeWithClamp ( int * out,
const btVector3 & point,
int isMax ) const
protected

given input vector, return quantized version

This routine is basically determining the gridpoint indices for a given input vector, answering the question: "which gridpoint is closest to the provided point?".

"with clamp" means that we restrict the point to be in the heightfield's axis-aligned bounding box.

Definition at line 246 of file btHeightfieldTerrainShape.cpp.

References getQuantized(), m_localAabbMax, and m_localAabbMin.

◆ setFlipTriangleWinding()

void setFlipTriangleWinding ( bool flipTriangleWinding)

Definition at line 166 of file btHeightfieldTerrainShape.h.

References m_flipTriangleWinding.

◆ setLocalScaling()

virtual void setLocalScaling ( const btVector3 & scaling)
virtual

in case we receive negative scaling

Definition at line 120 of file btBox2dShape.h.

◆ setTriangleInfoMap()

void setTriangleInfoMap ( btTriangleInfoMap * map)

Definition at line 219 of file btHeightfieldTerrainShape.h.

References m_triangleInfoMap.

◆ setUseDiamondSubdivision()

void setUseDiamondSubdivision ( bool useDiamondSubdivision = true)

Definition at line 161 of file btHeightfieldTerrainShape.h.

References m_useDiamondSubdivision.

◆ setUserIndex2()

void setUserIndex2 ( int index)

Definition at line 195 of file btHeightfieldTerrainShape.h.

References m_userIndex2.

◆ setUserValue3()

void setUserValue3 ( btScalar value)

Definition at line 203 of file btHeightfieldTerrainShape.h.

References m_userValue3.

◆ setUseZigzagSubdivision()

void setUseZigzagSubdivision ( bool useZigzagSubdivision = true)

could help compatibility with Ogre heightfields. See https://code.google.com/p/bullet/issues/detail?id=625

Definition at line 164 of file btHeightfieldTerrainShape.h.

References m_useZigzagSubdivision.

◆ ~btHeightfieldTerrainShape()

btHeightfieldTerrainShape::~btHeightfieldTerrainShape ( )
virtual

Definition at line 120 of file btHeightfieldTerrainShape.cpp.

References clearAccelerator().

Variable Documentation

◆ [union]

union { ... }

◆ __pad0__

btHeightfieldTerrainShape simulates a 2D heightfield terrain

The caller is responsible for maintaining the heightfield array; this class does not make a copy.

The heightfield can be dynamic so long as the min/max height values capture the extremes (heights must always be in that range).

The local origin of the heightfield is assumed to be the exact center (as determined by width and length and height, with each axis multiplied by the localScaling).

NOTE: be careful with coordinates. If you have a heightfield with a local min height of -100m, and a max height of +500m, you may be tempted to place it at the origin (0,0) and expect the heights in world coordinates to be -100 to +500 meters. Actually, the heights will be -300 to +300m, because bullet will re-center the heightfield based on its AABB (which is determined by the min/max heights). So keep in mind that once you create a btHeightfieldTerrainShape object, the heights will be adjusted relative to the center of the AABB. This is different to the behavior of many rendering engines, but is useful for physics engines.

Most (but not all) rendering and heightfield libraries assume upAxis = 1 (that is, the y-axis is "up"). This class allows any of the 3 coordinates to be "up". Make sure your choice of axis is consistent with your rendering system.

The heightfield heights are determined from the data type used for the heightfieldData array.

  • PHY_UCHAR: height at a point is the uchar value at the grid point, multipled by heightScale. uchar isn't recommended because of its inability to deal with negative values, and low resolution (8-bit).
  • PHY_SHORT: height at a point is the short int value at that grid point, multipled by heightScale.
  • PHY_FLOAT: height at a point is the float value at that grid point. heightScale is ignored when using the float heightfield data type.

Whatever the caller specifies as minHeight and maxHeight will be honored. The class will not inspect the heightfield to discover the actual minimum or maximum heights. These values are used to determine the heightfield's axis-aligned bounding box, multiplied by localScaling.

For usage and testing see the TerrainDemo.

Definition at line 73 of file btHeightfieldTerrainShape.h.

◆ m_flipQuadEdges

bool m_flipQuadEdges
protected

Definition at line 103 of file btHeightfieldTerrainShape.h.

◆ m_flipTriangleWinding

bool m_flipTriangleWinding
protected

Definition at line 106 of file btHeightfieldTerrainShape.h.

Referenced by setFlipTriangleWinding().

◆ m_heightDataType

PHY_ScalarType m_heightDataType
protected

Definition at line 102 of file btHeightfieldTerrainShape.h.

Referenced by getRawHeightFieldValue().

◆ m_heightfieldDataFloat

const btScalar* m_heightfieldDataFloat

Definition at line 98 of file btHeightfieldTerrainShape.h.

Referenced by getRawHeightFieldValue().

◆ m_heightfieldDataShort

const short* m_heightfieldDataShort

Definition at line 97 of file btHeightfieldTerrainShape.h.

Referenced by getRawHeightFieldValue().

◆ m_heightfieldDataUnknown

const void* m_heightfieldDataUnknown

Definition at line 99 of file btHeightfieldTerrainShape.h.

◆ m_heightfieldDataUnsignedChar

const unsigned char* m_heightfieldDataUnsignedChar

Definition at line 96 of file btHeightfieldTerrainShape.h.

Referenced by getHeightfieldRawData(), and getRawHeightFieldValue().

◆ m_heightScale

btScalar m_heightScale
protected

Definition at line 94 of file btHeightfieldTerrainShape.h.

Referenced by getRawHeightFieldValue().

◆ m_heightStickLength

int m_heightStickLength
protected

Definition at line 89 of file btHeightfieldTerrainShape.h.

Referenced by buildAccelerator().

◆ m_heightStickWidth

int m_heightStickWidth
protected

terrain data

Definition at line 88 of file btHeightfieldTerrainShape.h.

Referenced by buildAccelerator(), and getRawHeightFieldValue().

◆ m_length

btScalar m_length
protected

◆ m_localAabbMax

btVector3 m_localAabbMax
protected

Definition at line 84 of file btHeightfieldTerrainShape.h.

◆ m_localAabbMin

btVector3 m_localAabbMin
protected

Definition at line 83 of file btHeightfieldTerrainShape.h.

◆ m_localOrigin

btVector3 m_localOrigin
protected

Definition at line 85 of file btHeightfieldTerrainShape.h.

◆ m_localScaling

btVector3 m_localScaling
protected

Definition at line 109 of file btHeightfieldTerrainShape.h.

◆ m_maxHeight

btScalar m_maxHeight
protected

Definition at line 91 of file btHeightfieldTerrainShape.h.

◆ m_minHeight

btScalar m_minHeight
protected

Definition at line 90 of file btHeightfieldTerrainShape.h.

◆ m_triangleInfoMap

struct btTriangleInfoMap* m_triangleInfoMap
protected

Definition at line 120 of file btHeightfieldTerrainShape.h.

Referenced by getTriangleInfoMap(), and setTriangleInfoMap().

◆ m_upAxis

◆ m_useDiamondSubdivision

bool m_useDiamondSubdivision
protected

Definition at line 104 of file btHeightfieldTerrainShape.h.

Referenced by setUseDiamondSubdivision().

◆ m_userIndex2

int m_userIndex2
protected

Definition at line 117 of file btHeightfieldTerrainShape.h.

Referenced by getUserIndex2(), and setUserIndex2().

◆ m_userValue3

btScalar m_userValue3
protected

Definition at line 118 of file btHeightfieldTerrainShape.h.

Referenced by getUserValue3(), and setUserValue3().

◆ m_useZigzagSubdivision

bool m_useZigzagSubdivision
protected

Definition at line 105 of file btHeightfieldTerrainShape.h.

Referenced by setUseZigzagSubdivision().

◆ m_vboundsChunkSize

int m_vboundsChunkSize
protected

Definition at line 115 of file btHeightfieldTerrainShape.h.

Referenced by buildAccelerator().

◆ m_vboundsGrid

btAlignedObjectArray<Range> m_vboundsGrid
protected

Definition at line 112 of file btHeightfieldTerrainShape.h.

Referenced by buildAccelerator(), and clearAccelerator().

◆ m_vboundsGridLength

int m_vboundsGridLength
protected

Definition at line 114 of file btHeightfieldTerrainShape.h.

Referenced by buildAccelerator().

◆ m_vboundsGridWidth

int m_vboundsGridWidth
protected

Definition at line 113 of file btHeightfieldTerrainShape.h.

Referenced by buildAccelerator().

◆ m_width

btScalar m_width
protected

Definition at line 92 of file btHeightfieldTerrainShape.h.

◆ max

btScalar max

Definition at line 79 of file btHeightfieldTerrainShape.h.