Guest User

Untitled

a guest
Jan 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. if (skeletonFrame != null)
  2. {
  3. //int skeletonSlot = 0;
  4. Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
  5. skeletonFrame.CopySkeletonDataTo(skeletonData);
  6.  
  7. Skeleton playerSkeleton = (from s in skeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
  8.  
  9. if (playerSkeleton != null)
  10. {
  11. Joint rightHand = playerSkeleton.Joints[JointType.HandRight];
  12.  
  13. handPosition = new Vector2((((0.5f * rightHand.Position.X) + 0.5f) * (640)), (((-0.5f * rightHand.Position.Y) + 0.5f) * (480)));
  14.  
  15. var rightHands = playerSkeleton.Joints[JointType.HandRight];
  16. var rightHandsX = rightHands.Position.X;
  17. var rightHandsY = rightHands.Position.Y;
  18. var rightHandsZ = rightHands.Position.Z;
  19.  
  20.  
  21. if (Math.Sqrt(Math.Pow(rightHandsX - position.X, 2) + Math.Pow(rightHandsY - position.Y, 2)) < 20)
  22. {
  23.  
  24. // Exit();
  25. }
  26.  
  27.  
  28.  
  29. if (Math.Sqrt(Math.Pow(rightHandsX - start_bttn.Bounds.X, 1) + Math.Pow(rightHandsY - start_bttn.Bounds.Y, 1)) < 10)
  30. {
  31.  
  32. currentGameState = GameState.Selection;
  33. // Exit();
  34. }
  35.  
  36. if ((rightHandsX < GraphicsDevice.Viewport.Width / 2 + 150 && rightHandsX > GraphicsDevice.Viewport.Width / 2 - 75) && (rightHandsY > GraphicsDevice.Viewport.Height / 2 && rightHandsY < GraphicsDevice.Viewport.Height / 2 + 50))
  37. {
  38. currentGameState = GameState.Selection;
  39.  
  40. }
  41.  
  42. private void TrackHandMovement(Skeleton skeleton)
  43. {
  44. Joint leftHand = skeleton.Joints[JointType.HandLeft];
  45. Joint rightHand = skeleton.Joints[JointType.HandRight];
  46.  
  47. Joint leftShoulder = skeleton.Joints[JointType.ShoulderLeft];
  48. Joint rightShoulder = skeleton.Joints[JointType.ShoulderRight];
  49.  
  50. Joint rightHip = skeleton.Joints[JointType.HipRight];
  51.  
  52. // the right hand joint is being tracked
  53. if (rightHand.TrackingState == JointTrackingState.Tracked)
  54. {
  55. // the hand is sufficiently in front of the shoulder
  56. if (rightShoulder.Position.Z - rightHand.Position.Z > 0.4)
  57. {
  58. double xScaled = (rightHand.Position.X - leftShoulder.Position.X) / ((rightShoulder.Position.X - leftShoulder.Position.X) * 2) * SystemParameters.PrimaryScreenWidth;
  59. double yScaled = (rightHand.Position.Y - rightShoulder.Position.Y) / (rightHip.Position.Y - rightShoulder.Position.Y) * SystemParameters.PrimaryScreenHeight;
  60.  
  61. // the hand has moved enough to update screen position (jitter control / smoothing)
  62. if (Math.Abs(rightHand.Position.X - xPrevious) > MoveThreshold || Math.Abs(rightHand.Position.Y - yPrevious) > MoveThreshold)
  63. {
  64. RightHandX = xScaled;
  65. RightHandY = yScaled;
  66.  
  67. xPrevious = rightHand.Position.X;
  68. yPrevious = rightHand.Position.Y;
  69.  
  70. // reset the tracking timer
  71. trackingTimerCounter = 10;
  72. }
  73. }
  74. }
  75. }
  76.  
  77. Shoulders = top of screen
  78. Hips = bottom of screen
  79. Left Should = left most on screen
Add Comment
Please, Sign In to add comment