AcquireByEntityId.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "AcquireByEntityId.h"
  9. #include <AzCore/EBus/EBus.h>
  10. #include <AzCore/Component/TransformBus.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzCore/Serialization/EditContext.h>
  13. #include <AzCore/Math/Transform.h>
  14. #include <StartingPointCamera/StartingPointCameraConstants.h>
  15. namespace Camera
  16. {
  17. void AcquireByEntityId::Reflect(AZ::ReflectContext* reflection)
  18. {
  19. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflection);
  20. if (serializeContext)
  21. {
  22. // Deprecating the CameraTargetComponent. This acquire behavior makes it obsolete
  23. serializeContext->ClassDeprecate("CameraTargetComponent", AZ::Uuid("{0D6A6574-4B79-4907-8529-EB61F343D957}"));
  24. serializeContext->Class<AcquireByEntityId>()
  25. ->Version(1)
  26. ->Field("Entity Target", &AcquireByEntityId::m_target)
  27. ->Field("Use Target Rotation", &AcquireByEntityId::m_shouldUseTargetRotation)
  28. ->Field("Use Target Position", &AcquireByEntityId::m_shouldUseTargetPosition);
  29. AZ::EditContext* editContext = serializeContext->GetEditContext();
  30. if (editContext)
  31. {
  32. editContext->Class<AcquireByEntityId>("AcquireByEntityId", "Acquires a target by entity ref")
  33. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  34. ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
  35. ->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_target, "Entity target", "Specify an entity to target")
  36. ->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_shouldUseTargetRotation, "Use target rotation", "Set to false to not have the camera orient itself with the target")
  37. ->DataElement(AZ::Edit::UIHandlers::Default, &AcquireByEntityId::m_shouldUseTargetPosition, "Use target position", "Set to false to not have the camera position itself with the target");
  38. }
  39. }
  40. }
  41. bool AcquireByEntityId::AcquireTarget(AZ::Transform& outTransformInformation)
  42. {
  43. if (m_target.IsValid())
  44. {
  45. AZ::Transform targetsTransform = AZ::Transform::Identity();
  46. AZ::TransformBus::EventResult(targetsTransform, m_target, &AZ::TransformInterface::GetWorldTM);
  47. if (m_shouldUseTargetPosition)
  48. {
  49. outTransformInformation.SetTranslation(targetsTransform.GetTranslation());
  50. }
  51. if (m_shouldUseTargetRotation)
  52. {
  53. const AZ::Vector3 translation = outTransformInformation.GetTranslation();
  54. outTransformInformation = targetsTransform;
  55. outTransformInformation.SetTranslation(translation);
  56. }
  57. return true;
  58. }
  59. return false;
  60. }
  61. } // namespace Camera