void Start()
 {
 	handmodel = GetComponent<HandModel>();
     _grabedObj = null;
     palmPostion = handmodel.GetPalmPosition();
     velocity = Vector3.zero;
 }
    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;
    }
Esempio n. 3
0
 protected void EmitHand(HandModel value = null)
 {
     EventHandler<LMWidgets.EventArg<HandData>> handler = HandEvent;
                 if (handler != null) {
                         handler (this, new LMWidgets.EventArg<HandData> (new HandData (value)));
                 }
 }
    public void Start()
    {
        if (!LeapHandController)
            throw new System.Exception("Leap Hand Controller has not been assigned!");

        _handModel = Utilities.GetHandModel(LeapHandController, HandModelType);
    }
Esempio n. 5
0
 HandModel CreateHand(HandModel model) {
   HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                          as HandModel;
   hand_model.gameObject.SetActive(true);
   IgnoreHandCollisions(hand_model);
   return hand_model;
 }
	bool IsReadyToCastBolts(HandModel leftHand, HandModel rightHand){
		
		//Debug.Log (HandRecog.PalmsFacingEachOther (handController, leftHand, rightHand, palmDirMinAngle));

		return HandRecog.PalmsFacingEachOther (handController, leftHand, rightHand, palmDirMinAngle) &&
			HandRecog.IsHandClenchingStrict (leftHand, handClenchingMinAngle) && HandRecog.IsHandClenchingStrict (rightHand, handClenchingMinAngle);
	}
Esempio n. 7
0
    // Use this for initialization
    void Start()
    {
        Current_Hand = new HandAttributes();

        cur_hand_model = transform.GetComponent<HandModel>();
        handInFrame = false;
        //   Debug.Log(cur_hand_model.name);
    }
	public static Vector3 DirectionBetweenPalm(HandModel fromHand, HandModel toHand){

		Vector3 fromHandPalmPos = fromHand.GetPalmPosition ();
		Vector3 toHandPalmPos = toHand.GetPalmPosition ();

		return Math3dExt.Direction (fromHandPalmPos, toHandPalmPos);

	}
	Vector3 GetFireBallSpawnPosition(HandModel hand, float distance){

		Vector3 palmPos = hand.GetPalmPosition ();

		Vector3 palmDir = hand.GetPalmNormal ();

		return palmPos + Vector3.Scale(palmDir,new Vector3(distance,distance,distance));
	}
	public static float DistanceBetweenPalms(HandModel handOne, HandModel handTwo){

		Vector3 handOnePalmPos = handOne.GetPalmPosition();
		Vector3 handTwoPalmPos = handTwo.GetPalmPosition ();

		return Math3dExt.Distance (handOnePalmPos, handTwoPalmPos);

	}
Esempio n. 11
0
  protected virtual void Awake() {
    _handModel = GetComponent<HandModel>();
    _renderer = GetComponentInChildren<Renderer>();

    _fadePropertyBlock = new MaterialPropertyBlock();
    _renderer.GetPropertyBlock(_fadePropertyBlock);
    _fadePropertyBlock.SetFloat("_Fade", 0);
    _renderer.SetPropertyBlock(_fadePropertyBlock);
  }
Esempio n. 12
0
        HandModel FirstRightHand(HandModel[] handsInScene)
        {
            foreach (HandModel hand in handsInScene) {
                                if (hand.GetLeapHand ().IsRight)
                                        return hand;
                        }

                        return null;
        }
Esempio n. 13
0
    public HandModel[] GetAllGraphicsHands()
    {
        if (hand_graphics_ == null)
          return new HandModel[0];

        HandModel[] models = new HandModel[hand_graphics_.Count];
        hand_graphics_.Values.CopyTo(models, 0);
        return models;
    }
Esempio n. 14
0
    private bool IsHandPresent()
    {
        if (!_handModel)
            _handModel = Utilities.GetHandModel(LeapHandController, HandModelType);

        if (_handModel == null)
            return false;

        return true;
    }
 private bool IsHand(Collider other)
 {
     if (other.transform.parent && other.transform.parent.parent && other.transform.parent.parent.GetComponent<HandModel> ()) {
         _HandModel = other.transform.parent.parent.GetComponent<HandModel> ();
         return true;
     } else {
         _HandModel = null;
         return false;
     }
 }
