// add isGhost! public Person(SkeletonWrapper skeletonData, Color c, bool isGhost) { hashCode = HASH_CODE; HASH_CODE += 1; this.skeletonData = skeletonData; this.isGhost = isGhost; // Retrieve hand data. Joint rightHand = skeletonData.getRightHandJoint(); Joint leftHand = skeletonData.getLeftHandJoint(); // Retrieve torso data. if (isGhost == false) { Joint shoulderCenter = skeletonData.getCenterShoulderJoint(); Joint spine = skeletonData.getSpineJoint(); torsoTop = shoulderCenter.Position; torsoBottom = spine.Position; } leftHandPosition = leftHand.Position; rightHandPosition = rightHand.Position; this.color = c; canSpawnBoids = true; this.rightHand = new Hand(rightHand); this.leftHand = new Hand(leftHand); }
private void TrackWave(SkeletonWrapper skeleton, int userID, ref WaveGestureTracker tracker, long timestamp) { // The check for a user wave in this implementation is fairly simple. If the user raises their hand directly above their // shoulder then they are merely primed for a wave. If they raise it above and to the left or right of their shoulder, // or if they move that hand left or right after having primed it, then we count that as a wave. For such an implementation // the WaveGestureState is not genuinley necessary however if we choose to change our approach (eg, require three motions to // constitute a valid wave) then the use of this struct will render these changes much simpler. // Retrieve the relevent hand and shoulder for the user depending on which hand/shoulder pair that we // are checking for a wave. Joint leftHand = skeleton.getLeftHandJoint(); Joint rightHand = skeleton.getRightHandJoint(); Joint centerOfShoulders = skeleton.getCenterShoulderJoint(); // Metric measurement double distanceBetweenHandsSq = (Math.Pow(leftHand.Position.X - rightHand.Position.X, 2) + Math.Pow(leftHand.Position.Y - rightHand.Position.Y, 2)); // If the user joints are tracked... if (leftHand.TrackingState == JointTrackingState.Tracked && rightHand.TrackingState == JointTrackingState.Tracked) { // If the user is not taking forever... if (tracker.State == WaveGestureState.InProgress && tracker.Timestamp + WAVE_MOVEMENT_TIMEOUT < timestamp) { tracker.UpdateState(WaveGestureState.Failure, timestamp); } // If the user's hands are overlapping... else if (distanceBetweenHandsSq <= HAND_DISTANCE_THRESHHOLD_SQ) { // If the user is waving to the left... // (We assume that, through the act of overlapping their hands, users will naturally center their hands over their torso.) if (leftHand.Position.X < (centerOfShoulders.Position.X + WAVE_THRESHOLD)) { tracker.UpdatePosition(WavePosition.Left, timestamp); } // Check if the user is waving to the right... else if (leftHand.Position.X > (centerOfShoulders.Position.X - WAVE_THRESHOLD)) { tracker.UpdatePosition(WavePosition.Right, timestamp); } else { tracker.UpdatePosition(WavePosition.Neutral, timestamp); } // end if-else if-else // If the user has not yet achieved a wave but have satisfied the number of wave iterations... if (tracker.State != WaveGestureState.Success && tracker.IterationCount == REQUIRED_ITERATIONS) { // Then they're waving. tracker.UpdateState(WaveGestureState.Success, timestamp); // If we have observers... if (GestureDetected != null) { // Notify them and let them know which direction the user waved and with which hand they waved. GestureDetected(this, new WaveGestureEventArgs(userID)); } // end if } // end if } else { if (tracker.State == WaveGestureState.InProgress) { tracker.UpdateState(WaveGestureState.Failure, timestamp); } else { tracker.Reset(); } // end if-else } // end if-else if-else } // end if }