Sign in to follow this  

A question about btHeightfieldTerrainShape

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.

[code]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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this