Jump to content
  • Advertisement
Sign in to follow this  
ayleen

A question about btHeightfieldTerrainShape

This topic is 2701 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

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

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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!