Beispiel #1
0
 public override string ToJSON()
 {
     PositionRatio p = new PositionRatio(this.Pos);
     return "{\"Id\":\"" + Id + "\",\"X\":\"" + p.X + "\",\"Y\":\"" + Pos.Y + "\",\"Z\":\"" + p.Z + "\",\"radius\":\"" + radius/(2*PositionRatio.maxX) + "\"}";
 }
Beispiel #2
0
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            Position3D right_hand_pos = null;
            Position3D right_wrist_pos = null;
            Position3D left_hand_pos = null;
            Position3D left_wrist_pos = null;
            foreach (Skeleton skeleton in skeletons)
            {
                if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                {
                    //余裕があれば書き変えたい
                    foreach (Joint joint in skeleton.Joints)
                    {
                        if (joint.JointType == JointType.HandRight)
                        {
                            right_hand_pos = new Position3D(joint.Position.X, joint.Position.Y, joint.Position.Z);
                        }
                        else if (joint.JointType == JointType.WristRight)
                        {
                            right_wrist_pos = new Position3D(joint.Position.X, joint.Position.Y, joint.Position.Z);
                        }
                        else if (joint.JointType == JointType.HandLeft)
                        {
                            left_hand_pos = new Position3D(joint.Position.X, joint.Position.Y, joint.Position.Z);
                        }
                        else if (joint.JointType == JointType.WristLeft)
                        {
                            left_wrist_pos = new Position3D(joint.Position.X, joint.Position.Y, joint.Position.Z);
                        }
                    }
                }
            }

            Position3D right_stick;
            Position3D left_stick;

            if (right_hand_pos != null && right_wrist_pos != null)
            {
                right_stick = Stick.GetPositionOfEndOfStickRight(right_hand_pos, right_wrist_pos);
                tracksRight.Trail(right_stick);

                Drumset.DetectResult result = drumset.Detect(tracksRight);

                if (result != null)
                {
                    System.Console.WriteLine(result);
                }

                if (cnt1 > 3)
                {
                    PositionRatio r1 = new PositionRatio(right_hand_pos);
                    PositionRatio r2 = new PositionRatio(right_stick);
                    //System.Console.WriteLine(r1.ToJSON() + "\n" + r2.ToJSON());
                    sendMessage("stick", r1.ToJSON() + "&" + r2.ToJSON() + "&R");
                    cnt1 = 0;
                }
                cnt1++;
            }
            if (left_hand_pos != null && left_wrist_pos != null)
            {
                left_stick = Stick.GetPositionOfEndOfStickLeft(left_hand_pos, left_wrist_pos);
                tracksLeft.Trail(left_stick);
                Drumset.DetectResult result = drumset.Detect(tracksLeft);

                if (result != null)
                {
                    System.Console.WriteLine(result);
                }

                if (cnt2 > 3)
                {
                    PositionRatio l1 = new PositionRatio(left_hand_pos);
                    PositionRatio l2 = new PositionRatio(left_stick);
                    //System.Consol2 =riteLine(r1.ToJSON() + "\n" + r2.ToJSON());
                    sendMessage("stick", l1.ToJSON() + "&" + l2.ToJSON() + "&L");
                    cnt2 = 0;
                }
                cnt2++;

            }
        }