I am making a game using Ogre3D and Kinect. The avatar in Ogre is controlled by the kinect. Now I want to implement physics but I am running into problems with Bullet.
I have "connected" the entities with the rigibodies with pairs.
std::vector<std::pair<Ogre::Entity *, btRigidBody *>> dynamicObjects;
std::vector<std::pair<Ogre::Entity *, btRigidBody *>> staticObjects;
I have no problem getting my Ogre enities follow the rigidbodies like this:
for (int i = 0; i < dynamicObjects.size(); i++) {
try {
btTransform tr;
dynamicObjects[i].second->getMotionState()->getWorldTransform(tr);
btVector3 pos = tr.getOrigin();
btQuaternion qut = tr.getRotation();
dynamicObjects[i].first->getParentSceneNode()->setOrientation(Ogre::Quaternion(qut.getW(), qut.getX(), qut.getY(), qut.getZ()));
Ogre::Vector3 localPos = dynamicObjects[i].first->getParentSceneNode()->getParentSceneNode()->convertWorldToLocalPosition(Ogre::Vector3(pos.x(), pos.y(), pos.z()));
dynamicObjects[i].first->getParentSceneNode()->setPosition(localPos);
} catch (Ogre::Exception e) {
}
However I can't seem to do the opposite, by making the rigidbodies follow the entity, which is necessary for the player controllet by Kinect. This code does not seem to do anything.
btTransform tr;
staticObjects[0].second->getMotionState()->getWorldTransform(tr);
Ogre::Vector3 entityPos = staticObjects[0].first->getParentSceneNode()->getPosition();
tr.setOrigin(btVector3(entityPos.x, entityPos.y, entityPos.z));
staticObjects[0].second->setWorldTransform(tr);
Both parts are placed in an update loop.