mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-10 15:45:37 +00:00
added camera flip control, fixed input rotation axis
This commit is contained in:
parent
ec9cf4d3c6
commit
a2d87d5f5b
@ -24,5 +24,5 @@ void MouseLookEvent::event(Type type, int index, const void *p)
|
|||||||
float y = arg->state.Y.rel * sensY;
|
float y = arg->state.Y.rel * sensY;
|
||||||
|
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
world->rotateObject(world->getPlayer().getPlayer(), -y, 0.f, -x, true);
|
world->rotateObject(world->getPlayer().getPlayer(), -y, 0.f, x, true);
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,16 @@ namespace MWRender
|
|||||||
// we are only interested in X and Y rotation
|
// we are only interested in X and Y rotation
|
||||||
|
|
||||||
// Rotate around X axis
|
// Rotate around X axis
|
||||||
Ogre::Quaternion xr(Ogre::Radian(rot.x), Ogre::Vector3::UNIT_X);
|
Ogre::Quaternion xr(Ogre::Degree(rot.x), Ogre::Vector3::UNIT_X);
|
||||||
|
|
||||||
// Rotate around Y axis
|
// Rotate around Y axis
|
||||||
Ogre::Quaternion yr(Ogre::Radian(-rot.z), Ogre::Vector3::UNIT_Y);
|
Ogre::Quaternion yr(Ogre::Degree(-rot.z), Ogre::Vector3::UNIT_Y);
|
||||||
|
|
||||||
pitchNode->setOrientation(xr);
|
pitchNode->setOrientation(xr);
|
||||||
yawNode->setOrientation(yr);
|
yawNode->setOrientation(yr);
|
||||||
|
|
||||||
|
controlFlip();
|
||||||
|
|
||||||
return !mVanityModeEnabled;
|
return !mVanityModeEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +53,32 @@ namespace MWRender
|
|||||||
Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode();
|
Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode();
|
||||||
|
|
||||||
pitchNode->pitch(Ogre::Degree(rot.x));
|
pitchNode->pitch(Ogre::Degree(rot.x));
|
||||||
yawNode->yaw(Ogre::Degree(rot.z));
|
yawNode->yaw(Ogre::Degree(-rot.z));
|
||||||
|
|
||||||
|
controlFlip();
|
||||||
|
|
||||||
return !mVanityModeEnabled;
|
return !mVanityModeEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::controlFlip()
|
||||||
|
{
|
||||||
|
Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode();
|
||||||
|
Ogre::Quaternion orient = pitchNode->getOrientation();
|
||||||
|
|
||||||
|
float pitchAngle =
|
||||||
|
(2 * Ogre::Degree(Ogre::Math::ACos(orient.w)).valueDegrees());
|
||||||
|
|
||||||
|
// Limit the pitch between -90 degress and +90 degrees, Quake3-style.
|
||||||
|
if (pitchAngle > 90.0f)
|
||||||
|
{
|
||||||
|
Ogre::Real sqrt = Ogre::Math::Sqrt(0.5f);
|
||||||
|
if (orient.x > 0) {
|
||||||
|
// Set orientation to 90 degrees on X-axis.
|
||||||
|
pitchNode->setOrientation(Ogre::Quaternion(sqrt, sqrt, 0, 0));
|
||||||
|
} else if (orient.x < 0) {
|
||||||
|
// Sets orientation to -90 degrees on X-axis.
|
||||||
|
pitchNode->setOrientation(Ogre::Quaternion(sqrt, -sqrt, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ namespace MWRender
|
|||||||
bool mFirstPersonView;
|
bool mFirstPersonView;
|
||||||
bool mVanityModeEnabled;
|
bool mVanityModeEnabled;
|
||||||
|
|
||||||
|
void controlFlip();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Player (Ogre::Camera *camera, Ogre::SceneNode* mNode);
|
Player (Ogre::Camera *camera, Ogre::SceneNode* mNode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user