mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
initial vanity mode support
This commit is contained in:
parent
c46eeaa100
commit
a7aeda9a3b
3 changed files with 90 additions and 20 deletions
|
@ -24,19 +24,29 @@ namespace MWRender
|
|||
pitchNode->attachObject(mCamera);
|
||||
}
|
||||
|
||||
bool Player::rotate(const Ogre::Vector3 &rot, bool adjust)
|
||||
void Player::rotateImpl(Ogre::Vector3 &rot, bool adjust, float r)
|
||||
{
|
||||
bool force = !mVanityMode && !mPreviewMode;
|
||||
Ogre::Vector3 newRot = rot;
|
||||
rotateCamera(rot, adjust);
|
||||
|
||||
rotateCamera(newRot, adjust);
|
||||
|
||||
if (!force || !mFirstPersonView) {
|
||||
moveCamera(400.f, 1600.f);
|
||||
if (mVanityMode || mPreviewMode || !mFirstPersonView) {
|
||||
moveCamera(r);
|
||||
}
|
||||
updateListener();
|
||||
}
|
||||
|
||||
return force;
|
||||
bool Player::rotate(const Ogre::Vector3 &rot, bool adjust)
|
||||
{
|
||||
Ogre::Vector3 _rot = rot;
|
||||
rotateImpl(_rot, adjust, 400.f);
|
||||
|
||||
mUpdates = 0;
|
||||
mTimeIdle = 0.f;
|
||||
|
||||
if (mVanityMode) {
|
||||
toggleVanityMode();
|
||||
}
|
||||
|
||||
return !mVanityMode && !mPreviewMode;
|
||||
}
|
||||
|
||||
void Player::rotateCamera(Ogre::Vector3 &rot, bool adjust)
|
||||
|
@ -67,7 +77,7 @@ namespace MWRender
|
|||
}
|
||||
}
|
||||
|
||||
void Player::moveCamera(float rsq, float hsq)
|
||||
void Player::moveCamera(float r)
|
||||
{
|
||||
/*
|
||||
Ogre::Quaternion orient =
|
||||
|
@ -97,7 +107,7 @@ namespace MWRender
|
|||
|
||||
Ogre::Ray ray(Ogre::Vector3(0, 0, 0), dir);
|
||||
|
||||
mCameraNode->setPosition(ray.getPoint(800.f));
|
||||
mCameraNode->setPosition(ray.getPoint(r));
|
||||
}
|
||||
|
||||
std::string Player::getHandle() const
|
||||
|
@ -145,13 +155,20 @@ namespace MWRender
|
|||
|
||||
void Player::update(float duration)
|
||||
{
|
||||
if (!mVanityMode) {
|
||||
++mUpdates;
|
||||
mTimeIdle += duration;
|
||||
if (mTimeIdle > 30.f) {
|
||||
toggleVanityMode();
|
||||
}
|
||||
}
|
||||
if (mFirstPersonView && !mVanityMode) {
|
||||
return;
|
||||
}
|
||||
if (mVanityMode) {
|
||||
/// \todo adjust rotation constantly
|
||||
} else {
|
||||
/// \todo move camera closer or change view mode if needed
|
||||
Ogre::Vector3 rot(0.f, 0.f, 0.f);
|
||||
rot.z = Ogre::Degree(3.f * duration).valueRadians();
|
||||
rotateImpl(rot, true, 300.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,14 +178,28 @@ namespace MWRender
|
|||
if (mFirstPersonView) {
|
||||
mCameraNode->setPosition(0.f, 0.f, 0.f);
|
||||
} else {
|
||||
moveCamera(400.f, 1600.f);
|
||||
moveCamera(400.f);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::toggleVanityMode()
|
||||
{
|
||||
/// \todo move camera
|
||||
mVanityMode = !mVanityMode;
|
||||
|
||||
float r = 400.f;
|
||||
Ogre::Vector3 rot(0.f, 0.f, 0.f);
|
||||
if (mVanityMode) {
|
||||
mPitch = getPitchAngle();
|
||||
mYaw = getYawAngle();
|
||||
|
||||
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();
|
||||
}
|
||||
rotateImpl(rot, false, r);
|
||||
}
|
||||
|
||||
void Player::togglePreviewMode()
|
||||
|
@ -176,4 +207,28 @@ namespace MWRender
|
|||
/// \todo move camera
|
||||
mPreviewMode = !mPreviewMode;
|
||||
}
|
||||
|
||||
float Player::getPitchAngle()
|
||||
{
|
||||
Ogre::Quaternion orient
|
||||
= mCamera->getParentSceneNode()->getOrientation();
|
||||
|
||||
float angle =
|
||||
(2 * Ogre::Degree(Ogre::Math::ASin(orient.x)).valueDegrees());
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
float Player::getYawAngle()
|
||||
{
|
||||
Ogre::Quaternion orient
|
||||
= mCameraNode->getOrientation();
|
||||
|
||||
float angle =
|
||||
(2 * Ogre::Degree(Ogre::Math::ASin(orient.y)).valueDegrees());
|
||||
if (orient.w < 0) {
|
||||
angle = -angle;
|
||||
}
|
||||
return -angle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Ogre
|
||||
{
|
||||
{
|
||||
class Vector3;
|
||||
class Camera;
|
||||
class SceneNode;
|
||||
|
@ -30,15 +29,22 @@ namespace MWRender
|
|||
bool mVanityMode;
|
||||
bool mPreviewMode;
|
||||
|
||||
float mPitch, mYaw;
|
||||
|
||||
float mTimeIdle;
|
||||
int mUpdates;
|
||||
|
||||
float limitPitchAngle(float limitAbs, float shift = 0.f);
|
||||
|
||||
/// 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, float h);
|
||||
void moveCamera(float r);
|
||||
|
||||
float getYawAngle();
|
||||
float getPitchAngle();
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -309,7 +309,17 @@ void RenderingManager::update (float duration){
|
|||
|
||||
mRendering.update(duration);
|
||||
|
||||
mLocalMap->updatePlayer( mRendering.getCamera()->getRealPosition(), mRendering.getCamera()->getRealOrientation() );
|
||||
float *fpos =
|
||||
MWBase::Environment::get()
|
||||
.getWorld()
|
||||
->getPlayer()
|
||||
.getPlayer()
|
||||
.getRefData()
|
||||
.getPosition()
|
||||
.pos;
|
||||
Ogre::Vector3 pos(fpos[0], fpos[1], fpos[2]);
|
||||
|
||||
mLocalMap->updatePlayer(pos, mRendering.getCamera()->getRealOrientation() );
|
||||
|
||||
if (mWater) {
|
||||
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
|
||||
|
@ -323,7 +333,6 @@ void RenderingManager::update (float duration){
|
|||
);
|
||||
mWater->update(duration);
|
||||
}
|
||||
|
||||
mPlayer->update(duration);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue