Beispiel #1
0
 public jPairs(Skeleton skel)
 {
     LRHand = new jPair(skel, JointType.HandLeft, JointType.HandRight, "LRHand");
     LHandHead = new jPair(skel, JointType.HandLeft, JointType.Head, "LHandHead");
     RHandHead = new jPair(skel, JointType.HandRight, JointType.Head, "RHandHead");
     LRFoot = new jPair(skel, JointType.FootLeft, JointType.FootRight, "LRFoot");
     LHandLFoot = new jPair(skel, JointType.HandLeft, JointType.FootLeft, "LHandLFoot");
     RHandRFoot = new jPair(skel, JointType.HandRight, JointType.FootRight, "RHandRFoot");
     LHandRFoot = new jPair(skel, JointType.HandLeft, JointType.FootRight, "LHandRFoot");
     RHandLFoot = new jPair(skel, JointType.HandRight, JointType.FootLeft, "RHandLFoot");
     HeadSpine = new jPair(skel, JointType.Head, JointType.Spine, "HeadSpine");
     LRShoulder = new jPair(skel, JointType.ShoulderLeft, JointType.ShoulderRight, "LRShoulder");
 }
        public distanceMessages(jPair myJPair)
        {
            register = myJPair.distReg;
            //messageSender = mSend;
            StringBuilder addressRoot = new StringBuilder();
            addressRoot.Append("/");
            addressRoot.Append(myJPair.jointType0.ToString());
            addressRoot.Append("_");
            addressRoot.Append(myJPair.jointType1.ToString());
            addressRoot.Append("/");
            String root = addressRoot.ToString();

            StringBuilder xAddress = new StringBuilder(root);
            StringBuilder yAddress = new StringBuilder(root);
            StringBuilder zAddress = new StringBuilder(root);
            StringBuilder xyAddress = new StringBuilder(root);
            StringBuilder xzAddress = new StringBuilder(root);
            StringBuilder yzAddress = new StringBuilder(root);
            StringBuilder xyzAddress = new StringBuilder(root);
            StringBuilder angle = new StringBuilder(root);

            xAddress.Append("x");
            yAddress.Append("y");
            zAddress.Append("z");
            xyAddress.Append("xy");
            xzAddress.Append("xz");
            yzAddress.Append("yz");
            xyzAddress.Append("xyz");
            angle.Append("theta");

            xdistOSC = new OscMessage(xAddress.ToString(), (float)myJPair.pair.xdist);
            ydistOSC = new OscMessage(yAddress.ToString(), (float)myJPair.pair.ydist);
            zdistOSC = new OscMessage(zAddress.ToString(), (float)myJPair.pair.zdist);
            xydistOSC = new OscMessage(xyAddress.ToString(), (float)myJPair.pair.xydist);
            xzdistOSC = new OscMessage(xzAddress.ToString(), (float)myJPair.pair.xzdist);
            yzdistOSC = new OscMessage(yzAddress.ToString(), (float)myJPair.pair.yzdist);
            xyzdistOSC = new OscMessage(xyzAddress.ToString(), (float)myJPair.pair.xyzdist);
            angleOSC = new OscMessage(angle.ToString(), (float)myJPair.pair.theta);
        }
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        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);
                }
            }
            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(backgroundBrush, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.DrawBonesAndJoints(skel, dc);

                            //

                            if (jOn[0])
                            {
                                indivJoint joint1 = new indivJoint(skel, j_values[0], "joint1");
                                positionMessages j1_messages = new positionMessages(joint1);
                                joint1.posReg.copy(jReg[0]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[0, i])
                                    {
                                        j1_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[1])
                            {
                                indivJoint joint2 = new indivJoint(skel, j_values[1], "joint2");
                                positionMessages j2_messages = new positionMessages(joint2);
                                joint2.posReg.copy(jReg[1]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[1, i])
                                    {
                                        j2_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[2])
                            {
                                indivJoint joint3 = new indivJoint(skel, j_values[2], "joint3");
                                positionMessages j3_messages = new positionMessages(joint3);
                                joint3.posReg.copy(jReg[2]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[2, i])
                                    {
                                        j3_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[3])
                            {
                                indivJoint joint4 = new indivJoint(skel, j_values[3], "joint4");
                                positionMessages j4_messages = new positionMessages(joint4);
                                joint4.posReg.copy(jReg[3]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[3, i])
                                    {
                                        j4_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[4])
                            {
                                indivJoint joint5 = new indivJoint(skel, j_values[4], "joint5");
                                positionMessages j5_messages = new positionMessages(joint5);
                                joint5.posReg.copy(jReg[4]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[4, i])
                                    {
                                        j5_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[5])
                            {
                                indivJoint joint6 = new indivJoint(skel, j_values[5], "joint6");
                                positionMessages j6_messages = new positionMessages(joint6);
                                joint6.posReg.copy(jReg[5]);
                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[5, i])
                                    {
                                        j6_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[6])
                            {
                                indivJoint joint7 = new indivJoint(skel, j_values[6], "joint7");
                                positionMessages j7_messages = new positionMessages(joint7);
                                joint7.posReg.copy(jReg[6]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[6, i])
                                    {
                                        j7_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[7])
                            {
                                indivJoint joint8 = new indivJoint(skel, j_values[7], "joint8");
                                positionMessages j8_messages = new positionMessages(joint8);
                                joint8.posReg.copy(jReg[7]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[7, i])
                                    {
                                        j8_messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (jOn[8])
                            {
                                indivJoint joint9 = new indivJoint(skel, j_values[8], "joint9");
                                positionMessages j9_messages = new positionMessages(joint9);
                                joint9.posReg.copy(jReg[8]);
                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[8, i])
                                    {
                                        j9_messages.sendMessages(UDPs[i]);
                                    }
                                }

                            }

                            if (jOn[9])
                            {
                                indivJoint joint10 = new indivJoint(skel, j_values[9], "joint10");
                                positionMessages j10_messages = new positionMessages(joint10);
                                joint10.posReg.copy(jReg[9]);
                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (j_IP[9, i])
                                    {
                                        j10_messages.sendMessages(UDPs[i]);
                                    }
                                }

                            }

                            //defines joint pairs
                            if (pOn[0])
                            {
                                jPair pair1 = new jPair(skel, p_values[0,0], p_values[0,1], "pair1");
                                distanceMessages p1_Messages = new distanceMessages(pair1);
                                pair1.distReg.copy(pReg[0]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (p_IP[0, i])
                                    {
                                        p1_Messages.sendMessages(UDPs[i]);
                                    }
                                }

                            }

                            if (pOn[1])
                            {
                                jPair pair2 = new jPair(skel, p_values[1, 0], p_values[1, 1], "pair2");
                                distanceMessages p2_Messages = new distanceMessages(pair2);
                                pair2.distReg.copy(pReg[1]);

                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (p_IP[1, i])
                                    {
                                        p2_Messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                            if (pOn[2])
                            {
                                jPair pair3 = new jPair(skel, p_values[2, 0], p_values[2, 1], "pair3");
                                distanceMessages p3_Messages = new distanceMessages(pair3);
                                pair3.distReg.copy(pReg[2]);
                                for (int i = 0; i < numSenders; i++)
                                {
                                    if (p_IP[2, i])
                                    {
                                        p3_Messages.sendMessages(UDPs[i]);
                                    }
                                }
                            }

                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                            this.centerPointBrush,
                            null,
                            this.SkeletonPointToScreen(skel.Position),
                            BodyCenterThickness,
                            BodyCenterThickness);
                        }
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight));
            }
        }