A question about btHeightfieldTerrainShape

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
ayleen
Posts: 1
Joined: Tue Feb 22, 2011 2:14 pm

A question about btHeightfieldTerrainShape

Post by ayleen » Tue Feb 22, 2011 2:32 pm

Hi
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.

thanks

Code: Select all

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)
   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;

   mCollisionShapes.push_back(lColShape);

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

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

   if (lMass!=0.0f)
   {
           lColShape->calculateLocalInertia(lMass,lLocalInertia);
   }

   btDefaultMotionState* lMotionState = new btDefaultMotionState(tr);

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


   mWorld->addRigidBody(lBody);
   mGroundBodyList.push_back(lBody);
   return lBody;
}

Post Reply