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

formatting

Signed-off-by: Adam Dabrowski <[email protected]>
Adam Dabrowski 2 жил өмнө
parent
commit
402fe9c7af

+ 40 - 42
Project/Gem/Source/KrakenCamera/FollowingCameraComponent.cpp

@@ -1,20 +1,17 @@
 /*
-* Copyright (c) Contributors to the Open 3D Engine Project.
-* For complete copyright and license terms please see the LICENSE at the root of this distribution.
-*
-* SPDX-License-Identifier: Apache-2.0 OR MIT
-*
-*/
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
 
 #include "FollowingCameraComponent.h"
-
-#include <AzCore/Serialization/SerializeContext.h>
 #include <AzCore/Serialization/EditContext.h>
-
+#include <AzCore/Serialization/SerializeContext.h>
 #include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
 #include <MathConversion.h>
 
-
 namespace AppleKraken
 {
 
@@ -39,10 +36,16 @@ namespace AppleKraken
                     ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game"))
                     ->Attribute(AZ::Edit::Attributes::Category, "AppleKraken")
                     ->DataElement(AZ::Edit::UIHandlers::CheckBox, &FollowingCameraComponent::m_isActive, "Active", "")
-                    ->DataElement(AZ::Edit::UIHandlers::EntityId, &FollowingCameraComponent::m_target, "Target", "Entity of the followed object")
-                    ->DataElement(AZ::Edit::UIHandlers::Default, &FollowingCameraComponent::m_smoothingBuffer, "SmoothingLength", "Number of past transform used to smooth")
+                    ->DataElement(
+                        AZ::Edit::UIHandlers::EntityId, &FollowingCameraComponent::m_target, "Target", "Entity of the followed object")
+                    ->DataElement(
+                        AZ::Edit::UIHandlers::Default,
+                        &FollowingCameraComponent::m_smoothingBuffer,
+                        "SmoothingLength",
+                        "Number of past transform used to smooth")
                     ->DataElement(AZ::Edit::UIHandlers::Default, &FollowingCameraComponent::m_zoomSpeed, "Zoom Speed", "Zoom speed")
-                    ->DataElement(AZ::Edit::UIHandlers::Default, &FollowingCameraComponent::m_rotationSpeed, "Rotation Speed", "Rotation Speed");
+                    ->DataElement(
+                        AZ::Edit::UIHandlers::Default, &FollowingCameraComponent::m_rotationSpeed, "Rotation Speed", "Rotation Speed");
             }
         }
     }
