1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:53:51 +00:00

Refactoring. Simplification of camera interface.

This commit is contained in:
Petr Mikheev 2020-07-25 22:42:58 +02:00
parent ed3426cf2f
commit 694e0b5906
10 changed files with 42 additions and 93 deletions

View file

@ -427,9 +427,8 @@ namespace MWBase
virtual void togglePreviewMode(bool enable) = 0; virtual void togglePreviewMode(bool enable) = 0;
virtual bool toggleVanityMode(bool enable) = 0; virtual bool toggleVanityMode(bool enable) = 0;
virtual void allowVanityMode(bool allow) = 0; virtual void allowVanityMode(bool allow) = 0;
virtual void changeVanityModeScale(float factor) = 0;
virtual bool vanityRotateCamera(float * rot) = 0; virtual bool vanityRotateCamera(float * rot) = 0;
virtual void setCameraDistance(float dist, bool adjust = false, bool override = true)=0; virtual void adjustCameraDistance(float dist) = 0;
virtual void applyDeferredPreviewRotationToPlayer(float dt) = 0; virtual void applyDeferredPreviewRotationToPlayer(float dt) = 0;
virtual void disableDeferredPreviewRotation() = 0; virtual void disableDeferredPreviewRotation() = 0;

View file

@ -26,7 +26,7 @@
namespace MWInput namespace MWInput
{ {
const float ZOOM_SCALE = 120.f; /// Used for scrolling camera in and out const float ZOOM_SCALE = 10.f; /// Used for scrolling camera in and out
ActionManager::ActionManager(BindingsManager* bindingsManager, ActionManager::ActionManager(BindingsManager* bindingsManager,
osgViewer::ScreenCaptureHandler::CaptureOperation* screenCaptureOperation, osgViewer::ScreenCaptureHandler::CaptureOperation* screenCaptureOperation,
@ -195,6 +195,8 @@ namespace MWInput
void ActionManager::executeAction(int action) void ActionManager::executeAction(int action)
{ {
auto* inputManager = MWBase::Environment::get().getInputManager();
auto* windowManager = MWBase::Environment::get().getWindowManager();
// trigger action activated // trigger action activated
switch (action) switch (action)
{ {
@ -211,7 +213,7 @@ namespace MWInput
toggleConsole (); toggleConsole ();
break; break;
case A_Activate: case A_Activate:
MWBase::Environment::get().getInputManager()->resetIdleTime(); inputManager->resetIdleTime();
activate(); activate();
break; break;
case A_MoveLeft: case A_MoveLeft:
@ -272,18 +274,18 @@ namespace MWInput
showQuickKeysMenu(); showQuickKeysMenu();
break; break;
case A_ToggleHUD: case A_ToggleHUD:
MWBase::Environment::get().getWindowManager()->toggleHud(); windowManager->toggleHud();
break; break;
case A_ToggleDebug: case A_ToggleDebug:
MWBase::Environment::get().getWindowManager()->toggleDebugWindow(); windowManager->toggleDebugWindow();
break; break;
case A_ZoomIn: case A_ZoomIn:
if (MWBase::Environment::get().getInputManager()->getControlSwitch("playerviewswitch") && MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols") && !MWBase::Environment::get().getWindowManager()->isGuiMode()) if (inputManager->getControlSwitch("playerviewswitch") && inputManager->getControlSwitch("playercontrols") && !windowManager->isGuiMode())
MWBase::Environment::get().getWorld()->setCameraDistance(ZOOM_SCALE, true, true); MWBase::Environment::get().getWorld()->adjustCameraDistance(-ZOOM_SCALE);
break; break;
case A_ZoomOut: case A_ZoomOut:
if (MWBase::Environment::get().getInputManager()->getControlSwitch("playerviewswitch") && MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols") && !MWBase::Environment::get().getWindowManager()->isGuiMode()) if (inputManager->getControlSwitch("playerviewswitch") && inputManager->getControlSwitch("playercontrols") && !windowManager->isGuiMode())
MWBase::Environment::get().getWorld()->setCameraDistance(-ZOOM_SCALE, true, true); MWBase::Environment::get().getWorld()->adjustCameraDistance(ZOOM_SCALE);
break; break;
case A_QuickSave: case A_QuickSave:
quickSave(); quickSave();
@ -292,19 +294,19 @@ namespace MWInput
quickLoad(); quickLoad();
break; break;
case A_CycleSpellLeft: case A_CycleSpellLeft:
if (checkAllowedToUseItems() && MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Magic)) if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Magic))
MWBase::Environment::get().getWindowManager()->cycleSpell(false); MWBase::Environment::get().getWindowManager()->cycleSpell(false);
break; break;
case A_CycleSpellRight: case A_CycleSpellRight:
if (checkAllowedToUseItems() && MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Magic)) if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Magic))
MWBase::Environment::get().getWindowManager()->cycleSpell(true); MWBase::Environment::get().getWindowManager()->cycleSpell(true);
break; break;
case A_CycleWeaponLeft: case A_CycleWeaponLeft:
if (checkAllowedToUseItems() && MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory)) if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Inventory))
MWBase::Environment::get().getWindowManager()->cycleWeapon(false); MWBase::Environment::get().getWindowManager()->cycleWeapon(false);
break; break;
case A_CycleWeaponRight: case A_CycleWeaponRight:
if (checkAllowedToUseItems() && MWBase::Environment::get().getWindowManager()->isAllowed(MWGui::GW_Inventory)) if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Inventory))
MWBase::Environment::get().getWindowManager()->cycleWeapon(true); MWBase::Environment::get().getWindowManager()->cycleWeapon(true);
break; break;
case A_Sneak: case A_Sneak:

