1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-31 23:15:41 +00:00

update camera code, add idle time

This commit is contained in:
greye 2012-08-18 01:31:57 +04:00
parent 14f293882c
commit b8e56d61d3
4 changed files with 63 additions and 20 deletions

View file

@ -46,6 +46,7 @@ namespace MWInput
, mCameraYMultiplier (Settings::Manager::getFloat("camera y multiplier", "Input"))
, mUIYMultiplier (Settings::Manager::getFloat("ui y multiplier", "Input"))
, mPreviewPOVDelay(0.f)
, mTimeIdle(0.f)
{
Ogre::RenderWindow* window = ogre.getWindow ();
size_t windowHnd;
@ -164,24 +165,30 @@ namespace MWInput
toggleConsole ();
break;
case A_Activate:
resetIdleTime();
activate();
break;
case A_Journal:
toggleJournal ();
break;
case A_AutoMove:
resetIdleTime();
toggleAutoMove ();
break;
case A_ToggleSneak:
/// \todo implement
resetIdleTime();
break;
case A_ToggleWalk:
resetIdleTime();
toggleWalking ();
break;
case A_ToggleWeapon:
resetIdleTime();
toggleWeapon ();
break;
case A_ToggleSpell:
resetIdleTime();
toggleSpell ();
break;
}
@ -265,6 +272,18 @@ namespace MWInput
}
}
}
if (actionIsActive(A_MoveForward) ||
actionIsActive(A_MoveBackward) ||
actionIsActive(A_MoveLeft) ||
actionIsActive(A_MoveRight) ||
actionIsActive(A_Jump) ||
actionIsActive(A_Crouch) ||
actionIsActive(A_TogglePOV))
{
resetIdleTime();
} else {
updateIdleTime(dt);
}
}
void InputManager::setDragDrop(bool dragDrop)
@ -402,6 +421,8 @@ namespace MWInput
if (mMouseLookEnabled)
{
resetIdleTime();
float x = arg.state.X.rel * mCameraSensitivity * 0.2;
float y = arg.state.Y.rel * mCameraSensitivity * 0.2 * (mInvertY ? -1 : 1) * mUIYMultiplier;
@ -528,6 +549,25 @@ namespace MWInput
Ogre::Root::getSingleton().queueEndRendering ();
}
void InputManager::resetIdleTime()
{
if (mTimeIdle < 0) {
MWBase::Environment::get().getWorld()->toggleVanityMode(false, false);
}
mTimeIdle = 0.f;
}
void InputManager::updateIdleTime(float dt)
{
if (mTimeIdle >= 0.f) {
mTimeIdle += dt;
}
if (mTimeIdle > 30.f) {
MWBase::Environment::get().getWorld()->toggleVanityMode(true, false);
mTimeIdle = -1.f;
}
}
bool InputManager::actionIsActive (int id)
{
return mInputCtrl->getChannel (id)->getValue () == 1;

View file

@ -83,7 +83,6 @@ namespace MWInput
virtual void enableDetectingBindingMode (int action);
virtual void resetToDefaultBindings();
public:
virtual bool keyPressed( const OIS::KeyEvent &arg );
virtual bool keyReleased( const OIS::KeyEvent &arg );
@ -140,6 +139,7 @@ namespace MWInput
float mCameraYMultiplier;
float mUIYMultiplier;
float mPreviewPOVDelay;
float mTimeIdle;
bool mMouseLookEnabled;
bool mGuiCursorEnabled;
@ -149,10 +149,12 @@ namespace MWInput
std::map<std::string, bool> mControlSwitch;
private:
void adjustMouseRegion(int width, int height);
void resetIdleTime();
void updateIdleTime(float dt);
private:
void toggleMainMenu();
void toggleSpell();

View file

@ -2,7 +2,6 @@
#include <OgreSceneNode.h>
#include <OgreCamera.h>
#include <OgreRay.h>
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
@ -38,9 +37,6 @@ namespace MWRender
bool Player::rotate(const Ogre::Vector3 &rot, bool adjust)
{
mUpdates = 0;
mTimeIdle = 0.f;
if (mVanity.enabled) {
toggleVanityMode(false);
}
@ -120,13 +116,6 @@ namespace MWRender
void Player::update(float duration)
{
Ogre::Vector3 pos = mPlayerNode->getPosition();
if (!mVanity.enabled) {
++mUpdates;
mTimeIdle += duration;
if (mTimeIdle > 30.f) {
toggleVanityMode(true);
}
}
if (mAnimation) {
mAnimation->runAnimation(duration);
}
@ -145,10 +134,10 @@ namespace MWRender
mFirstPersonView = !mFirstPersonView;
if (mFirstPersonView) {
mCamera->setPosition(0.f, 0.f, 0.f);
mCameraNode->setPosition(0.f, 0.f, 128.f);
setLowHeight(false);
} else {
mCamera->setPosition(0.f, 0.f, mCameraDistance);
mCameraNode->setPosition(0.f, 0.f, 104.f);
setLowHeight(true);
}
mPlayerNode->setVisible(!mFirstPersonView, false);
}
@ -176,15 +165,17 @@ namespace MWRender
float offset = mPreviewCam.offset;
Ogre::Vector3 rot(0.f, 0.f, 0.f);
if (mVanity.enabled) {
mPlayerNode->setVisible(true, false);
rot.x = Ogre::Degree(-30.f).valueRadians();
mMainCam.offset = mCamera->getPosition().z;
mPlayerNode->setVisible(true, false);
setLowHeight(true);
} else {
rot.x = getPitch();
offset = mMainCam.offset;
mPlayerNode->setVisible(!mFirstPersonView, false);
setLowHeight(!mFirstPersonView);
}
rot.z = getYaw();
mCamera->setPosition(0.f, 0.f, offset);
@ -201,15 +192,17 @@ namespace MWRender
mPreviewMode = enable;
float offset = mCamera->getPosition().z;
if (mPreviewMode) {
mPlayerNode->setVisible(true, false);
mMainCam.offset = offset;
offset = mPreviewCam.offset;
mPlayerNode->setVisible(true, false);
setLowHeight(true);
} else {
mPreviewCam.offset = offset;
offset = mMainCam.offset;
mPlayerNode->setVisible(!mFirstPersonView, false);
setLowHeight(!mFirstPersonView);
}
mCamera->setPosition(0.f, 0.f, offset);
rotateCamera(Ogre::Vector3(getPitch(), 0.f, getYaw()), false);
@ -357,4 +350,13 @@ namespace MWRender
{
mFreeLook = enable;
}
void Player::setLowHeight(bool low)
{
if (low) {
mCameraNode->setPosition(0.f, 0.f, mHeight * 0.85);
} else {
mCameraNode->setPosition(0.f, 0.f, mHeight);
}
}
}

View file

@ -45,9 +45,6 @@ namespace MWRender
bool mDistanceAdjusted;
float mTimeIdle;
int mUpdates;
/// Updates sound manager listener data
void updateListener();
@ -61,6 +58,8 @@ namespace MWRender
void compensateYaw(float diff);
void setLowHeight(bool low = true);
public:
Player (Ogre::Camera *camera, Ogre::SceneNode* mNode);