@@ -72,7 +75,8 @@ namespace AppleKraken
 
     void FollowingCameraComponent::OnTick(float deltaTime, AZ::ScriptTimePoint /*time*/)
     {
-        if (!m_target.IsValid()){
+        if (!m_target.IsValid())
+        {
             AZ_Warning("FollowingCameraComponent", false, "m_target is empty!");
         }
         if (!m_isActive)
@@ -86,47 +90,41 @@ namespace AppleKraken
         m_lastTransforms.push_back(AZStd::make_pair(target_world_transform.GetTranslation(), deltaTime));
         m_lastRotations.push_back(AZStd::make_pair(target_world_transform.GetRotation(), deltaTime));
 
-        if (m_lastTransforms.size() > m_smoothingBuffer){
+        if (m_lastTransforms.size() > m_smoothingBuffer)
+        {
             m_lastTransforms.pop_front();
             m_lastRotations.pop_front();
         }
         AZ::Vector3 translation = SmoothTranslation();
         AZ::Quaternion quat = SmoothRotation();
-        AZ::Transform filtered_transform =
-            {
-                translation,
-                AZ::Quaternion::CreateRotationZ(quat.GetEulerRadians().GetZ()),
-                target_world_transform.GetUniformScale()
-            };
+        AZ::Transform filtered_transform = { translation,
+                                             AZ::Quaternion::CreateRotationZ(quat.GetEulerRadians().GetZ()),
+                                             target_world_transform.GetUniformScale() };
 
         auto modified_transform = m_initialPose.GetInverse();
-        AZ::Transform rotation_transform =
-            {
-                {0.0, 0.0, 0.0},
-               AZ::Quaternion::CreateRotationY(m_rotationChange2) *  AZ::Quaternion::CreateRotationZ(m_rotationChange) ,
-                1.0
-            };
+        AZ::Transform rotation_transform = {
+            { 0.0, 0.0, 0.0 }, AZ::Quaternion::CreateRotationY(m_rotationChange2) * AZ::Quaternion::CreateRotationZ(m_rotationChange), 1.0
+        };
         modified_transform *= rotation_transform;
         modified_transform.Invert();
 
         AZ::Vector3 translation_modifier = modified_transform.GetBasisY() * m_zoomChange;
         auto modified_translation = modified_transform.GetTranslation() + translation_modifier;
-        modified_transform.SetTranslation( modified_translation );
+        modified_transform.SetTranslation(modified_translation);
 
         EBUS_EVENT_ID(GetEntityId(), AZ::TransformBus, SetWorldTM, filtered_transform * modified_transform);
-
-
     }
 
     AZ::Vector3 FollowingCameraComponent::SmoothTranslation() const
     {
-        AZ::Vector3 sum{0};
-        float normalization{0};
-        for (const auto& p : m_lastTransforms){
+        AZ::Vector3 sum{ 0 };
+        float normalization{ 0 };
+        for (const auto& p : m_lastTransforms)
+        {
             sum += p.first * p.second;
-            normalization+=p.second;
+            normalization += p.second;
         }
-        return sum/normalization;
+        return sum / normalization;
     }
 
     AZ::Quaternion FollowingCameraComponent::SmoothRotation() const
@@ -134,13 +132,14 @@ namespace AppleKraken
         // Smoothing is done by taking an exponential map. Note that the exponential map is the same thing as 'ScaledAxisAngle'
         // for 3D rotations. This map can be treated as linear space locally.
         // In that linear space the average is computed. It should give a pleasant experience for slow-moving objects.
-        float normalization{0};
-        AZ::Vector3 sum{0};
-        for (const auto& p : m_lastRotations){
+        float normalization{ 0 };
+        AZ::Vector3 sum{ 0 };
+        for (const auto& p : m_lastRotations)
+        {
             sum += p.second * (p.first.ConvertToScaledAxisAngle());
-            normalization+=p.second;
+            normalization += p.second;
         }
-        return AZ::Quaternion::CreateFromScaledAxisAngle(sum/normalization);
+        return AZ::Quaternion::CreateFromScaledAxisAngle(sum / normalization);
     }
 
     bool FollowingCameraComponent::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel)
@@ -194,6 +193,5 @@ namespace AppleKraken
         {
             m_rotationChange2 -= m_rotationSpeed;
         }
-
     }
-}
+} // namespace AppleKraken

+ 8 - 10
Project/Gem/Source/KrakenCamera/FollowingCameraComponent.h

@@ -10,8 +10,8 @@
 
 #include <AzCore/Component/Component.h>
 #include <AzCore/Component/TickBus.h>
-#include <AzFramework/Input/Events/InputChannelEventListener.h>
 #include <AzFramework/Components/TransformComponent.h>
+#include <AzFramework/Input/Events/InputChannelEventListener.h>
 
 namespace AppleKraken
 {
@@ -27,17 +27,17 @@ namespace AppleKraken
         static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
 
         static void Reflect(AZ::ReflectContext* reflection);
-        
+
         AZ_COMPONENT(FollowingCameraComponent, "{92317883-9956-455E-9A1C-BF8986DC2F80}", AZ::Component);
-        
+
         // AZ::Component
         void Init() override;
         void Activate() override;
         void Deactivate() override;
-        
+
         // AZ::TickBus
         void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
-        
+
         // AzFramework::InputChannelEventListener
         bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
 
@@ -65,9 +65,7 @@ namespace AppleKraken
         const float m_zoomMin = -25.f;
         const float m_zoomMax = 0.6f;
 
-
-        AZStd::deque<AZStd::pair<AZ::Vector3,float>> m_lastTransforms;
-        AZStd::deque<AZStd::pair<AZ::Quaternion,float>> m_lastRotations;
-
+        AZStd::deque<AZStd::pair<AZ::Vector3, float>> m_lastTransforms;
+        AZStd::deque<AZStd::pair<AZ::Quaternion, float>> m_lastRotations;
     };
-}
+} // namespace AppleKraken