Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Member Functions | Protected Attributes
btHeightfieldTerrainShape Class Reference

btHeightfieldTerrainShape simulates a 2D heightfield terrain More...

#include <btHeightfieldTerrainShape.h>

Inheritance diagram for btHeightfieldTerrainShape:
Inheritance graph
[legend]
Collaboration diagram for btHeightfieldTerrainShape:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 btHeightfieldTerrainShape (int heightStickWidth, int heightStickHeight, void *heightfieldData, btScalar maxHeight, int upAxis, bool useFloatData, bool flipQuadEdges)
virtual ~btHeightfieldTerrainShape ()
void setUseDiamondSubdivision (bool useDiamondSubdivision=true)
virtual int getShapeType () const
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
virtual void setLocalScaling (const btVector3 &scaling)
virtual const btVector3getLocalScaling () const
virtual const char * getName () const
virtual btScalar getMargin () const
virtual void setMargin (btScalar collisionMargin)
virtual void getBoundingSphere (btVector3 &center, btScalar &radius) const
virtual btScalar getAngularMotionDisc () const
 getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
void calculateTemporalAabb (const btTransform &curTrans, const btVector3 &linvel, const btVector3 &angvel, btScalar timeStep, btVector3 &temporalAabbMin, btVector3 &temporalAabbMax) const
 calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep) result is conservative
SIMD_FORCE_INLINE bool isPolyhedral () const
SIMD_FORCE_INLINE bool isConvex () const
SIMD_FORCE_INLINE bool isConcave () const
SIMD_FORCE_INLINE bool isCompound () const
SIMD_FORCE_INLINE bool isInfinite () const
 isInfinite is used to catch simulation error (aabb check)
void setUserPointer (void *userPtr)
 optional user data pointer
void * getUserPointer () const

Protected Member Functions

virtual btScalar getHeightFieldValue (int x, int y) const
void quantizeWithClamp (int *out, const btVector3 &point, int isMax) const
void getVertex (int x, int y, btVector3 &vertex) const
bool testQuantizedAabbAgainstQuantizedAabb (int *aabbMin1, int *aabbMax1, const int *aabbMin2, const int *aabbMax2) const

Protected Attributes

btVector3 m_localAabbMin
btVector3 m_localAabbMax
int m_heightStickWidth
 terrain data
int m_heightStickLength
btScalar m_maxHeight
btScalar m_width
btScalar m_length
union {
unsigned char * m_heightfieldDataUnsignedChar
btScalarm_heightfieldDataFloat
void * m_heightfieldDataUnknown
}; 
bool m_useFloatData
bool m_flipQuadEdges
bool m_useDiamondSubdivision
int m_upAxis
btVector3 m_localScaling
btScalar m_collisionMargin

Detailed Description

btHeightfieldTerrainShape simulates a 2D heightfield terrain

Definition at line 22 of file btHeightfieldTerrainShape.h.


Constructor & Destructor Documentation

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

Definition at line 21 of file btHeightfieldTerrainShape.cpp.

: m_heightStickWidth(heightStickWidth),
m_heightStickLength(heightStickLength),
m_width((btScalar)heightStickWidth-1),
m_length((btScalar)heightStickLength-1),
m_maxHeight(maxHeight),
m_heightfieldDataUnknown(heightfieldData),
m_useFloatData(useFloatData),
m_flipQuadEdges(flipQuadEdges),
m_useDiamondSubdivision(false),
m_upAxis(upAxis),
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
{


       btScalar      quantizationMargin = 1.f;

       //enlarge the AABB to avoid division by zero when initializing the quantization values
       btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);

       btVector3     halfExtents(0,0,0);

       switch (m_upAxis)
       {
       case 0:
              {
                     halfExtents.setValue(
                            btScalar(m_maxHeight),
                            btScalar(m_width), //?? don't know if this should change
                            btScalar(m_length));
                     break;
              }
       case 1:
              {
                     halfExtents.setValue(
                            btScalar(m_width),
                            btScalar(m_maxHeight),
                            btScalar(m_length));
                     break;
              };
       case 2:
              {
                     halfExtents.setValue(
                            btScalar(m_width),
                            btScalar(m_length),
                            btScalar(m_maxHeight)
                     );
                     break;
              }
       default:
              {
                     //need to get valid m_upAxis
                     btAssert(0);
              }
       }

       halfExtents*= btScalar(0.5);
       
       m_localAabbMin = -halfExtents - clampValue;
       m_localAabbMax = halfExtents + clampValue;
       btVector3 aabbSize = m_localAabbMax - m_localAabbMin;

}

Here is the call graph for this function:

Definition at line 86 of file btHeightfieldTerrainShape.cpp.

{
}

Member Function Documentation

void btHeightfieldTerrainShape::calculateLocalInertia ( btScalar  mass,
btVector3 inertia 
) const [virtual]

