From 060ae943ae4cd8ecfb98bad5ab2a027a4a5c363e Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 27 Jan 2023 18:57:04 +0100 Subject: [PATCH 1/3] codechange: CameraManager.h - protected 3 functions --- source/main/gfx/camera/CameraManager.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/main/gfx/camera/CameraManager.h b/source/main/gfx/camera/CameraManager.h index 2c4083f7fc..a50d16e13e 100644 --- a/source/main/gfx/camera/CameraManager.h +++ b/source/main/gfx/camera/CameraManager.h @@ -66,10 +66,6 @@ class CameraManager void NotifyContextChange(); void NotifyVehicleChanged(ActorPtr new_vehicle); - void CameraBehaviorOrbitReset(); - bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg); - void CameraBehaviorOrbitUpdate(); - bool mouseMoved(const OIS::MouseEvent& _arg); bool mousePressed(const OIS::MouseEvent& _arg, OIS::MouseButtonID _id); @@ -102,6 +98,9 @@ class CameraManager void CameraBehaviorVehicleSplineUpdateSpline(); void CameraBehaviorVehicleSplineUpdateSplineDisplay(); void CreateCameraNode(); + void CameraBehaviorOrbitReset(); + bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg); + void CameraBehaviorOrbitUpdate(); Ogre::Camera* m_camera; Ogre::SceneNode* m_camera_node; From 847476a20378d628a9ca49c6d4da56029870f724 Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 27 Jan 2023 19:39:47 +0100 Subject: [PATCH 2/3] Improved cinecam mouse rotation The rotation speed no longer depends on rendering resolution. The rotation is faster overall, horizontal rotation is a little faster than vertical rotation. --- source/main/gfx/camera/CameraManager.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/main/gfx/camera/CameraManager.cpp b/source/main/gfx/camera/CameraManager.cpp index ff67bd7b3a..5c488af84a 100644 --- a/source/main/gfx/camera/CameraManager.cpp +++ b/source/main/gfx/camera/CameraManager.cpp @@ -940,12 +940,24 @@ void CameraManager::CameraBehaviorOrbitUpdate() bool CameraManager::CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg) { - const OIS::MouseState ms = _arg.state; + const Ogre::Vector2 ROT_SPEED(550.f, 330.f); - if (ms.buttonDown(OIS::MB_Right)) + if (_arg.state.buttonDown(OIS::MB_Right)) { App::GetGuiManager()->SetMouseCursorVisibility(GUIManager::MouseCursorVisibility::HIDDEN); + // Recalculate mouse motion relative to screen size + const Ogre::Vector2 mouse_nrel( + static_cast(_arg.state.X.rel) / static_cast(_arg.state.width), + static_cast(_arg.state.Y.rel) / static_cast(_arg.state.height)); + + // Calculate camera rotation + m_cam_rot_x += Degree(mouse_nrel.x * ROT_SPEED.x); + m_cam_rot_y += Degree(-mouse_nrel.y * ROT_SPEED.y); + + // Calculate camera zoom float scale = RoR::App::GetInputEngine()->isKeyDown(OIS::KC_LMENU) ? 0.002f : 0.02f; + m_cam_dist += -_arg.state.Z.rel * scale; + if (App::io_invert_orbitcam->getBool() && this->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM) { m_cam_rot_x += Degree(ms.X.rel * -0.13f); @@ -956,7 +968,6 @@ bool CameraManager::CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg) m_cam_rot_x += Degree(ms.X.rel * 0.13f); m_cam_rot_y += Degree(-ms.Y.rel * 0.13f); } - m_cam_dist += -ms.Z.rel * scale; return true; } From 181bb1b138c665a16704867f09ae515446de9e2f Mon Sep 17 00:00:00 2001 From: Petr Ohlidal Date: Fri, 27 Jan 2023 20:29:33 +0100 Subject: [PATCH 3/3] Added camera controls LOOK_LEFT+LOOK_RIGHT Renamed LOOKBACK to LOOK_BACK Changed toggle order: instead of resetting to front view first and then toggling the direction, the direction is toggled immediatelly and only a second press resets view to front. Note: LOOK_LEFT+LOOK_RIGHT have no default bindings because all numpad keys are taken. --- source/main/gfx/camera/CameraManager.cpp | 25 ++++++++++++------- source/main/gfx/camera/CameraManager.h | 2 ++ .../bindings/InputEngineAngelscript.cpp | 4 ++- source/main/utils/InputEngine.cpp | 4 ++- source/main/utils/InputEngine.h | 6 +++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/source/main/gfx/camera/CameraManager.cpp b/source/main/gfx/camera/CameraManager.cpp index 5c488af84a..eab3422f46 100644 --- a/source/main/gfx/camera/CameraManager.cpp +++ b/source/main/gfx/camera/CameraManager.cpp @@ -813,19 +813,26 @@ bool CameraManager::CameraBehaviorStaticMouseMoved(const OIS::MouseEvent& _arg) return false; } -void CameraManager::CameraBehaviorOrbitUpdate() +void CameraManager::CameraBehaviorOrbitToggleAngle(events ev, Ogre::Degree angle) { - if (RoR::App::GetInputEngine()->getEventBoolValueBounce(EV_CAMERA_LOOKBACK)) + if (RoR::App::GetInputEngine()->getEventBoolValueBounce(ev)) { - if (m_cam_rot_x > Degree(0)) + if (m_cam_rot_x != angle) { - m_cam_rot_x = Degree(0); + m_cam_rot_x = angle; } else { - m_cam_rot_x = Degree(180); + m_cam_rot_x = Degree(0); } } +} + +void CameraManager::CameraBehaviorOrbitUpdate() +{ + this->CameraBehaviorOrbitToggleAngle(EV_CAMERA_LOOK_BACK, Degree(180)); + this->CameraBehaviorOrbitToggleAngle(EV_CAMERA_LOOK_LEFT, Degree(270)); + this->CameraBehaviorOrbitToggleAngle(EV_CAMERA_LOOK_RIGHT, Degree(90)); if (App::io_invert_orbitcam->getBool() && this->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM) { @@ -960,13 +967,13 @@ bool CameraManager::CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg) if (App::io_invert_orbitcam->getBool() && this->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM) { - m_cam_rot_x += Degree(ms.X.rel * -0.13f); - m_cam_rot_y += Degree(-ms.Y.rel * -0.13f); + m_cam_rot_x += Degree(_arg.state.X.rel * -0.13f); + m_cam_rot_y += Degree(-_arg.state.Y.rel * -0.13f); } else { - m_cam_rot_x += Degree(ms.X.rel * 0.13f); - m_cam_rot_y += Degree(-ms.Y.rel * 0.13f); + m_cam_rot_x += Degree(_arg.state.X.rel * 0.13f); + m_cam_rot_y += Degree(-_arg.state.Y.rel * 0.13f); } return true; } diff --git a/source/main/gfx/camera/CameraManager.h b/source/main/gfx/camera/CameraManager.h index a50d16e13e..5d0ba29dd3 100644 --- a/source/main/gfx/camera/CameraManager.h +++ b/source/main/gfx/camera/CameraManager.h @@ -22,6 +22,7 @@ #pragma once #include "Application.h" +#include "InputEngine.h" #include #include @@ -101,6 +102,7 @@ class CameraManager void CameraBehaviorOrbitReset(); bool CameraBehaviorOrbitMouseMoved(const OIS::MouseEvent& _arg); void CameraBehaviorOrbitUpdate(); + void CameraBehaviorOrbitToggleAngle(RoR::events ev, Ogre::Degree angle); Ogre::Camera* m_camera; Ogre::SceneNode* m_camera_node; diff --git a/source/main/scripting/bindings/InputEngineAngelscript.cpp b/source/main/scripting/bindings/InputEngineAngelscript.cpp index d4d1768c27..0b4792566e 100644 --- a/source/main/scripting/bindings/InputEngineAngelscript.cpp +++ b/source/main/scripting/bindings/InputEngineAngelscript.cpp @@ -108,7 +108,9 @@ void registerEventTypeEnum(asIScriptEngine* engine) result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_DOWN", EV_CAMERA_DOWN ); ROR_ASSERT(result >= 0); result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_FREE_MODE", EV_CAMERA_FREE_MODE ); ROR_ASSERT(result >= 0); result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_FREE_MODE_FIX", EV_CAMERA_FREE_MODE_FIX ); ROR_ASSERT(result >= 0); - result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOKBACK", EV_CAMERA_LOOKBACK ); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOK_BACK", EV_CAMERA_LOOK_BACK ); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOK_LEFT", EV_CAMERA_LOOK_LEFT ); ROR_ASSERT(result >= 0); + result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_LOOK_RIGHT", EV_CAMERA_LOOK_RIGHT ); ROR_ASSERT(result >= 0); result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_RESET", EV_CAMERA_RESET ); ROR_ASSERT(result >= 0); result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_ROTATE_DOWN", EV_CAMERA_ROTATE_DOWN ); ROR_ASSERT(result >= 0); result = engine->RegisterEnumValue("inputEvents", "EV_CAMERA_ROTATE_LEFT", EV_CAMERA_ROTATE_LEFT ); ROR_ASSERT(result >= 0); diff --git a/source/main/utils/InputEngine.cpp b/source/main/utils/InputEngine.cpp index 50a36298fd..4b7779de5b 100644 --- a/source/main/utils/InputEngine.cpp +++ b/source/main/utils/InputEngine.cpp @@ -337,7 +337,9 @@ InputEvent eventInfo[] = { // Camera {"CAMERA_CHANGE", EV_CAMERA_CHANGE, "Keyboard EXPL+C", _LC("InputEvent", "change camera mode")}, - {"CAMERA_LOOKBACK", EV_CAMERA_LOOKBACK, "Keyboard NUMPAD1", _LC("InputEvent", "look back (toggles between normal and lookback)")}, + {"CAMERA_LOOK_BACK", EV_CAMERA_LOOK_BACK, "Keyboard NUMPAD1", _LC("InputEvent", "look back (toggles between normal and lookback)")}, + {"CAMERA_LOOK_LEFT", EV_CAMERA_LOOK_LEFT, "", _LC("InputEvent", "look left (toggles between normal and lookleft)")}, + {"CAMERA_LOOK_RIGHT", EV_CAMERA_LOOK_RIGHT, "", _LC("InputEvent", "look right (toggles between normal and lookright)")}, {"CAMERA_RESET", EV_CAMERA_RESET, "Keyboard NUMPAD5", _LC("InputEvent", "reset the camera position")}, {"CAMERA_ROTATE_DOWN", EV_CAMERA_ROTATE_DOWN, "Keyboard NUMPAD2", _LC("InputEvent", "rotate camera down")}, {"CAMERA_ROTATE_LEFT", EV_CAMERA_ROTATE_LEFT, "Keyboard NUMPAD4", _LC("InputEvent", "rotate camera left")}, diff --git a/source/main/utils/InputEngine.h b/source/main/utils/InputEngine.h index cf4cc44d1a..135313387e 100644 --- a/source/main/utils/InputEngine.h +++ b/source/main/utils/InputEngine.h @@ -115,8 +115,10 @@ enum events EV_CAMERA_DOWN, EV_CAMERA_FREE_MODE, EV_CAMERA_FREE_MODE_FIX, - EV_CAMERA_LOOKBACK, //!< look back (toggles between normal and lookback) - EV_CAMERA_RESET, //!< reset the camera position + EV_CAMERA_LOOK_BACK, //!< look back (toggles between normal and lookback) + EV_CAMERA_LOOK_LEFT, //!< look left (toggles between normal and lookleft) + EV_CAMERA_LOOK_RIGHT, //!< look right (toggles between normal and lookright) + EV_CAMERA_RESET, //!< reset the camera position/rotation EV_CAMERA_ROTATE_DOWN, //!< rotate camera down EV_CAMERA_ROTATE_LEFT, //!< rotate camera left EV_CAMERA_ROTATE_RIGHT, //!< rotate camera right