Motion Matching: Automatic target mode for trajectory query
* Consolidated the different automatic path generation modes into a single automatic demo mode. * Moved the static phase variable to a member so that multiple instances won't follow the same path and speedup the phase increment. Signed-off-by: Benjamin Jillich <jillich@amazon.com>
This commit is contained in:
@@ -12,44 +12,13 @@
|
||||
|
||||
namespace EMotionFX::MotionMatching
|
||||
{
|
||||
AZ::Vector3 SampleFunction(TrajectoryQuery::EMode mode, float offset, float radius, float phase)
|
||||
AZ::Vector3 SampleFunction(float offset, float radius, float phase)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case TrajectoryQuery::MODE_TWO:
|
||||
{
|
||||
AZ::Vector3 displacement = AZ::Vector3::CreateZero();
|
||||
displacement.SetX(radius * sinf(phase + offset) );
|
||||
displacement.SetY(cosf(phase + offset));
|
||||
return displacement;
|
||||
}
|
||||
|
||||
case TrajectoryQuery::MODE_THREE:
|
||||
{
|
||||
AZ::Vector3 displacement = AZ::Vector3::CreateZero();
|
||||
const float rad = radius * cosf(radius + phase*0.2f);
|
||||
displacement.SetX(rad * sinf(phase + offset));
|
||||
displacement.SetY(rad * cosf(phase + offset));
|
||||
return displacement;
|
||||
}
|
||||
|
||||
case TrajectoryQuery::MODE_FOUR:
|
||||
{
|
||||
AZ::Vector3 displacement = AZ::Vector3::CreateZero();
|
||||
displacement.SetX(radius * sinf(phase + offset));
|
||||
displacement.SetY(radius*2.0f * cosf(phase + offset));
|
||||
return displacement;
|
||||
}
|
||||
|
||||
// MODE_ONE and default
|
||||
default:
|
||||
{
|
||||
AZ::Vector3 displacement = AZ::Vector3::CreateZero();
|
||||
displacement.SetX(radius * sinf(phase * 0.7f + offset) + radius * 0.75f * cosf(phase * 2.0f + offset * 2.0f));
|
||||
displacement.SetY(radius * cosf(phase * 0.4f + offset));
|
||||
return displacement;
|
||||
}
|
||||
}
|
||||
phase += 10.7;
|
||||
AZ::Vector3 displacement = AZ::Vector3::CreateZero();
|
||||
displacement.SetX(radius * sinf(phase * 0.7f + offset) + radius * 0.75f * cosf(phase * 2.0f + offset * 2.0f));
|
||||
displacement.SetY(radius * cosf(phase * 0.4f + offset));
|
||||
return displacement;
|
||||
}
|
||||
|
||||
void TrajectoryQuery::Update(const ActorInstance* actorInstance,
|
||||
@@ -88,19 +57,18 @@ namespace EMotionFX::MotionMatching
|
||||
}
|
||||
else
|
||||
{
|
||||
static float phase = 0.0f;
|
||||
phase += timeDelta * pathSpeed;
|
||||
AZ::Vector3 base = SampleFunction(mode, 0.0f, pathRadius, phase);
|
||||
m_automaticModePhase += timeDelta * pathSpeed;
|
||||
AZ::Vector3 base = SampleFunction(0.0f, pathRadius, m_automaticModePhase);
|
||||
for (size_t i = 0; i < numFutureSamples; ++i)
|
||||
{
|
||||
const float offset = i * 0.1f;
|
||||
const AZ::Vector3 curSample = SampleFunction(mode, offset, pathRadius, phase);
|
||||
const AZ::Vector3 curSample = SampleFunction(offset, pathRadius, m_automaticModePhase);
|
||||
AZ::Vector3 displacement = curSample - base;
|
||||
m_futureControlPoints[i].m_position = actorInstance->GetWorldSpaceTransform().m_position + displacement;
|
||||
|
||||
// Evaluate a control point slightly further into the future than the actual
|
||||
// one and use the position difference as the facing direction.
|
||||
const AZ::Vector3 deltaSample = SampleFunction(mode, offset + 0.01f, pathRadius, phase);
|
||||
const AZ::Vector3 deltaSample = SampleFunction(offset + 0.01f, pathRadius, m_automaticModePhase);
|
||||
const AZ::Vector3 dir = deltaSample - curSample;
|
||||
m_futureControlPoints[i].m_facingDirection = dir.GetNormalizedSafe();
|
||||
}
|
||||
|
||||
@@ -36,10 +36,7 @@ namespace EMotionFX::MotionMatching
|
||||
enum EMode : AZ::u8
|
||||
{
|
||||
MODE_TARGETDRIVEN = 0,
|
||||
MODE_ONE = 1,
|
||||
MODE_TWO = 2,
|
||||
MODE_THREE = 3,
|
||||
MODE_FOUR = 4
|
||||
MODE_AUTOMATIC = 1
|
||||
};
|
||||
|
||||
void Update(const ActorInstance* actorInstance,
|
||||
@@ -64,5 +61,7 @@ namespace EMotionFX::MotionMatching
|
||||
|
||||
AZStd::vector<ControlPoint> m_pastControlPoints;
|
||||
AZStd::vector<ControlPoint> m_futureControlPoints;
|
||||
|
||||
float m_automaticModePhase = 0.0f; //< Current phase for the automatic demo mode. Not needed by the target-driven mode.
|
||||
};
|
||||
} // namespace EMotionFX::MotionMatching
|
||||
|
||||
Reference in New Issue
Block a user