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 static MoCapBodyFrame Average(params MoCapBodyFrame[] values) { if (values == null || values.Length == 0) { throw new Exception("Empty values list!"); } var transforms = new TransformTime[(int)MoCapKinectBone.Count][]; for (var i = 0; i < (int)MoCapKinectBone.Count; i++) { transforms[i] = new TransformTime[values.Length]; for (var j = 0; j < values.Length; j++) { transforms[i][j] = values[j].SkeletonTransforms[i]; } } var ret = new MoCapBodyFrame { SkeletonTransforms = new TransformTime[(int)MoCapKinectBone.Count] }; for (var i = 0; i < (int)MoCapKinectBone.Count; i++) { ret.SkeletonTransforms[i] = TransformTime.Average(transforms[i]); } return(ret); }
public static void Average(ref MoCapData data, int smoothingFactor) { if (data.BodyFrames == null || data.BodyFrames.Length == 0 || data.FaceFrames == null || data.FaceFrames.Length == 0) throw new Exception("Invalid data!"); if (smoothingFactor <= 0 || smoothingFactor > data.BodyFrames.Length || smoothingFactor > data.FaceFrames.Length) throw new Exception("Invalid smoothing factor value!"); var bodyFrames = new MoCapBodyFrame[data.BodyFrames.Length/smoothingFactor]; var tempBodyFrames = new MoCapBodyFrame[smoothingFactor]; for (var i = 0; i < data.BodyFrames.Length/smoothingFactor; i++) { for (var j = 0; j < smoothingFactor; j++) tempBodyFrames[j] = data.BodyFrames[i*smoothingFactor + j]; bodyFrames[i] = MoCapBodyFrame.Average(tempBodyFrames); } var faceFrames = new MoCapFaceFrame[data.FaceFrames.Length/smoothingFactor]; var tempFaceFrames = new MoCapFaceFrame[smoothingFactor]; for (var i = 0; i < data.FaceFrames.Length/smoothingFactor; i++) { for (var j = 0; j < smoothingFactor; j++) tempFaceFrames[j] = data.FaceFrames[i*smoothingFactor + j]; faceFrames[i] = MoCapFaceFrame.Average(tempFaceFrames); } data.BodyFrames = bodyFrames; data.FaceFrames = faceFrames; }
public static void Average(ref MoCapData data, int smoothingFactor) { if (data.BodyFrames == null || data.BodyFrames.Length == 0 || data.FaceFrames == null || data.FaceFrames.Length == 0) { throw new Exception("Invalid data!"); } if (smoothingFactor <= 0 || smoothingFactor > data.BodyFrames.Length || smoothingFactor > data.FaceFrames.Length) { throw new Exception("Invalid smoothing factor value!"); } var bodyFrames = new MoCapBodyFrame[data.BodyFrames.Length / smoothingFactor]; var tempBodyFrames = new MoCapBodyFrame[smoothingFactor]; for (var i = 0; i < data.BodyFrames.Length / smoothingFactor; i++) { for (var j = 0; j < smoothingFactor; j++) { tempBodyFrames[j] = data.BodyFrames[i * smoothingFactor + j]; } bodyFrames[i] = MoCapBodyFrame.Average(tempBodyFrames); } var faceFrames = new MoCapFaceFrame[data.FaceFrames.Length / smoothingFactor]; var tempFaceFrames = new MoCapFaceFrame[smoothingFactor]; for (var i = 0; i < data.FaceFrames.Length / smoothingFactor; i++) { for (var j = 0; j < smoothingFactor; j++) { tempFaceFrames[j] = data.FaceFrames[i * smoothingFactor + j]; } faceFrames[i] = MoCapFaceFrame.Average(tempFaceFrames); } data.BodyFrames = bodyFrames; data.FaceFrames = faceFrames; }
public static MoCapBodyFrame Average(params MoCapBodyFrame[] values) { if (values == null || values.Length == 0) throw new Exception("Empty values list!"); var transforms = new TransformTime[(int) MoCapKinectBone.Count][]; for (var i = 0; i < (int) MoCapKinectBone.Count; i++) { transforms[i] = new TransformTime[values.Length]; for (var j = 0; j < values.Length; j++) transforms[i][j] = values[j].SkeletonTransforms[i]; } var ret = new MoCapBodyFrame { SkeletonTransforms = new TransformTime[(int) MoCapKinectBone.Count] }; for (var i = 0; i < (int) MoCapKinectBone.Count; i++) ret.SkeletonTransforms[i] = TransformTime.Average(transforms[i]); return ret; }
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)); }