RadiusWeightModifierComponentController.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <PostProcess/RadiusWeightModifier/RadiusWeightModifierComponentController.h>
  9. #include <AzCore/RTTI/BehaviorContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. void RadiusWeightModifierComponentController::Reflect(AZ::ReflectContext* context)
  16. {
  17. RadiusWeightModifierComponentConfig::Reflect(context);
  18. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  19. {
  20. serializeContext->Class<RadiusWeightModifierComponentController>()
  21. ->Version(0)
  22. ->Field("Configuration", &RadiusWeightModifierComponentController::m_configuration);
  23. }
  24. if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
  25. {
  26. behaviorContext->EBus<PostFxWeightRequestBus>("PostFxWeightRequestBus");
  27. }
  28. }
  29. void RadiusWeightModifierComponentController::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  30. {
  31. provided.push_back(AZ_CRC_CE("PostFXWeightModifierService"));
  32. }
  33. void RadiusWeightModifierComponentController::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  34. {
  35. incompatible.push_back(AZ_CRC_CE("PostFXWeightModifierService"));
  36. }
  37. void RadiusWeightModifierComponentController::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  38. {
  39. required.push_back(AZ_CRC_CE("PostFXLayerService"));
  40. }
  41. RadiusWeightModifierComponentController::RadiusWeightModifierComponentController(const RadiusWeightModifierComponentConfig& config)
  42. : m_configuration(config)
  43. {
  44. }
  45. void RadiusWeightModifierComponentController::Activate(EntityId entityId)
  46. {
  47. m_entityId = entityId;
  48. PostFxWeightRequestBus::Handler::BusConnect(m_entityId);
  49. }
  50. void RadiusWeightModifierComponentController::Deactivate()
  51. {
  52. PostFxWeightRequestBus::Handler::BusDisconnect(m_entityId);
  53. m_entityId.SetInvalid();
  54. }
  55. void RadiusWeightModifierComponentController::SetConfiguration(const RadiusWeightModifierComponentConfig& config)
  56. {
  57. m_configuration = config;
  58. }
  59. float RadiusWeightModifierComponentController::GetWeightAtPosition(const AZ::Vector3& influencerPosition) const
  60. {
  61. AZ::Vector3 postfxCenterPosition = AZ::Vector3::CreateZero();
  62. AZ::TransformBus::EventResult(postfxCenterPosition, m_entityId, &AZ::TransformInterface::GetWorldTranslation);
  63. float magnitude = postfxCenterPosition.GetDistance(influencerPosition);
  64. return AZ::GetMax(0.0f, 1 - magnitude / m_configuration.m_radius);
  65. }
  66. }
  67. }