FollowingCameraComponent.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Component/Component.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzFramework/Components/TransformComponent.h>
  12. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  13. namespace AppleKraken
  14. {
  15. //! Experimental, demo only class for simple camera movement smoothing
  16. // TODO - research damping and smoothing camera, use exponential mapping for rotation smoothing as well.
  17. class FollowingCameraComponent
  18. : public AZ::Component
  19. , public AZ::TickBus::Handler
  20. , public AzFramework::InputChannelEventListener
  21. {
  22. public:
  23. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  24. static void Reflect(AZ::ReflectContext* reflection);
  25. AZ_COMPONENT(FollowingCameraComponent, "{92317883-9956-455E-9A1C-BF8986DC2F80}", AZ::Component);
  26. // AZ::Component
  27. void Init() override;
  28. void Activate() override;
  29. void Deactivate() override;
  30. // AZ::TickBus
  31. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  32. // AzFramework::InputChannelEventListener
  33. bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
  34. private:
  35. void OnKeyboardEvent(const AzFramework::InputChannel& inputChannel);
  36. AZ::Vector3 SmoothTranslation() const;
  37. AZ::Quaternion SmoothRotation() const;
  38. bool m_isActive = true;
  39. AZ::Transform m_initialPose;
  40. AZ::EntityId m_target;
  41. float m_rotationChange = 0.0f;
  42. float m_rotationChange2 = 0.0f;
  43. float m_zoomChange = 0.0f;
  44. int m_smoothingBuffer = 30;
  45. float m_zoomSpeed = 0.06f;
  46. float m_rotationSpeed = 0.05f;
  47. const float m_zoomMin = -25.f;
  48. const float m_zoomMax = 0.6f;
  49. AZStd::deque<AZStd::pair<AZ::Vector3, float>> m_lastTransforms;
  50. AZStd::deque<AZStd::pair<AZ::Quaternion, float>> m_lastRotations;
  51. };
  52. } // namespace AppleKraken