2
0
Эх сурвалжийг харах

Fix FollowingCameraComponent: allow fly camera (#778)

Signed-off-by: Jan Hanca <[email protected]>
Jan Hanca 10 сар өмнө
parent
commit
d84a036aa3

+ 1 - 0
Gems/ROS2/Code/CMakeLists.txt

@@ -64,6 +64,7 @@ ly_add_target(
             Gem::Atom_RPI.Public
             Gem::Atom_Feature_Common.Static
             Gem::Atom_Component_DebugCamera.Static
+            Gem::Atom_AtomBridge.Static
             Gem::StartingPointInput
             Gem::PhysX5.Static
             Gem::LmbrCentral.API

+ 33 - 22
Gems/ROS2/Code/Source/SimulationUtils/FollowingCameraComponent.cpp

@@ -7,6 +7,7 @@
  */
 
 #include "FollowingCameraComponent.h"
+#include <AtomBridge/FlyCameraInputBus.h>
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/SerializeContext.h>
 #include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
@@ -29,8 +30,6 @@ namespace ROS2
     {
     }
 
-
-
     void FollowingCameraComponent::Reflect(AZ::ReflectContext* reflection)
     {
         FollowingCameraConfiguration::Reflect(reflection);
@@ -89,6 +88,8 @@ namespace ROS2
         if (m_configuration.m_defaultView < m_configuration.m_predefinedViews.size())
         {
             m_currentView = m_configuration.m_predefinedViews[m_configuration.m_defaultView];
+            AZ::AtomBridge::FlyCameraInputBus::EventResult(
+                m_disableCameraMove, m_currentView, &AZ::AtomBridge::FlyCameraInputBus::Events::GetIsEnabled);
         }
         InputChannelEventListener::Connect();
         AZ::TickBus::Handler::BusConnect();
@@ -105,7 +106,8 @@ namespace ROS2
         const AZ::Vector3 axisX = transform.GetBasisX();
         const AZ::Vector3 axisY = transform.GetBasisY();
 
-        const AZ::Matrix3x3 projectionOnXY {AZ::Matrix3x3::CreateFromColumns(AZ::Vector3::CreateAxisX(), AZ::Vector3::CreateAxisY(), AZ::Vector3::CreateZero())};
+        const AZ::Matrix3x3 projectionOnXY{ AZ::Matrix3x3::CreateFromColumns(
+            AZ::Vector3::CreateAxisX(), AZ::Vector3::CreateAxisY(), AZ::Vector3::CreateZero()) };
 
         const AZ::Vector3 newAxisZ = AZ::Vector3::CreateAxisZ(); // new axis Z points up
 
@@ -226,26 +228,29 @@ namespace ROS2
     void FollowingCameraComponent::OnKeyboardEvent(const AzFramework::InputChannel& inputChannel)
     {
         const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
-        if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericW)
-        {
-            m_opticalAxisTranslation += m_configuration.m_zoomSpeed;
-            m_opticalAxisTranslation = AZStd::min(m_opticalAxisTranslation, m_configuration.m_opticalAxisTranslationMin);
-            return;
-        }
-        if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericS)
-        {
-            m_opticalAxisTranslation -= m_configuration.m_zoomSpeed;
-            return;
-        }
-        if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericA)
-        {
-            m_rotationOffset -= m_configuration.m_rotationSpeed;
-            return;
-        }
-        if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericD)
+        if (!m_disableCameraMove)
         {
-            m_rotationOffset += m_configuration.m_rotationSpeed;
-            return;
+            if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericW)
+            {
+                m_opticalAxisTranslation += m_configuration.m_zoomSpeed;
+                m_opticalAxisTranslation = AZStd::min(m_opticalAxisTranslation, m_configuration.m_opticalAxisTranslationMin);
+                return;
+            }
+            if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericS)
+            {
+                m_opticalAxisTranslation -= m_configuration.m_zoomSpeed;
+                return;
+            }
+            if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericA)
+            {
+                m_rotationOffset -= m_configuration.m_rotationSpeed;
+                return;
+            }
+            if (channelId == AzFramework::InputDeviceKeyboard::Key::AlphanumericD)
+            {
+                m_rotationOffset += m_configuration.m_rotationSpeed;
+                return;
+            }
         }
 
         // channelId is a numeric key (Key::Alphanumeric0-Key::Alphanumeric9)
@@ -256,6 +261,12 @@ namespace ROS2
                 m_currentView = m_configuration.m_predefinedViews[viewId];
                 m_lastTranslationsBuffer.clear();
                 m_lastRotationsBuffer.clear();
+                m_rotationOffset = 0.0f;
+                m_opticalAxisTranslation = 0.0f;
+
+                m_disableCameraMove = false; // reset value before reading
+                AZ::AtomBridge::FlyCameraInputBus::EventResult(
+                    m_disableCameraMove, m_currentView, &AZ::AtomBridge::FlyCameraInputBus::Events::GetIsEnabled);
             }
         }
     }

+ 1 - 0
Gems/ROS2/Code/Source/SimulationUtils/FollowingCameraComponent.h

@@ -81,6 +81,7 @@ namespace ROS2
         float m_rotationOffset = 0.0f; //!< The rotation change from the input.
         float m_opticalAxisTranslation = 0.0f; //!< The zoom change from the input.
         AZ::EntityId m_currentView; //!< Current used view point.
+        bool m_disableCameraMove = false; //!< Disable camera move (used when fly camera is selected).
 
         FollowingCameraConfiguration m_configuration; //!< The configuration of the following camera.
     };