I have two questions if someone could help me:
Question 1:
Due to user interface requirements I need to be able to determine the orientation of an object and display it to the user in XYZ format as degrees around the local axis i.e. X: 90, Z: 0, Y: 45 I then need to be able to take a users modifications to these values and apply them back to the objects orientation.
The problem is that I’m mathematically challenged and seem to be experiencing some difficulty understanding how to manipulate a Quaternion.
Could someone help me to understand why I’m seeing the values from the code below. I’m assuming that too many people are using this for it to be a bug and is therefore a mistake on my part.
Code: Select all
void createDefaultCamera( void )
{
Ogre::Quaternion q;
Ogre::Radian rad;
mCamera = mSceneMgr->createCamera( "Default" );
mCamera->setPosition( Vector3( 0, 0, 500 ) );
mCamera->setFixedYawAxis( false );
////////////////////////////////////////////
// Set Yaw Only
// Zero out
mCamera->setOrientation( Ogre::Quaternion::IDENTITY );
rad = Ogre::Radian( 1.5 );
mCamera->yaw( rad );
q = mCamera->getOrientation();
rad = q.getPitch(); // rad is set to 1.5
rad = q.getYaw(); // rad is set to 0
rad = q.getRoll(); // rad is set to 0
////////////////////////////////////////////
// Set Pitch Only
// Zero out
mCamera->setOrientation( Ogre::Quaternion::IDENTITY );
rad = Ogre::Radian( 1.5 );
mCamera->pitch( rad );
q = mCamera->getOrientation();
rad = q.getPitch(); // rad is set to 0
rad = q.getYaw(); // rad is set to 0
rad = q.getRoll(); // rad is set to 1.5
////////////////////////////////////////////
// Set Roll Only
// Zero out
mCamera->setOrientation( Ogre::Quaternion::IDENTITY );
rad = Ogre::Radian( 1.5 );
mCamera->roll( rad );
q = mCamera->getOrientation();
rad = q.getPitch(); // rad is set to 0
rad = q.getYaw(); // rad is set to 1.5
rad = q.getRoll(); // rad is set to 0
////////////////////////////////////////////
// Combine
// Zero out
mCamera->setOrientation( Ogre::Quaternion::IDENTITY );
rad = Ogre::Radian( 1.5 );
mCamera->pitch( rad );
rad = Ogre::Radian( 2 );
mCamera->yaw( rad );
rad = Ogre::Radian( 2.5 );
mCamera->roll( rad );
q = mCamera->getOrientation();
rad = q.getPitch(); // rad is set to -0.50071
rad = q.getYaw(); // rad is set to 0.048277
rad = q.getRoll(); // rad is set to 1.60435
// Look back along -Z
mCamera->lookAt( Vector3( 0, 0, -300 ) );
mCamera->setNearClipDistance( 5 );
}It would appear that getPitch() returns the yaw, getRoll() returns the pitch and that getYaw() returns the roll. That is until you combine calls to pitch(), yaw() and roll() at which point the numbers returned by getPitch(), getYaw() and getRoll() cease to make any sense to me. As I said I believe this to be my misunderstanding of how to manipulate Quaternion’s. Changing setFixedYawAxis() to true seems to have no impact on the first 3 tests. The result on the last test is to produce more numbers that I don’t understand the relevance of.
Question 2:
Could someone tell me how to convert a Quaternion to a Vector and then convert the Vector back to a Quaternion without data loss of course. I have seen this done in other products like. I need to be able to do this in order to comply with an existing network protocol.
If anyone could help me out with this it would certainly ease my rate of hair loss
I’m using Ogre 0.15.1 on XP with MS VC 2003