View file

@ -190,10 +190,7 @@ namespace MWInput
mGamepadZoom = 0; mGamepadZoom = 0;
if (mGamepadZoom) if (mGamepadZoom)
{ MWBase::Environment::get().getWorld()->adjustCameraDistance(-mGamepadZoom);
MWBase::Environment::get().getWorld()->changeVanityModeScale(mGamepadZoom);
MWBase::Environment::get().getWorld()->setCameraDistance(mGamepadZoom, true, true);
}
} }
return triedToMove; return triedToMove;
@ -291,12 +288,12 @@ namespace MWInput
{ {
if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERRIGHT)
{ {
mGamepadZoom = arg.value * 0.85f / 1000.f; mGamepadZoom = arg.value * 0.85f / 1000.f / 12.f;
return; // Do not propagate event. return; // Do not propagate event.
} }
else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT) else if (arg.axis == SDL_CONTROLLER_AXIS_TRIGGERLEFT)
{ {
mGamepadZoom = -arg.value * 0.85f / 1000.f; mGamepadZoom = -arg.value * 0.85f / 1000.f / 12.f;
return; // Do not propagate event. return; // Do not propagate event.
} }
} }

View file

@ -70,6 +70,7 @@ namespace MWInput
mBindingsManager->mouseMoved(arg); mBindingsManager->mouseMoved(arg);
MWBase::InputManager* input = MWBase::Environment::get().getInputManager(); MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
MWBase::World* world = MWBase::Environment::get().getWorld();
input->setJoystickLastUsed(false); input->setJoystickLastUsed(false);
input->resetIdleTime(); input->resetIdleTime();
@ -102,19 +103,14 @@ namespace MWInput
rot[2] = -x; rot[2] = -x;
// Only actually turn player when we're not in vanity mode // Only actually turn player when we're not in vanity mode
if (!MWBase::Environment::get().getWorld()->vanityRotateCamera(rot) && input->getControlSwitch("playerlooking")) if (!world->vanityRotateCamera(rot) && input->getControlSwitch("playerlooking"))
{ {
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer(); MWWorld::Player& player = world->getPlayer();
player.yaw(x); player.yaw(x);
player.pitch(y); player.pitch(y);
} }
else if (!input->getControlSwitch("playerlooking")) else if (!input->getControlSwitch("playerlooking"))
MWBase::Environment::get().getWorld()->disableDeferredPreviewRotation(); world->disableDeferredPreviewRotation();
if (arg.zrel && input->getControlSwitch("playerviewswitch") && input->getControlSwitch("playercontrols")) //Check to make sure you are allowed to zoomout and there is a change
{
MWBase::Environment::get().getWorld()->changeVanityModeScale(static_cast<float>(arg.zrel));
}
} }
} }

View file

@ -418,26 +418,24 @@ namespace MWRender
return mCameraDistance; return mCameraDistance;
} }
void Camera::updateBaseCameraDistance(float dist, bool adjust) void Camera::adjustCameraDistance(float delta)
{ {
if (isFirstPerson()) if (!isFirstPerson())
return; {
if(isNearest() && delta < 0.f && getMode() != Mode::Preview && getMode() != Mode::Vanity)
if (adjust) toggleViewMode();
dist += std::min(mCameraDistance - getCameraDistanceCorrection(), mBaseCameraDistance); else
mBaseCameraDistance = std::min(mCameraDistance - getCameraDistanceCorrection(), mBaseCameraDistance) + delta;
mIsNearest = dist <= mNearest; }
mBaseCameraDistance = osg::clampBetween(dist, mNearest, mFurthest); else if (delta > 0.f)
Settings::Manager::setFloat("third person camera distance", "Camera", mBaseCameraDistance); {
toggleViewMode();
mBaseCameraDistance = 0;
} }
void Camera::setCameraDistance(float dist, bool adjust) mIsNearest = mBaseCameraDistance <= mNearest;
{ mBaseCameraDistance = osg::clampBetween(mBaseCameraDistance, mNearest, mFurthest);
if (isFirstPerson()) Settings::Manager::setFloat("third person camera distance", "Camera", mBaseCameraDistance);
return;
if (adjust)
dist += mCameraDistance;
mCameraDistance = osg::clampBetween(dist, 10.f, mFurthest);
} }
float Camera::getCameraDistanceCorrection() const float Camera::getCameraDistanceCorrection() const

