XRRayInteractorComponent.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <Atom/RPI.Public/AuxGeom/AuxGeomFeatureProcessorInterface.h>
  12. #include <AzCore/Component/Entity.h>
  13. #include <OpenXRVk/OpenXRVkActionsInterface.h>
  14. #include <AzFramework/Components/CameraBus.h>
  15. #include <AtomLyIntegration/CommonFeatures/Material/MaterialAssignmentId.h>
  16. #include <XRInteractableComponent.h>
  17. namespace OpenXRVk
  18. {
  19. //! XRRayInteractorComponent draws line from controller
  20. class XRRayInteractorComponent
  21. : public AZ::Component
  22. , public AZ::TickBus::Handler
  23. {
  24. public:
  25. AZ_COMPONENT(OpenXRVk::XRRayInteractorComponent, "{ABD92123-AB30-233B-23AA-123BDEFC3821}");
  26. static void Reflect(AZ::ReflectContext* context);
  27. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  28. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  29. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  30. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  31. protected:
  32. // AZ::Component
  33. void Init() override;
  34. void Activate() override;
  35. void Deactivate() override;
  36. // AZ::TickBus::Handler
  37. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  38. private:
  39. AZ::EntityId m_currentlyHoveredEntity = AZ::EntityId();
  40. float m_maxLength = 10;
  41. AZStd::string m_gripControlActionLabel;
  42. AZ::Color m_initialRayColor = AZ::Color(0.2f, 0.8f, 0.1f, 1.0f);
  43. AZ::Color m_hoveringRayColor = AZ::Color(0.2f, 0.2f, 0.8f, 1.0f);
  44. AZ::Render::MaterialAssignmentId assignmentId;
  45. bool m_colorDefined = false;
  46. float m_XZnonUniformScale = 0;
  47. void CheckEndHovering();
  48. void ProcessOpenXRActions();
  49. //! A cache of OpenXRVk Action Handles that provide straight
  50. //! access into the user's input.
  51. IOpenXRActions::ActionHandle m_controllerSqueezeHandle;
  52. float m_currentSqueezeValue = 0;
  53. // Grab functionality
  54. AZ::EntityId m_heldEntity = AZ::EntityId();
  55. AZ::Transform m_grabOffset = AZ::Transform::CreateIdentity();
  56. AZ::Vector3 m_lastFramePosition = AZ::Vector3::CreateZero();
  57. AZ::Vector3 m_currentVelocity = AZ::Vector3::CreateZero();
  58. XRInteractableComponent* GetXRInterctableComponent(AZ::EntityId entityId);
  59. void GrabHoveredEntity();
  60. void ReleaseHeldEntity();
  61. };
  62. } // namespace OpenXRVk