Esempio n. 16
0
        public virtual void InitData(HandModel hand)
        {
            List <AbstractTsf> tmpBones = new List <AbstractTsf>();

            for (int b = 0; b < hand.allTransforms.Length; b++)
            {
                tmpBones.Add(new AbstractTsf(hand.allTransforms[b], Space.World));
            }

            bones = tmpBones.ToArray();
        }
Esempio n. 17
0
 /// <summary>
 /// Meteodo eseguito all'avvio dello script.
 /// </summary>
 void Start()
 {
     hand_model = GetComponent <HandModel>();
     leap_hand  = hand_model.GetLeapHand();
     if (leap_hand == null)
     {
         Debug.LogError("No leap_hand founded");
     }
     // assegna l'azione UpdateBrushSize all'evento di movimento dello slider
     BrushSizeSlider.HorizontalSlideEvent = new Action <float>(UpdateBrushSize);
 }
    new protected HandModel CreateHand(HandModel model)
    {
        HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                               as HandModel;

        hand_model.gameObject.SetActive(true);

        ParticleSystem[] particleSystems = hand_model.GetComponentsInChildren <ParticleSystem>();
        foreach (ParticleSystem system in particleSystems)
        {
            system.Stop();
        }

        Utils.IgnoreCollisions(hand_model.gameObject, gameObject);

        // add scripts...
        foreach (FingerModel finger in hand_model.fingers)
        {
            if (finger.GetType() == typeof(RigidFinger))
            {
                RigidFinger rigidFinger = finger as RigidFinger;
                foreach (Transform bone in rigidFinger.bones)
                {
                    if (bone == null)
                    {
                        continue;
                    }
                    GameObject bGameObject = bone.gameObject;
                    Rigidbody  bRigidBody  = bGameObject.gameObject.GetComponent <Rigidbody>() as Rigidbody;
                    bRigidBody.isKinematic            = false;
                    bRigidBody.useGravity             = false;
                    bRigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                }

                rigidFinger.bones[rigidFinger.bones.Length - 1].gameObject.tag = "FingerTip";
            }
        }



        Collider[] allCls = hand_model.GetComponentsInChildren <Collider>();
        foreach (Collider lcl in allCls)
        {
            foreach (Collider refCl in allCls)
            {
                if (!lcl.Equals(refCl))
                {
                    //Physics.IgnoreCollision(lcl, refCl, true);
                }
            }
        }

        return(hand_model);
    }
	public static bool IsPalmFacingDownwards(HandModel hand, float theta){
		Vector3 dir = hand.GetPalmNormal ();

		float angle = Vector3.Angle (dir, -1* hand.transform.up);

		if (Math.Abs (angle) <= theta)
			return true;

		return false;

	}
Esempio n. 20
0
 /**
  * Destroys a HandModel instance if HandController.destroyHands is true (the default).
  * If you set destroyHands to false, you must destroy the hand instances elsewhere in your code.
  */
 protected void DestroyHand(HandModel hand_model)
 {
     if (destroyHands)
     {
         Destroy(hand_model.gameObject);
     }
     else
     {
         hand_model.SetLeapHand(null);
     }
 }
Esempio n. 21
0
    private void restrictRightHandMovement()
    {
        Hand justHand = ChangingHeights.Instance.getRightHand();
        //  SkeletalHand skeletalHand = (SkeletalHand) justHand;
        HandModel rightGraphicHand = ChangingHeights.Instance.getRightGraphicHand();

        if (rightGraphicHand == null)
        {
            return;
        }
    }
Esempio n. 22
0
    void FixedUpdate()
    {
        UpdatePalmRotation();
        UpdatePinchPosition();
        HandModel hand_model = GetComponent <HandModel>();

        Leap.Hand leap_hand = hand_model.GetLeapHand();

        if (leap_hand == null)
        {
            return;
        }

        PinchState new_pinch_state = GetNewPinchState();

        if (pinch_state_ == PinchState.kPinched)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (active_object_ != null)
            {
                ContinueHardPinch();
            }
        }
        else if (pinch_state_ == PinchState.kReleasing)
        {
            if (new_pinch_state == PinchState.kReleased)
            {
                OnRelease();
            }
            else if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else if (active_object_ != null)
            {
                ContinueSoftPinch();
            }
        }
        else
        {
            if (new_pinch_state == PinchState.kPinched)
            {
                StartPinch();
            }
            else
            {
                Hover();
            }
        }
        pinch_state_ = new_pinch_state;
    }
