/// <summary> /// Deserialize a skeleton /// </summary> /// <param name="reader">Binary reader</param> /// <returns>Deserialized skeleton</returns> private kinect.Skeleton DeserializeSkeleton(BinaryReader reader) { kinect.Skeleton skeleton = new kinect.Skeleton(); skeleton.ClippedEdges = (kinect.FrameEdges)reader.ReadInt32(); kinect.SkeletonPoint point = new kinect.SkeletonPoint(); point.X = reader.ReadSingle(); point.Y = reader.ReadSingle(); point.Z = reader.ReadSingle(); skeleton.Position = point; skeleton.TrackingId = reader.ReadInt32(); skeleton.TrackingState = (kinect.SkeletonTrackingState)reader.ReadInt32(); int jointsCount = reader.ReadInt32(); for (int index = 0; index < jointsCount; index++) { kinect.JointType jointType = (kinect.JointType)reader.ReadInt32(); kinect.Joint joint = skeleton.Joints[jointType]; joint.TrackingState = (kinect.JointTrackingState)reader.ReadInt32(); point.X = reader.ReadSingle(); point.Y = reader.ReadSingle(); point.Z = reader.ReadSingle(); joint.Position = point; skeleton.Joints[joint.JointType] = joint; } return(skeleton); }
private static void SumWithFatherPosition( Dictionary <Microsoft.Kinect.JointType, Vector3D> jointVectors, Microsoft.Kinect.JointType jointType) { jointVectors[jointType] += jointVectors[(Microsoft.Kinect.JointType)JointTypeHelper.GetFather((PreposeGestures.JointType)jointType)]; }
private static void SumWithFatherPosition( Dictionary <Microsoft.Kinect.JointType, Vector3D> jointVectors, List <PreposeGestures.JointType> targetCalculatedJoints, Microsoft.Kinect.JointType jointType) { if (targetCalculatedJoints.Contains((PreposeGestures.JointType)jointType)) { jointVectors[jointType] += jointVectors[(Microsoft.Kinect.JointType)JointTypeHelper.GetFather((PreposeGestures.JointType)jointType)]; } }
public static Vector3D CalcAbsoluteJointPosition( Dictionary <Microsoft.Kinect.JointType, Vector3D> jointVectors, Microsoft.Kinect.JointType jointType) { var result = jointVectors[jointType]; var fatherJointType = (Microsoft.Kinect.JointType)JointTypeHelper.GetFather((PreposeGestures.JointType)jointType); if (jointType != Microsoft.Kinect.JointType.SpineBase) { result += CalcAbsoluteJointPosition(jointVectors, fatherJointType); } return(result); }
void ProcessHandGesture(KBody user, J hand, HandState curState, HandState oldState) { var id = user.TrackingId; var uiInteracting = uiInterState != UIInterState.IDLE && uiInterUserId == id && uiInterHand == hand; var shoulderPos = user.Joints[J.SpineShoulder].Position; //filter on old state if (oldState == HandState.Closed) { if (uiInterState == UIInterState.GRABBING_MENU && uiInteracting) { uiInterState = UIInterState.IDLE; if (user.Joints[hand].Position.Y < shoulderPos.Y) { interCbWithIdleRefresh(id, InteractionType.RELEASE_MENU_SHOW, 0); } else { interCbWithIdleRefresh(id, InteractionType.RELEASE_MENU_CANCEL, 0); } } else { interCbWithIdleRefresh(id, InteractionType.RELEASE, hand); } } else if (oldState == HandState.Lasso) { interCbWithIdleRefresh(id, InteractionType.END_DRAW, hand); } //filter on current state if (curState == HandState.Closed) { if (uiInterState == UIInterState.PEEKING_MENU && uiInteracting) { uiInterState = UIInterState.GRABBING_MENU; interCbWithIdleRefresh(id, InteractionType.GRAB_MENU, hand); } else { interCbWithIdleRefresh(id, InteractionType.GRAB, hand); } } else if (curState == HandState.Lasso) { interCbWithIdleRefresh(id, InteractionType.BEGIN_DRAW, hand); } }
private static PreposeGestures.JointType Convert(Microsoft.Kinect.JointType jointType) { return((PreposeGestures.JointType)jointType); }
public VisualizableJoint(kinect.JointType jt) { this.TrackingState = kinect.JointTrackingState.NotTracked; this.jointType = jt; this.IsJointOfInterest = false; }
private void StrategyPersonFollowing() { haveATargetNow = false; bool haveSkeleton = false; bool lostSkeletons = false; DateTime Now = DateTime.Now; //kinect.JointType targetJointType = kinect.JointType.HandLeft; kinect.JointType targetJointType = kinect.JointType.Spine; setCurrentGoalDistance(null); // measured value, best case is distance to skeleton, can be null if we completely lost target, or assumed to be 5 meters for red shirt. FollowDirectionTargetDistanceToGoalMeters = TargetDistanceToGoalMeters; // desired value. We want to stop at this distance to human and keep him in front of the robot. SetLightsTrackingSkeleton(false); SetLightsTrackingRedShirt(false); if (!_mapperVicinity.robotState.ignoreKinectSkeletons) { var tmpAllSkeletons = frameProcessor.AllSkeletons; // get a snapshot of the pointer to allocated array, and then take sweet time processing it knowing it will not change var skels = from s in tmpAllSkeletons where s.IsSkeletonActive && s.JointPoints[targetJointType].TrackingState == kinect.JointTrackingState.Tracked orderby s.JointPoints[targetJointType].Z select s; int skelsCount = skels.Count(); if (skelsCount != skelsCountPrev) { int deltaSkelsCount = skelsCount - skelsCountPrev; skelsCountPrev = skelsCount; //if (deltaSkelsCount < 0) //{ // if ((Now - lastAmazing).TotalSeconds > 10.0d) // { // lastAmazing = Now; // _soundsHelper.PlaySound("you were amazing", 0.5d); // } //} //else //{ // _soundsHelper.PlaySound("skeletons number changed", 0.2d); //} //talkerToHuman.ensureAnnouncementDelay(); if (skelsCount > 0) { frameProcessor.doSaveOneImage = _mapperVicinity.robotState.doPhotos; // snap a picture //_mainWindow.PlayRandomSound(); //talkerToHuman.Say(9, "" + skelsCount + " tasty human" + (skelsCount > 1 ? "s" : "")); HeadlightsOff(); } else { lostSkeletons = true; } } if (skelsCount > 0) { haveSkeleton = true; #region Have a skeleton, follow it lastHadSkeletons = Now; // found the first skeleton; track it: VisualizableSkeletonInformation vsi = skels.FirstOrDefault(); if (vsi == null) { // this really, really should not happen, especially now when we allocate frameProcessor.AllSkeletons for every frame. Tracer.Error("StrategyPersonFollowing() vsi == null"); return; } VisualizableJoint targetJoint = vsi.JointPoints[targetJointType]; //bool isSkeletonActive = vsi.IsSkeletonActive; always true SkeletonPose skeletonPose = vsi.SkeletonPose; // when changed, announce pose and react to it: ReactOnSkeletonPose(skeletonPose); // Warning: VisualizableJoint::ComputePanTilt() can set Pan or Tilt to NaN if (targetJoint != null && !double.IsNaN(targetJoint.Pan) && !double.IsNaN(targetJoint.Tilt)) { haveATargetNow = true; SetLightsTrackingSkeleton(true); double targetPanRelativeToRobot = _state.currentPanKinect + targetJoint.Pan; double targetPanRelativeToHead = targetJoint.Pan; //Tracer.Trace("================== currentPanKinect=" + _state.currentPanKinect + " targetJoint.Pan=" + targetJoint.Pan + " targetPanRelativeToRobot=" + targetPanRelativeToRobot); // guns rotate (pan) with Kinect, but tilt independently of Kinect. They are calibrated when Kinect tilt = 0 targetPan = targetPanRelativeToHead; targetTilt = targetJoint.Tilt + _state.currentTiltKinect; double kinectTurnEstimate = targetPanRelativeToRobot - _state.currentPanKinect; bool shouldTurnKinect = Math.Abs(kinectTurnEstimate) > smallMovementsAngleTreshold; // don't follow small movements SetDesiredKinectPlatformPan(shouldTurnKinect ? (double?)targetPanRelativeToRobot : null); // will be processed in computeAndExecuteKinectPlatformTurn() when head turn measurement comes. setPanTilt(targetPan, targetTilt); double distanceToHumanMeters = targetJoint.Z; // actual distance from Kinect to human bool tooCloseToHuman = distanceToHumanMeters < TargetDistanceToGoalMeters - 0.1d; // cannot shoot, likely backing up bool veryCloseToHuman = distanceToHumanMeters < TargetDistanceToGoalMeters + 0.1d; // can talk to human, likely in the dead zone and not moving #region Greet the Human if (veryCloseToHuman && talkerToHuman.canTalk()) { frameProcessor.doSaveOneImage = _mapperVicinity.robotState.doPhotos; // snap a picture talkerToHuman.TalkToHuman(); } #endregion // Greet the Human #region Shoot the Human if (skeletonPose == shootingPose) { if (!tooCloseToHuman) { //lock (shootingPoseLock) //{ if (!shotAtHuman && (Now - lastShotAtHuman).TotalSeconds > 2.0d) { lastShotAtHuman = Now; shotAtHuman = true; talkerToHuman.Say(9, "good boy"); SpawnIterator(ShootGunOnce); } //} } } else { shotAtHuman = false; } #endregion // Shoot the Human ComputeMovingVelocity(distanceToHumanMeters, targetPanRelativeToRobot, 0.25d, 10.0d); } // else // { // // we have skeleton(s) but the target joint is not visible. What to do here? // } #endregion // Have a skeleton, follow it } else if ((Now - lastHadSkeletons).TotalSeconds < 1.0d) { return; // may be just temporary loss of skeletons, wait a little before switching to red shirt } } // end ignoreKinectSkeletons if (!_mapperVicinity.robotState.ignoreRedShirt && !haveSkeleton && frameProcessor.videoSurveillanceDecider != null) { #region Have a red shirt, follow it VideoSurveillanceTarget target = frameProcessor.videoSurveillanceDecider.mainColorTarget; if (target != null && (Now - target.TimeStamp).TotalSeconds < 0.5d) // must also be recent { lastHadRedShirt = Now; haveATargetNow = true; SetLightsTrackingRedShirt(true); double targetPanRelativeToRobot = target.Pan; // already adjusted for currentPanKinect //Tracer.Trace("+++++++++++++++ currentPanKinect=" + _state.currentPanKinect + " target.Pan=" + target.Pan + " targetPanRelativeToRobot=" + targetPanRelativeToRobot); //Tracer.Trace(" target.Pan=" + target.Pan + " Tilt=" + target.Tilt); // guns rotate (pan) with Kinect, but tilt independently of Kinect. They are calibrated when Kinect tilt = 0 targetPan = targetPanRelativeToRobot - _state.currentPanKinect; targetTilt = target.Tilt; // currentTiltKinect already accounted for by VideoSurveillance //Tracer.Trace("+++++++++++++++ currentTiltKinect=" + _state.currentTiltKinect + " target.Tilt=" + target.Tilt + " targetTilt=" + targetTilt); //if((DateTime.Now - lastTurnedKinectPlatform).TotalSeconds > 1.0d) { lastTurnedKinectPlatform = DateTime.Now; double kinectTurnEstimate = targetPan; // targetPanRelativeToRobot - _state.currentPanKinect; bool shouldTurnKinect = Math.Abs(kinectTurnEstimate) > smallMovementsAngleTreshold; // don't follow small movements SetDesiredKinectPlatformPan(shouldTurnKinect ? (double?)targetPanRelativeToRobot : null); // will be processed in computeAndExecuteKinectPlatformTurn() when head turn measurement comes. } //Tracer.Trace(string.Format(" targetPan={0:0.00} Tilt={1:0.00} PanKinect={2:0.00}", targetPan, targetTilt, _state.currentPanKinect)); setPanTilt(targetPan, targetTilt); double bestKinectTilt = targetTilt; // will be limited to +-27 degrees SetDesiredKinectTilt(bestKinectTilt); // choose robotTacticsType - current tactics is move towards human: var mostRecentParkingSensor = _state.MostRecentParkingSensor; double redShirtDistanceMetersEstimated = mostRecentParkingSensor == null ? TargetDistanceToGoalMeters : Math.Min(mostRecentParkingSensor.parkingSensorMetersLF, mostRecentParkingSensor.parkingSensorMetersRF); //Tracer.Trace("redShirtDistanceEstimated = " + redShirtDistanceMetersEstimated); ComputeMovingVelocity(redShirtDistanceMetersEstimated, targetPanRelativeToRobot, 0.35d, 10.0d); if (_mapperVicinity.robotState.robotTacticsType == RobotTacticsType.None && Math.Abs(redShirtDistanceMetersEstimated - TargetDistanceToGoalMeters) < 0.35d && Math.Abs(targetPan) < 10.0d && (DateTime.Now - lastGunsFiredOnRed).TotalSeconds > 5.0d) { lastGunsFiredOnRed = Now; //talkerToHuman.Say(9, "red shirt"); SpawnIterator(ShootGunOnce); } if (!hadATarget || lostSkeletons) // just acquired target, or lost all Skeletons { frameProcessor.doSaveOneImage = _mapperVicinity.robotState.doPhotos; // snap a picture //talkerToHuman.Say(9, "red shirt"); //nextAnnouncementDelay = _soundsHelper.Announce("$lady in red", nextAnnouncementDelayDefault, 0.05d); //nextAnnouncementDelay = _soundsHelper.Announce("red shirt", nextAnnouncementDelayDefault, 0.05d); talkerToHuman.rewindDialogue(); } } else { if (target == null) { Tracer.Trace("----------------- no main color target"); } else { Tracer.Trace("----------------- main color target too old at " + (Now - target.TimeStamp).TotalSeconds + " sec"); } } #endregion // Have a red shirt, follow it } // end ignoreRedShirt else if ((Now - lastHadRedShirt).TotalSeconds < 1.0d) { _mapperVicinity.robotDirection.bearing = null; // indication for tactics to compute collisions and stop. return; // may be just temporary loss of red shirt, wait a little before switching to sound } else if (!haveSkeleton && !_mapperVicinity.robotState.ignoreKinectSounds) { // we let voice recognizer have control for several seconds, if we can't track skeleton or red shirt anyway. if ((Now - lastVoiceLocalized).TotalSeconds > 5.0d) { // choose robotTacticsType - current tactics is Stop: _mapperVicinity.robotState.robotTacticsType = RobotTacticsType.None; } } if (!haveATargetNow) { // no target means stopping PerformAvoidCollision(null, 1.0d); // just in case setCurrentGoalDistance(null); _mapperVicinity.robotDirection.bearing = null; // indication for tactics to compute collisions and stop. _mapperVicinity.robotState.robotTacticsType = RobotTacticsType.None; StopMoving(); _state.MovingState = MovingState.Unable; _state.Countdown = 0; // 0 = immediate response } if (hadATarget && !haveATargetNow) { lastLostTargets = Now; secondsSinceLostTargetLast = -1; haveATargetNowState = 0; if ((Now - lastThanksForStoppingBy).TotalSeconds > 60.0d) { lastThanksForStoppingBy = Now; talkerToHuman.Say(9, "thanks for stopping by!"); } //talkerToHuman.Say(9, "lost all humans"); //string messageToSay = "$lost all humans"; //nextAnnouncementDelay = _soundsHelper.Announce(messageToSay, nextAnnouncementDelayDefault, 0.1d); talkerToHuman.rewindDialogue(); lastTargetPanSwitch = 0; StartHeadAnimationCombo(HeadComboAnimations.Restpose, false); AddHeadAnimationCombo(HeadComboAnimations.BlinkCycle, true, 0.4d); } hadATarget = haveATargetNow; // set flag for the next cycle #region Target Lost Routine if (!haveATargetNow) { if (_mapperVicinity.robotState.doLostTargetRoutine) { // after losing targets, rotate both directions for a while, and then stop and wait: int secondsSinceLostTarget = (int)Math.Round((Now - lastLostTargets).TotalSeconds); if (secondsSinceLostTarget != secondsSinceLostTargetLast) { // we come here once every second when the target is not in view. secondsSinceLostTargetLast = secondsSinceLostTarget; if (secondsSinceLostTarget <= 30) { HeadlightsOn(); double tmpPanKinect = 0.0d; switch (secondsSinceLostTarget) { case 0: case 1: // stop for now: setCurrentGoalDistance(null); _mapperVicinity.robotState.robotTacticsType = RobotTacticsType.None; SetDesiredKinectTilt(3.0d); return; case 2: case 3: case 4: if (haveATargetNowState != 1) { tmpPanKinect = 50.0d * Math.Sign(targetPan); Tracer.Trace("setPanTilt() 1 Kinect pan=" + tmpPanKinect); SetDesiredKinectPlatformPan(tmpPanKinect); setGunsParked(); haveATargetNowState = 1; talkerToHuman.Say(9, "One"); } break; case 5: case 6: case 7: if (haveATargetNowState != 2) { Tracer.Trace("setPanKinect() 2 Kinect pan=0"); SetDesiredKinectPlatformPan(0.0d); haveATargetNowState = 2; talkerToHuman.Say(9, "Two"); } break; case 8: case 9: case 10: if (haveATargetNowState != 3) { tmpPanKinect = -50.0d * Math.Sign(targetPan); Tracer.Trace("setPanKinect() 3 Kinect pan=" + tmpPanKinect); SetDesiredKinectPlatformPan(tmpPanKinect); haveATargetNowState = 3; talkerToHuman.Say(9, "Three"); } break; case 11: case 12: if (haveATargetNowState != 4) { Tracer.Trace("setPanKinect() 4 Kinect pan=0"); SetDesiredKinectPlatformPan(0.0d); haveATargetNowState = 4; talkerToHuman.Say(9, "Four"); } break; } if (secondsSinceLostTarget > 12 && secondsSinceLostTarget % 6 == 0 && lastTargetPanSwitch != secondsSinceLostTarget) { lastTargetPanSwitch = secondsSinceLostTarget; targetPan = -targetPan; // switch rotation direction every 6 seconds Tracer.Trace("setPanKinect() 5 Kinect pan=0"); talkerToHuman.Say(9, "Switch"); SetDesiredKinectPlatformPan(0.0d); } setCurrentGoalBearingRelativeToRobot(60.0d * Math.Sign(targetPan)); // keep in the same direction where the target last was, aiming at 60 degrees for a steep turn in place // choose robotTacticsType - rotate towards where the target was last seen: setCurrentGoalDistance(TargetDistanceToGoalMeters); FollowDirectionMaxVelocityMmSec = MinimumForwardVelocityMmSec; // ;ModerateForwardVelocityMmSec _mapperVicinity.robotState.robotTacticsType = RobotTacticsType.FollowDirection; } else { // stop, sing a song and wait for a target to appear: FollowDirectionMaxVelocityMmSec = 0.0d; setCurrentGoalDistance(null); _mapperVicinity.robotState.robotTacticsType = RobotTacticsType.None; haveATargetNowState = 0; int lonelyPlayTime = 180; // the song is 2:40 - give it 3 minutes to play if (secondsSinceLostTarget % 20 == 0 && (lastWaitingForHumansAnnounced == 0 || lastWaitingForHumansAnnounced == secondsSinceLostTarget - lonelyPlayTime)) { lastWaitingForHumansAnnounced = secondsSinceLostTarget; //talkerToHuman.Say(9, "waiting for humans"); _soundsHelper.Announce("$lonely", 5.0d, 0.05d); // play "I-am-Mr-Lonely.mp3" really quietly talkerToHuman.rewindDialogue(); lastWaitingForHumansAnnounced = 0; HeadlightsOff(); } Tracer.Trace("secondsSinceLostTarget=" + secondsSinceLostTarget); if (secondsSinceLostTarget % 10 == 0) { Tracer.Trace("setPanKinect() 5 Kinect pan=" + panKinectSearchAngles[panKinectSearchIndex]); SetDesiredKinectTilt(3.0d); SetDesiredKinectPlatformPan(panKinectSearchAngles[panKinectSearchIndex++]); if (panKinectSearchIndex >= panKinectSearchAngles.Length) { panKinectSearchIndex = 0; } } } } } else // !doLostTargetRoutine { // just assume safe position and wait till a new target appears in front of the camera: HeadlightsOff(); if ((DateTime.Now - lastLostTargets).TotalSeconds > 3.0d) { SafePosture(); } // stop for now: setCurrentGoalDistance(null); _mapperVicinity.robotDirection.bearing = null; _mapperVicinity.robotState.robotTacticsType = RobotTacticsType.None; } } #endregion // Target Lost Routine }
private void writeJoint(XmlWriter writerXML, StringBuilder csv, Body curBody, string name, Microsoft.Kinect.JointType jt) { writerXML.WriteStartElement(name); writerXML.WriteStartElement("x"); writerXML.WriteString(curBody.Joints[jt].Position.X.ToString()); writerXML.WriteEndElement(); writerXML.WriteStartElement("y"); writerXML.WriteString(curBody.Joints[jt].Position.Y.ToString()); writerXML.WriteEndElement(); writerXML.WriteStartElement("z"); writerXML.WriteString(curBody.Joints[jt].Position.Z.ToString()); writerXML.WriteEndElement(); writerXML.WriteEndElement(); csv.AppendFormat("\t{0},\t{1},\t{2}", curBody.Joints[jt].Position.X.ToString(), curBody.Joints[jt].Position.Y.ToString(), curBody.Joints[jt].Position.Z.ToString()); csv.Append((jt != Final_Joint) ? ',' : '\n', 1); }
public static MyJointType ToMyJointType(this KJointType kJointType) { return((MyJointType)(int)kJointType); }
public Joint GetJoint(JointType joint) { Microsoft.Kinect.JointType jointType = (Microsoft.Kinect.JointType)Enum.Parse(typeof(Microsoft.Kinect.JointType), joint.ToString()); return(new Joint(_skeleton.Joints[jointType])); }
public static MyJointType ToMyJointType(this KJointType kJointType) { return(JointConversionTable[(int)kJointType]); }
void DetectEvent(KBody user) { var id = user.TrackingId; var oldHands = usersHands[id]; var now = DateTime.Now; var clippedEdges = (user.ClippedEdges & (FrameEdges.Right | FrameEdges.Left | FrameEdges.Top)) != 0; var lastLeftEventElapsed = now - oldHands.LeftChangeTime; var lastRightEventElapsed = now - oldHands.RightChangeTime; var topHeadPos = user.Joints[J.Head].Position; var spineMidPos = user.Joints[J.SpineMid].Position; var leftCoord = CameraPointToScreen(user.Joints[J.HandLeft].Position); var rightCoord = CameraPointToScreen(user.Joints[J.HandRight].Position); var leftWristPos = user.Joints[J.WristLeft].Position; var rightWristPos = user.Joints[J.WristRight].Position; var leftHandTracked = user.Joints[J.HandLeft].TrackingState == TrackingState.Tracked; var rightHandTracked = user.Joints[J.HandRight].TrackingState == TrackingState.Tracked; var leftEngaged = leftHandTracked && leftWristPos.Y > spineMidPos.Y + ENGAGED_SPINE_OFFSET; var rightEngaged = rightHandTracked && rightWristPos.Y > spineMidPos.Y + ENGAGED_SPINE_OFFSET; //Hand shape gestures: //both hands logic: if (lastLeftEventElapsed > ANTI_SPAM_SPAN || lastRightEventElapsed > ANTI_SPAM_SPAN) { var leftClosed = user.HandLeftState == HandState.Closed; var rightClosed = user.HandRightState == HandState.Closed; var oldLeftClosed = oldHands.LeftState == HandState.Closed; var oldRightClosed = oldHands.RightState == HandState.Closed; if (leftEngaged && rightEngaged && leftClosed && rightClosed && (!oldLeftClosed || !oldRightClosed)) { interCbWithIdleRefresh(id, InteractionType.BEGIN_CREATING_OBJECT, 0); } else if (oldLeftClosed && oldRightClosed && (!leftClosed || !rightClosed)) { interCbWithIdleRefresh(id, InteractionType.FINISH_CREATING_OBJECT, 0); } // old hand state is updated below } //left hand logic: if (lastLeftEventElapsed > ANTI_SPAM_SPAN) { if (user.HandLeftState == HandState.Unknown || user.HandLeftState == HandState.NotTracked) { //hand gesture expired if (oldHands.LeftState != HandState.Unknown && now - oldHands.LeftChangeTime > EXPIRE_STATE_SPAN) { ProcessHandGesture(user, J.HandLeft, user.HandLeftState, oldHands.LeftState); oldHands.LeftState = HandState.Unknown; } } else if (user.HandLeftState != oldHands.LeftState && (user.HandLeftState != HandState.Lasso || leftEngaged)) { ProcessHandGesture(user, J.HandLeft, user.HandLeftState, oldHands.LeftState); oldHands.LeftState = user.HandLeftState; oldHands.LeftChangeTime = now; } } //right hand logic: if (lastRightEventElapsed > ANTI_SPAM_SPAN) { if (user.HandRightState == HandState.Unknown || user.HandRightState == HandState.NotTracked) { //hand gesture expired if (oldHands.RightState != HandState.Unknown && now - oldHands.RightChangeTime > EXPIRE_STATE_SPAN) { ProcessHandGesture(user, J.HandRight, user.HandRightState, oldHands.RightState); oldHands.RightState = HandState.Unknown; } } else if (user.HandRightState != oldHands.RightState && (user.HandRightState != HandState.Lasso || rightEngaged)) { ProcessHandGesture(user, J.HandRight, user.HandRightState, oldHands.RightState); oldHands.RightState = user.HandRightState; oldHands.RightChangeTime = now; } } if (id == uiInterUserId) { // menu peeking gestures: //left hand logic: if (leftEngaged && !clippedEdges && leftWristPos.Y > topHeadPos.Y && user.HandLeftState == HandState.Open) { if (uiInterState == UIInterState.IDLE) { uiInterState = UIInterState.PEEKING_MENU; uiInterHand = J.HandLeft; interCbWithIdleRefresh(id, InteractionType.PEEK_MENU, J.HandLeft); } } else if (uiInterState == UIInterState.PEEKING_MENU && uiInterHand == J.HandLeft) { uiInterState = UIInterState.IDLE; interCbWithIdleRefresh(id, InteractionType.CANCEL_PEEK_MENU, J.HandLeft); } //right hand logic: if (rightEngaged && !clippedEdges && rightWristPos.Y > topHeadPos.Y && user.HandRightState == HandState.Open) { if (uiInterState == UIInterState.IDLE) { uiInterState = UIInterState.PEEKING_MENU; uiInterHand = J.HandRight; interCbWithIdleRefresh(id, InteractionType.PEEK_MENU, J.HandRight); } } else if (uiInterState == UIInterState.PEEKING_MENU && uiInterHand == J.HandRight) { uiInterState = UIInterState.IDLE; interCbWithIdleRefresh(id, InteractionType.CANCEL_PEEK_MENU, J.HandRight); } // Margin reaching logic: //left if (leftHandTracked && (leftCoord.X < gameSpace.Left || (user.ClippedEdges & FrameEdges.Left) != 0)) { if (leftEngaged && uiInterState == UIInterState.IDLE) // put in nested if to allow keeping margin interaction if hand is lowered { uiInterState = UIInterState.REACHING_MARGIN; uiInterHand = J.HandLeft; interCbWithIdleRefresh(id, InteractionType.BEGIN_REACH_MARGIN, J.HandLeft); } } else if (uiInterState == UIInterState.REACHING_MARGIN && uiInterHand == J.HandLeft) { uiInterState = UIInterState.IDLE; interCbWithIdleRefresh(id, InteractionType.END_REACH_MARGIN, J.HandLeft); } //right if (rightHandTracked && (rightCoord.X > gameSpace.Right || (user.ClippedEdges & FrameEdges.Right) != 0)) { if (rightEngaged && uiInterState == UIInterState.IDLE) { uiInterState = UIInterState.REACHING_MARGIN; uiInterHand = J.HandRight; interCbWithIdleRefresh(id, InteractionType.BEGIN_REACH_MARGIN, J.HandRight); } } else if (uiInterState == UIInterState.REACHING_MARGIN && uiInterHand == J.HandRight) { uiInterState = UIInterState.IDLE; interCbWithIdleRefresh(id, InteractionType.END_REACH_MARGIN, J.HandRight); } } }
void Kinect20__receivepoints(Microsoft.Kinect.JointType jt, double x, double y, double z) { switch (jt) { case JointType.HandLeft: //左手 HandLeft Canvas.SetLeft(this.leftHand, x); Canvas.SetTop(this.leftHand, y); break; case JointType.HandRight: //右手 HandRight Canvas.SetLeft(this.rightHand, x); Canvas.SetTop(this.rightHand, y); break; } //其他骨骼数据 //show other joints data if (jt == JointType.HipLeft) { this.textBlock1.Text = "HipLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.SpineBase) { this.textBlock2.Text = "SpineBase X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.ShoulderLeft) { this.textBlock3.Text = "ShoulderLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.Head) { this.textBlock4.Text = "Head X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.ShoulderLeft) { this.textBlock5.Text = "ShoulderLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.ElbowLeft) { this.textBlock6.Text = "ElbowLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.WristLeft) { this.textBlock7.Text = "WristLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.ShoulderRight) { this.textBlock8.Text = "ShoulderRight X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.ElbowRight) { this.textBlock9.Text = "ElbowRight X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.WristRight) { this.textBlock10.Text = "WristRight X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.HipLeft) { this.textBlock11.Text = "HipLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.KneeLeft) { this.textBlock12.Text = "KneeLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.AnkleLeft) { this.textBlock13.Text = "AnkleLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.FootLeft) { this.textBlock14.Text = "FootLeft X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.HipRight) { this.textBlock15.Text = "HipRight X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } else if (jt == JointType.KneeRight) { this.textBlock16.Text = "KneeRight X:" + x.ToString() + " Y:" + y.ToString() + " Z:" + z.ToString(); } }