I have a SceneNode that goes forward when 'W' is pressed (by adding a Vector3(0,0,-1) to the current position).
I'm trying to rotate the SceneNode based on mouse.X.rel in order to change where the SceneNode's Z Axis is pointed at, but so far I managed to 'turn my head' and the scene node keeps moving at the original direction.
Here's the relevant pieces of code:
In MainApp::go()
Code: Select all
p = scene->createSceneNode("p");
p->setPosition(Ogre::Vector3::ZERO);
p->setOrientation(Ogre::Quaternion::IDENTITY);
p->attachObject(camera);
Code: Select all
Ogre::Vector3 direction = p->getOrientation() * Ogre::Vector3::NEGATIVE_UNIT_Z;
direction.y = 0;
direction.normalise();
// ms below is a MouseState grabbed a few lines above
Ogre::Quaternion rotate = Ogre::Quaternion(-Ogre::Degree(ms.X.rel*0.1), Ogre::Vector3::UNIT_Y);
Ogre::Vector3 newDirection = rotate * direction;
Ogre::Quaternion newOrientation = Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo(newDirection);
p->setOrientation(newOrientation);
I'm using Ogre 1.9.0.
Thank you!