Beispiel #1
0
        public static Quaternion LocalRotation(ref MoCapBodyFrame frame, MoCapKinectBone bone,
                                               bool withCalibration = true)
        {
            if (!IsValidKinectBone(bone))
            {
                throw new ArgumentException("Invalid Kinect bone!");
            }

            var node = GetBoneHierarchyNode(bone);

            if (node.Parent == null)
            {
                return(frame.SkeletonTransforms[(int)bone].Rotation);
            }

            var parentBone = node.Parent.Current;

            while (!IsValidMecanimBone(Kinect2Mecanim(parentBone)))
            {
                parentBone = GetBoneHierarchyNode(parentBone).Parent.Current;
            }

            return
                (Quaternion.Inverse(frame.SkeletonTransforms[(int)parentBone].Rotation *
                                    (withCalibration
                                       ? Calibration.Calibration[(int)parentBone].Unit
                                       : Quaternion.Identity)) *
                 (frame.SkeletonTransforms[(int)bone].Rotation *
                  (withCalibration ? Calibration.Calibration[(int)bone].Unit : Quaternion.Identity)));
        }
        public MoCapKinectBoneHierarchyNode this[MoCapKinectBone bone]
        {
            get
            {
                if (!MoCapBoneMapper.IsValidKinectBone(bone))
                {
                    throw new ArgumentException("Invalid Kinect bone!");
                }

                if (Current == bone)
                {
                    return(this);
                }

                foreach (var child in Children)
                {
                    var value = child[bone];
                    if (value != null)
                    {
                        return(value);
                    }
                }

                return(null);
            }
        }
Beispiel #3
0
 public static MoCapMecanimBone Kinect2Mecanim(MoCapKinectBone bone)
 {
     if (!IsValidKinectBone(bone))
     {
         return(MoCapMecanimBone.Unknown);
     }
     return(Kinect2MecanimMapping[(int)bone]);
 }
Beispiel #4
0
        public static MoCapKinectBoneHierarchyNode GetBoneHierarchyNode(MoCapKinectBone bone)
        {
            if (!IsValidKinectBone(bone))
            {
                throw new ArgumentException("Invalid Kinect bone!");
            }

            return(KinectBoneHierarchyRoot[bone]);
        }
        public MoCapKinectBoneHierarchyNode this[MoCapKinectBone bone]
        {
            get
            {
                if (!MoCapBoneMapper.IsValidKinectBone(bone))
                    throw new ArgumentException("Invalid Kinect bone!");

                if (Current == bone)
                    return this;

                foreach (var child in Children)
                {
                    var value = child[bone];
                    if (value != null)
                        return value;
                }

                return null;
            }
        }
Beispiel #6
0
 public static bool IsValidKinectBone(MoCapKinectBone bone)
 {
     return(bone != MoCapKinectBone.Unknown && bone != MoCapKinectBone.Count);
 }
Beispiel #7
0
        public static Quaternion LocalRotation(ref MoCapBodyFrame frame, MoCapKinectBone bone,
            bool withCalibration = true)
        {
            if (!IsValidKinectBone(bone))
                throw new ArgumentException("Invalid Kinect bone!");

            var node = GetBoneHierarchyNode(bone);

            if (node.Parent == null)
                return frame.SkeletonTransforms[(int) bone].Rotation;

            var parentBone = node.Parent.Current;

            while (!IsValidMecanimBone(Kinect2Mecanim(parentBone)))
                parentBone = GetBoneHierarchyNode(parentBone).Parent.Current;

            return
                Quaternion.Inverse(frame.SkeletonTransforms[(int) parentBone].Rotation*
                                   (withCalibration
                                       ? Calibration.Calibration[(int) parentBone].Unit
                                       : Quaternion.Identity))*
                (frame.SkeletonTransforms[(int) bone].Rotation*
                 (withCalibration ? Calibration.Calibration[(int) bone].Unit : Quaternion.Identity));
        }
Beispiel #8
0
 public static MoCapMecanimBone Kinect2Mecanim(MoCapKinectBone bone)
 {
     if (!IsValidKinectBone(bone))
         return MoCapMecanimBone.Unknown;
     return Kinect2MecanimMapping[(int) bone];
 }
Beispiel #9
0
 public static bool IsValidKinectBone(MoCapKinectBone bone)
 {
     return bone != MoCapKinectBone.Unknown && bone != MoCapKinectBone.Count;
 }
Beispiel #10
0
        public static MoCapKinectBoneHierarchyNode GetBoneHierarchyNode(MoCapKinectBone bone)
        {
            if (!IsValidKinectBone(bone))
                throw new ArgumentException("Invalid Kinect bone!");

            return KinectBoneHierarchyRoot[bone];
        }