Esempio n. 23
0
 void OnTriggerEnter(Collider collider)
 {
     if (IsHand(collider))
     {
         //Debug.Log("Rein");
         m = collider.gameObject.GetComponentInParent<HandModel>();
         movementEnabled = true;
         sx = m.transform.position.x;
         sx = collider.transform.position.x;
     }
 }
Esempio n. 24
0
        void StartNewHand()
        {
            if (null != current)
            {
                SaveCurrentHand();
            }

            current       = new HandModel();
            current.Seats = new List <SeatModel>();
            current.Round = HandRound.Initialization;
        }
Esempio n. 25
0
 protected override void OnStart()
 {
     _Hand        = GetComponent <HandModel>();
     _ScaleVector = new Vector2((float)VRGUI.Width / Screen.width, (float)VRGUI.Height / Screen.height);
     if (!_Hand)
     {
         VRLog.Error("Hand not found! Disabling...");
         enabled = false;
         return;
     }
 }
Esempio n. 26
0
 // Use this for initialization
 void Start()
 {
     minPinchDistance = 0.01f;
     maxPinchDistance = 0.12f;
     pinchStart       = 0.8f;
     pinchToContinue  = 0.6f;
     pinching         = false;
     interfaceActive  = false;
     hand             = transform.GetChild(3).GetComponent <HandModel>();
     l = transform.GetChild(4).gameObject;
 }
Esempio n. 27
0
    IEnumerator Fire(HandModel currentHand)
    {
        canFire = false;
        //Debug.Log (canFire);

        GameObject justFired = Instantiate (ammo, currentHand.transform.position + currentHand.GetPalmNormal() * offset , currentHand.GetPalmRotation()) as GameObject;
        justFired.GetComponent<moveProjectile> ().target = target;
        //justFired.GetComponent<moveProjectile> ().force = Quaternion.LookRotation( handController.transform.forward, Vector3.down).eulerAngles;
        yield return new WaitForSeconds (delay);
            canFire = true;
    }
Esempio n. 28
0
    private bool GetHand()
    {
        var allHands = _controller.GetAllGraphicsHands();
        if (allHands.Length == 0)
        {
            return false;
        }

        _handModel = allHands[0];
        return true;
    }
Esempio n. 29
0
        public static int GetBonesCount(HandModel hand)
        {
            int n = 2; // wrist + forearm

            for (int i = 0; i < hand.fingers.Length; i++)
            {
                n += hand.fingers[i].bones.Length;
            }

            return(n);
        }
Esempio n. 30
0
    /** Returns a copy of the hand model list. */
    public HandModel[] GetAllGraphicsHands()
    {
        if (hand_graphics_ == null)
        {
            return(new HandModel[0]);
        }

        HandModel[] models = new HandModel[hand_graphics_.Count];
        hand_graphics_.Values.CopyTo(models, 0);
        return(models);
    }
Esempio n. 31
0
    protected void UpdatePinchPosition()
    {
        HandModel hand_model = GetComponent <HandModel>();

        current_pinch_position_ = 0.5f * (hand_model.fingers[0].GetTipPosition() +
                                          hand_model.fingers[1].GetTipPosition());

        Vector3 delta_pinch = current_pinch_position_ - filtered_pinch_position_;

        filtered_pinch_position_ += (1.0f - positionFiltering) * delta_pinch;
    }
Esempio n. 32
0
        private void ClearHandCardsByHand(HandModel handModel)
        {
            foreach (var handCard in db.HandCard.Where(h => h.HandId == handModel.hand_id))
            {
                db.HandCard.Remove(handCard);
            }


            db.SaveChanges();
            db.Hand.Remove(handModel);
            db.SaveChanges();
        }
Esempio n. 33
0
    protected HandModel CreateHand(HandModel model)
    {
        HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                               as HandModel;

        hand_model.gameObject.SetActive(true);
        Leap.Utils.IgnoreCollisions(hand_model.gameObject, gameObject);

        hand_model.gameObject.transform.parent = transform;

        return(hand_model);
    }
Esempio n. 34
0
  private void IgnoreHandCollisions(HandModel hand) {
    // Ignores hand collisions with immovable objects.
    Collider[] colliders = gameObject.GetComponentsInChildren<Collider>();
    Collider[] hand_colliders = hand.GetComponentsInChildren<Collider>();

    for (int i = 0; i < colliders.Length; ++i) {
      for (int h = 0; h < hand_colliders.Length; ++h) {
        if (colliders[i].rigidbody == null)
          Physics.IgnoreCollision(colliders[i], hand_colliders[h]);
      }
    }
  }
