TrajectoryQuery.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #pragma once
  9. #include <AzCore/Math/Vector3.h>
  10. #include <AzCore/Math/Color.h>
  11. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  12. #include <EMotionFX/Source/Pose.h>
  13. #include <TrajectoryHistory.h>
  14. namespace EMotionFX::MotionMatching
  15. {
  16. class FeatureTrajectory;
  17. //! Builds the input trajectory query data for the motion matching algorithm.
  18. //! Reads the number of past and future samples and the time ranges from the trajectory feature,
  19. //! constructs the future trajectory based on the target and the past trajectory based on the trajectory history.
  20. class EMFX_API TrajectoryQuery
  21. {
  22. public:
  23. struct ControlPoint
  24. {
  25. AZ::Vector3 m_position;
  26. AZ::Vector3 m_facingDirection;
  27. };
  28. enum EMode : AZ::u8
  29. {
  30. MODE_TARGETDRIVEN = 0,
  31. MODE_AUTOMATIC = 1
  32. };
  33. void Update(const ActorInstance& actorInstance,
  34. const FeatureTrajectory* trajectoryFeature,
  35. const TrajectoryHistory& trajectoryHistory,
  36. EMode mode,
  37. const AZ::Vector3& targetPos,
  38. const AZ::Vector3& targetFacingDir,
  39. bool useTargetFacingDir,
  40. float timeDelta,
  41. float pathRadius,
  42. float pathSpeed);
  43. void DebugDraw(AzFramework::DebugDisplayRequests& debugDisplay, const AZ::Color& color) const;
  44. const AZStd::vector<ControlPoint>& GetPastControlPoints() const { return m_pastControlPoints; }
  45. const AZStd::vector<ControlPoint>& GetFutureControlPoints() const { return m_futureControlPoints; }
  46. private:
  47. static void DebugDrawControlPoints(AzFramework::DebugDisplayRequests& debugDisplay,
  48. const AZStd::vector<ControlPoint>& controlPoints,
  49. const AZ::Color& color);
  50. void PredictFutureTrajectory(const ActorInstance& actorInstance,
  51. const FeatureTrajectory* trajectoryFeature,
  52. const AZ::Vector3& targetPos,
  53. const AZ::Vector3& targetFacingDir,
  54. bool useTargetFacingDir);
  55. AZStd::vector<ControlPoint> m_pastControlPoints;
  56. AZStd::vector<ControlPoint> m_futureControlPoints;
  57. float m_positionBias = 2.0f; //< Indicates how fast the curve will bend towards the target.
  58. float m_rotationBias = 3.0f; //< Indicates how fast the facing direction matches the target facing direction.
  59. float m_deadZone = 0.2f; //< Similarly to a joystick deadzone, this represents the area around the character that does not respond to movement.
  60. float m_automaticModePhase = 0.0f; //< Current phase for the automatic demo mode. Not needed by the target-driven mode.
  61. };
  62. } // namespace EMotionFX::MotionMatching