0

骨格関節 (x,y,z) 座標がボタンの x,y,z 座標を超えているときに、何かを実行できるようにしたいだけです。. 次のコードがありますが、どういうわけか正しく動作しません。.手が動くとすぐに、ボタンに手が届かなくても何かが行われます

    if (skeletonFrame != null)
                {
                    //int skeletonSlot = 0;
                    Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletonData);

                    Skeleton playerSkeleton = (from s in skeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();

                    if (playerSkeleton != null)
                    {
                        Joint rightHand = playerSkeleton.Joints[JointType.HandRight];

                        handPosition = new Vector2((((0.5f * rightHand.Position.X) + 0.5f) * (640)), (((-0.5f * rightHand.Position.Y) + 0.5f) * (480)));

                        var rightHands = playerSkeleton.Joints[JointType.HandRight];
                        var rightHandsX = rightHands.Position.X;
                        var rightHandsY = rightHands.Position.Y;
                        var rightHandsZ = rightHands.Position.Z;


                        if (Math.Sqrt(Math.Pow(rightHandsX - position.X, 2) + Math.Pow(rightHandsY - position.Y, 2)) < 20)
                        {

                           // Exit();
                        }



if (Math.Sqrt(Math.Pow(rightHandsX - start_bttn.Bounds.X, 1) + Math.Pow(rightHandsY - start_bttn.Bounds.Y, 1)) < 10)
                        {

                            currentGameState = GameState.Selection;
                            // Exit();
                        }

if ((rightHandsX < GraphicsDevice.Viewport.Width / 2 + 150 && rightHandsX > GraphicsDevice.Viewport.Width / 2 - 75) && (rightHandsY > GraphicsDevice.Viewport.Height / 2 && rightHandsY < GraphicsDevice.Viewport.Height / 2 + 50))
                        {
                            currentGameState = GameState.Selection;

                        }

}

4

1 に答える 1

1

これが私の手の追跡機能です。それがあなたが望むことをするかどうか、またはあなたを近づけるかどうかを確認してください...

    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;
                }
            }
        }
    }

手の位置を画面の位置に変換するための計算が少しあります。人々によってストロークは異なりますが、私の論理は次のとおりです。

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

画面の右端の位置を取得するために、左肩と右肩の間の距離を取り、それを右肩に追加します。

于 2012-09-26T21:44:02.930 に答える