FlyCameraInputComponent.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/Input/Events/InputChannelEventListener.h>
  12. #include <Cry_Math.h>
  13. #include <AtomBridge/FlyCameraInputBus.h>
  14. namespace AZ
  15. {
  16. namespace AtomBridge
  17. {
  18. /// This is based on the FlyCameraInputComponent in SamplesProject and is just used to test the CameraComponent
  19. class FlyCameraInputComponent
  20. : public AZ::Component
  21. , public AZ::TickBus::Handler
  22. , public AzFramework::InputChannelEventListener
  23. , public FlyCameraInputBus::Handler
  24. {
  25. public:
  26. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  27. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  28. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  29. static void Reflect(AZ::ReflectContext* reflection);
  30. AZ_COMPONENT(FlyCameraInputComponent, "{7AE0D6AD-691C-41B6-9DD5-F23F78B1A02E}");
  31. virtual ~FlyCameraInputComponent();
  32. // AZ::Component
  33. void Init() override;
  34. void Activate() override;
  35. void Deactivate() override;
  36. // AZ::TickBus
  37. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  38. // AzFramework::InputChannelEventListener
  39. bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
  40. // FlyCameraInputInterface
  41. void SetIsEnabled(bool isEnabled) override;
  42. bool GetIsEnabled() override;
  43. private:
  44. void OnMouseEvent(const AzFramework::InputChannel& inputChannel);
  45. void OnKeyboardEvent(const AzFramework::InputChannel& inputChannel);
  46. void OnGamepadEvent(const AzFramework::InputChannel& inputChannel);
  47. void OnTouchEvent(const AzFramework::InputChannel& inputChannel, const Vec2& screenPosition);
  48. void OnVirtualLeftThumbstickEvent(const AzFramework::InputChannel& inputChannel, const Vec2& screenPosition);
  49. void OnVirtualRightThumbstickEvent(const AzFramework::InputChannel& inputChannel, const Vec2& screenPosition);
  50. float GetViewWidth() const;
  51. float GetViewHeight() const;
  52. static const AZ::Crc32 UnknownInputChannelId;
  53. // Editable Properties
  54. float m_moveSpeed = 20.0f;
  55. float m_rotationSpeed = 5.0f;
  56. float m_mouseSensitivity = 0.025f;
  57. float m_virtualThumbstickRadiusAsPercentageOfScreenWidth = 0.1f;
  58. bool m_InvertRotationInputAxisX = false;
  59. bool m_InvertRotationInputAxisY = false;
  60. bool m_isEnabled = true;
  61. // Run-time Properties
  62. Vec3 m_movement = ZERO;
  63. Vec2 m_rotation = ZERO;
  64. Vec2 m_leftDownPosition = ZERO;
  65. AZ::Crc32 m_leftFingerId = UnknownInputChannelId;
  66. Vec2 m_rightDownPosition = ZERO;
  67. AZ::Crc32 m_rightFingerId = UnknownInputChannelId;
  68. int m_thumbstickTextureId = 0;
  69. };
  70. }
  71. }