mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-20 07:23:53 +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);
|
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;
|
rotateCamera(rot, adjust);
|
||||||
Ogre::Vector3 newRot = rot;
|
|
||||||
|
|
||||||
rotateCamera(newRot, adjust);
|
if (mVanityMode || mPreviewMode || !mFirstPersonView) {
|
||||||
|
moveCamera(r);
|
||||||
if (!force || !mFirstPersonView) {
|
|
||||||
moveCamera(400.f, 1600.f);
|
|
||||||
}
|
}
|
||||||
updateListener();
|
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)
|
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 =
|
Ogre::Quaternion orient =
|
||||||
|
@ -97,7 +107,7 @@ namespace MWRender
|
||||||
|
|
||||||
Ogre::Ray ray(Ogre::Vector3(0, 0, 0), dir);
|
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
|
std::string Player::getHandle() const
|
||||||
|
@ -145,13 +155,20 @@ namespace MWRender
|
||||||
|
|
||||||
void Player::update(float duration)
|
void Player::update(float duration)
|
||||||
{
|
{
|
||||||
|
if (!mVanityMode) {
|
||||||
|
++mUpdates;
|
||||||
|
mTimeIdle += duration;
|
||||||
|
if (mTimeIdle > 30.f) {
|
||||||
|
toggleVanityMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (mFirstPersonView && !mVanityMode) {
|
if (mFirstPersonView && !mVanityMode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mVanityMode) {
|
if (mVanityMode) {
|
||||||
/// \todo adjust rotation constantly
|
Ogre::Vector3 rot(0.f, 0.f, 0.f);
|
||||||
} else {
|
rot.z = Ogre::Degree(3.f * duration).valueRadians();
|
||||||
/// \todo move camera closer or change view mode if needed
|
rotateImpl(rot, true, 300.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,14 +178,28 @@ namespace MWRender
|
||||||
if (mFirstPersonView) {
|
if (mFirstPersonView) {
|
||||||
mCameraNode->setPosition(0.f, 0.f, 0.f);
|
mCameraNode->setPosition(0.f, 0.f, 0.f);
|
||||||
} else {
|
} else {
|
||||||
moveCamera(400.f, 1600.f);
|
moveCamera(400.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::toggleVanityMode()
|
void Player::toggleVanityMode()
|
||||||
{
|
{
|
||||||
/// \todo move camera
|
|
||||||
mVanityMode = !mVanityMode;
|
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()
|
void Player::togglePreviewMode()
|
||||||
|
@ -176,4 +207,28 @@ namespace MWRender
|
||||||
/// \todo move camera
|
/// \todo move camera
|
||||||
mPreviewMode = !mPreviewMode;
|
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,7 +3,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
class Vector3;
|
class Vector3;
|
||||||
|
@ -30,15 +29,22 @@ namespace MWRender
|
||||||
bool mVanityMode;
|
bool mVanityMode;
|
||||||
bool mPreviewMode;
|
bool mPreviewMode;
|
||||||
|
|
||||||
|
float mPitch, mYaw;
|
||||||
|
|
||||||
float mTimeIdle;
|
float mTimeIdle;
|
||||||
|
int mUpdates;
|
||||||
|
|
||||||
float limitPitchAngle(float limitAbs, float shift = 0.f);
|
float limitPitchAngle(float limitAbs, float shift = 0.f);
|
||||||
|
|
||||||
/// Updates sound manager listener data
|
/// Updates sound manager listener data
|
||||||
void updateListener();
|
void updateListener();
|
||||||
|
|
||||||
|
void rotateImpl(Ogre::Vector3 &rot, bool adjust, float r);
|
||||||
void rotateCamera(Ogre::Vector3 &rot, bool adjust);
|
void rotateCamera(Ogre::Vector3 &rot, bool adjust);
|
||||||
void moveCamera(float r, float h);
|
void moveCamera(float r);
|
||||||
|
|
||||||
|
float getYawAngle();
|
||||||
|
float getPitchAngle();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,17 @@ void RenderingManager::update (float duration){
|
||||||
|
|
||||||
mRendering.update(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) {
|
if (mWater) {
|
||||||
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
|
Ogre::Vector3 cam = mRendering.getCamera()->getRealPosition();
|
||||||
|
@ -323,7 +333,6 @@ void RenderingManager::update (float duration){
|
||||||
);
|
);
|
||||||
mWater->update(duration);
|
mWater->update(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
mPlayer->update(duration);
|
mPlayer->update(duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue