コード例 #1
0
            /// <summary>
            /// SkeletonFrameReady gets fired every skeleton frame update, and refreshes the LocatedSensor's
            ///  global and relative skeleton maps
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void refreshSkeletonPositions(object sender, SkeletonFrameReadyEventArgs e)
            {
                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) {
                    if (skeletonFrame != null) {
                        // First, get the relative skeletons - easy peasy
                        Skeleton[] skeletonsR = new Skeleton[skeletonFrame.SkeletonArrayLength];
                        skeletonFrame.CopySkeletonDataTo(skeletonsR);
                        this.relativeSkeletons = skeletonsR.ToList<Skeleton>();

                        // Now global skeletons...
                        // First, clear our global skeletons list.
                        //  We'll be building this back up from scratch here
                        this.globalSkeletons.Clear();
                        // Next, iterate through all the skeletons, applying a rotation and translation
                        //  to get us into global coordinates
                        foreach (Skeleton skel in this.relativeSkeletons) {
                            // Add a temporary skeleton object to store transformed
                            //  data into
                            Skeleton tempSkel = skel;

                            foreach (Joint j in skel.Joints){
                                // Make a new joint, then put it into our temporary joint
                                //  collection
                                JointType type = j.JointType;
                                Joint tempJoint = tempSkel.Joints[type];
                                // Copy the current joint state
                                JointTrackingState tracking = j.TrackingState;
                                tempJoint.TrackingState = tracking;

                                // However, we transform the position of the joint at least
                                SkeletonPoint shiftedPoint = new SkeletonPoint();
                                // Rotate the points
                                DenseMatrix point = new DenseMatrix(1, 3);
                                point[0, 0] = j.Position.X;
                                point[0, 1] = j.Position.Y;
                                point[0, 2] = j.Position.Z;
                                var rotatedPoint = point.Multiply(this.rotationMatrix);

                                // Then shift them by the global coordinates.
                                shiftedPoint.X = (float)rotatedPoint[0, 0] + this.xOffset;
                                shiftedPoint.Y = (float)rotatedPoint[0, 1] + this.yOffset;
                                shiftedPoint.Z = (float)rotatedPoint[0, 2] + this.zOffset;
                                tempJoint.Position = shiftedPoint;

                                tempSkel.Joints[type] = tempJoint;
                            }
                            // Next, alter the higher-level parameters of our skeleton
                            SkeletonPoint shiftedPosition = new SkeletonPoint();
                            // Rotate
                            DenseMatrix p = new DenseMatrix(1, 3);
                            p[0, 0] = tempSkel.Position.X;
                            p[0, 1] = tempSkel.Position.Y;
                            p[0, 2] = tempSkel.Position.Z;
                            var rPoint = p.Multiply(this.rotationMatrix);

                            // Then shift them by the global coordinates.
                            shiftedPosition.X = (float)rPoint[0, 0] + this.xOffset;
                            shiftedPosition.Y = (float)rPoint[0, 1] + this.yOffset;
                            shiftedPosition.Z = (float)rPoint[0, 2] + this.zOffset;

                            tempSkel.Position = shiftedPosition;

                            // Now add that skeleton to our global skeleton list
                            this.globalSkeletons.Add(tempSkel);
                        }

                    }
                }
            }