Implements btCollisionShape.

Definition at line 326 of file btHeightfieldTerrainShape.cpp.

{
       //moving concave objects not supported
       
       inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
}

Here is the call graph for this function:

void btCollisionShape::calculateTemporalAabb ( const btTransform curTrans,
const btVector3 linvel,
const btVector3 angvel,
btScalar  timeStep,
btVector3 temporalAabbMin,
btVector3 temporalAabbMax 
) const [inherited]

calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep) result is conservative

Definition at line 49 of file btCollisionShape.cpp.

{
       //start with static aabb
       getAabb(curTrans,temporalAabbMin,temporalAabbMax);

       btScalar temporalAabbMaxx = temporalAabbMax.getX();
       btScalar temporalAabbMaxy = temporalAabbMax.getY();
       btScalar temporalAabbMaxz = temporalAabbMax.getZ();
       btScalar temporalAabbMinx = temporalAabbMin.getX();
       btScalar temporalAabbMiny = temporalAabbMin.getY();
       btScalar temporalAabbMinz = temporalAabbMin.getZ();

       // add linear motion
       btVector3 linMotion = linvel*timeStep;
       //todo: simd would have a vector max/min operation, instead of per-element access
       if (linMotion.x() > btScalar(0.))
              temporalAabbMaxx += linMotion.x(); 
       else
              temporalAabbMinx += linMotion.x();
       if (linMotion.y() > btScalar(0.))
              temporalAabbMaxy += linMotion.y(); 
       else
              temporalAabbMiny += linMotion.y();
       if (linMotion.z() > btScalar(0.))
              temporalAabbMaxz += linMotion.z(); 
       else
              temporalAabbMinz += linMotion.z();

       //add conservative angular motion
       btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
       btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
       temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
       temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);

       temporalAabbMin -= angularMotion3d;
       temporalAabbMax += angularMotion3d;
}

Here is the call graph for this function:

void btHeightfieldTerrainShape::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.

Implements btCollisionShape.

Definition at line 92 of file btHeightfieldTerrainShape.cpp.

{
/*
       aabbMin.setValue(-1e30f,-1e30f,-1e30f);
       aabbMax.setValue(1e30f,1e30f,1e30f);
*/

       btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5);

       btMatrix3x3 abs_b = t.getBasis().absolute();  
       btPoint3 center = t.getOrigin();
       btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
                 abs_b[1].dot(halfExtents),
                abs_b[2].dot(halfExtents));
       extent += btVector3(getMargin(),getMargin(),getMargin());

       aabbMin = center - extent;
       aabbMax = center + extent;


}

Here is the call graph for this function:

btScalar btCollisionShape::getAngularMotionDisc ( ) const [virtual, inherited]

getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.

Definition at line 40 of file btCollisionShape.cpp.

{
       btVector3     center;
       btScalar disc;
       getBoundingSphere(center,disc);
       disc += (center).length();
       return disc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btCollisionShape::getBoundingSphere ( btVector3 center,
btScalar radius 
) const [virtual, inherited]

Definition at line 28 of file btCollisionShape.cpp.

{
       btTransform tr;
       tr.setIdentity();
       btVector3 aabbMin,aabbMax;

       getAabb(tr,aabbMin,aabbMax);

       radius = (aabbMax-aabbMin).length()*btScalar(0.5);
       center = (aabbMin+aabbMax)*btScalar(0.5);
}

Here is the call graph for this function:

Here is the caller graph for this function:

btScalar btHeightfieldTerrainShape::getHeightFieldValue ( int  x,
int  y 
) const [protected, virtual]

Definition at line 114 of file btHeightfieldTerrainShape.cpp.

{
       btScalar val = 0.f;
       if (m_useFloatData)
       {
              val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x];
       } else
       {
              //assume unsigned short int
              unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x];
              val = heightFieldValue* (m_maxHeight/btScalar(65535));
       }
       return val;
}

Here is the caller graph for this function:

Implements btCollisionShape.

Definition at line 337 of file btHeightfieldTerrainShape.cpp.

{
       return m_localScaling;
}
virtual btScalar btConcaveShape::getMargin ( ) const [inline, virtual, inherited]

Implements btCollisionShape.

Definition at line 38 of file btConcaveShape.h.

                                          {
              return m_collisionMargin;
       }

Here is the caller graph for this function:

virtual const char* btHeightfieldTerrainShape::getName ( ) const [inline, virtual]

Implements btCollisionShape.

Definition at line 86 of file btHeightfieldTerrainShape.h.

{return "HEIGHTFIELD";}
virtual int btHeightfieldTerrainShape::getShapeType ( ) const [inline, virtual]

Implements btCollisionShape.

Definition at line 70 of file btHeightfieldTerrainShape.h.

