I implements terrain shape with that code:
Code: Select all
btHeightfieldTerrainShape* groundShape = new btHeightfieldTerrainShape(size, size, data, heightScale, minHeight, maxHeight, upAxis, PHY_FLOAT, true);
collisionShapes.push_back(groundShape);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(5, 0, 5)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
//groundRigidBody->setCollisionFlags(groundRigidBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
groundRigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
groundRigidBody->setActivationState(DISABLE_DEACTIVATION);
dynamicsWorld->addRigidBody(groundRigidBody);
Then, i create character, and calling to physics manager for creating kinematic controller:
Code: Select all
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(1, 50, 1));
btPairCachingGhostObject* m_ghostObject = new btPairCachingGhostObject();
m_ghostObject->setWorldTransform(startTransform);
btScalar characterHeight = 1.75;
btScalar characterWidth = 1.75;
btConvexShape* capsule = new btCapsuleShape(characterWidth, characterHeight);
m_ghostObject->setCollisionShape(capsule);
m_ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
btScalar stepHeight = btScalar(0.35);
btKinematicCharacterController* m_character = new btKinematicCharacterController(m_ghostObject, capsule, stepHeight);
dynamicsWorld->addCollisionObject(m_ghostObject, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter);
dynamicsWorld->addAction(m_character);
I've been reading a huge amount of the information and a lot of posts in the gamedev forums, but i still didn't find any solution of this problem.
I will appreciate if anyone would help me to solve it.