5 using SiliconStudio.Core.Mathematics;
7 namespace SiliconStudio.
Paradox.Input
9 internal sealed
class GestureRecognizerComposite : GestureRecognizerContMotion
11 private GestureConfigComposite ConfigComposite {
get {
return (GestureConfigComposite)Config; } }
13 private int firstFingerId;
14 private int secondFingerId;
16 private Vector2 beginVectorNormalized;
18 private float beginVectorLength;
26 private float currentRotation;
28 private float lastRotation;
30 private float lastScale;
32 private float currentScale;
34 public GestureRecognizerComposite(GestureConfigComposite config,
float screenRatio)
35 : base(config, screenRatio)
39 protected override void InitializeGestureVariables()
42 var keysEnum = FingerIdsToLastPos.Keys.GetEnumerator();
43 keysEnum.MoveNext(); firstFingerId = keysEnum.Current;
44 keysEnum.MoveNext(); secondFingerId = keysEnum.Current;
46 var beginDirVec = FingerIdsToLastPos[secondFingerId] - FingerIdsToLastPos[firstFingerId];
47 beginVectorNormalized = Vector2.Normalize(beginDirVec);
48 beginVectorLength = beginDirVec.Length();
50 beginCenter = (FingerIdsToLastPos[secondFingerId] + FingerIdsToLastPos[firstFingerId]) / 2;
51 lastCenter = beginCenter;
56 protected override bool GestureBeginningConditionFulfilled()
58 return Math.Abs(currentRotation) >= ConfigComposite.MinimumRotationAngle
59 || currentScale <= ConfigComposite.MinimumScaleValueInv || currentScale >= ConfigComposite.MinimumScaleValue
60 || (currentCenter - beginCenter).Length() >= ConfigComposite.MinimumTranslationDistance;
63 protected override void UpdateGestureVarsAndPerfomChecks()
65 var currentVector = FingerIdsToLastPos[secondFingerId] - FingerIdsToLastPos[firstFingerId];
66 var currentVectorNormalized = Vector2.Normalize(currentVector);
69 var rotSign = beginVectorNormalized[0] * currentVectorNormalized[1] - beginVectorNormalized[1] * currentVectorNormalized[0];
70 currentRotation = Math.Sign(rotSign) * (
float)Math.Acos(
Vector2.Dot(currentVectorNormalized, beginVectorNormalized));
73 currentCenter = (FingerIdsToLastPos[secondFingerId] + FingerIdsToLastPos[firstFingerId]) / 2;
76 currentScale = Math.Abs(beginVectorLength) >
MathUtil.ZeroTolerance? currentVector.Length() / beginVectorLength: 0;
79 protected override
void AddGestureEventToCurrentList(
GestureState state)
81 var deltaRotation = currentRotation - lastRotation;
82 var deltaScale = currentScale - lastScale;
83 CurrentGestureEvents.Add(
new GestureEventComposite(state, ElapsedSinceLast, ElapsedSinceBeginning, deltaRotation, currentRotation, deltaScale, currentScale,
84 NormalizeVector(beginCenter), NormalizeVector(lastCenter), NormalizeVector(currentCenter)));
86 lastRotation = currentRotation;
87 lastScale = currentScale;
88 lastCenter = currentCenter;
90 base.AddGestureEventToCurrentList(state);
Represents a two dimensional mathematical vector.