void* btCollisionShape::getUserPointer ( ) const [inline, inherited]

Definition at line 101 of file btCollisionShape.h.

       {
              return m_userPointer;
       }

Here is the caller graph for this function:

void btHeightfieldTerrainShape::getVertex ( int  x,
int  y,
btVector3 vertex 
) const [protected]

Definition at line 133 of file btHeightfieldTerrainShape.cpp.

{

       btAssert(x>=0);
       btAssert(y>=0);
       btAssert(x<m_heightStickWidth);
       btAssert(y<m_heightStickLength);


       btScalar      height = getHeightFieldValue(x,y);

       switch (m_upAxis)
       {
       case 0:
              {
              vertex.setValue(
                     height,
                     (-m_width/btScalar(2.0)) + x,
                     (-m_length/btScalar(2.0) ) + y
                     );
                     break;
              }
       case 1:
              {
                     vertex.setValue(
                     (-m_width/btScalar(2.0)) + x,
                     height,
                     (-m_length/btScalar(2.0)) + y
                     );
                     break;
              };
       case 2:
              {
                     vertex.setValue(
                     (-m_width/btScalar(2.0)) + x,
                     (-m_length/btScalar(2.0)) + y,
                     height
                     );
                     break;
              }
       default:
              {
                     //need to get valid m_upAxis
                     btAssert(0);
              }
       }

       vertex*=m_localScaling;
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

SIMD_FORCE_INLINE bool btCollisionShape::isCompound ( ) const [inline, inherited]

Definition at line 68 of file btCollisionShape.h.

Here is the call graph for this function:

Here is the caller graph for this function:

SIMD_FORCE_INLINE bool btCollisionShape::isConcave ( ) const [inline, inherited]

Definition at line 64 of file btCollisionShape.h.

Here is the call graph for this function:

Here is the caller graph for this function:

SIMD_FORCE_INLINE bool btCollisionShape::isConvex ( ) const [inline, inherited]

Definition at line 60 of file btCollisionShape.h.

Here is the call graph for this function:

Here is the caller graph for this function:

SIMD_FORCE_INLINE bool btCollisionShape::isInfinite ( ) const [inline, inherited]

isInfinite is used to catch simulation error (aabb check)

Definition at line 74 of file btCollisionShape.h.

Here is the call graph for this function:

SIMD_FORCE_INLINE bool btCollisionShape::isPolyhedral ( ) const [inline, inherited]

Definition at line 55 of file btCollisionShape.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void btHeightfieldTerrainShape::processAllTriangles ( btTriangleCallback callback,
const btVector3 aabbMin,
const btVector3 aabbMax 
) const [virtual]

Implements btConcaveShape.

Definition at line 202 of file btHeightfieldTerrainShape.cpp.

{
       (void)callback;
       (void)aabbMax;
       (void)aabbMin;

       //quantize the aabbMin and aabbMax, and adjust the start/end ranges

       int    quantizedAabbMin[3];
       int    quantizedAabbMax[3];

       btVector3     localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
       btVector3     localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
       
       quantizeWithClamp(quantizedAabbMin, localAabbMin,0);
       quantizeWithClamp(quantizedAabbMax, localAabbMax,1);
       
       

       int startX=0;
       int endX=m_heightStickWidth-1;
       int startJ=0;
       int endJ=m_heightStickLength-1;

       switch (m_upAxis)
       {
       case 0:
              {
                     quantizedAabbMin[1]+=m_heightStickWidth/2-1;
                     quantizedAabbMax[1]+=m_heightStickWidth/2+1;
                     quantizedAabbMin[2]+=m_heightStickLength/2-1;
                     quantizedAabbMax[2]+=m_heightStickLength/2+1;

                     if (quantizedAabbMin[1]>startX)
                            startX = quantizedAabbMin[1];
                     if (quantizedAabbMax[1]<endX)
                            endX = quantizedAabbMax[1];
                     if (quantizedAabbMin[2]>startJ)
                            startJ = quantizedAabbMin[2];
                     if (quantizedAabbMax[2]<endJ)
                            endJ = quantizedAabbMax[2];
                     break;
              }
       case 1:
              {
                     quantizedAabbMin[0]+=m_heightStickWidth/2-1;
                     quantizedAabbMax[0]+=m_heightStickWidth/2+1;
                     quantizedAabbMin[2]+=m_heightStickLength/2-1;
                     quantizedAabbMax[2]+=m_heightStickLength/2+1;

                     if (quantizedAabbMin[0]>startX)
                            startX = quantizedAabbMin[0];
                     if (quantizedAabbMax[0]<endX)
                            endX = quantizedAabbMax[0];
                     if (quantizedAabbMin[2]>startJ)
                            startJ = quantizedAabbMin[2];
                     if (quantizedAabbMax[2]<endJ)
                            endJ = quantizedAabbMax[2];
                     break;
              };
       case 2:
              {
                     quantizedAabbMin[0]+=m_heightStickWidth/2-1;
                     quantizedAabbMax[0]+=m_heightStickWidth/2+1;
                     quantizedAabbMin[1]+=m_heightStickLength/2-1;
                     quantizedAabbMax[1]+=m_heightStickLength/2+1;

                     if (quantizedAabbMin[0]>startX)
                            startX = quantizedAabbMin[0];
                     if (quantizedAabbMax[0]<endX)
                            endX = quantizedAabbMax[0];
                     if (quantizedAabbMin[1]>startJ)
                            startJ = quantizedAabbMin[1];
                     if (quantizedAabbMax[1]<endJ)
                            endJ = quantizedAabbMax[1];
                     break;
              }
       default:
              {
                     //need to get valid m_upAxis
                     btAssert(0);
              }
       }

       
  

       for(int j=startJ; j<endJ; j++)
       {
              for(int x=startX; x<endX; x++)
              {
                     btVector3 vertices[3];
                     if (m_flipQuadEdges || (m_useDiamondSubdivision && !((j+x) & 1)))
                     {
        //first triangle
        getVertex(x,j,vertices[0]);
        getVertex(x+1,j,vertices[1]);
        getVertex(x+1,j+1,vertices[2]);
        callback->processTriangle(vertices,x,j);
        //second triangle
        getVertex(x,j,vertices[0]);
        getVertex(x+1,j+1,vertices[1]);
        getVertex(x,j+1,vertices[2]);
        callback->processTriangle(vertices,x,j);                      
                     } else
                     {
        //first triangle
        getVertex(x,j,vertices[0]);
        getVertex(x,j+1,vertices[1]);
        getVertex(x+1,j,vertices[2]);
        callback->processTriangle(vertices,x,j);
        //second triangle
        getVertex(x+1,j,vertices[0]);
        getVertex(x,j+1,vertices[1]);
        getVertex(x+1,j+1,vertices[2]);
        callback->processTriangle(vertices,x,j);
                     }
              }
       }

       

}

Here is the call graph for this function:

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

Definition at line 185 of file btHeightfieldTerrainShape.cpp.

{
       btVector3 clampedPoint(point);
       clampedPoint.setMax(m_localAabbMin);
       clampedPoint.setMin(m_localAabbMax);

       btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;

       //TODO: optimization: check out how to removed this btFabs
              
       out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) );
       out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) );
       out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) );
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

