mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 13:23:53 +00:00
far better camera movement
This commit is contained in:
parent
a7aeda9a3b
commit
db94018865
2 changed files with 14 additions and 58 deletions
|
@ -24,20 +24,9 @@ namespace MWRender
|
|||
pitchNode->attachObject(mCamera);
|
||||
}
|
||||
|
||||
void Player::rotateImpl(Ogre::Vector3 &rot, bool adjust, float r)
|
||||
{
|
||||
rotateCamera(rot, adjust);
|
||||
|
||||
if (mVanityMode || mPreviewMode || !mFirstPersonView) {
|
||||
moveCamera(r);
|
||||
}
|
||||
updateListener();
|
||||
}
|
||||
|
||||
bool Player::rotate(const Ogre::Vector3 &rot, bool adjust)
|
||||
{
|
||||
Ogre::Vector3 _rot = rot;
|
||||
rotateImpl(_rot, adjust, 400.f);
|
||||
rotateCamera(rot, adjust);
|
||||
|
||||
mUpdates = 0;
|
||||
mTimeIdle = 0.f;
|
||||
|
@ -49,7 +38,7 @@ namespace MWRender
|
|||
return !mVanityMode && !mPreviewMode;
|
||||
}
|
||||
|
||||
void Player::rotateCamera(Ogre::Vector3 &rot, bool adjust)
|
||||
void Player::rotateCamera(const Ogre::Vector3 &rot, bool adjust)
|
||||
{
|
||||
Ogre::SceneNode *pitchNode = mCamera->getParentSceneNode();
|
||||
Ogre::SceneNode *yawNode = pitchNode->getParentSceneNode();
|
||||
|
@ -75,39 +64,7 @@ namespace MWRender
|
|||
pitchNode->setOrientation(xr);
|
||||
yawNode->setOrientation(yr);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::moveCamera(float r)
|
||||
{
|
||||
/*
|
||||
Ogre::Quaternion orient =
|
||||
mCamera->getParentSceneNode()->getOrientation();
|
||||
|
||||
float pitchAngle =
|
||||
(2 * Ogre::Degree(Ogre::Math::ASin(orient.x)).valueDegrees());
|
||||
|
||||
orient = mCameraNode->getOrientation();
|
||||
float yawAngle =
|
||||
(2 * Ogre::Degree(Ogre::Math::ASin(orient.y)).valueDegrees());
|
||||
|
||||
float tana = Ogre::Math::Tan(Ogre::Degree(pitchAngle));
|
||||
float tansq = tana * tana;
|
||||
|
||||
float r1 = hsq * rsq / (hsq + rsq * tansq);
|
||||
float zsq = r1 * tansq;
|
||||
r1 = Ogre::Math::Sqrt(r1);
|
||||
|
||||
Ogre::Vector3 pos;
|
||||
pos.y = -Ogre::Math::Sqrt(zsq);
|
||||
pos.z = r1 * Ogre::Math::Sin(Ogre::Degree(yawAngle).valueDegrees());
|
||||
pos.x = r1 * Ogre::Math::Cos(Ogre::Degree(yawAngle).valueDegrees());
|
||||
*/
|
||||
Ogre::Vector3 dir = mCamera->getRealDirection();
|
||||
dir.x = -dir.x, dir.y = -dir.y, dir.z = -dir.z;
|
||||
|
||||
Ogre::Ray ray(Ogre::Vector3(0, 0, 0), dir);
|
||||
|
||||
mCameraNode->setPosition(ray.getPoint(r));
|
||||
updateListener();
|
||||
}
|
||||
|
||||
std::string Player::getHandle() const
|
||||
|
@ -168,7 +125,7 @@ namespace MWRender
|
|||
if (mVanityMode) {
|
||||
Ogre::Vector3 rot(0.f, 0.f, 0.f);
|
||||
rot.z = Ogre::Degree(3.f * duration).valueRadians();
|
||||
rotateImpl(rot, true, 300.f);
|
||||
rotateCamera(rot, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,9 +133,9 @@ namespace MWRender
|
|||
{
|
||||
mFirstPersonView = !mFirstPersonView;
|
||||
if (mFirstPersonView) {
|
||||
mCameraNode->setPosition(0.f, 0.f, 0.f);
|
||||
mCamera->setPosition(0.f, 0.f, 0.f);
|
||||
} else {
|
||||
moveCamera(400.f);
|
||||
mCamera->setPosition(0.f, 0.f, 400.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,20 +143,21 @@ namespace MWRender
|
|||
{
|
||||
mVanityMode = !mVanityMode;
|
||||
|
||||
float r = 400.f;
|
||||
float offset = 300.f;
|
||||
Ogre::Vector3 rot(0.f, 0.f, 0.f);
|
||||
if (mVanityMode) {
|
||||
mPitch = getPitchAngle();
|
||||
mYaw = getYawAngle();
|
||||
mPitch = getPitchAngle();
|
||||
mOffset = mCamera->getPosition().z;
|
||||
|
||||
rot.x = Ogre::Degree(-30.f).valueRadians();
|
||||
rot.z = 0;
|
||||
r = 300.f;
|
||||
} else {
|
||||
rot.x = Ogre::Degree(mPitch).valueRadians();
|
||||
rot.z = Ogre::Degree(mYaw).valueRadians();
|
||||
offset = mOffset;
|
||||
}
|
||||
rotateImpl(rot, false, r);
|
||||
mCamera->setPosition(0.f, 0.f, offset);
|
||||
rotateCamera(rot, false);
|
||||
}
|
||||
|
||||
void Player::togglePreviewMode()
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace MWRender
|
|||
bool mVanityMode;
|
||||
bool mPreviewMode;
|
||||
|
||||
float mPitch, mYaw;
|
||||
float mPitch, mYaw, mOffset;
|
||||
|
||||
float mTimeIdle;
|
||||
int mUpdates;
|
||||
|
@ -39,9 +39,7 @@ namespace MWRender
|
|||
/// Updates sound manager listener data
|
||||
void updateListener();
|
||||
|
||||
void rotateImpl(Ogre::Vector3 &rot, bool adjust, float r);
|
||||
void rotateCamera(Ogre::Vector3 &rot, bool adjust);
|
||||
void moveCamera(float r);
|
||||
void rotateCamera(const Ogre::Vector3 &rot, bool adjust);
|
||||
|
||||
float getYawAngle();
|
||||
float getPitchAngle();
|
||||
|
|
Loading…
Reference in a new issue