2

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.

pergy
  • 5,285
  • 1
  • 22
  • 36
Hopploppa
  • 142
  • 9
  • Does `entityPos` has the correct value, according to your debugging process? – cppBeginner Jul 13 '17 at 11:01
  • You really should debug the values. I suspect that you should pass `getParentSceneNode()->getDerivedPosition()` to physics, as it seems that you use world frame there and local frame on scene node – pergy Jul 25 '17 at 12:46

0 Answers0