After weeks of trying to write a basic 3rd person camera I need some help and an aspirin. I have succeeded in making a camera which follows an Irrlicht node but now I can't get my camera to work with a Bullet body. My math skills are a bit rusty so don't be mad at me if I make an obvious mistake
. I can't really find what I'm doing wrong :
Code: Select all
btRigidBody* body; //which is the body I want to follow, let's say it's already set
scene::ICameraSceneNode* cam; //the camera, already set too
core::vector3df offset(0,0,-150); //where I want the camera to be from the body
const btQuaternion& TQuat = body->getOrientation();
core::quaternion q(TQuat.getX(), TQuat.getY(), TQuat.getZ(), TQuat.getW());
core::vector3df rotation;
q.toEuler(rotation);
rotation *= core::RADTODEG;
core::vector3df direction = rotation.rotationToDirection().normalize();
btVector3 bodyPos = body->getCenterOfMassPosition();
core::vector3df position = core::vector3df(bodyPos.x(),bodyPos.y(),bodyPos.z());
cam->bindTargetAndRotation(true);
cam->setPosition(position+offset*direction);
cam->setTarget(position);
When the body rotates, the camera, instead of rotating with it, goes forward over the z-axis and when the rotation reaches 90° over x or y the camera goes through the center of the body and turn back (to keep looking to the body which is the target). First I thought that I didn't understant how rotationToDirection worked but I use it to say in which direction the body should move and it works. Honestly I have no idea what is going on
. Obviously I tried numerous workaround (with the rotateXYBy methods for example) but nothing worked.