void processFrame(Frame frame, DefaultHandInterface dhi) { int currentHandCount = frame.Hands.Count; if (currentHandCount != prevHandCount) // start counting { currentTransitionLife = 0; prevHandCountBeforeTransition = prevHandCount; isTransitioning = true; } if (isTransitioning) { if (currentTransitionLife < maxTransitionLife) { currentTransitionLife += Time.deltaTime; handleTransitionPhase(frame, prevHandCountBeforeTransition, currentTransitionLife, dhi); } else { isTransitioning = false; } } else { handleStablePhase(frame, dhi); } prevHandCount = currentHandCount; }
public void Add(DefaultHandInterface handInterface) { if (handInterface != null) { handInterfaces.Add(handInterface); } }
void handleStablePhase(Frame frame, DefaultHandInterface dhi) { OneHandInterface ohi = dhi as OneHandInterface; TwoHandInterface thi = dhi as TwoHandInterface; switch (frame.Hands.Count) { case 0: dhi.Zero(); break; case 1: if (ohi != null) { ohi.One(frame.Hands[0]); } break; case 2: if (thi != null) { thi.Two(HandUtils.designateRightLeftHands(frame)); } break; default: dhi.TooManyHands(); break; } }
void handleTransitionPhase(Frame frame, int hbtCount, float ctl, DefaultHandInterface dhi) { OneHandInterface ohi = dhi as OneHandInterface; TwoHandInterface thi = dhi as TwoHandInterface; switch (frame.Hands.Count) { case 0: if (hbtCount == 1 && ohi != null) { ohi.OneToZero(ctl); } if (hbtCount == 2 && thi != null) { thi.TwoToZero(ctl); } if (hbtCount > 2) { dhi.TooManyHands(); } break; case 1: Hand currentHand = frame.Hands[0]; if (hbtCount == 0 && ohi != null) { ohi.ZeroToOne(currentHand, ctl); } if (hbtCount == 2 && thi != null) { thi.TwoToOne(currentHand, ctl); } if (hbtCount > 2) { dhi.TooManyHands(); } break; case 2: Hand[] currentHands = HandUtils.designateRightLeftHands(frame); if (hbtCount == 0 && thi != null) { thi.ZeroToTwo(currentHands, ctl); } if (hbtCount == 1 && thi != null) { thi.OneToTwo(currentHands, ctl); } if (hbtCount > 2) { dhi.TooManyHands(); } break; default: dhi.TooManyHands(); break; } }