protected override void UpdateTracker() { previousPosition = Position; previousOrientation = Orientation; previousGrabbingStrength = currentGrabbingStrength; //get the rightmost hand in the frame if (handController.GetAllGraphicsHands().Length != 0) { handModel = handController.GetAllGraphicsHands()[0]; handModel.transform.GetComponentInChildren<SkinnedMeshRenderer>().enabled = visibleHand; hand = handModel.GetLeapHand(); currentGrabbingStrength = lowPassFilter(hand.GrabStrength, previousGrabbingStrength); Position = lowPassFilter(handModel.GetPalmPosition(), previousPosition); Orientation = lowPassFilter(handModel.GetPalmDirection(), previousOrientation); } //mask/display the graphical hand on key down if (Input.GetKeyDown(visibleHandKey)) { var smr = handModel.transform.GetComponentInChildren<SkinnedMeshRenderer>(); visibleHand = !visibleHand; } Translation = Position - previousPosition; Rotation = previousOrientation - Orientation; }
private void DrawDebugLines() { HandModel hand = GetComponent <HandModel>(); Debug.DrawLine(hand.GetElbowPosition(), hand.GetWristPosition(), Color.red); Debug.DrawLine(hand.GetWristPosition(), hand.GetPalmPosition(), Color.white); Debug.DrawLine(hand.GetPalmPosition(), hand.GetPalmPosition() + hand.GetPalmNormal(), Color.black); Debug.Log(Vector3.Dot(hand.GetPalmDirection(), hand.GetPalmNormal())); }
void Update() { if (active && isRight) { line.SetPosition(0, hand_model.GetPalmPosition()); line.SetPosition(1, (hand_model.GetPalmDirection() * 20f));//+ 2 * hand_model.GetPalmPosition());// * finger.GetTipPosition()); rr.origin = hand_model.GetPalmPosition(); rr.direction = hand_model.GetPalmDirection(); int bitLayer = 1 << 15; if (Physics.Raycast(hand_model.GetPalmPosition(), hand_model.GetPalmDirection(), out hit, Mathf.Infinity, bitLayer)) { if (hit.collider.CompareTag("ViewTable")) { hit.collider.gameObject.GetComponent <Table>().AltActivation(); } } } }
void ReleaseFireBall(HandModel hand){ if (currentFireBall && IsCastingStarted && !HandRecog.IsHandClenchingNonStrict (hand, clenchingAngle) && hand.GetLeapHand().Confidence > confidenceLevel) { currentFireBall.Release (hand.GetPalmDirection (), 5.0f); IsCastingStarted = false; currentFireBall = null; spellControl.ReleaseCastingControl (); } }
public static bool IsFingerBentWithinAngle(HandModel hand, int fingerIndex, int boneIndex, float minAngle, float maxAngle){ FingerModel finger = hand.fingers [fingerIndex]; Vector3 fingerDir = finger.GetBoneDirection (boneIndex); Vector3 palmNormal = hand.GetPalmNormal (); Vector3 palmDir = hand.GetPalmDirection (); if (fingerIndex == 0) { float angle = Math3d.SignedVectorAngle (palmDir, fingerDir, palmNormal); //Debug.Log ("Finger: " + finger.fingerType + ", bone: " + boneIndex + ", angle to palm direction: " + angle); if (angle >= minAngle && angle <= maxAngle) return true; } else if (fingerIndex > 0) { Vector3 projPlane = Vector3.Cross(palmNormal, palmDir).normalized; Vector3 projVector = Math3d.ProjectVectorOnPlane(projPlane,fingerDir).normalized; float angle = Math3d.SignedVectorAngle(palmNormal,projVector,projPlane); //Debug.Log ("Finger: " + finger.fingerType + ", bone: " + boneIndex + ", angle to palm direction: " + angle); if (angle >= minAngle && angle <= maxAngle) return true; } return false; }
public static float AngleBetweenPalmsDirections(HandModel leftHand, HandModel rightHand, Vector3 projectPlane){ Vector3 leftPalmDir = leftHand.GetPalmDirection (); Vector3 rightPalmDir = rightHand.GetPalmDirection (); Vector3 leftPalmDirProj = Math3d.ProjectVectorOnPlane (projectPlane, leftPalmDir).normalized; Vector3 rightPalmDirProj = Math3d.ProjectVectorOnPlane (projectPlane, rightPalmDir).normalized; float angle = Math3d.SignedVectorAngle (leftPalmDirProj, rightPalmDirProj, projectPlane); return angle; }
public static float AngleBetweenFingerAndPalmDirection(HandModel hand, int fingerIndex, int boneIndex){ Vector3 palmVector = hand.GetPalmDirection (); Vector3 palmNormal = hand.GetPalmNormal (); Vector3 crossVect = Vector3.Cross (palmVector, palmNormal).normalized; //Debug.Log (crossVect.normalized); float angle = AngleBetweenFingerAndVector (hand, fingerIndex, boneIndex, palmVector, crossVect); return angle; // if (fingerIndex == 0) { // // if (hand.GetLeapHand ().IsRight) { // return angle; // } else { // return -angle; // } // // } else { // // return -angle; // } // }
public static float AngleBetweenFingerTipsVertical(HandModel hand, int fingerIndexOne, int fingerIndexTwo){ Vector3 palmVector = hand.GetPalmDirection (); Vector3 palmNormal = hand.GetPalmNormal (); Vector3 crossVect = Vector3.Cross (palmVector, palmNormal).normalized; return AngleBetweenFingerTips (hand, fingerIndexOne, fingerIndexTwo, crossVect); }
// Update is called once per frame void Update() { hand = transform.GetComponent <HandModel> (); //Somente deve funcionar na mão escolhida, direita ou esquerda if (maoCerta) { for (int i = 0; i < 2; i++) { dedos [i] = hand.fingers [i + 1].GetBoneCenter(3); distancias [i] = (dedos [i] - hand.GetPalmPosition()).magnitude; //distâncias dos dedos à palma da mão } //Verifica se a mão está fechada e próxima da base ou se o usuário quer ter que alcançar a seringa para pega-la if (pegando()) { if ((hand.GetPalmPosition() - baseSeringaPosition).magnitude < distBaseSeringa || !GetComponentInParent <escolherMao> ().alcançarSeringa) { pegou = true; } } //"Prende" a seringa à palma da mão, utilizando sua posição e rotação + ajustes if (pegou) { seringa.transform.position = hand.GetPalmPosition() + hand.GetPalmNormal() * distSeringa.x + Vector3.Cross(hand.GetPalmDirection(), hand.GetPalmNormal()).normalized *distSeringa.y + hand.GetPalmDirection() * distSeringa.z; seringa.transform.rotation = hand.GetPalmRotation() * rotSeringa; GetComponentInParent <escolherMao> ().Congelar(); } //Solta a seringa de volta a base else { seringa.transform.position = baseSeringaPosition; seringa.transform.rotation = baseSeringaRotation; } //Verifica se a mão está aberta e próxima da base da seringa ou se o usuário quer soltar a seringa a qualquer momento if (soltando()) { if ((hand.GetPalmPosition() - baseSeringaPosition).magnitude < distBaseSeringa || !GetComponentInParent <escolherMao> ().alcançarSeringa) { pegou = false; } } } }
public override void UpdateHand() { //skip the update if there's any unset parameters (i.e. we're not initialised properly yet) if (targetHand == null || hand_ == null || hand_.Direction == null) { return; } Vector3 offs = targetHand.GetPalmDirection() * offset; for (int f = 0; f < fingers.Length; ++f) { if (fingers[f] != null) { ((fingers[f]) as RigidIKFinger).offset_ = offs; fingers[f].UpdateFinger(); } } if (palm != null) { Rigidbody palmBody = palm.GetComponent <Rigidbody>(); if (palmBody) { palmBody.MovePosition(GetPalmCenter() + offs); palmBody.MoveRotation(GetPalmRotation()); } else { palm.position = GetPalmCenter() + offs; palm.rotation = GetPalmRotation(); } } if (forearm != null) { // Set arm dimensions. CapsuleCollider capsule = forearm.GetComponent <CapsuleCollider>(); if (capsule != null) { // Initialization capsule.direction = 2; forearm.localScale = new Vector3(1f, 1f, 1f); // Update capsule.radius = GetArmWidth() / 2f; capsule.height = GetArmLength() + GetArmWidth(); } Rigidbody forearmBody = forearm.GetComponent <Rigidbody>(); if (forearmBody) { forearmBody.MovePosition(GetArmCenter()); forearmBody.MoveRotation(GetArmRotation()); } else { forearm.position = GetArmCenter(); forearm.rotation = GetArmRotation(); } } }
protected GraspState GetNewGraspState() { HandModel handModel = this.GetComponent <HandModel>(); Hand leapHand = handModel.GetLeapHand(); /* * Vector leapThumbTip = leapHand.Fingers[0].TipPosition; * float closestDistance = Mathf.Infinity; * * // Check thumb tip distance to joints on all other fingers. * // If it's close enough, we are in a grasp position. * for (int i = 1; i < HandModel.NUM_FINGERS; i++) { * Finger finger = leapHand.Fingers[i]; * * for (int j = 0; j < FingerModel.NUM_BONES; j++) { * Vector leapJointPosition = finger.Bone((Bone.BoneType)j).NextJoint; * * float distanceToThumbTip = leapJointPosition.DistanceTo(leapThumbTip); * closestDistance = Mathf.Min(closestDistance, distanceToThumbTip); * } * * //float distanceToThumbTip = leapHand.Fingers[i].TipPosition.DistanceTo(leapThumbTip); * //closestDistance = Mathf.Min(closestDistance, distanceToThumbTip); * } */ // check destruction if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null) { // get finger centroid (except thumb) Vector3 centroid = leapHand.Fingers[1].TipPosition.ToUnityScaled() * .25f + leapHand.Fingers[2].TipPosition.ToUnityScaled() * .25f + leapHand.Fingers[3].TipPosition.ToUnityScaled() * .25f + leapHand.Fingers[4].TipPosition.ToUnityScaled() * .25f; float distance = Vector3.Distance(leapHand.PalmPosition.ToUnityScaled(), centroid); if (distance <= GraspController.MIN_FINGER_TO_PALM_DISTANCE) { /*ContainerController containerController = GameObject.FindGameObjectWithTag("Container").GetComponent<ContainerController>(); * containerController.initiateDestructionByGrabbing(this.ActiveObject.gameObject); */ return(GraspState.RELEASED); } } // power grasp conditions: // - grabstrength > .5 -> difficult for rotated hands otherwise if (leapHand.GrabStrength > .35f) { return(GraspState.GRASPED); } // Scale trigger distance by thumb proximal bone length. float proximalLength = leapHand.Fingers[0].Bone(Bone.BoneType.TYPE_PROXIMAL).Length; if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null) { //return GraspState.GRASPED; // check if fingers point away from palm Vector3 axis = handModel.GetPalmDirection(); int stretchedFingers = 0; for (int i = 1; i < 5; i++) { Vector3 fingerAxis = handModel.fingers[i].GetRay().direction; float angle = Vector3.Angle(axis, fingerAxis); //UnityEngine.Debug.Log(i + ": " + angle); if (angle > 0 && angle < 40) { stretchedFingers++; } } /*this.invalidCounter++; * if (this.invalidCounter >= GraspController.MAX_SUCCESSIVE_GRAB_FLUCTUATIONS) * { * return GraspState.RELEASED; * }*/ if (stretchedFingers >= 3) { return(GraspState.RELEASED); } else { return(GraspState.GRASPED); } } return(GraspState.RELEASED); }
protected GraspState GetNewGraspState() { HandModel handModel = this.GetComponent <HandModel>(); Hand leapHand = handModel.GetLeapHand(); // check destruction if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null) { // TODO: implement some kind of check for the overall grip aperture, if it falls // below a certain threshold, the object should be destroyed and the returned // state should be 'RELEASED'. Please stick to the initiateDestructionByGrabbing // method from the ContainerController. To search within the scene you can // use for instance the FindGameObjectWithTag method. Vector3 centroid = leapHand.Fingers[1].TipPosition.ToUnityScaled() * .25f + leapHand.Fingers[2].TipPosition.ToUnityScaled() * .25f + leapHand.Fingers[3].TipPosition.ToUnityScaled() * .25f + leapHand.Fingers[4].TipPosition.ToUnityScaled() * .25f; float distance = Vector3.Distance(leapHand.PalmPosition.ToUnityScaled(), centroid); if (distance <= GraspController.MIN_FINGER_TO_PALM_DISTANCE) { ContainerController containerController = GameObject.FindGameObjectWithTag("Container").GetComponent <ContainerController>(); containerController.initiateDestructionByGrabbing(this.ActiveObject.gameObject); return(GraspState.RELEASED); } } // power grasp conditions: // - grabstrength > .5 -> difficult for rotated hands otherwise if (leapHand.GrabStrength > .35f) { return(GraspState.GRASPED); } // Scale trigger distance by thumb proximal bone length. float proximalLength = leapHand.Fingers[0].Bone(Bone.BoneType.TYPE_PROXIMAL).Length; if (this.CurrentGraspState == GraspState.GRASPED && this.ActiveObject != null) { //return GraspState.GRASPED; // check if fingers point away from palm Vector3 axis = handModel.GetPalmDirection(); int stretchedFingers = 0; for (int i = 1; i < 5; i++) { Vector3 fingerAxis = handModel.fingers[i].GetRay().direction; float angle = Vector3.Angle(axis, fingerAxis); //UnityEngine.Debug.Log(i + ": " + angle); if (angle > 0 && angle < 40) { stretchedFingers++; } } if (stretchedFingers >= 3) { return(GraspState.RELEASED); } else { return(GraspState.GRASPED); } } return(GraspState.RELEASED); }
void ReleaseBolts(HandModel leftHand, HandModel rightHand){ if (currentThunderBolt ) { currentThunderBolt.Release ((leftHand.GetPalmDirection () + rightHand.GetPalmDirection ()).normalized, 5.0f); IsCastingStarted = false; spellControl.ReleaseCastingControl (); currentThunderBolt = null; } }