XRInteractableComponent.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <AzFramework/Physics/RigidBodyBus.h>
  16. #include <AzFramework/Physics/SimulatedBodies/RigidBody.h>
  17. #include <Source/RigidBodyComponent.h>
  18. namespace OpenXRVk
  19. {
  20. //! XRInteractableComponent defines that the object can be taken using the RayInteractor
  21. class XRInteractableComponent
  22. : public AZ::Component
  23. , public AZ::TickBus::Handler
  24. , public Physics::RigidBodyNotificationBus::Handler
  25. {
  26. public:
  27. enum class XRInteractableType : AZ::u32 {
  28. Simple
  29. };
  30. AZ_COMPONENT(OpenXRVk::XRInteractableComponent, "{9234ABCD-234B-12AB-242D-6436DEFC38BB}");
  31. static void Reflect(AZ::ReflectContext* context);
  32. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  33. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  34. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  35. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  36. // Called when the pointer is hovering over this object
  37. virtual void OnHoverStart();
  38. // Called when the pointer stops hovering over this object
  39. virtual void OnHoverEnd();
  40. virtual void OnGrab();
  41. virtual void OnRelease(const AZ::Vector3& impulse);
  42. bool IsHovering() { return m_isHovering; }
  43. bool IsGrabbing() { return m_isGrabbing; }
  44. protected:
  45. // AZ::Component
  46. void Init() override;
  47. void Activate() override;
  48. void Deactivate() override;
  49. // AZ::TickBus::Handler
  50. void OnTick(float deltaTime, AZ::ScriptTimePoint timePoint) override;
  51. private:
  52. bool m_isHovering = false;
  53. XRInteractableType m_XRInteractableType = XRInteractableType::Simple;
  54. // Animation state
  55. float m_hoverTime = 0.0f;
  56. bool m_hovering = false;
  57. bool m_scalingUp = true;
  58. // Scale state
  59. AZ::Vector3 m_originalScale = AZ::Vector3::CreateOne();
  60. bool m_hasNonUniform = false;
  61. bool m_originalScaleCached = false;
  62. void CacheOriginalScale();
  63. bool m_isGrabbing = false;
  64. PhysX::RigidBodyComponent* m_cachedRigidBodyComponent = nullptr;
  65. };
  66. } // namespace OpenXRVk