Esempio n. 35
0
    /**
     * Checks whether the hand is pinching and updates the position of the pinched object.
     */
    void Update()
    {
        bool      trigger_pinch = false;
        HandModel hand_model    = GetComponent <HandModel>();
        Hand      leap_hand     = hand_model.GetLeapHand();

        forceSpringConstant = (float)(Mathf.Abs(Physics.gravity.y) * 9.8) / 2;

        if (leap_hand == null)
        {
            return;
        }

        // Scale trigger distance by thumb proximal bone length.
        Vector leap_thumb_tip   = leap_hand.Fingers[0].TipPosition;
        float  proximal_length  = leap_hand.Fingers[0].Bone(Bone.BoneType.TYPE_PROXIMAL).Length;
        float  trigger_distance = proximal_length * TRIGGER_DISTANCE_RATIO;

        // Check thumb tip distance to joints on all other fingers.
        // If it's close enough, start pinching.
        for (int i = 1; i < HandModel.NUM_FINGERS && !trigger_pinch; ++i)
        {
            Finger finger = leap_hand.Fingers[i];

            for (int j = 0; j < FingerModel.NUM_BONES && !trigger_pinch; ++j)
            {
                Vector leap_joint_position = finger.Bone((Bone.BoneType)j).NextJoint;
                if (leap_joint_position.DistanceTo(leap_thumb_tip) < trigger_distance)
                {
                    trigger_pinch = true;
                }
            }
        }

        Vector3 pinch_position = hand_model.fingers[0].GetTipPosition();

        // Only change state if it's different.
        if (trigger_pinch && !pinching_)
        {
            OnPinch(pinch_position);
        }
        else if (!trigger_pinch && pinching_)
        {
            OnRelease();
        }

        // Accelerate what we are grabbing toward the pinch.
        if (grabbed_ != null)
        {
            Vector3 distance = pinch_position - grabbed_.transform.position;
            grabbed_.GetComponent <Rigidbody>().AddForce(forceSpringConstant * distance);
        }
    }
Esempio n. 36
0
    void OnTriggerEnter(Collider other)
    {
        handModel = GetHandModel(other);

        if (handModel != null)
        {
            foreach (MeshRenderer child in gameObject.GetComponentsInChildren <MeshRenderer>())
            {
                child.material.color = Color.cyan;
            }
        }
    }
    public Transform palm;      //palm for hand's speed calculation


    void Start()
    {
        container = GameObject.Find("Container").GetComponent <RectTransform>();

        isOpen     = false;             //Only for DropDown Test
        handModel  = GetComponent <HandModel> ();
        controller = new Controller();
        controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
        controller.Config.SetFloat("Gesture.Swipe.MinLength", 50f);             //Set Gesture: Minimum Length
        controller.Config.SetFloat("Gesture.Swipe.MinVelocity", 400f);          //Set Gestrue: Minimum Velocity
        controller.Config.Save();
    }
Esempio n. 38
0
        private void ActiveUpdate()
        {
            var curpos = HandModel.GetIndexVector();
            var rp     = new Polar3(curpos - _anchor);                  // rp  = relative position
            var rrp    = rp - _lastRp;                                  // rrp = relative relative position

            _lastRp = rp;

            var factor = -150f;

            _zoomEvent.Invoke((float)rrp.R * factor);
        }
Esempio n. 39
0
    HandData CreateHand(HandModel model)
    {
        HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                           as HandModel;
        hand_model.transform.localScale = transform.localScale;

        HandData hand_data = new HandData();
        hand_data.model = hand_model;
        hand_data.hand_id = -1;

        return hand_data;
    }
Esempio n. 40
0
 // Use this for initialization
 void Start()
 {
     hand_model = GetComponent <HandModel>();
     print(hand_model);
     provider  = GetComponent <LeapServiceProvider>();
     leap_hand = hand_model.GetLeapHand();
     print(leap_hand);
     if (leap_hand == null)
     {
         Debug.LogError("Error: No leap_hand found");
     }
 }