void btHeightfieldTerrainShape::setLocalScaling ( const btVector3 scaling) [virtual]

Implements btCollisionShape.

Definition at line 333 of file btHeightfieldTerrainShape.cpp.

{
       m_localScaling = scaling;
}
virtual void btConcaveShape::setMargin ( btScalar  collisionMargin) [inline, virtual, inherited]

Implements btCollisionShape.

Definition at line 41 of file btConcaveShape.h.

       {
              m_collisionMargin = collisionMargin;
       }
void btHeightfieldTerrainShape::setUseDiamondSubdivision ( bool  useDiamondSubdivision = true) [inline]

Definition at line 68 of file btHeightfieldTerrainShape.h.

{ m_useDiamondSubdivision = useDiamondSubdivision;}
void btCollisionShape::setUserPointer ( void *  userPtr) [inline, inherited]

optional user data pointer

Definition at line 96 of file btCollisionShape.h.

       {
              m_userPointer = userPtr;
       }

Here is the caller graph for this function:

bool btHeightfieldTerrainShape::testQuantizedAabbAgainstQuantizedAabb ( int *  aabbMin1,
int *  aabbMax1,
const int *  aabbMin2,
const int *  aabbMax2 
) const [inline, protected]

Definition at line 53 of file btHeightfieldTerrainShape.h.

       {
              bool overlap = true;
              overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
              overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
              overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
              return overlap;
       }

Member Data Documentation

union { ... } [protected]

Definition at line 29 of file btConcaveShape.h.

Definition at line 42 of file btHeightfieldTerrainShape.h.

Definition at line 30 of file btHeightfieldTerrainShape.h.

terrain data

Definition at line 29 of file btHeightfieldTerrainShape.h.

Definition at line 33 of file btHeightfieldTerrainShape.h.

Definition at line 26 of file btHeightfieldTerrainShape.h.

Definition at line 25 of file btHeightfieldTerrainShape.h.

Definition at line 47 of file btHeightfieldTerrainShape.h.

Definition at line 31 of file btHeightfieldTerrainShape.h.

Definition at line 45 of file btHeightfieldTerrainShape.h.

Definition at line 43 of file btHeightfieldTerrainShape.h.

Definition at line 41 of file btHeightfieldTerrainShape.h.

Definition at line 32 of file btHeightfieldTerrainShape.h.


The documentation for this class was generated from the following files: