3
0

OffsetPosition.cpp 2.1 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 "OffsetPosition.h"
  9. #include <AzCore/Math/Transform.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Math/Quaternion.h>
  13. namespace Camera
  14. {
  15. void OffsetPosition::Reflect(AZ::ReflectContext* reflection)
  16. {
  17. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  18. if (serializeContext)
  19. {
  20. serializeContext->Class<OffsetPosition>()
  21. ->Version(1)
  22. ->Field("Positional Offset", &OffsetPosition::m_positionalOffset)
  23. ->Field("Offset Is Relative", &OffsetPosition::m_isRelativeOffset);
  24. AZ::EditContext* editContext = serializeContext->GetEditContext();
  25. if (editContext)
  26. {
  27. editContext->Class<OffsetPosition>("OffsetPosition", "Offset the acquired position of the camera's current target")
  28. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  29. ->DataElement(0, &OffsetPosition::m_positionalOffset, "Positional Offset", "The vector offset from the current position")
  30. ->DataElement(0, &OffsetPosition::m_isRelativeOffset, "Offset Is Relative", "Uses world coordinates for the offset when false and local coordinates when true");
  31. }
  32. }
  33. }
  34. void OffsetPosition::AdjustLookAtTarget([[maybe_unused]] float deltaTime, [[maybe_unused]] const AZ::Transform& targetTransform, AZ::Transform& outLookAtTargetTransform)
  35. {
  36. if (m_isRelativeOffset)
  37. {
  38. outLookAtTargetTransform.SetTranslation(outLookAtTargetTransform.GetTranslation() + outLookAtTargetTransform.GetRotation().TransformVector(m_positionalOffset));
  39. }
  40. else
  41. {
  42. outLookAtTargetTransform.SetTranslation(outLookAtTargetTransform.GetTranslation() + m_positionalOffset);
  43. }
  44. }
  45. } // namespace Camera