FollowTargetFromAngle.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "FollowTargetFromAngle.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include "StartingPointCamera/StartingPointCameraUtilities.h"
  12. namespace Camera
  13. {
  14. void FollowTargetFromAngle::Reflect(AZ::ReflectContext* reflection)
  15. {
  16. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  17. if (serializeContext)
  18. {
  19. serializeContext->Class<FollowTargetFromAngle>()
  20. ->Version(1)
  21. ->Field("Angle", &FollowTargetFromAngle::m_angleInDegrees)
  22. ->Field("Rotation Type", &FollowTargetFromAngle::m_rotationType)
  23. ->Field("Distance From Target", &FollowTargetFromAngle::m_distanceFromTarget);
  24. AZ::EditContext* editContext = serializeContext->GetEditContext();
  25. if (editContext)
  26. {
  27. editContext->Class<FollowTargetFromAngle>("FollowTargetFromAngle", "Follows behind the target by Angle degrees about RotationType")
  28. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  29. ->DataElement(0, &FollowTargetFromAngle::m_angleInDegrees, "Angle", "The angle to rotate about RotationType")
  30. ->Attribute(AZ::Edit::Attributes::Suffix, "degrees")
  31. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &FollowTargetFromAngle::m_rotationType, "Rotation Type", "Choose to Yaw, Pitch or Roll Angle degrees")
  32. ->EnumAttribute(EulerAngleType::Yaw, "Yaw")
  33. ->EnumAttribute(EulerAngleType::Pitch, "Pitch")
  34. ->EnumAttribute(EulerAngleType::Roll, "Roll")
  35. ->DataElement(0, &FollowTargetFromAngle::m_distanceFromTarget, "Distance From Target", "The range at which to follow the target from")
  36. ->Attribute(AZ::Edit::Attributes::Suffix, "m");
  37. }
  38. }
  39. }
  40. void FollowTargetFromAngle::AdjustCameraTransform([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& initialCameraTransform, const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
  41. {
  42. // calculate new position based on angles and distance
  43. AZ::Transform rotation = CreateRotationFromEulerAngle(m_rotationType, AZ::DegToRad(m_angleInDegrees));
  44. inOutCameraTransform = rotation;
  45. inOutCameraTransform.SetTranslation(targetTransform.GetTranslation() - rotation.GetBasis(ForwardBackward) * m_distanceFromTarget);
  46. }
  47. } //namespace Camera