• Advertisement
Sign in to follow this  

A question about btHeightfieldTerrainShape

This topic is 2581 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am new with opengl and bullet and am trying to do a simple terrain using btHeightfieldTerrainShape. I have a heightfield map loaded from an image and the data is stored in unsigned char array, I am not sure if I send the correct parameters to btHeightfieldTerrainShape, because the terrain does' collide on all surface with other objects. I have seen the terrain demo but I dont'n understand and need some help here.

btRigidBody *PhysicsWorld::addRigidBodyTerrain(const QVector3D &pSize,const QVector3D &pPosition, const float pMass,float min,float max,unsigned char data[])
// qDebug() << "field size " << pSize;
//min = 0; max = 17
//position is (0,0,0)
//size is 256x256
int heightStickWidth = pSize.x() ;
int heightStickLength = pSize.z() ;

btScalar heightScale = 0.2;

// btHeightfieldTerrainShape* terrain = new btHeightfieldTerrainShape(heightStickWidth,heightStickLength, data,heightScale,min, max,1,PHY_UCHAR,false);
btHeightfieldTerrainShape* terrain = new btHeightfieldTerrainShape(heightStickWidth ,heightStickLength,data, max ,1,false,true);

qDebug() << "max : " << max << " min : " << min;
qDebug() << "pos : " << pPosition;

float offset = (max-min)*0.5;

btCollisionShape* lColShape = terrain;


btTransform tr;
tr.setOrigin(btVector3(pPosition.x(), pPosition.y()+offset , pPosition.z()));

btScalar lMass(pMass);
btVector3 lLocalInertia(0,0,0);

if (lMass!=0.0f)

btDefaultMotionState* lMotionState = new btDefaultMotionState(tr);

btRigidBody::btRigidBodyConstructionInfo lRbInfo(lMass,lMotionState,lColShape,lLocalInertia);
btRigidBody* lBody = new btRigidBody(lRbInfo);

return lBody;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement