how to use skeletal joint to act as cursor using bounds (No gestures)

前端 未结 1 1214
滥情空心
滥情空心 2021-01-28 02:05

I just want to be able to do something when my skeletal joint (x,y,z) coordinates are over the x,y,z coordinates of the button . . I have the following code but somehow it doesn

相关标签:
1条回答
  • 2021-01-28 02:50

    Here is my hand tracking function. See if it does what you want, or gets you closer...

        private void TrackHandMovement(Skeleton skeleton)
        {
            Joint leftHand = skeleton.Joints[JointType.HandLeft];
            Joint rightHand = skeleton.Joints[JointType.HandRight];
    
            Joint leftShoulder = skeleton.Joints[JointType.ShoulderLeft];
            Joint rightShoulder = skeleton.Joints[JointType.ShoulderRight];
    
            Joint rightHip = skeleton.Joints[JointType.HipRight];
    
            // the right hand joint is being tracked
            if (rightHand.TrackingState == JointTrackingState.Tracked)
            {
                // the hand is sufficiently in front of the shoulder
                if (rightShoulder.Position.Z - rightHand.Position.Z > 0.4)
                {
                    double xScaled = (rightHand.Position.X - leftShoulder.Position.X) / ((rightShoulder.Position.X - leftShoulder.Position.X) * 2) * SystemParameters.PrimaryScreenWidth;
                    double yScaled = (rightHand.Position.Y - rightShoulder.Position.Y) / (rightHip.Position.Y - rightShoulder.Position.Y) * SystemParameters.PrimaryScreenHeight;
    
                    // the hand has moved enough to update screen position (jitter control / smoothing)
                    if (Math.Abs(rightHand.Position.X - xPrevious) > MoveThreshold || Math.Abs(rightHand.Position.Y - yPrevious) > MoveThreshold)
                    {
                        RightHandX = xScaled;
                        RightHandY = yScaled;
    
                        xPrevious = rightHand.Position.X;
                        yPrevious = rightHand.Position.Y;
    
                        // reset the tracking timer
                        trackingTimerCounter = 10;
                    }
                }
            }
        }
    

    There is a bit of math in there to translate the hand position to the screen position. Different strokes for different folks, but my logic is:

    Shoulders = top of screen
    Hips = bottom of screen
    Left Should = left most on screen
    

    To get the right most screen position, I take the distance between the left & right shoulder and add it to the right shoulder.

    0 讨论(0)
提交回复
热议问题