we add our heightfield like below. MyHeightfield is a float array which right now is only filled with zeros.
Code: Select all
btHeightfieldTerrainShape* groundShape = new btHeightfieldTerrainShape(terrain.width, terrain.height, &MyHeightfield, 1, 0, 50, 1, PHY_FLOAT, true);
btCollisionShape* fallShape = new btSphereShape(1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(terrain.width / 2, 25, terrain.height / 2)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
groundRigidBody->setRestitution(0.5);
groundRigidBody->setFriction(10);
groundRigidBody->setCollisionFlags(groundRigidBody->getCollisionFlags() || btCollisionObject::CF_STATIC_OBJECT);
dynamicsWorld->addRigidBody(groundRigidBody);
btDefaultMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(10, 10, 30)));
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
fallShape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, fallShape, fallInertia);
fallRigidBody1 = new btRigidBody(fallRigidBodyCI);
fallRigidBody1->setRestitution(0.9);
fallRigidBody1->setFriction(10);
fallRigidBody1->setActivationState(DISABLE_DEACTIVATION);
dynamicsWorld->addRigidBody(fallRigidBody1);
Code: Select all
dynamicsWorld->stepSimulation(1/60.f, 1);
https://www.dropbox.com/s/gltaujhf00c8f ... 804%29.mp4