XRControllerComponent.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/CameraBus.h>
  12. #include <OpenXRVk/OpenXRVkActionsInterface.h>
  13. namespace OpenXRVk
  14. {
  15. //! XRControllerComponent uses the OpenXRVk::OpenXRActionsInterface to read user input to control an VR controller.
  16. class XRControllerComponent
  17. : public AZ::Component
  18. , public AZ::TickBus::Handler
  19. , public Camera::CameraNotificationBus::Handler
  20. {
  21. public:
  22. AZ_COMPONENT(XRControllerComponent, "{5DA45A04-A900-345C-23DE-23BD03BC3820}");
  23. static void Reflect(AZ::ReflectContext* context);
  24. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  25. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  26. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  27. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  28. protected:
  29. // AZ::Component
  30. void Activate() override;
  31. void Deactivate() override;
  32. // Camera::CameraNotificationBus::Handler overrides
  33. void OnActiveViewChanged(const AZ::EntityId&) override;
  34. // AZ::TickBus::Handler
  35. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  36. private:
  37. void ProcessOpenXRActions();
  38. AZ::EntityId m_cameraEntity;
  39. // Transient data...
  40. AZ::Transform m_movement = AZ::Transform::CreateIdentity();
  41. // Serialized data...
  42. AZStd::string m_controllerPoseActionLabel;
  43. //! A cache of OpenXRVk Action Handles that provide straight
  44. //! access into the user's input.
  45. IOpenXRActions::ActionHandle m_controllerPoseHandle;
  46. };
  47. } // namespace OpenXRVk