public override bool CheckConditions() { var leftThumb = GestureSystem.GetLimb(InteractionLimb.LeftThumbTip); var leftIndex = GestureSystem.GetLimb(InteractionLimb.LeftIndexTip); var rightThumb = GestureSystem.GetLimb(InteractionLimb.RightThumbTip); var rightIndex = GestureSystem.GetLimb(InteractionLimb.RightIndexTip); if (leftThumb == null || leftIndex == null || rightThumb == null || rightIndex == null) { return(IsGestureActive); } if (IsGestureActive) { // if the gesture is already active, we only need to check if the user is still pinching their fingers together var isPinchingLeft = GestureUtil.IsInProximity(DeactivationDistance, new[] { leftThumb, leftIndex }); var isPinchingRight = GestureUtil.IsInProximity(DeactivationDistance, new[] { rightThumb, rightIndex }); if (isPinchingLeft && isPinchingRight) { // gesture still active GesturePosLeft = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex }); GesturePosRight = GestureUtil.GetCenterPosition(new[] { rightThumb, rightIndex }); GesturePosCenter = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex, rightThumb, rightIndex }); RaiseGestureActiveEvent(); } else { // one of the hands stopped pinching - stop gesture IsGestureActive = false; RaiseGestureStopEvent(); } } else { // gesture not active, so we'll check if the gesture is initiated var isPinchingLeft = GestureUtil.CollidesWith(leftThumb, leftIndex); var isPinchingRight = GestureUtil.CollidesWith(rightThumb, rightIndex); var areHandsTogether = GestureUtil.IsInProximity(ActivationDistance, new[] { leftThumb, leftIndex, rightThumb, rightIndex }); if (isPinchingLeft && isPinchingRight && areHandsTogether) { IsGestureActive = true; GesturePosLeft = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex }); GesturePosRight = GestureUtil.GetCenterPosition(new[] { rightThumb, rightIndex }); GesturePosCenter = GestureUtil.GetCenterPosition(new[] { leftThumb, leftIndex, rightThumb, rightIndex }); RaiseGestureStartEvent(); } } return(IsGestureActive); }
public void EndPickup(GestureEventArgs e) { if (pickedUpObject != null) { pickedUpObject.transform.position = transform.position + offset; var body = pickedUpObject.GetComponent <Rigidbody>(); body.detectCollisions = true; // apply last known velocity of gesture var velocity = pickedUpObject.transform.position - GestureUtil.GetCenterPosition(lastGesturePositions); body.AddForce(velocity * 60); lastGesturePositions.Clear(); pickedUpObject = null; } }
public void FinishCreation(GestureEventArgs e) { var gesture = e.Sender as IPositionGesture; if (gesture != null) { // turn on rigidbody on again var body = CreatedInstance.GetComponent <Rigidbody>(); body.detectCollisions = true; var pos = gesture.GetGesturePosition(Hand.Both); CreatedInstance.transform.position = pos; // apply last known velocity of gesture var velocity = pos - GestureUtil.GetCenterPosition(lastGesturePositions); body.AddForce(velocity * 60); lastGesturePositions.Clear(); _createdInstances.Add(CreatedInstance); CreatedInstance = null; } }