View file

@ -136,14 +136,8 @@ namespace MWRender
void update(float duration, bool paused=false); void update(float duration, bool paused=false);
/// Set base camera distance for current mode. Don't work on 1st person view. /// Adds distDelta to the camera distance. Switches 3rd/1st person view if distance is less than limit.
/// \param adjust Indicates should distance be adjusted or set. void adjustCameraDistance(float distDelta);
void updateBaseCameraDistance(float dist, bool adjust = false);
/// Set camera distance for current mode. Don't work on 1st person view.
/// \param adjust Indicates should distance be adjusted or set.
/// Default distance can be restored with setCameraDistance().
void setCameraDistance(float dist, bool adjust = false);
float getCameraDistance() const; float getCameraDistance() const;

View file

@ -1325,27 +1325,6 @@ namespace MWRender
return true; return true;
} }
void RenderingManager::setCameraDistance(float dist, bool adjust, bool override)
{
if(!mCamera->isVanityOrPreviewModeEnabled() && !mCamera->isFirstPerson())
{
if(mCamera->isNearest() && dist > 0.f)
mCamera->toggleViewMode();
else if (override)
mCamera->updateBaseCameraDistance(-dist / 120.f * 10, adjust);
else
mCamera->setCameraDistance(-dist / 120.f * 10, adjust);
}
else if(mCamera->isFirstPerson() && dist < 0.f)
{
mCamera->toggleViewMode();
if (override)
mCamera->updateBaseCameraDistance(0.f, false);
else
mCamera->setCameraDistance(0.f, false);
}
}
void RenderingManager::resetCamera() void RenderingManager::resetCamera()
{ {
mCamera->reset(); mCamera->reset();
@ -1386,12 +1365,6 @@ namespace MWRender
mCamera->allowVanityMode(allow); mCamera->allowVanityMode(allow);
} }
void RenderingManager::changeVanityModeScale(float factor)
{
if(mCamera->isVanityOrPreviewModeEnabled())
mCamera->updateBaseCameraDistance(-factor/120.f*10, true);
}
void RenderingManager::overrideFieldOfView(float val) void RenderingManager::overrideFieldOfView(float val)
{ {
if (mFieldOfViewOverridden != true || mFieldOfViewOverride != val) if (mFieldOfViewOverridden != true || mFieldOfViewOverride != val)

View file

@ -210,7 +210,6 @@ namespace MWRender
// camera stuff // camera stuff
bool vanityRotateCamera(const float *rot); bool vanityRotateCamera(const float *rot);
void setCameraDistance(float dist, bool adjust, bool override);
void resetCamera(); void resetCamera();
float getCameraDistance() const; float getCameraDistance() const;
Camera* getCamera(); Camera* getCamera();
@ -219,7 +218,6 @@ namespace MWRender
void togglePreviewMode(bool enable); void togglePreviewMode(bool enable);
bool toggleVanityMode(bool enable); bool toggleVanityMode(bool enable);
void allowVanityMode(bool allow); void allowVanityMode(bool allow);
void changeVanityModeScale(float factor);
/// temporarily override the field of view with given value. /// temporarily override the field of view with given value.
void overrideFieldOfView(float val); void overrideFieldOfView(float val);

View file

@ -2394,19 +2394,14 @@ namespace MWWorld
mRendering->allowVanityMode(allow); mRendering->allowVanityMode(allow);
} }
void World::changeVanityModeScale(float factor)
{
mRendering->changeVanityModeScale(factor);
}
bool World::vanityRotateCamera(float * rot) bool World::vanityRotateCamera(float * rot)
{ {
return mRendering->vanityRotateCamera(rot); return mRendering->vanityRotateCamera(rot);
} }
void World::setCameraDistance(float dist, bool adjust, bool override_) void World::adjustCameraDistance(float dist)
{ {
mRendering->setCameraDistance(dist, adjust, override_); mRendering->getCamera()->adjustCameraDistance(dist);
} }
void World::setupPlayer() void World::setupPlayer()

View file

@ -533,11 +533,8 @@ namespace MWWorld
bool toggleVanityMode(bool enable) override; bool toggleVanityMode(bool enable) override;
void allowVanityMode(bool allow) override; void allowVanityMode(bool allow) override;
void changeVanityModeScale(float factor) override;
bool vanityRotateCamera(float * rot) override; bool vanityRotateCamera(float * rot) override;
void setCameraDistance(float dist, bool adjust = false, bool override = true) override; void adjustCameraDistance(float dist) override;
void applyDeferredPreviewRotationToPlayer(float dt) override; void applyDeferredPreviewRotationToPlayer(float dt) override;
void disableDeferredPreviewRotation() override; void disableDeferredPreviewRotation() override;