Rotate.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 "Rotate.h"
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include "StartingPointCamera/StartingPointCameraUtilities.h"
  12. namespace Camera
  13. {
  14. void Rotate::Reflect(AZ::ReflectContext* reflection)
  15. {
  16. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  17. if (serializeContext)
  18. {
  19. serializeContext->Class<Rotate>()
  20. ->Version(1)
  21. ->Field("Angle", &Rotate::m_angleInDegrees)
  22. ->Field("Axis", &Rotate::m_axisType);
  23. AZ::EditContext* editContext = serializeContext->GetEditContext();
  24. if (editContext)
  25. {
  26. editContext->Class<Rotate>("Rotate", "Rotate Camera Angle degrees about its Axis")
  27. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  28. ->DataElement(0, &Rotate::m_angleInDegrees, "Angle", "The angle of rotation")
  29. ->Attribute(AZ::Edit::Attributes::Suffix, "degrees")
  30. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &Rotate::m_axisType, "Axis", "The relative Axis of rotation")
  31. ->EnumAttribute(AxisOfRotation::X_Axis, "X")
  32. ->EnumAttribute(AxisOfRotation::Y_Axis, "Y")
  33. ->EnumAttribute(AxisOfRotation::Z_Axis, "Z");
  34. }
  35. }
  36. }
  37. void Rotate::AdjustCameraTransform([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& initialCameraTransform, [[maybe_unused]] const AZ::Transform& targetTransform, AZ::Transform& inOutCameraTransform)
  38. {
  39. AZ::Vector3 position = inOutCameraTransform.GetTranslation();
  40. inOutCameraTransform.SetTranslation(AZ::Vector3::CreateZero());
  41. AZ::Transform axisRotation = CreateRotationFromEulerAngle(static_cast<EulerAngleType>(m_axisType), AZ::DegToRad(m_angleInDegrees));
  42. inOutCameraTransform = inOutCameraTransform * axisRotation;
  43. inOutCameraTransform.SetTranslation(position);
  44. }
  45. } // namespace Camera