Esempio n. 41
0
    protected virtual void Awake()
    {
        //find the Animator somewhere in this gameobject's hierarchy
        Transform t = transform;

        while (t != null)
        {
            if (t.gameObject.GetComponent <Animator>())
            {
                animator = t.gameObject.GetComponent <Animator>();
                rootNode = t.gameObject;
                break;
            }
            t = t.parent;
        }
        if (animator == null)
        {
            Debug.LogError("IKOrionLeapHandController:: no animator found on GameObject or any of its parent transforms. Are you sure you added IKLeapHandController to a properly defined rigged avatar?");
        }

        if (leftHand == null && avatarLeftHand != null)
        {
            leftHand = avatarLeftHand.GetComponent <RiggedHand>();
        }
        if (rightHand == null && avatarRightHand != null)
        {
            rightHand = avatarRightHand.GetComponent <RiggedHand>();
        }

        if (leftHand == null)
        {
            Debug.LogError("IKOrionLeapHandController::Awake::No Rigged Hand set for left hand parameter. You have to set this in the inspector.");
        }
        if (rightHand == null)
        {
            Debug.LogError("IKOrionLeapHandController::Awake::No Rigged Hand set for right hand parameter. You have to set this in the inspector.");
        }

        if (leftPhysicsHand != null)
        {
            if (leftHand != null)
            {
                leftPhysicsHand.targetHand = leftHand;
            }
        }
        if (rightPhysicsHand != null)
        {
            if (rightHand != null)
            {
                rightPhysicsHand.targetHand = rightHand;
            }
        }
    }
Esempio n. 42
0
    private const float MIN_CONFIDENCE         = 0.2f;                                  //Minimum value of handmodel confidence
    #endregion

    // Update is called once per frame
    void Update()
    {
        //define LeapHands & Fingers
        handModel = GetComponent <HandModel> ();
        leapHand  = handModel.GetLeapHand();
        //get indexfinger
        indexFingerModel = handModel.fingers [1];
        //get indexfingerTip position
        indexTip = indexFingerModel.GetTipPosition();
        //get thumbTip position
        thumbTip = leapHand.Fingers [0].TipPosition.ToUnityScaled();

        //calculating velocity of finger
        currPosition = thumbTip;
        velocity     = (currPosition - prePosition).magnitude / Time.deltaTime;
        prePosition  = thumbTip;

        //Trigger test (true: thumbTip got close to rest of fingers)
        bool patternTrigger = false;

        for (int i = 1; i < 5 && !patternTrigger; ++i)
        {
            for (int j = 0; j < 4 && !patternTrigger; ++j)
            {
                Finger.FingerJoint joint      = (Finger.FingerJoint)(j);
                Vector3            difference = leapHand.Fingers[i].JointPosition(joint).ToUnityScaled() - thumbTip;
                if (difference.magnitude < THUMB_TRIGGER_DISTANCE &&
                    leapHand.Confidence > MIN_CONFIDENCE)
                {
                    //Trigger is ON
                    patternTrigger = true;
                }
            }
        }
        //Particle system On/Off
        switch (patternTrigger)
        {
        case (true):
            //Start recording finger position
            AddPositionCache(indexTip);
            transform.FindChild("particle").gameObject.SetActive(true);
            break;

        case (false):
            transform.FindChild("particle").gameObject.SetActive(false);
            break;
        }

        if (DetectFingerGesture())
        {
            //Detected!
        }
    }
Esempio n. 43
0
 /// <summary>
 /// Start viene eseguito una volta quando parte lo script (al primo frame).
 /// </summary>
 void Start()
 {
     // Prende il componente mano dal contenitore delle mani.
     hand_model = this.GetComponent <RigidHand>();
     // Prende la mano inserita.
     leap_hand = hand_model.GetLeapHand();
     // Se non è presente nessuna mano solleva un errore.
     if (leap_hand == null)
     {
         Debug.LogError("No leap_hand founded");
     }
 }
Esempio n. 44
0
 void Start()
 {
     Physics.gravity = new Vector3(0, -2.0f, 0);
     if (LeapHandController)
     {
         leftHandModel  = LeapHandController.transform.GetChild(2).GetComponent <HandModel>();
         rightHandModel = LeapHandController.transform.GetChild(3).GetComponent <HandModel>();
         leftHand       = LeapHandController.transform.GetChild(2).gameObject;
         rightHand      = LeapHandController.transform.GetChild(3).gameObject;
     }
     cubePicked = true;
 }
Esempio n. 45
0
        void AddHandPoints(HandModel handModel)
        {
            Vector3 v = handModel.fingers [1].GetTipPosition (); // will be world position

                        v -= MyCamera.transform.position;
                        v *= SCALE_RATIO;
                        v += MyCamera.transform.position;

                        SpinePoints.Add (Ceiling (v));
                        while (SpinePoints.Count > MAX_POINTS)
                                SpinePoints.RemoveAt (0);
        }
