bool DoesPoseMatch(Animator currAnimatedBody, BodyPoseData poseDataToMatch) { if (currAnimatedBody == null) { return(false); } var currOrientations = GenerateBoneOrientations(currAnimatedBody); var rotated = RotatePoseOrientationsTowardsAnimator(poseDataToMatch.BonesOrientations, currAnimatedBody); for (var i = 0; i < currOrientations.Length; i++) { if (poseDataToMatch.RelevantBoneData[i] && Vector3.Dot(currOrientations[i], rotated[i]) < m_BodyPoseDotProductMatchTolerance) { return(false); } } return(true); }
public void checkBodyTrackers() { // loop through each body tracker foreach (BodyPoseEvent bpe in bodyPoseEvents) { BodyPoseData bpd = bpe.bodyPoseData; BodyPartGroup[] bpgs = bpd.bodyPartGroups; // loop through each bodyPartGroup and retrieve all relevant ranges bool meetsCriteria = true; // check if the bodytrackers are within this rotation foreach (BodyPartGroup bpg in bpgs) { String bodyPartName = bpg.bodyPart.ToString();// get the enum type // search for the Bone from the BoneController Transform bodyPart; BoneFromBodyPart(bodyPartName, out bodyPart); //Debug.Log(bodyPart); Quaternion currentRotation = bodyPart.localRotation; Debug.Log("Angle at " + bodyPartName + " " + currentRotation.eulerAngles); if (bpg.isLocalRotationX) { if (currentRotation.eulerAngles.x < bpg.minLocalRotationX || currentRotation.eulerAngles.x > bpg.maxLocalRotationX) { meetsCriteria = false; break; } // convert degrees to quanterion values } if (bpg.isLocalRotationY) { // convert degrees to quanterion values if (currentRotation.eulerAngles.y < bpg.minLocalRotationY || currentRotation.eulerAngles.y > bpg.maxLocalRotationY) { meetsCriteria = false; break; } } if (bpg.isLocalRotationZ) { // convert degrees to quanterion values if (currentRotation.eulerAngles.z < bpg.minLocalRotationZ || currentRotation.eulerAngles.z > bpg.maxLocalRotationZ) { meetsCriteria = false; break; } } } // Debug.Log(bpe.bodyPoseData.name + " this meets criteria" + meetsCriteria); if (meetsCriteria & !bpe.isVisualEffectPlaying) { Debug.Log(bpe.bodyPoseData.name + " Meets criteria!"); bpe.isVisualEffectPlaying = true; bpe.visualEffect.Play(); // send the event to the appropriate character event attached to the bodyposeData } else if (!meetsCriteria & bpe.isVisualEffectPlaying) { Debug.Log(bpe.bodyPoseData.name + "will stop playing!"); bpe.isVisualEffectPlaying = false; bpe.visualEffect.Stop(); } else { Debug.Log(bpe.bodyPoseData.name + "VFX will not play"); } } }