Orientation issue

Xenomorph

09-05-2010 07:42:01

Hi there,
I have some issues with setting my character's (Ogre's mesh) orientation to the NxOgre::Actor's orientation and vise versa. I don't know if there is a conversion issue with the NxOgre::Quat and the Ogre::Quaternion, but it doesn't work properly. It should though, unless I made a mistake which I hope you can point out to me.
Ok, here is what I had before I started using NxOgre which is setting my character's position and orientation acording to the user's input which worked perfectly fine:
//get the direction
Ogre::Quaternion orientation = mObjectNode->getOrientation();
orientation.normalise();
Vector3 forward = orientation * Ogre::Vector3(0, 0, 1.0);
forward.normalise();
Vector3 right = orientation * Ogre::Vector3(-1.0, 0, 0);
right.normalise();

Ogre::Quaternion rollPitch = Quaternion(Degree(mAngleRoll), forward) *
Quaternion(Degree(mAnglePitch), right);
Ogre::Quaternion yaw = Quaternion(Degree(mAngleYaw), Vector3::UNIT_Y);
orientation = rollPitch * yaw;

Vector3 position = ((SceneNode*)mObjectNode->getChild("AvatarMoveNode"))->getPosition();
mDirection = orientation * position;
mDirection.normalise();
Vector3 planeDirection = mDirection;
planeDirection.y = 0;

mObjectNode->setOrientation(rollPitch);
mMovementNode->setOrientation(yaw);

//move to direction
mMovementNode->translate(planeDirection * mSpeed * frameRate, Node::TS_WORLD);

Now, what I'm trying to do is to have a dynamic actor and control it with forces. But I want to control the actor's pitch, roll, and yaw with the user's input like before. So, after getting the Quaternions to set the orientation of the actor I set the orientation with setGlobalOrientation and set the position with setGlobalPosition. Then I get the GlobalPosition and set my character's position with that value and with the orientation I use the rollPitch and yaw quaternions like above because i want my camera to be directly behind the character. If I do it like this then the character should be at the same position than the actor and it should have the same orientation than the actor. The position is the same, so it works, but the orientation doesn't work. The orientation of the actor actually behaves like it is supposed to and is perfectly fine, but the character's orientation acts a little differently. It's hard to explain how it moves, but it doesn't move entirely correct. I hope you see what the problem is within the code because I don't :)
So, here is the new code that doesn't work properly:
//get the direction
Ogre::Quaternion orientation = mActor->getGlobalOrientationQuat().as<Ogre::Quaternion>();
//Ogre::Quaternion orientation = mObjectNode->getOrientation();
orientation.normalise();
Vector3 forward = orientation * Ogre::Vector3(0, 0, 1.0);
forward.normalise();
Vector3 right = orientation * Ogre::Vector3(-1.0, 0, 0);
right.normalise();

Ogre::Quaternion rollPitch = Quaternion(Degree(mAngleRoll), forward) *
Quaternion(Degree(mAnglePitch), right);
Ogre::Quaternion yaw = Quaternion(Degree(mAngleYaw), Vector3::UNIT_Y);
orientation = rollPitch * yaw;

mDirection = orientation * Vector3(0,0,1);
mDirection.normalise();
Vector3 planeDirection = mDirection;
planeDirection.y = 0;

mActor->setGlobalOrientationQuat(orientation);
mObjectNode->setOrientation(rollPitch);
mMovementNode->setOrientation(yaw);

//move to direction
Vector3 actorPosition = mActor->getGlobalPosition().as<Ogre::Vector3>();
actorPosition.y += ACTOR_POS_OFFSET_Y;
mMovementNode->setPosition(actorPosition);

I hope everything I said up there makes sense :) I mean all I want is that the character's orientation is the same as the actor's orientation.

Also, I just want to let you know that when I swith this two lines:
Ogre::Quaternion orientation = mActor->getGlobalOrientationQuat().as<Ogre::Quaternion>();
//Ogre::Quaternion orientation = mObjectNode->getOrientation();

then I get the exact opposite behavior. The character's orientation works perfectly fine, but then the actor's orientation behaves exactly like the character's orientation before I made the switch. So, I really don't know why this is.
Please help me out. Any help is highly appreciated! Thanks in advance!