Пример #1
0
        /// <summary>
        /// Clones this object.
        /// </summary>
        /// <returns>The newly created clone.</returns>
        public NUIJoint Clone()
        {
            NUIJoint clone = new NUIJoint(this.jointType, this.position, this.rotation, this.inferred);

            clone.inferredQuality = this.inferredQuality;

            return(clone);
        }
Пример #2
0
        /// <summary>
        /// Create a new Animation with a constrained fps based on this animation.
        /// </summary>
        /// <param name="fps">The new frame rate</param>
        /// <returns>A new animation constrained by a given frame rate.</returns>
        public NUIHumanoidAnimation ConstrainFramerate(int fps)
        {
            NUIHumanoidAnimation animation = new NUIHumanoidAnimation();

            NUIAnimationKeyframe finalFrame = this.Keyframes[this.Keyframes.Count - 1];
            float finalTime      = finalFrame.ElapsedTime;
            float currentTime    = 0f;
            float timeIncrements = (1 / (float)fps);

            while (currentTime < finalTime)
            {
                // Find one or two keyframes that straddle the currentTime
                NUIAnimationKeyframe keyframe1 = null;
                NUIAnimationKeyframe keyframe2 = null;

                for (int i = 0; i < this.Keyframes.Count - 1; i++)
                {
                    keyframe1 = this.Keyframes[i];
                    keyframe2 = this.Keyframes[i + 1];

                    if (keyframe1.ElapsedTime <= currentTime && currentTime < keyframe2.ElapsedTime)
                    {
                        break;
                    }
                }

                // Determine the joint values at the current Time.
                if (currentTime == keyframe1.ElapsedTime)
                {
                    animation.AddKeyframe(keyframe1.Skeleton, (long)(currentTime * 1000));
                }
                else if (keyframe1.ElapsedTime <= currentTime && currentTime < keyframe2.ElapsedTime)
                {
                    NUISkeleton tweenedSkeleton = new NUISkeleton();

                    foreach (NUIJointType jointType in keyframe1.Skeleton.Joints.Keys)
                    {
                        float   t        = (currentTime - keyframe1.ElapsedTime) / (keyframe2.ElapsedTime - keyframe1.ElapsedTime);
                        Vector3 position = Vector3.Lerp(keyframe1.Skeleton.Joints[jointType].Position, keyframe2.Skeleton.Joints[jointType].Position, t);

                        Quaternion rotation = Quaternion.identity;
                        if (keyframe1.Skeleton.Joints[jointType].Rotation.w != 0 && keyframe2.Skeleton.Joints[jointType].Rotation.w != 0)
                        {
                            rotation = Quaternion.Lerp(keyframe1.Skeleton.Joints[jointType].Rotation, keyframe2.Skeleton.Joints[jointType].Rotation, t);
                        }
                        NUIJoint nuiJoint = new NUIJoint(jointType, position, rotation, false);
                        tweenedSkeleton.Joints.Add(jointType, nuiJoint);
                    }

                    animation.AddKeyframe(tweenedSkeleton, (long)(currentTime * 1000));
                }

                currentTime += timeIncrements;
            }

            return(animation);
        }
Пример #3
0
        /// <summary>
        /// Make a clone of this skeleton. Creating a deep copy of the Joints
        /// and shallow copy of the Structure.
        /// </summary>
        /// <returns>A new NUISkeleton.</returns>
        public NUISkeleton Clone()
        {
            NUISkeleton clone = new NUISkeleton();

            clone.Structure = this.Structure;

            foreach (var joint in this.Joints)
            {
                NUIJoint jointClone = joint.Value.Clone();
                clone.Joints.Add(jointClone.JointType, jointClone);
            }

            return(clone);
        }
Пример #4
0
        public static NUISkeleton GetNUISkeleton(ZigInputJoint[] Skeleton)
        {
            NUISkeleton nuiSkeleton = new NUISkeleton();

            foreach (ZigInputJoint inputJoint in Skeleton)
            {
                NUIJointType jointType = ZigToNUIJointMapping(inputJoint.Id);

                // Convert position from mm to meters
                Vector3 position = inputJoint.Position / 1000f;

                NUIJoint joint = new NUIJoint(jointType, position, inputJoint.Rotation, inputJoint.Inferred);
                if (!nuiSkeleton.Joints.ContainsKey(jointType))
                {
                    nuiSkeleton.Joints.Add(jointType, joint);
                }
            }

            return(nuiSkeleton);
        }
Пример #5
0
        public static NUISkeleton GetNUISkeleton(SkeletonFrameData skeleton)
        {
            var nuiSkeleton = new NUISkeleton();

            for (NUIJointType jt = NUIJointType.SpineBase; jt <= NUIJointType.ThumbRight; jt++)
            {
                Vector3    position      = new Vector3();
                Quaternion orientation   = new Quaternion();
                var        trackingState = CinemaSuite.CinemaMocap.System.Core.TrackingState.NotTracked;

                skeleton.GetJointData(jt, out position, out orientation, out trackingState);

                NUIJoint joint = new NUIJoint(jt, position, orientation, trackingState != CinemaSuite.CinemaMocap.System.Core.TrackingState.Tracked);
                if (!nuiSkeleton.Joints.ContainsKey(jt))
                {
                    nuiSkeleton.Joints.Add(jt, joint);
                }
            }

            return(nuiSkeleton);
        }
Пример #6
0
        public static NUISkeleton GetNUISkeleton(Body body)
        {
            var nuiSkeleton = new NUISkeleton();

            for (JointType jt = JointType.SpineBase; jt <= JointType.ThumbRight; jt++)
            {
                NUIJointType jointType = JointTypeToNUIJointTypeMapping(jt);

                Vector3 position = new Vector3(body.Joints[jt].Position.X, body.Joints[jt].Position.Y, body.Joints[jt].Position.Z);

                // Reverse the Z
                position.z *= -1;

                Quaternion orientation = new Quaternion(body.JointOrientations[jt].Orientation.X, body.JointOrientations[jt].Orientation.Y, body.JointOrientations[jt].Orientation.Z, body.JointOrientations[jt].Orientation.W);

                NUIJoint joint = new NUIJoint(jointType, position, orientation, body.Joints[jt].TrackingState != Windows.Kinect.TrackingState.Tracked);
                if (!nuiSkeleton.Joints.ContainsKey(jointType))
                {
                    nuiSkeleton.Joints.Add(jointType, joint);
                }
            }

            return(nuiSkeleton);
        }