Update: I've posted complete code in the reply below for a demo that shows the 'looking at the camera' feature correctly.
1) Getting global position of bones
The tutorial gets the global position/orientation of bones this way:
Code: Select all
//we want the head to be facing the camera, along the vector between the camera and the head
//this is done in world space for simplicity
Ogre::Vector3 headBonePosition = headBone->getWorldPosition();
Code: Select all
Ogre::Quaternion neckBoneWorldOrientation = neckBone->getWorldOrientation();
... it should be this way instead:
Code: Select all
Ogre::Vector3 headBonePosition = ent->_getParentNodeFullTransform() * headBone->_getDerivedPosition();
Code: Select all
Ogre::Quaternion neckBoneWorldOrientation = ent->getParentSceneNode()->getWorldOrientation() * neckBone->getWorldOrientation();
2) Testing for pitch and yaw
The tutorial tests for the pitch and yaw of the head rotation using the getRoll() and getPitch() Quaternion methods, even though, according to the thread ( http://www.ogre3d.org/phpBB2/viewtopic. ... 6f4e2718c6 ), those methods are not reliable, since Quaternions don't directly store the yaw, pitch, and roll and actually return some values that may not correspond to the actual yaw, pitch, and roll (though it's not a bug).
Some other way of testing and enforcing restrains of the neck should be implemented, I guess?
3) Adjusting angles
Also, it seems that the .ToAngleAxis(angle,axis) method used in the tutorial might return an angle between 0 and 2*PI rather than between -PI and PI. Can anyone confirm that this is how it works? In either case, the tutorial seems to assume that it's just a positive angle between 0 and PI, and thus does not account for rotation in both directions, which give very odd results sometimes. When instead handling rotation in both directions, the head rotates more naturally in all cases.
I'm just new to much of this stuff and not completely sure that I've got it right, so I haven't updated the wiki tutorial myself. But can someone confirm the observations I've made?
And also: Are the tutorials in the wiki not tested before being put online? It would seem that someone would have spotted that it doesn't actually work if it had been tested (well unless the animated entity is in a scene node with no transformation at all and the camera only looks from certain angles).
Thanks for taking the time to look at this.
Rune