1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-02 06:45:31 +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;
@ -9,29 +10,48 @@ using namespace OEngine::Render;
void MouseLookEvent::event(Type type, int index, const void *p) void MouseLookEvent::event(Type type, int index, const void *p)
{ {
if(type != EV_MouseMove || camera == NULL) return; if(type != EV_MouseMove || camera == NULL) return;
MouseEvent *arg = (MouseEvent*)(p); MouseEvent *arg = (MouseEvent*)(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)
{
// The camera before pitching
/*Quaternion nopitch = camera->getParentSceneNode()->getOrientation();
if(flipProt) camera->getParentSceneNode()->pitch(Degree(-y));
{
// The camera before pitching
Quaternion nopitch = camera->getOrientation();
camera->pitch(Degree(-y)); // Apply some failsafe measures against the camera flipping
// upside down. Is the camera close to pointing straight up or
// down?
if(Ogre::Vector3(camera->getParentSceneNode()->getOrientation()*Ogre::Vector3::UNIT_Y)[1] <= 0.1)
// If so, undo the last pitch
camera->getParentSceneNode()->setOrientation(nopitch);*/
//camera->getU
// Apply some failsafe measures against the camera flipping // Angle of rotation around the X-axis.
// upside down. Is the camera close to pointing straight up or float pitchAngle = (2 * Ogre::Degree(Ogre::Math::ACos(camera->getParentSceneNode()->getOrientation().w)).valueDegrees());
// down?
if(camera->getUp()[1] <= 0.1) // Just to determine the sign of the angle we pick up above, the
// If so, undo the last pitch // value itself does not interest us.
camera->setOrientation(nopitch); float pitchAngleSign = camera->getParentSceneNode()->getOrientation().x;
}
else // Limit the pitch between -90 degress and +90 degrees, Quake3-style.
camera->pitch(Degree(-y)); 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));
}
}
} }