InteractionTracker.PositionVelocityInPixelsPerSecond 屬性

定義

目前套用至位置的速度。

PositionVelocityInPixelsPerSecond 屬性代表 InteractionTracker 在慣性中的目前位置速度。 此屬性有兩個主要使用案例:在發生互動之後擷取InteractionTracker的位置速度,或參考ExpressionAnimationInteractionTracker的最新速度。

public:
 property float3 PositionVelocityInPixelsPerSecond { float3 get(); };
float3 PositionVelocityInPixelsPerSecond();
public Vector3 PositionVelocityInPixelsPerSecond { get; }
var vector3 = interactionTracker.positionVelocityInPixelsPerSecond;
Public ReadOnly Property PositionVelocityInPixelsPerSecond As Vector3

屬性值

Vector3 Vector3

float3

目前套用至位置的速度。

範例

// Listen for the InertiaStateEntered event, so we can grab PositionVelocityInPixelsPerSecond value.
public void InertiaStateEntered(InteractionTracker sender, InteractionTrackerInertiaStateEnteredArgs args)
{
  // Grab the current velocity of InteractionTracker after interaction occurs out of the args when the event is fired.
  Vector3 interactionVelocity = args.PositionVelocityInPixelsPerSecond;}
}

void CustomSpringMotion(float springCoefficient, float dampingCoefficient, float maxPosition)
{
  // Create the InertiaModifier that will be a custom motion emulating a spring
  InteractionTrackerInertiaMotion modifier = InteractionTrackerInertiaMotion.Create(_compositor);

  modifier.Condition = _compositor.CreateExpressionAnimation("this.Target.NaturalRestingPosition.X > maxPosition");
  modifier.Condition.SetScalarParameter("maxPosition", maxPosition);

  // Utilize the current Velocity of InteractionTracker in the Expression defining 	the custom spring motion
  modifier.Motion = _compositor.CreateExpressionAnimation("(-springStiffnessCoefficient * (this.Target.Position.X – maxPosition)) + (-dampingCoefficient * this.target.PositionVelocityInPixelsPerSecond.X");
  modifier.Motion.SetScalarParameter("springStiffnessCoefficient", 	springCoefficient);
  modifier.Motion.SetScalarParameter("dampingCoefficient", dampingCoefficient);
  modifier.Motion.SetScalarParameter("maxPosition", maxPosition); 
}

備註

InertiaStateEntered 事件存取 PositionVelocityInPixelsPerSecond 屬性時,您會根據互動擷取計算速度的快照集。 只有在發生互動之後,才會引發此事件。

適用於