RotateCameraLookAt.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <CameraFramework/ICameraLookAtBehavior.h>
  10. #include <AzCore/Math/Transform.h>
  11. #include <AzCore/RTTI/ReflectContext.h>
  12. #include <AzCore/std/string/string.h>
  13. #include <LmbrCentral/Scripting/GameplayNotificationBus.h>
  14. #include "StartingPointCamera/StartingPointCameraConstants.h"
  15. #include <AzCore/Memory/SystemAllocator.h>
  16. namespace Camera
  17. {
  18. //////////////////////////////////////////////////////////////////////////
  19. /// This will rotate the camera LookAt transform. If you have a camera that
  20. /// is closely following a target, say in third person perspective you
  21. /// would not want the target to pitch while looking up and down. You may
  22. /// also desire the ability to swivel the camera around the target while
  23. /// the target remains stationary.
  24. //////////////////////////////////////////////////////////////////////////
  25. class RotateCameraLookAt
  26. : public ICameraLookAtBehavior
  27. , public AZ::GameplayNotificationBus::Handler
  28. {
  29. public:
  30. ~RotateCameraLookAt() override = default;
  31. AZ_RTTI(RotateCameraLookAt, "{B72C5BE7-2DAF-412B-BBBB-F216B3DFB9A0}", ICameraLookAtBehavior);
  32. AZ_CLASS_ALLOCATOR(RotateCameraLookAt, AZ::SystemAllocator);
  33. static void Reflect(AZ::ReflectContext* reflection);
  34. //////////////////////////////////////////////////////////////////////////
  35. // ICameraLookAtBehavior
  36. void AdjustLookAtTarget(float deltaTime, const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform) override;
  37. void Activate(AZ::EntityId) override;
  38. void Deactivate() override;
  39. //////////////////////////////////////////////////////////////////////////
  40. // AZ::GameplayNotificationBus
  41. void OnEventBegin(const AZStd::any&) override;
  42. void OnEventUpdating(const AZStd::any&) override;
  43. void OnEventEnd(const AZStd::any&) override;
  44. private:
  45. //////////////////////////////////////////////////////////////////////////
  46. // Reflected data
  47. AxisOfRotation m_axisOfRotation = AxisOfRotation::X_Axis;
  48. AZStd::string m_eventName = "";
  49. float m_rotationSpeedScale = 1.f;
  50. bool m_shouldInvertAxis = false;
  51. //////////////////////////////////////////////////////////////////////////
  52. // internal data
  53. float m_rotationAmount = 0.f;
  54. AZ::EntityId m_rigEntity;
  55. };
  56. } // namespace Camera