Esempio n. 46
0
 // Update is called once per frame
 void Update()
 {
     if (hand == null)
     {
         hand = transform.parent.GetComponent <HandModel>();
         followTarget.transform.position = hand.palm.position;
     }
     else
     {
         followTarget.transform.position = hand.palm.position;
     }
 }
Esempio n. 47
0
    /*
     * void Update()
     * {
     * HandModel handModel = this.GetComponent<HandModel>();
     * Hand leapHand = handModel.GetLeapHand();
     * GameObject info = GameObject.Find("FeedbackDisplay");
     * 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);
     * info.GetComponent<UnityEngine.UI.Text>().text = leapHand.GrabStrength.ToString() + "\n" + this.CurrentGraspState + "\n " + distance;
     * }
     */
    /*
     * void Update()
     * {
     *  HandModel handModel = this.GetComponent<HandModel>();
     *  Vector3 axis = handModel.GetPalmDirection();
     *
     *  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 + " :" + handModel.GetLeapHand().GrabStrength);
     *  }
     * }
     */
    void FixedUpdate()
    {
        this.UpdatePalmRotation();
        this.UpdateGraspPosition();
        HandModel handModel = this.GetComponent <HandModel>();
        Hand      leapHand  = handModel.GetLeapHand();

        if (leapHand == null)
        {
            return;
        }

        GraspState newGraspState = this.GetNewGraspState();

        if (this.CurrentGraspState == GraspState.GRASPED)
        {
            if (newGraspState == GraspState.RELEASED)
            {
                this.OnRelease();
            }
            else if (this.ActiveObject != null)
            {
                this.ContinueHardGrasp();
            }
        }
        else if (this.CurrentGraspState == GraspState.RELEASING)
        {
            if (newGraspState == GraspState.RELEASED)
            {
                this.OnRelease();
            }
            else if (newGraspState == GraspState.GRASPED)
            {
                this.StartGrasp();
            }
            else if (this.ActiveObject != null)
            {
                this.ContinueSoftGrasp();
            }
        }
        else
        {
            if (newGraspState == GraspState.GRASPED)
            {
                this.StartGrasp();
            }
            else
            {
                this.Hover();
            }
        }
        this.CurrentGraspState = newGraspState;
    }
Esempio n. 48
0
 void Update()
 {
     handModel = GetComponent <HandModel>();
     leapHand  = handModel.GetLeapHand();
     finger    = handModel.fingers[1];
     indexTip  = finger.GetTipPosition();
     AddPositionCache(indexTip);
     if (DetectCircleGesture() || DetectPolygonGesture())
     {
         // Detected!
     }
 }
Esempio n. 49
0
 // set the hand references
 public void SetHand(HandModel hand, Chirality handedness)
 {
     if (handedness == Chirality.Left)
     {
         lHand    = hand;
         lFingers = hand.fingers;
     }
     else if (handedness == Chirality.Right)
     {
         rHand    = hand;
         rFingers = hand.fingers;
     }
 }
Esempio n. 50
0
        // Replaceable by inherited classes
        public virtual void InitData(HandModel hand)
        {
            List <AbstractTsf> tmpBones = new List <AbstractTsf>();

            // InputDataProvider.bones will always be 24 items length
            for (int b = 0; b < 24; b++)
            {
                // Initialize .bones with empty AbstractTsfs
                tmpBones.Add(new AbstractTsf(b.ToString(), Space.World));
            }

            bones = tmpBones.ToArray();
        }
Esempio n. 51
0
 public void ClearHand(Chirality handedness)
 {
     if (handedness == Chirality.Left)
     {
         lHand    = null;
         lFingers = null;
     }
     else if (handedness == Chirality.Right)
     {
         rHand    = null;
         rFingers = null;
     }
 }
	public static bool IsHandClenchingStrict(HandModel hand, float minAngle){

		bool a = HandRecog.IsIndexFingerTipBent (hand, minAngle);
		bool b = HandRecog.IsMiddleFingerTipBent (hand, minAngle);
		//Debug.Log ("Middle Finger Bent: " + b );
		bool c = HandRecog.IsRingFingerTipBent (hand, minAngle);
		bool d = HandRecog.IsLittleFingerTipBent (hand, minAngle);

		bool t = HandRecog.IsThumbTipBent (hand, minAngle);

		return a && b && c && t && d;

	}
