getYPosition() public method

public getYPosition ( ) : double
return double
示例#1
0
        //This function will be implemented by you in the subclass files provided.
        //A simple example of highlighting targets when hovered over has been provided below

        //Note: targets is a dictionary that allows you to retrieve the corresponding target on screen
        //and manipulate its state and position, as well as hide/show it (see class defn. below).
        //It is indexed from 1, thus you can retrieve an individual target with the expression
        //targets[3], which would retrieve the target labeled "3" on screen.
        public virtual void processSkeletonFrame(SkeletonData skeleton, Dictionary <int, Target> targets)
        {
            /*Example implementation*/

            foreach (var target in targets)
            {
                Target cur      = target.Value;
                int    targetID = cur.id; //ID in range [1..5]

                //Scale the joints to the size of the window
                Joint leftHand  = skeleton.Joints[JointID.HandLeft].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
                Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);

                //Calculate how far our left hand is from the target in both x and y directions
                double deltaX_left = Math.Abs(leftHand.Position.X - cur.getXPosition());
                double deltaY_left = Math.Abs(leftHand.Position.Y - cur.getYPosition());

                //Calculate how far our right hand is from the target in both x and y directions
                double deltaX_right = Math.Abs(rightHand.Position.X - cur.getXPosition());
                double deltaY_right = Math.Abs(rightHand.Position.Y - cur.getYPosition());

                //If we have a hit in a reasonable range, highlight the target
                if (deltaX_left < 15 && deltaY_left < 15 || deltaX_right < 15 && deltaY_right < 15)
                {
                    cur.setTargetSelected();
                }
                else
                {
                    cur.setTargetUnselected();
                }
            }
        }
示例#2
0
        public override void processSkeletonFrame(SkeletonData skeleton, Dictionary <int, Target> targets)
        {
            foreach (var target in targets)
            {
                Target cur      = target.Value;
                int    targetID = cur.id; //ID in range [1..5]

                //Scale the joints to the size of the window
                Joint rightElbow = skeleton.Joints[JointID.ElbowRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
                Joint rightHand  = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);

                double deltaX_arm = rightHand.Position.X - rightElbow.Position.X;
                double deltaY_arm = rightHand.Position.Y - rightElbow.Position.Y;

                double slope_arm     = (deltaY_arm / deltaX_arm);
                double intercept_arm = rightElbow.Position.Y - slope_arm * rightElbow.Position.X;
                double distance      = Math.Abs(cur.getYPosition() - slope_arm * cur.getXPosition() - intercept_arm) / Math.Sqrt(Math.Pow(slope_arm, 2) + 1);


                //If we have a hit in a reasonable range, highlight the target
                if (distance < 20)
                {
                    if ((Math.Sign(deltaX_arm) == -1 && cur.getXPosition() < rightHand.Position.X) ||
                        Math.Sign(deltaX_arm) == 1 && cur.getXPosition() > rightHand.Position.X)
                    {
                        if (rightHandTargetID < 0)
                        {
                            startTimer(cur, 1.0);
                        }
                    }
                }
                else
                {
                    if (rightHandTargetID == targetID)
                    {
                        stopTimer(cur);
                    }
                }
            }
        }
        private static Boolean ballIntersectsTarget(BallModel ball, Target target)
        {
            double ballX = ball.X;
            double ballY = ball.Y;
            double ballR = ball.R;
            double targetX = target.getXPosition();
            double targetY = target.getYPosition();
            double targetR = target.getTargetRadius();
            double distance = Math.Sqrt(Math.Pow(ballX - targetX,2) + Math.Pow(ballY - targetY,2));

            return distance < targetR+ballR*0.3;
        }
        private int increaseOrDecrease(Joint hand, int lr, Target cur)
        {
            double deltaX = hand.Position.X - cur.getXPosition();
            double deltaY = - (hand.Position.Y - cur.getYPosition());
            double angle = Math.Atan(deltaY/deltaX);

            if (deltaX < 0)
            {
                angle += Math.PI;
            }
            if (angle < 0)
            {
                angle += (2*Math.PI);
            }
            if (thetas[lr] == -1)
            {
                thetas[lr] = angle;
                return 0;
            }
            double delta_theta = angle - thetas[lr];
            thetas[lr] = angle;
            if (delta_theta > Math.PI)
            {
                return 1;
            }
            if (delta_theta < -1 * Math.PI)
            {
                return -1;
            }
            if (delta_theta > 0)
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }