Physics Simulation Forum


All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Feb 22, 2011 2:32 pm 

Joined: Tue Feb 22, 2011 2:14 pm
Posts: 1
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)
   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;

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group