Esempio n. 53
0
	public static float AngleBetweenPalmsNormals(HandModel leftHand, HandModel rightHand, Vector3 projectPlane){

		Vector3 leftPalmNorm = leftHand.GetPalmNormal ();
		Vector3 rightPalmNorm = rightHand.GetPalmNormal ();

		Vector3 leftPalmNormProj = Math3d.ProjectVectorOnPlane (projectPlane,leftPalmNorm).normalized;
		Vector3 rightPalmNormProj = Math3d.ProjectVectorOnPlane (projectPlane,rightPalmNorm).normalized;

		float angle = Math3d.SignedVectorAngle (leftPalmNorm, rightPalmNorm,projectPlane);

		return angle;

	}
Esempio n. 54
0
 // Update is called once per frame
 void Update()
 {
     //Debug.Log("index --> " + _indexColliding);
     //Debug.Log("thumb --> " + _thumbColliding);
     if (isGrabbed)
     {
         HandModel handModel = followObject.GetComponent <HandModel>();
         Vector3   pos       = handModel.GetPalmPosition().ToVector().ToVector3();
         Debug.Log("is grabbed by " + handModel.name);
         Debug.Log("position -> " + pos.ToString());
         gameObject.transform.position = pos;
     }
 }
	void CastFireBall(HandModel hand){
		
		if (!IsCastingStarted && hand.GetLeapHand().Confidence >= confidenceLevel && !spellControl.SpellCasting()) {

			spellControl.SpellCasting ();

			IsCastingStarted = true;

			currentFireBall = GameObject.Instantiate (fireBallPrefab, GetFireBallSpawnPosition (hand, fireBallSpawnLocation), hand.gameObject.transform.rotation) as FireBall;

			//currentFireBall.transform.SetParent (handController.transform);
		}
			
	}
	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 ();
		}


	}
	void UpdateFireBall(HandModel hand){

		if (currentFireBall ) {

			currentFireBall.transform.position = GetFireBallSpawnPosition (hand, fireBallSpawnLocation);
			//currentFireBall.transform.rotation = transform.rotation;

			if (IsCastingStarted && HandRecog.IsPalmFacingUpwards(hand,palmFacingUpAngle)) {

				currentFireBall.Grow (Time.deltaTime);
			}
		}
			
	}
Esempio n. 58
0
 public bool HorizonCheck(HandModel hand)
 {
     Ray ray = new Ray(m_rayRoot.position, (hand.GetPalmPosition() - m_rayRoot.position).normalized);
     Debug.DrawRay(m_rayRoot.position, ray.direction * 10000.0f, new Color(1.0f, 0.0f,0.0f));
     RaycastHit hitInfo;
     LayerMask mask = LayerMask.GetMask("Earth");
     bool hit = Physics.Raycast(ray, out hitInfo, 10000.0f, mask);
     if ( hit ) {
       return true;
     }
     else {
       return false;
     }
 }
//	//Detect if index finger, middle finger, ring finger and little finger are straight (not bent).
//	public static bool FourFingersStraight(HandModel hand){
//
//		return !IsIndexFingerBent (hand, 3) && !IsMiddleFingerBent (hand, 3) && !IsRingFingerBent (hand, 3)
//			&& !IsLittleFingerBent (hand, 3);
//
//	}
//
	public static bool IsPalmFacingUpwards(HandModel hand, float theta ){

		Vector3 dir = hand.GetPalmNormal ();

		//Vector3 worldUp = hand.transform.TransformDirection(hand.transform.up);

		float angle = Vector3.Angle (dir, hand.transform.up);

		//Debug.Log (angle);

		if (Math.Abs (angle) <= theta)
			return true;

		return false;

	}
	void CastBolts(HandModel leftHand, HandModel rightHand ){


		if (!IsCastingStarted && !spellControl.SpellCasting()) {

			Vector3 middle = leftHand.GetPalmPosition () + rightHand.GetPalmPosition ();

			currentThunderBolt = GameObject.Instantiate (thunderBoltPrefab, middle, gameObject.transform.rotation) as ThunderBolt;
			currentThunderBolt.SetPosition (leftHand.GetPalmPosition (), rightHand.GetPalmPosition ());

			IsCastingStarted = true;
			spellControl.GrabCastingControl ();
		}

	

	}