1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-02 09:45:32 +00:00

fix camera bug

This commit is contained in:
gugus 2011-02-23 12:28:46 +01:00
parent ada4616fd3
commit ab1fa41c24

View file

@ -2,6 +2,7 @@
#include <OIS/OIS.h> #include <OIS/OIS.h>
#include <OgreCamera.h> #include <OgreCamera.h>
#include <OgreSceneNode.h>
using namespace OIS; using namespace OIS;
using namespace Ogre; using namespace Ogre;
@ -16,22 +17,41 @@ void MouseLookEvent::event(Type type, int index, const void *p)
float x = arg->state.X.rel * sensX; float x = arg->state.X.rel * sensX;
float y = arg->state.Y.rel * sensY; float y = arg->state.Y.rel * sensY;
camera->yaw(Degree(-x)); camera->getParentSceneNode()->getParentSceneNode()->yaw(Degree(-x));
camera->getParentSceneNode()->pitch(Degree(-y));
if(flipProt) if(flipProt)
{ {
// The camera before pitching // The camera before pitching
Quaternion nopitch = camera->getOrientation(); /*Quaternion nopitch = camera->getParentSceneNode()->getOrientation();
camera->pitch(Degree(-y)); camera->getParentSceneNode()->pitch(Degree(-y));
// Apply some failsafe measures against the camera flipping // Apply some failsafe measures against the camera flipping
// upside down. Is the camera close to pointing straight up or // upside down. Is the camera close to pointing straight up or
// down? // down?
if(camera->getUp()[1] <= 0.1) if(Ogre::Vector3(camera->getParentSceneNode()->getOrientation()*Ogre::Vector3::UNIT_Y)[1] <= 0.1)
// If so, undo the last pitch // If so, undo the last pitch
camera->setOrientation(nopitch); camera->getParentSceneNode()->setOrientation(nopitch);*/
//camera->getU
// Angle of rotation around the X-axis.
float pitchAngle = (2 * Ogre::Degree(Ogre::Math::ACos(camera->getParentSceneNode()->getOrientation().w)).valueDegrees());
// Just to determine the sign of the angle we pick up above, the
// value itself does not interest us.
float pitchAngleSign = camera->getParentSceneNode()->getOrientation().x;
// Limit the pitch between -90 degress and +90 degrees, Quake3-style.
if (pitchAngle > 90.0f)
{
if (pitchAngleSign > 0)
// Set orientation to 90 degrees on X-axis.
camera->getParentSceneNode()->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
Ogre::Math::Sqrt(0.5f), 0, 0));
else if (pitchAngleSign < 0)
// Sets orientation to -90 degrees on X-axis.
camera->getParentSceneNode()->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),
-Ogre::Math::Sqrt(0.5f), 0, 0));
}
} }
else
camera->pitch(Degree(-y));
} }