private void FixedUpdate()
 {
     currentFrame = leapMotionController.Frame();
     gestures = currentFrame.Gestures();
     hands = currentFrame.Hands;
     fingers = currentFrame.Fingers;
     tools = currentFrame.Tools;
 }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        hands = frame.Hands;

        righthand = hands.Rightmost;
        if (righthand != null) {
            Debug.Log (righthand.GrabStrength);
        }
    }
예제 #3
0
 public bool UpdateData(HandList hands)
 {
     try
     {
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
예제 #4
0
파일: LeapMath.cs 프로젝트: intuilab/LeapIA
 /// <summary>
 /// Test if at least one hand is above the Leap. Permits to reduce the Leap's field of detection and to avoid untimely detection of hands.
 /// This function is implemented because the Leap detects hand when there is nothing, for exemple it considers my head as a hand when I'm just sitting on my chair.
 /// </summary>
 /// <param name="hands">The list of hands to test</param>
 /// <returns>If at least one hand is above the Leap</returns>
 public static bool IsAboveTheLeap(HandList hands)
 {
     foreach (Hand hand in hands)
     {
         if (hand.PalmPosition.x > -ParametersOther.Instance.LeapMath_xBoundaryForHandDetection
             && hand.PalmPosition.x < ParametersOther.Instance.LeapMath_xBoundaryForHandDetection
             && hand.PalmPosition.z > -ParametersOther.Instance.LeapMath_zBoundaryForHandDetection
             && hand.PalmPosition.z < ParametersOther.Instance.LeapMath_zBoundaryForHandDetection)
         {
             return true;
         }
     }
     return false;
 }
 void Update()
 {
     frame = controller.Frame();
     hands = frame.Hands;
     if (hands.Count > 0) {
         timeLeft = 10.0f;
         isHandsInScene = true;
     }
     else {
         timeLeft -= Time.deltaTime;
         if (timeLeft < 0)
             isHandsInScene = false;
     }
 }
예제 #6
0
    void Update()
    {
        if (controller.Frame () != null)
        {
            frame = controller.Frame();
            hands = frame.Hands;
            rightmost = hands.Rightmost;
            handX = rightmost.PalmPosition.x;
            handY = rightmost.PalmPosition.y;
            handZ = rightmost.PalmPosition.z;
        }

        if (controller == null)
            controller = new Controller();
    }
    void Update()
    {
        frame = controller.Frame();
        hands = frame.Hands;

        if (hands.Count != 0) {
            timeLeft = 10;
            changeIntensity(maxIntensity);
        }
        else {
            timeLeft -= Time.deltaTime;
            if (timeLeft < 0)
                changeIntensity(minIntensity);
        }
    }
	// Update is called once per frame
	void Update () 
	{
		if (leapController.IsConnected){
			leapFrame = leapController.Frame();
			leapHands = leapFrame.Hands;
			if (!leapHands.IsEmpty){
				trackingHand = leapHands.Frontmost;
			}
			//print ("Tracking Hand X: " + trackingHand.PalmPosition.x);
			//print ("Tracking Hand Y: " + trackingHand.PalmPosition.y);
		}

		PitchChange();
		ColorChange ();

	}
예제 #9
0
	void Update ()
	{
		//transform gives you main camera
		//initialize hand positions
		Frame frame = controller.Frame();
		handList = frame.Hands;
		leftHand = handList.Leftmost;
		rightHand = handList.Rightmost;

		if (!rightFistForward() && !leftFistForward ()) {
			panEnabled = true;
				}
		if (rightHandForward() && leftHandForward () && handList.Count==2 && panEnabled) {//both hands facing forward
			toggleGestures(false);
			transform.position += (rightHandPrev.x - rightHand.PalmPosition.x) * transform.right * Mathf.Abs(rightHand.PalmVelocity.x) * Time.deltaTime * 1/5;
			transform.position += (rightHandPrev.y - rightHand.PalmPosition.y) * transform.up * Mathf.Abs(rightHand.PalmVelocity.y) * Time.deltaTime * 1/5;
		}
		if (rightFistForward () && leftHandForward () && handList.Count==2) {
			toggleGestures(false);
			print ("rotateleft");
		}
		if (rightHandForward () && leftFistForward () && handList.Count==2) {
			toggleGestures(false);
			print ("rotateleft");
		}


		foreach (Gesture g in frame.Gestures()){
			//print (g.Type.ToString());
			if(g.Type == Gesture.GestureType.TYPECIRCLE && g.State==Gesture.GestureState.STATE_STOP){
				print ("circlestop");
				GameObject newSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
				newSphere.transform.position = new Vector3(Random.Range(4,7),Random.Range(4,5),Random.Range(0,1));
				newSphere.AddComponent<Rigidbody>();
				newSphere.transform.parent = createdObjects.transform;
			}
			if(g.Type == Gesture.GestureType.TYPESWIPE && g.State==Gesture.GestureState.STATE_STOP){
				//g = (SwipeGesture)g;
			}

		}
		leftHandPrev = leftHand.PalmPosition;
		rightHandPrev = rightHand.PalmPosition;
		leftDirPrev = leftHand.Direction;
		rightDirPrev = rightHand.Direction;
	}//eo update
예제 #10
0
 private void RecordData(Frame frame, HandList hands, FingerList fingers)
 {
     if (CsvRecordingActivated)
     {
         lock (this)
         {
             foreach (Hand hand in hands)
             {
                 m_CSVWriter.RecordHand(frame.Id, hand.Id, hand.Fingers.Count, hand.PalmPosition, hand.PalmNormal, hand.PalmVelocity, hand.SphereCenter, hand.SphereRadius, frame.Timestamp);
             }
             foreach (Finger finger in fingers)
             {
                 m_CSVWriter.RecordFinger(frame.Id, finger.Id, finger.Hand.Id, fingers.Frontmost.Id == finger.Id, finger.Direction, finger.TipPosition, finger.TipVelocity, finger.Length, finger.Width, frame.Timestamp);
             }
         }
     }
 }
예제 #11
0
    public void MoveDetection()
    {
        Frame currentFrame = cntrlr.Frame();
        ListeMain = currentFrame.Hands;

        DebutPosition = false;
        foreach (Hand hand in ListeMain)
        {
            Saut = false;
            Tir = false;
            Stop = false;
            stop.TestGesture(hand);
            tir.TestGesture(hand);
            rightMove.TestGesture(hand);
            leftMove.TestGesture(hand);
            saut.TestGesture(hand);
        }
    }
예제 #12
0
  private void UpdateModels(Dictionary<int, HandModel> all_hands, HandList leap_hands,
                            HandModel left_model, HandModel right_model) {
    List<int> ids_to_check = new List<int>(all_hands.Keys);

    // Go through all the active hands and update them.
    int num_hands = leap_hands.Count;
    for (int h = 0; h < num_hands; ++h) {
      Hand leap_hand = leap_hands[h];
      
      // Only create or update if the hand is enabled.
      if ((leap_hand.IsLeft && left_model != null) ||
          (leap_hand.IsRight && right_model != null)) {

        ids_to_check.Remove(leap_hand.Id);

        // Create the hand and initialized it if it doesn't exist yet.
        if (!all_hands.ContainsKey(leap_hand.Id)) {
          HandModel model = leap_hand.IsLeft? left_model : right_model;
          HandModel new_hand = CreateHand(model);
          new_hand.SetLeapHand(leap_hand);
          new_hand.SetController(this);
          new_hand.InitHand();
          all_hands[leap_hand.Id] = new_hand;
        }

        // Make sure we update the Leap Hand reference.
        HandModel hand_model = all_hands[leap_hand.Id];
        hand_model.SetLeapHand(leap_hand);

        // Set scaling based on reference hand.
        float hand_scale = leap_hand.PalmWidth / MODEL_PALM_WIDTH;
        hand_model.transform.localScale = hand_scale * transform.localScale;

        hand_model.UpdateHand();
      }
    }

    // Destroy all hands with defunct IDs.
    for (int i = 0; i < ids_to_check.Count; ++i) {
      Destroy(all_hands[ids_to_check[i]].gameObject);
      all_hands.Remove(ids_to_check[i]);
    }
  }
예제 #13
0
    void GetHands()
    {
        frame = controller.Frame();
        hands = frame.Hands;

        if (!hands.IsEmpty)
        {
            PalmPosition1 = hands[0].PalmPosition.ToUnityScaled();

            if (hands[1] != null)
                PalmPosition2 = hands[1].PalmPosition.ToUnityScaled();

            var handDirection = hands[0].Direction.ToUnity();

            if (hands[0].IsLeft)
            {

                float strength = hands[0].GrabStrength;

            }
            else if (hands[0].IsRight)
            {

                float strength = hands[0].GrabStrength;

            }

            if (hands[1].IsLeft)
            {

            }
            else if (hands[1].IsRight)
            {

            }
        }
        else
        {

        }
    }
예제 #14
0
    void UpdateModels(List<HandData> all_hand_data, HandModel model, HandList leap_hands)
    {
        // Show and update active hands.
        int num_hands = leap_hands.Count;
        int h = 0;
        for (; h < num_hands; ++h) {
          Hand leap_hand = leap_hands[h];

          // Create the hand if it doesn't exist.
          if (h >= all_hand_data.Count)
        all_hand_data.Add(CreateHand(model));

          HandData hand_data = all_hand_data[h];
          hand_data.model.SetLeapHand(leap_hand);

          // TODO: Mirror the right hand from the left.
          /*
          if (leap_hand.IsLeft)
        hand_data.model.transform.localScale = transform.localScale;
          else {
        // Negating scale and rotating 180 will mirror the object.
        hand_data.model.transform.rotation = Quaternion.AngleAxis(180, Vector3.left) * hand_data.model.transform.rotation;
        hand_data.model.transform.localScale = -transform.localScale;
          }
          */

          // Decide to Init or Update.
          int id = leap_hand.Id;
          if (num_active_hands_ <= h || id != hand_data.hand_id) {
        hand_data.model.InitHand(transform);
        hand_data.hand_id = id;
          }
          else
        hand_data.model.UpdateHand(transform);
        }

        // Hide inactive hands.
        for (; h < num_active_hands_; ++h) {
          all_hand_data[h].model.DisableHand();
        }
    }
예제 #15
0
 private void HandDetection(HandList hands, FingerList fingers)
 {
     /********************** HAND DETECTION ************************************/
     if ((!hands.IsEmpty && LeapMath.IsAboveTheLeap(hands)) || (!fingers.IsEmpty && LeapMath.IsAboveTheLeap(fingers))) // if there is at least one hand or one finger, and if it is more or less above the device
     {
         // and if this hand was not present in the previous frame
         if (!m_HandInPreviousFrame)
         {
             RaiseHandPresentEvent(); // we raise the HandPresent event
             m_HandInPreviousFrame = true;
         }
     }
     else
     {
         if (m_HandInPreviousFrame)
         {
             RaiseHandRemovedEvent(); // but if there is no hand or finger in this frame, but there was in the previous frame, we raise the HandRemoved event
             m_HandInPreviousFrame = false;
         }
     }
     /***************************************************************************/
 }
        public override void positionDidUpdate(HandList hands)
        {
            this.hands = hands;

            if (this.hands.Count == this.NumberOfHandsRequired)
            {
                if (isDesiredNumberOfFingersPerHand())
                {
                    MotionAverages averages = averageVectorForHands();

                    if (averages != null)
	                {
		                this.TapPosition = averages.positionAverage;
                        this.TapVelocity = averages.velocityAverage;

                        processTouchVectors(averages);
	                }

                    //Callback
                    callback();
                }
            }
        }
        public override void positionDidUpdate(HandList hands)
        {
            this.hands = hands;

            if (this.hands.Count == this.NumberOfHandsRequired)
            {
                if (isDesiredNumberOfFingersPerHand())
                {
                    MotionAverages averages = averageVectorForHands();

                    if (averages != null)
                    {
                        if (velocityHighEnough(averages))
                        {
                            switch (this.state) {
                            case MotionGestureRecognizerState.MotionGestureRecognizerStatePossible:
                                //Helps with false positives due to change of direction
                                if (accelerationCounter > 3) {
                                    accelerationCounter = 0;
                                    this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateBegan;
                                }
                                else {
                                    accelerationCounter++;
                                }
                                break;
                            case MotionGestureRecognizerState.MotionGestureRecognizerStateBegan:
                                this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateChanged;
                                break;
                            case MotionGestureRecognizerState.MotionGestureRecognizerStateChanged:
                                this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateChanged;
                                break;
                                
                            default:
                                break;
                        }
                        }
                        else
                        {
                            switch (this.state)
                            {
                                case MotionGestureRecognizerState.MotionGestureRecognizerStateBegan:
                                    if (decelerationCounter > 1)
                                    {
                                        decelerationCounter = 0;
                                        this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateEnded;
                                    }
                                    else
                                    {
                                        decelerationCounter++;
                                    }
                                    break;
                                case MotionGestureRecognizerState.MotionGestureRecognizerStateChanged:
                                    if (decelerationCounter > 1)
                                    {
                                        decelerationCounter = 0;
                                        this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateEnded;
                                    }
                                    else
                                    {
                                        decelerationCounter++;
                                    }
                                    break;
                                case MotionGestureRecognizerState.MotionGestureRecognizerStateEnded:
                                    this.state = MotionGestureRecognizerState.MotionGestureRecognizerStatePossible;
                                    break;
                                default:
                                    break;
                            }
                        }

                        //Callback
                        callback();
                    }

                }
            }
            
        }
 //IMotion leapCoreInterface = new MotionListener();
 public virtual void positionDidUpdate(HandList hands)
 {
     throw new NotImplementedException();
 }
    //Gesture Even ZoomInOut
    void ZoomInOut(Gesture gesture,HandList handsForGesture)
    {
        if (handsForGesture[0].IsLeft && gesture.Type == Gesture.GestureType.TYPESWIPE)
        {
            Debug.Log("left zoom");
            SwipeGesture Swipe = new SwipeGesture(gesture);
            Vector swipeDirection = Swipe.Direction;
            if (swipeDirection.x < 0)
            {
                if (leftCamera.camera.fieldOfView < maxFov)
                {
                    leftCamera.camera.fieldOfView += zoomScale;
                    rightCamera.camera.fieldOfView += zoomScale;
                }

            }
            else if (swipeDirection.x > 0)
            {
                if (leftCamera.camera.fieldOfView > minFov)
                {
                    leftCamera.camera.fieldOfView -= zoomScale;
                    rightCamera.camera.fieldOfView -= zoomScale;
                }
            }
        }

        else if ((!handsForGesture[0].IsLeft) && gesture.Type == Gesture.GestureType.TYPESWIPE)
        {
            Debug.Log("right zoom");
            SwipeGesture Swipe = new SwipeGesture(gesture);
            Vector swipeDirection = Swipe.Direction;
            if (swipeDirection.x > 0 )
            {
                if (leftCamera.camera.fieldOfView < maxFov)
                {
                    leftCamera.camera.fieldOfView += zoomScale;
                    rightCamera.camera.fieldOfView += zoomScale;
                }
            }
            else if (swipeDirection.x < 0)
            {
                if (leftCamera.camera.fieldOfView > minFov)
                {
                    leftCamera.camera.fieldOfView -= zoomScale;
                    rightCamera.camera.fieldOfView -= zoomScale;
                }
            }
        }
    }
예제 #20
0
 public void AddCard(RegularRummyCard thisCard)
 {
     UpdateCard(thisCard);
     HandList.Add(thisCard);
 }
예제 #21
0
        public void detectHandPosition(Leap.Frame frame)
        {
            HandList allHands = frame.Hands;

            foreach (Hand hand in allHands)
            {
                if (intUitgelezen == 1)
                {
                    for (int i = 0; i < hand.Fingers.Count; i++)
                    {
                        Finger finger = hand.Fingers[i];

                        string fingerName     = finger.ToString();
                        Vector mcpPos         = finger.JointPosition(Finger.FingerJoint.JOINT_MCP);
                        Vector tipPos         = finger.JointPosition(Finger.FingerJoint.JOINT_TIP);
                        float  angle          = (float)(mcpPos.AngleTo(tipPos) * (180 / Math.PI));
                        Vector fingerPosition = finger.TipPosition;
                        float  distance       = hand.PalmPosition.DistanceTo(tipPos);


                        if (i == 0)
                        {
                            txtDuim.Text = distance.ToString();
                            oduim        = distance;
                            txtDuim.Text = oduim.ToString();
                        }
                        if (i == 1)
                        {
                            txtWijsvinger.Text = distance.ToString();
                            owijsvinger        = distance;
                            txtWijsvinger.Text = owijsvinger.ToString();
                        }
                        if (i == 2)
                        {
                            txtMiddelvinger.Text = distance.ToString();
                            omiddelvinger        = distance;
                            txtMiddelvinger.Text = omiddelvinger.ToString();
                        }
                        if (i == 3)
                        {
                            txtRingvinger.Text = distance.ToString();
                            oringvinger        = distance;
                            txtRingvinger.Text = oringvinger.ToString();
                        }
                        if (i == 4)
                        {
                            txtPink.Text = distance.ToString();
                            opink        = distance;
                            txtPink.Text = opink.ToString();
                        }
                    }
                    intUitgelezen = 2;
                }

                if (intUitgelezen == 2)
                {
                    float duim         = 0;
                    float wijsvinger   = 0;
                    float middelvinger = 0;
                    float ringvinger   = 0;
                    float pink         = 0;

                    float pitch = hand.Direction.Pitch;
                    float yaw   = hand.Direction.Yaw;
                    float roll  = hand.PalmNormal.Roll;

                    double degPitch = pitch * (180 / Math.PI); //convert to degree
                    double degYaw   = yaw * (180 / Math.PI);
                    double degRoll  = roll * (180 / Math.PI);

                    int intPitch = (int)degPitch;
                    int intYaw   = (int)degYaw;
                    int intRoll  = (int)degRoll;

                    txtDuim.Text  = "een";
                    lblTekst.Text = " ";



                    for (int i = 0; i < hand.Fingers.Count; i++)
                    {
                        Finger finger = hand.Fingers[i];

                        string fingerName     = finger.ToString();
                        Vector mcpPos         = finger.JointPosition(Finger.FingerJoint.JOINT_MCP);
                        Vector tipPos         = finger.JointPosition(Finger.FingerJoint.JOINT_TIP);
                        float  angle          = (float)(mcpPos.AngleTo(tipPos) * (180 / Math.PI));
                        Vector fingerPosition = finger.TipPosition;
                        float  distance       = hand.PalmPosition.DistanceTo(tipPos);


                        if (i == 0)
                        {
                            txtDuim.Text = distance.ToString();
                            duim         = distance;
                        }
                        if (i == 1)
                        {
                            txtWijsvinger.Text = distance.ToString();
                            wijsvinger         = distance;
                        }
                        if (i == 2)
                        {
                            txtMiddelvinger.Text = distance.ToString();
                            middelvinger         = distance;
                        }
                        if (i == 3)
                        {
                            txtRingvinger.Text = distance.ToString();
                            ringvinger         = distance;
                        }
                        if (i == 4)
                        {
                            txtPink.Text = distance.ToString();
                            pink         = distance;
                        }
                    }

                    //A//
                    if ((intRoll > -30) && (oduim - duim) < 10 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "A";
                        intLetter     = 1;
                    }
                    //B//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) < 15 && (opink - pink) < 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "B";
                        intLetter     = 2;
                    }
                    //D//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "D";
                        intLetter     = 3;
                    }
                    //E//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "E";
                        intLetter     = 4;
                    }
                    //F//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) < 15 && (opink - pink) < 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "F";
                        intLetter     = 5;
                    }


                    //H//
                    else if ((intRoll < -60) && (oduim - duim) < 10 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "H";
                        intLetter     = 6;
                    }


                    //I//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) < 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = ("I");
                        intLetter     = 7;
                    }
                    //K//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "K";
                        intLetter     = 8;
                    }
                    //L//
                    else if ((intRoll > -30) && (oduim - duim) < 10 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "L";
                        intLetter     = 9;
                    }
                    //W//
                    else if ((intRoll > -30) && (oduim - duim) > 10 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) < 15 && (opink - pink) > 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "W";
                        intLetter     = 10;
                    }
                    //Y//
                    else if ((intRoll > -30) && (oduim - duim) < 10 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) < 15)
                    {
                        lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                        lblTekst.Text = "Y";
                        intLetter     = 11;
                    }



                    txtRoll.Text = intRoll.ToString();

                    if (blnBeginner == true)
                    {
                        pctGebaren.Visible           = true;
                        lblBeginnerVoorbeeld.Visible = true;
                        switch (intBeginner)
                        {
                        case 1:
                            pctGebaren.Image    = Properties.Resources._1;
                            lblOefenLetter.Text = "A";
                            break;

                        case 2:
                            pctGebaren.Image    = Properties.Resources._2;
                            lblOefenLetter.Text = "B";
                            break;

                        case 3:
                            pctGebaren.Image    = Properties.Resources._3;
                            lblOefenLetter.Text = "D";
                            break;

                        case 4:
                            pctGebaren.Image    = Properties.Resources._4;
                            lblOefenLetter.Text = "E";
                            break;

                        case 5:
                            pctGebaren.Image    = Properties.Resources._5;
                            lblOefenLetter.Text = "F";
                            break;

                        case 6:
                            pctGebaren.Image    = Properties.Resources._6;
                            lblOefenLetter.Text = "H";
                            break;

                        case 7:
                            pctGebaren.Image    = Properties.Resources._7;
                            lblOefenLetter.Text = "I";
                            break;

                        case 8:
                            pctGebaren.Image    = Properties.Resources._8;
                            lblOefenLetter.Text = "K";
                            break;

                        case 9:
                            pctGebaren.Image    = Properties.Resources._9;
                            lblOefenLetter.Text = "L";
                            break;

                        case 10:
                            pctGebaren.Image    = Properties.Resources._10;
                            lblOefenLetter.Text = "W";
                            break;

                        case 11:
                            pctGebaren.Image = Properties.Resources._11;

                            lblOefenLetter.Text = "Y";
                            break;
                        }
                    }
                    else if (blnExpert == true)
                    {
                        pctGebaren.Visible = false;
                        switch (intBeginner)
                        {
                        case 1:
                            pctGebaren.Image    = Properties.Resources._1;
                            lblOefenLetter.Text = "A";
                            break;

                        case 2:
                            pctGebaren.Image    = Properties.Resources._2;
                            lblOefenLetter.Text = "B";
                            break;

                        case 3:
                            pctGebaren.Image    = Properties.Resources._3;
                            lblOefenLetter.Text = "D";
                            break;

                        case 4:
                            pctGebaren.Image    = Properties.Resources._4;
                            lblOefenLetter.Text = "E";
                            break;

                        case 5:
                            pctGebaren.Image    = Properties.Resources._5;
                            lblOefenLetter.Text = "F";
                            break;

                        case 6:
                            pctGebaren.Image    = Properties.Resources._6;
                            lblOefenLetter.Text = "H";
                            break;

                        case 7:
                            pctGebaren.Image    = Properties.Resources._7;
                            lblOefenLetter.Text = "I";
                            break;

                        case 8:
                            pctGebaren.Image    = Properties.Resources._8;
                            lblOefenLetter.Text = "K";
                            break;

                        case 9:
                            pctGebaren.Image    = Properties.Resources._9;
                            lblOefenLetter.Text = "L";
                            break;

                        case 10:
                            pctGebaren.Image    = Properties.Resources._10;
                            lblOefenLetter.Text = "W";
                            break;

                        case 11:
                            pctGebaren.Image    = Properties.Resources._11;
                            lblOefenLetter.Text = "Y";
                            break;
                        }
                    }


                    /// <summary>
                    /// Kijken of letter overeenkomt met de nodige letter
                    /// nieuwe random letter kiezen
                    /// kijken of random letter dezelfde is als vorige keer
                    /// Zoja? Letter veranderen naar een letter die vlak hiervoor niet is voorgekomen
                    /// Zonee? Pak deze random letter
                    /// </summary>

                    txtTekst.Text += lblTekst.Text;

                    intDubbel = intBeginner;

                    if (blnBeginner)
                    {
                        if (intBeginner == intLetter)
                        {
                            if (i > 200)
                            {
                                if (txtTekst.Text.Substring(i, 1) == txtTekst.Text.Substring(i - 199, 1))
                                {
                                    txtResultaat.Text += txtTekst.Text.Substring(i, 1);

                                    txtResultaat.Text    += txtTekst.Text.Substring(i, 1);
                                    intBeginner           = rnd.Next(11);
                                    intScore             += 1;
                                    lblScore.Text         = intScore.ToString();
                                    lblScore.Visible      = true;
                                    lblScoreTekst.Visible = true;
                                    intDubbel             = intBeginner;

                                    if (blnBeginner)
                                    {
                                        pctJuist.Visible = true;
                                    }



                                    if (intBeginner == intDubbel)
                                    {
                                        intBeginner += 1;
                                        if (intBeginner > 11)
                                        {
                                            intBeginner = 1;
                                        }
                                    }
                                }
                                else
                                {
                                    pctJuist.Visible = false;
                                }
                            }
                        }
                    }
                    if (blnExpert)
                    {
                        if (intBeginner == intLetter)
                        {
                            txtResultaat.Text    += txtTekst.Text.Substring(i, 1);
                            intBeginner           = rnd.Next(11);
                            intScore             += 1;
                            lblScore.Text         = intScore.ToString();
                            lblScore.Visible      = true;
                            lblScoreTekst.Visible = true;
                            intDubbel             = intBeginner;

                            if (blnBeginner)
                            {
                                pctJuist.Visible = true;

                                pctJuist.Visible = false;
                            }



                            if (intBeginner == intDubbel)
                            {
                                intBeginner += 1;
                                if (intBeginner > 11)
                                {
                                    intBeginner = 1;
                                }
                            }
                        }
                    }



                    i += 1;
                }
            }
        }
예제 #22
0
    // Update is called once per frame
    void Update()
    {
        /*
         * if (Input.GetKeyDown (KeyCode.Escape) && _ckpause == false) {
         *      print("pause");
         *      _ckpause = true;
         * }
         * else if (Input.GetKeyDown (KeyCode.Escape) && _ckpause == true) {
         *      print("unpause");
         *      _ckpause = false;
         * }*/

        //keybords
        if (_ckpause == false)
        {
            if (Input.GetKey(KeyCode.Space) && ckjump == true)
            {
                jump();
            }
            if (Input.GetKeyDown(KeyCode.J))
            {
                pastpre(2);
            }
            if (Input.GetKeyDown(KeyCode.K))
            {
                pastpre(1);
            }
            if (Input.GetKey(KeyCode.L))
            {
                getitem = true;
            }
            if (Input.GetKeyUp(KeyCode.L))
            {
                getitem = false;
            }

            if (Input.GetKey(KeyCode.W))
            {
                walk(1);
            }
            else if (Input.GetKey(KeyCode.S))
            {
                walk(2);
            }
            else
            {
                _animation.Play("Idle");
            }
        }

        /*
         * if (_ckpause == true) {
         *      if(Input.GetKeyDown(KeyCode.W)&&pausemenu>1)pausemenu--;
         *      if(Input.GetKeyDown(KeyCode.S)&&pausemenu<3)pausemenu++;
         *      print(pausemenu);
         *      if(Input.GetKeyDown(KeyCode.Return)&&pausemenu==1)
         *      {
         *
         *      }
         *      if(Input.GetKeyDown(KeyCode.Return)&&pausemenu==2)
         *      {
         *
         *      }
         *      if(Input.GetKeyDown(KeyCode.Return)&&pausemenu==3)
         *      {
         *
         *      }
         * }
         */



        // Leap motion
        /**CONFIG**/
        controller.EnableGesture(Gesture.GestureType.TYPECIRCLE);
        controller.EnableGesture(Gesture.GestureType.TYPESWIPE);
        controller.Config.SetFloat("Gesture.ScreenTap.MinForwardVelocity", 10.0f);
        controller.Config.SetFloat("Gesture.Circle.MinRadius", 50.0f);
        controller.Config.SetFloat("Gesture.Circle.MinArc", Mathf.PI * 2);


        HandList      leap_Hands = controller.Frame().Hands;
        int           num_hands = leap_Hands.Count;
        Frame         frame = Frame.Invalid, previous = Frame.Invalid;
        CircleGesture circle = CircleGesture.Invalid as CircleGesture;

        if (controller.IsConnected)
        {
            frame = controller.Frame();
        }
        for (int i = 0; i < frame.Gestures().Count; i++)
        {
            if (frame.Gestures()[i].Type == Gesture.GestureType.TYPECIRCLE)
            {
                circle = new CircleGesture(frame.Gestures()[i]);
            }
        }
        //if(num_hands == 2)
        {
            //_pausemenu(2);
            for (int i = 0; i < num_hands; i++)
            {
                Hand leap_hand = leap_Hands[i];
                if (leap_hand.IsRight)
                {
                    RHand = leap_hand;
                }
                //if(leap_hand.IsLeft)LHand = leap_hand;

                /*if(LHand != null){
                 *                      if(leap_hand.PalmPosition.z<-20)walk(1);
                 *                      else if(leap_hand.PalmPosition.z>0)walk(2);
                 *                      if (leap_hand.PalmPosition.y > 210 && ckjump == true) jump ();
                 *      }*/
                //if(RHand != null)
                {
                    // past - present
                    if (circle.IsValid && circle.Pointable.Direction.AngleTo(circle.Normal) <= Mathf.PI / 2)
                    {
                        pastpre(1);
                    }
                    else
                    {
                        pastpre(2);
                    }



                    //Debug.Log("Right"+leap_hand.PalmPosition.y);
                    //get item
                    if (leap_hand.PalmPosition.y < 160)
                    {
                        getitem = true;
                    }
                    else if (leap_hand.PalmPosition.y > 160)
                    {
                        getitem = false;
                    }
                    //Debug.Log(getitem);
                }

                RHand = null;
                LHand = null;
            }
        }
    }
예제 #23
0
    // Update is called once per frame
    void Update()
    {
        Hand     rHand = Hand.Invalid as Hand, lHand = Hand.Invalid as Hand;
        HandList hands = controller.Frame().Hands;
        int      sth   = 0;

        for (int i = 0; i < hands.Count; i++)
        {
            if (hands[i].IsLeft)
            {
                lHand = hands[i];
            }
            if (hands[i].IsRight)
            {
                rHand = hands[i];
            }
        }
        if (rHand.PalmVelocity.y < -10F)
        {
            if (rUp != -1)
            {
                sth++;
            }
            rUp = -1;
        }
        else if (rHand.PalmVelocity.y > 10F)
        {
            if (rUp != 1)
            {
                sth++;
            }
            rUp = 1;
        }
        else
        {
            rUp = 0;
        }
        if (lHand.PalmVelocity.y < -10F)
        {
            if (lUp != -1)
            {
                sth++;
            }
            lUp = -1;
        }
        else if (lHand.PalmVelocity.y > 10F)
        {
            if (lUp != 1)
            {
                sth++;
            }
            lUp = 1;
        }
        else
        {
            lUp = 0;
        }
        if (sth == 2)
        {
            played = false;
        }
        if (rUp + lUp == 0 && rUp != 0 && !played)//riding hand
        {
            played = true;
            _animation.Play("Jump");
            StartCoroutine(MyMethod());            //deley 1.3 sec
        }
    }
예제 #24
0
    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            Cursor.visible = true;
            Application.Quit();
        }

        if (InstructionsText.enabled && !isFirst)
        {
            InstructionsText.enabled = false;
            prevTotalTime            = Time.time;
        }

        if (PointText.enabled)
        {
            if ((int)(Time.time - prevTotalTime) > 1)
            {
                PointText.enabled = false;
            }
        }

        if (!InstructionsText.enabled && !endWindow)
        {
            float currentTime = Time.time - prevTotalTime;
            if (currentTime > maxTime - 10f)
            {
                color = "red";
            }

            if (currentTime > maxTime)
            {
                skipWindow = true;
            }
        }

        if (controller.IsConnected)
        {
            currentFrame = controller.Frame();
            if (currentFrame.Id != prevFrame.Id)
            {
                Tool     pointable = currentFrame.Tools.Frontmost;
                HandList hands     = currentFrame.Hands;
                Hand     hand      = hands[0];
                Pointer.GetComponent <Renderer>().material = Yellow;
                if (hand.PinchStrength == 1)
                {
                    Pointer.GetComponent <Renderer>().material = Green;
                    if (initPinch)
                    {
                        if (skipWindow)
                        {
                            SetPosition();
                            skipWindow = false;
                            color      = "white";
                            PopSource.PlayOneShot(PopSound);
                            prevTotalTime = Time.time;
                        }
                        else if (endWindow)
                        {
                            PopSource.PlayOneShot(PopSound);
                            Application.LoadLevel(Application.loadedLevel);
                        }
                        else if (isDocked)
                        {
                            PopSource.PlayOneShot(PopSound);
                            float trialTime = Time.time - prevTotalTime;
                            File.AppendAllText(
                                folderPath + ".csv",
                                trialTime.ToString() + "," + initDistance.ToString() + "," + finalDistance.ToString() + Environment.NewLine);
                            SetPosition();
                            trialCount++;
                            PointText.enabled = true;
                            color             = "white";
                            if (trialCount >= totalTrials)
                            {
                                endWindow = true;
                            }

                            prevTotalTime = Time.time;
                        }
                    }

                    initPinch = false;
                }
                else
                {
                    initPinch = true;
                }

                if (pointable.IsValid && !skipWindow && !endWindow)
                {
                    Vector stabilizedPosition = pointable.StabilizedTipPosition;
                    currentPosition = new Vector3(
                        stabilizedPosition.x * scale,
                        stabilizedPosition.y * scale,
                        -stabilizedPosition.z * scale);
                    Vector  directionLeap = pointable.Direction;
                    Vector3 direction     = new Vector3(
                        directionLeap.x,
                        directionLeap.y,
                        -directionLeap.z);
                    Pointer.transform.LookAt(direction.normalized + Pointer.transform.position);
                    if (!isFirst)
                    {
                        Vector3 transVec = currentPosition - prevPosition;
                        CursorChair.transform.Translate(transVec);
                        CursorChair.transform.position = new Vector3(
                            Mathf.Clamp(CursorChair.transform.position.x, -cap, cap),
                            Mathf.Clamp(CursorChair.transform.position.y, -cap, cap),
                            Mathf.Clamp(CursorChair.transform.position.z, -cap, cap));
                    }

                    isFirst      = false;
                    prevPosition = currentPosition;
                }
                else
                {
                    isFirst = true;
                }

                EvaluateDock();
            }
        }
    }
예제 #25
0
    // Update is called once per frame
    void Update()
    {
        Frame    myFrame   = myController.Frame();
        HandList myHands   = myFrame.Hands;
        Hand     rightHand = myHands.Rightmost;
        //float roll = rightHand.PalmNormal;
        Vector position = rightHand.PalmPosition;
        bool   play     = false;
        float  avgx     = 0f;
        float  avgy     = 0f;
        float  avgz     = 0f;

        //if (!myFrame.Hands.IsEmpty) {
        //gameObject.rigidbody.AddForce(new Vector3(0.0f, 50000.0f, 0.0f));
        //}

        if (myHands.Count == 0)
        {
            Debug.Log("NOTHING HERE");
        }
        else if (myHands.Count > 1)
        {
            Debug.Log("TWO HANDS DETECTED");
        }
        else
        {
            play = true;
        }

        if (play == true)
        {
            //float difference=0;
            float totalx = 0, totaly = 0, totalz = 0;


            /*
             * /*for (int i=0; i<60; i++)
             * {
             * previous = myController.Frame(i).Hands.Rightmost.PalmNormal;
             * totalx+= previous.x;
             * totaly+= previous.y;
             * totalz+= previous.z;
             * }
             *
             * avgx= totalx/60;
             * avgy=totaly/60;
             * avgz=totalz/60;
             *
             * Vector current = myController.Frame().Hands.Rightmost.PalmNormal;
             * float diffx = (current.x - avgx)*100000;
             * float diffy = (current.y - avgy)*100000;
             * float diffz = (current.z - avgz)*100000;
             *
             * Debug.Log("diff   "+ diffx +"    " + diffy+ "   " + diffz );
             * //Debug.Log("current:   "+ current.x+"    " + current.y+ "   " + current.z);
             */
            //gameObject.rigidbody.AddForce (new Vector3 (0.0f, 0.0f, 50.0f));
        }

        /*if(UnityEngine.Input.GetKeyDown(KeyCode.W)) {
         *      gameObject.rigidbody.AddForce(new Vector3(0.0f, 0.0f, 500.0f));
         * }
         *
         * if(UnityEngine.Input.GetKeyDown(KeyCode.A)) {
         *      gameObject.rigidbody.AddForce(new Vector3(-500.0f, 0.0f, 0.0f));
         * }
         *
         * if(UnityEngine.Input.GetKeyDown(KeyCode.S)) {
         *      gameObject.rigidbody.AddForce(new Vector3(0.0f, 0.0f, -500.0f));
         * }
         *
         * if(UnityEngine.Input.GetKeyDown(KeyCode.D)) {
         *      gameObject.rigidbody.AddForce(new Vector3(500.0f, 0.0f, 0.0f));
         * }
         *
         * if(UnityEngine.Input.GetKeyDown(KeyCode.Space)) {
         *      gameObject.rigidbody.AddForce(new Vector3(0.0f, 100.0f, 0.0f));
         * }*/
    }
예제 #26
0
        public void detectHandPosition(Leap.Frame frame)
        {
            HandList allHands = frame.Hands;

            foreach (Hand hand in allHands)
            {
                float oduim         = 80;
                float owijsvinger   = 110;
                float omiddelvinger = 115;
                float oringvinger   = 107;
                float opink         = 94;
                float duim          = 0;
                float wijsvinger    = 0;
                float middelvinger  = 0;
                float ringvinger    = 0;
                float pink          = 0;
                float oroll         = 0;
                float pitch         = hand.Direction.Pitch;
                float yaw           = hand.Direction.Yaw;
                float roll          = hand.PalmNormal.Roll;

                double degPitch = pitch * (180 / Math.PI); //convert to degree
                double degYaw   = yaw * (180 / Math.PI);
                double degRoll  = roll * (180 / Math.PI);

                int intPitch = (int)degPitch;
                int intYaw   = (int)degYaw;
                int intRoll  = (int)degRoll;

                txtDuim.Text = "een";

                for (int i = 0; i < hand.Fingers.Count; i++)
                {
                    Finger finger = hand.Fingers[i];

                    string fingerName     = finger.ToString();
                    Vector mcpPos         = finger.JointPosition(Finger.FingerJoint.JOINT_MCP);
                    Vector tipPos         = finger.JointPosition(Finger.FingerJoint.JOINT_TIP);
                    float  angle          = (float)(mcpPos.AngleTo(tipPos) * (180 / Math.PI));
                    Vector fingerPosition = finger.TipPosition;
                    float  distance       = hand.PalmPosition.DistanceTo(tipPos);


                    if (i == 0)
                    {
                        txtDuim.Text = distance.ToString();
                        duim         = distance;
                        Vector vctDuim = finger.JointPosition(Finger.FingerJoint.JOINT_TIP);
                    }
                    if (i == 1)
                    {
                        txtWijsvinger.Text = distance.ToString();
                        wijsvinger         = distance;
                        Vector vctWijsvinger = finger.JointPosition(Finger.FingerJoint.JOINT_TIP);
                    }
                    if (i == 2)
                    {
                        txtMiddelvinger.Text = distance.ToString();
                        middelvinger         = distance;
                    }
                    if (i == 3)
                    {
                        txtRingvinger.Text = distance.ToString();
                        ringvinger         = distance;
                    }
                    if (i == 4)
                    {
                        txtPink.Text = distance.ToString();
                        pink         = distance;
                    }
                }

                //*//
                //*//

                //A//
                if ((intRoll > -65) && (oduim - duim) < 15 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text      = ("A");
                }
                //L//
                else if ((intRoll > -65) && (oduim - duim) < 15 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text      = ("L");
                }
                //H//
                else if ((intRoll < -65) && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text      = ("H");
                }
                //B//
                else if ((intRoll > -65) && (oduim - duim) > 15 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) < 15 && (opink - pink) < 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text      = ("B");
                }

                //I//
                else if ((intRoll > -65) && (oduim - duim) > 15 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) < 15)
                {
                    lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text = ("I");
                }
                //Love you//
                else if ((intRoll > -65) && (oduim - duim) < 15 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) < 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 50);
                    lblTekst.Text      = "Love you";
                }
                //E//

                else if ((intRoll > -65) && (oduim - duim) > 15 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                {
                    lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text = ("E");
                }
                //K//

                else if ((intRoll > -65) && (oduim - duim) > 15 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                {
                    lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text = ("K");
                }
                //F//
                else if ((intRoll > -65) && (oduim - duim) > 15 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) < 15 && (opink - pink) < 15)
                {
                    lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text = ("F");
                }

                //High Five//
                else if ((intRoll > -65) && (oduim - duim) < 15 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) < 15 && (oringvinger - ringvinger) < 15 && (opink - pink) < 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 80);
                    lblTekst.Text      = ("High five");
                }
                //Y//
                else if ((intRoll > -65) && (oduim - duim) < 15 && (owijsvinger - wijsvinger) > 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) < 15)
                {
                    lblPintjes.Visible = false;
                    lblTekst.Font      = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text      = ("Y");
                }
                //D//

                else if ((intRoll > -65) && (oduim - duim) > 15 && (owijsvinger - wijsvinger) < 15 && (omiddelvinger - middelvinger) > 15 && (oringvinger - ringvinger) > 15 && (opink - pink) > 15)
                {
                    lblTekst.Font = new Font(lblTekst.Font.FontFamily, 150);
                    lblTekst.Text = ("D");
                }

                float grab = hand.GrabStrength;

                txtPitch.Text = intPitch.ToString();
                txtYaw.Text   = intYaw.ToString();
                txtRoll.Text  = intRoll.ToString();

                txtGrab.Text = grab.ToString();

                //
                //
            }
        }
예제 #27
0
        void IDealProcesses.PopulateDeals()
        {
            var tempList = _gameContainer.SingleInfo !.Hand.GetMailOrDealList <DealCard>(EnumCardCategory.Deal);

            _model !.CurrentDealList !.HandList.ReplaceRange(tempList);
        }
예제 #28
0
    void Update()
    {
        if (controlsInputHold.isControlsInputHold == false)
        {
            /// GET INPUT
            rotDelta = Vector3.zero;
            // -------- FORWARD ACCELERATION --------------

            // Use last device which provided input.



            //  --------  ROTATIONAL ACCELERATION --------------

            float triggerLeft  = 0;
            float triggerRight = 0;
            float xAcc         = 0;
            float yAcc         = 0;

            if (InputManager.Devices.Count > 1)
            {
                var inputDeviceConductor = InputManager.Devices[1];
                zAcc = inputDeviceConductor.Action1 * forwardControlScale;                 //* Time.deltaTime;

                triggerLeft  = inputDeviceConductor.LeftTrigger * rotationControlScale;
                triggerRight = -inputDeviceConductor.RightTrigger * rotationControlScale;
                xAcc         = 0.25f * inputDeviceConductor.LeftStickX * hControlScale;
                yAcc         = inputDeviceConductor.LeftStickY * vControlScale;
            }



            if (Input.GetKey(KeyCode.Q))
            {
                triggerLeft += 1.0f * rotationControlScale;
            }

            if (Input.GetKey(KeyCode.E))
            {
                triggerRight += 1.0f * -rotationControlScale;
            }

            if (Input.GetKey(KeyCode.W))
            {
                yAcc += 1.0f * vControlScale;
            }
            if (Input.GetKey(KeyCode.S))
            {
                yAcc += -1.0f * vControlScale;
            }
            if (Input.GetKey(KeyCode.A))
            {
                xAcc -= 1.0f * hControlScale;
            }
            if (Input.GetKey(KeyCode.D))
            {
                xAcc += 1.0f * hControlScale;
            }


            // --------- LEAP PART ------------
            applyLMCInput = false;
            if (lmcController != null)
            {
                Frame    frame     = lmcController.Frame();
                HandList hands     = frame.Hands;
                Hand     firstHand = hands[0];

                if (firstHand.IsValid)
                {
                    applyLMCInput = true;

                    float yaw   = firstHand.Direction.Yaw;                   //* 4.0f;
                    float pitch = -firstHand.Direction.Pitch;                //* 4.0f;
                    float roll  = firstHand.PalmNormal.Roll;                 //* 4.20f;

                    //transform.localEulerAngles = new Vector3(360.0f * pitch, 360.0f * yaw, 360.0f * roll);
                    rotVec = new Vector3(pitch, yaw, roll);

                    xAcc       += yaw;
                    yAcc       += pitch;
                    rotDelta.z += roll;

                    // use palm height as gas pedal
                    float normalizedHeight = 1.0f - (2.0f * Mathf.Clamp(firstHand.PalmPosition.ToUnityScaled().y, 0, 0.5f));
                    zAcc += normalizedHeight * forwardControlScale;
                }
            }

            // ------------ Turn boost adjustments ---------------

            if (xAcc > 0 && pva.rotationalVelocity.x < 0)
            {
                turnBoost_x = true;
            }
            if (xAcc < 0 && pva.rotationalVelocity.x > 0)
            {
                turnBoost_x = true;
            }

            if (yAcc > 0 && pva.rotationalVelocity.y < 0)
            {
                turnBoost_y = true;
            }
            if (yAcc < 0 && pva.rotationalVelocity.y > 0)
            {
                turnBoost_y = true;
            }

            if (xAcc == 0)
            {
                turnBoost_x = false;
            }
            if (yAcc == 0)
            {
                turnBoost_y = false;
            }

            if (turnBoost_x)
            {
                xAcc *= 4.0f;
            }
            if (turnBoost_y)
            {
                yAcc *= 4.0f;
            }

            rotDelta.x  = xAcc;
            rotDelta.y  = yAcc;
            rotDelta.z += triggerLeft + triggerRight;

            frictionToggleVector = Vector3.zero;
            if (rotDelta.x == 0)
            {
                frictionToggleVector.x = 1;
            }
            if (rotDelta.y == 0)
            {
                frictionToggleVector.y = 1;
            }
            if (rotDelta.z == 0)
            {
                frictionToggleVector.z = 1;
            }
        }


        // APPLY INPUT

        if (applyLMCInput == true)
        {
            transform.Rotate(2.0f * Mathf.PI * rotVec, Space.Self);
        }


        pva.angularFrictionAxisToggle = frictionToggleVector;
        pva.rotationalAcceleration    = rotDelta;

        // force velocity orientation
        Vector3 correctedVel = pva.velocity.magnitude * transform.forward;

        pva.velocity = correctedVel;

        // apply forward acceleration
        controlDelta = transform.forward * zAcc;
        if (controlDelta.magnitude > 0)
        {
            pva.isLinearDecay = false;
        }
        else
        {
            pva.isLinearDecay = true;
        }

        pva.acceleration = controlDelta;
    }
예제 #29
0
 public override void LoadSet(SavedSet payLoad)
 {
     HandList.ReplaceRange(payLoad.CardList);
 }
        /// <summary>
        /// Returns a list of hands which fall within a certain space around the gesture workspace.
        /// </summary>
        protected List<Hand> DetectedHands(HandList hands)
        {
            List<Hand> detected = new List<Hand>();

            foreach (Hand hand in hands)
            {
                if (hand.PalmPosition.z < GestureSpace.Bottom + SPACE_PADDING)
                    detected.Add(hand);
            }

            return detected;
        }
예제 #31
0
	void Update () {
        // Lorsqu'une main apparaît à l'écran elle est stockée dans le vecteur
		handListe = leapController.Frame ().Hands;

        // Si le vecteur est non vide on récupère la ou les mains présentes
		if (!handListe.IsEmpty) {
			Hand main = handListe [0];
			Hand main2 = handListe [1];
		

			if (main.GrabStrength > 0.5 && main2.GrabStrength < 0.5){
                //Si la première main est fermée et la deuxième ouverte (au cas où deux mains sont présentes)
                //On récupère la position de la main et on la convertie en vecteur qui peut être traité par unity
				newHandPosition = main.PalmPosition.ToUnityScaled();
				oldHandPosition.y *= -1;
				newHandPosition.y *= -1;

                //On déplace la scène en même temps que la main fermée se déplace
				Vector3 newGameObjectPosition = gameObject.transform.position + coefficient * (newHandPosition - oldHandPosition);
				gameObject.transform.position = newGameObjectPosition;
			}

			if (main.GrabStrength > 0.5 && main2.GrabStrength > 0.5){
                // Si les deux mains sont présentes et fermées, on va créer une rotation de la scène
                // en fonction du mouvement

                // On récupère le vecteur entre les deux mains
				Vector3 distance = main.PalmPosition.ToUnityScaled() - main2.PalmPosition.ToUnityScaled();

                // On ne prend pas en compte l'axe vertical (rotation autour de l'axe y souhaitée)
				distance.y = 0;

                // On prend le vecteur orthogonal
				Vector3 orthogonal = Vector3.Cross(distance,Vector3.up);
				float angle = speedRotation*Vector3.Angle(orthogonal, Vector3.forward);


                // On définit ensuite les sens de rotations
				if (main.IsLeft==true){

					if (main.PalmPosition.ToUnityScaled().z<main2.PalmPosition.ToUnityScaled().z){
						angle *= -1;
					}
				}

				else {

					if (main.PalmPosition.ToUnityScaled().z > main2.PalmPosition.ToUnityScaled().z){
						angle *= -1;
					}
				}
				
                // On effectue la rotation de la scène
				Quaternion rotationAngle = Quaternion.identity;
				rotationAngle.eulerAngles =  new Vector3(0,angle,0);
				gameObject.transform.rotation *= rotationAngle;
			}

			oldHandPosition = main.PalmPosition.ToUnityScaled();
		}

	}
예제 #32
0
            public override void OnFrame(Controller leap)
            {
                var frame = leap.Frame();

#if false
                // 今回のフレームで検出したすべての手、指、ツール
                HandList      hands      = frame.Hands;
                FingerList    fingers    = frame.Fingers;
                ToolList      tools      = frame.Tools;
                PointableList pointables = frame.Pointables;

                Console.WriteLine(string.Format(
                                      "Frame Data : Hands : {0} Fingers : {1} Extended Fingers : {2} Tools : {3} Pointers : {4}",
                                      hands.Count, fingers.Count, fingers.Extended().Count, tools.Count, pointables.Count));
#endif

#if false
                // 手のIDから、同じ手を追跡し続ける
                if (handId == -1)
                {
                    handId = frame.Hands[0].Id;
                }
                else
                {
                    Hand hand = frame.Hand(handId);
                    handId = hand.Id;

                    // 手の情報を表示する
                    Console.WriteLine(string.Format("ID : {0} 位置 : {1} 速度 : {2} 法線 : {3} 向き : {4}",
                                                    hand.Id, hand.PalmPosition, hand.PalmVelocity, hand.PalmNormal, hand.Direction));
                }
#endif

#if false
                // 一番左、右、手前の手を取得する
                HandList hands     = frame.Hands;
                Hand     leftMost  = hands.Leftmost;
                Hand     rightMost = hands.Rightmost;
                Hand     frontMost = hands.Frontmost;

                Console.WriteLine(string.Format("左 : {0} 右 : {1} 手前 : {2}",
                                                leftMost.PalmPosition, rightMost.PalmPosition, frontMost.PalmPosition));
#endif

#if false
                // 手に属している指とツールを取得する
                foreach (var hand in frame.Hands)
                {
                    Console.WriteLine(string.Format("ID : {0} ポインタ : {1} 指: {2} ツール : {3}",
                                                    hand.Id, hand.Pointables.Count, hand.Fingers.Count, hand.Fingers.Count));
                }
#endif

#if false
                // 指の情報を表示する
                foreach (var finger in frame.Fingers)
                {
                    Console.WriteLine(string.Format("ID : {0} 種類 : {1} 位置 : {2} 速度 : {3} 向き : {4}",
                                                    finger.Id, finger.Type, finger.TipPosition, finger.TipVelocity, finger.Direction));
                }
#endif

#if false
                // 指の関節情報を取得する
                foreach (var finger in frame.Fingers)
                {
                    // 末節骨(指先の骨)
                    var bone = finger.Bone(Bone.BoneType.TYPE_DISTAL);
                    Console.WriteLine(string.Format("種類 : {0} 中心 : {1} 上端 : {2} 下端 : {3}",
                                                    bone.Type, bone.Center, bone.PrevJoint, bone.NextJoint));
                }
#endif

#if true
                // 親指の定義を確認する
                foreach (var finger in frame.Fingers)
                {
                    if (finger.Type == Finger.FingerType.TYPE_THUMB)
                    {
                        for (int t = (int)Bone.BoneType.TYPE_METACARPAL; t <= (int)Bone.BoneType.TYPE_DISTAL; t++)
                        {
                            var bone = finger.Bone((Bone.BoneType)t);
                            Console.WriteLine(string.Format("種類 : {0} 長さ : {1}", bone.Type, bone.Length));
                        }
                    }
                }
#endif
            }
 ////////////////////////////////////////////////////////////////////////////////////////////////
 /*--------------------------------------------------------------------------------------------*/
 private void UpdateCursorsWithHands(HandList pLeapHands)
 {
     for ( int i = 0 ; i < pLeapHands.Count ; i++ ) {
         UpdateCursorsWithHand(pLeapHands[i]);
     }
 }
예제 #34
0
    // Update is called once per frame
    void Update()
    {
        gameTextDisplay2.text = resultMessage;

        switch (state)
        {
        case States.Preparing:

            if (resultMessage == "")
            {
                gameTextDisplay1.text = "Remove your hands off the screen to start";
            }
            else
            {
                gameTextDisplay1.text = "Remove your hands off the screen to restart";
            }
//			resultMessage

            if (leap_controller_.Frame().Hands.Count == 0)
            {
                resultMessage = "";
                state         = States.Playing;
                computer.transform.GetChild(computerMove).gameObject.SetActive(false);
                computer.transform.GetChild(computerMove).GetComponent <ComputerHandController>().DestroyAllHands();
                computerMove = Random.Range(0, 5);
                computer.transform.GetChild(computerMove).gameObject.SetActive(true);
            }
            break;

        case States.Playing:
            gameTextDisplay1.text = "Now make your gesture and place your hand in the center";

            Frame    frame = leap_controller_.Frame();
            HandList hands = frame.Hands;
            if (hands.Count >= 1)
            {
                Hand  firstHand = hands[0];
                float z         = firstHand.WristPosition.z;
                int   move      = classifier.getClassification(firstHand);
                if (move == -1)
                {
                    gameTextDisplay1.text = "Invalid gesture!";
                }
                else if (z <= playZ)
                {
                    resultMessage = "You played " + moveNames[move - 1] + ". Computer played " + moveNames[computerMove] + ". ";
//					gameTextDisplay.text
                    state = States.Preparing;
                    int result = mechanic.decision(move, computerMove + 1);
                    switch (result)
                    {
                    case (0):
                        resultMessage = resultMessage + "Draw!";
                        break;

                    case (1):
                        resultMessage = resultMessage + "Player wins!";
                        break;

                    case (2):
                        resultMessage = resultMessage + "Computer wins!";
                        break;

                    default:
                        break;
                    }
                }
            }

            break;

        default:
            break;
        }
    }
        public void CreateSet(IDeckDict <ChinazoCard> thisList, RummyProcesses <EnumSuitList, EnumColorList, ChinazoCard> .EnumRummyType whichSet, bool useSecond)
        {
            _whatSet   = whichSet;
            _useSecond = useSecond;
            var wildCol = thisList.Where(items => items.IsObjectWild == true).ToRegularDeckDict();

            thisList.ForEach(thisCard =>
            {
                thisCard.IsSelected = false;
                thisCard.Drew       = false;
            });
            if (_whatSet != RummyProcesses <EnumSuitList, EnumColorList, ChinazoCard> .EnumRummyType.Runs)
            {
                HandList.ReplaceRange(thisList);
                if (HandList.Count == 0)
                {
                    throw new BasicBlankException("the hand list was blank");
                }
                return;
            }
            EnumSuitList suitOfSet      = thisList.First(items => items.IsObjectWild == false).Suit;
            int          originalNumber = thisList.Count;
            var          tempCol        = thisList.Where(items => items.IsObjectWild == false).ToRegularDeckDict();

            if (useSecond == true)
            {
                tempCol = tempCol.OrderBy(items => items.SecondNumber).ToRegularDeckDict();
            }
            int firstNum;

            if (useSecond == true)
            {
                tempCol.First().UsedAs = (int)tempCol.First().SecondNumber;
            }
            else
            {
                tempCol.First().UsedAs = (int)tempCol.First().Value;
            }
            firstNum = tempCol.First().UsedAs;
            if (firstNum > 12)
            {
                throw new BasicBlankException("The first number cannot be higher than 12 for runs.");
            }
            tempCol.Last().UsedAs = (int)tempCol.Last().Value;
            int         whatFirst = firstNum;
            int         lastNum   = tempCol.Last().UsedAs;
            int         y         = tempCol.Count;
            ChinazoCard tempCard;

            for (int x = 2; x <= y; x++)
            {
                firstNum += 1;
                tempCard  = tempCol[x - 1];
                if ((int)tempCard.Value != firstNum)
                {
                    tempCard        = wildCol.First();
                    tempCard.UsedAs = firstNum;
                    tempCard.Suit   = suitOfSet;          //hopefully that is okay (?)
                    tempCol.Add(tempCard);
                    wildCol.RemoveSpecificItem(tempCard); //hopefully still works.
                    x--;
                }
                else
                {
                    if (useSecond == true)
                    {
                        tempCard.UsedAs = (int)tempCard.SecondNumber;
                    }
                    else
                    {
                        tempCard.UsedAs = (int)tempCard.Value;
                    }
                }
                if (tempCard.UsedAs > 14)
                {
                    throw new BasicBlankException("The use as cannot be higher than 14 ever");
                }
            }
            if (wildCol.Count > 0)
            {
                lastNum += 1;
                for (int x = lastNum; x <= 14; x++)
                {
                    if (wildCol.Count == 0)
                    {
                        break;
                    }
                    tempCard        = wildCol.First();
                    tempCard.UsedAs = x;
                    tempCard.Suit   = suitOfSet;
                    tempCol.Add(tempCard);
                    wildCol.RemoveSpecificItem(tempCard);
                }
                whatFirst--;
                for (int x = whatFirst; x >= 1; x += -1)
                {
                    if (wildCol.Count == 0)
                    {
                        break;
                    }
                    tempCard        = wildCol.First(); //hopefully still okay.
                    tempCard.UsedAs = x;
                    tempCard.Suit   = suitOfSet;
                    tempCol.Add(tempCard);
                    wildCol.RemoveSpecificItem(tempCard);
                }
                if (tempCol.Count != originalNumber)
                {
                    throw new BasicBlankException("Must have the same number of cards sent for creating set");
                }
            }
            if (tempCol.Any(items => items.UsedAs == 0))
            {
                throw new BasicBlankException("You must have accounted for all used.  Rethink");
            }
            var tempList = tempCol.OrderBy(items => items.UsedAs).ToRegularDeckDict();

            HandList.ReplaceRange(tempList);
            if (HandList.Count == 0)
            {
                throw new BasicBlankException("HandList Blank");
            }
            _firstNumber = HandList.First().UsedAs;
        }
 //Respond to hand updates from the core
 public void positionDidUpdate(HandList hands)
 {
     foreach (MotionSubscriber subscriber in this.Subscribers)
     {
         if (subscriber.active)
         {
             subscriber.recognizer.positionDidUpdate(hands);
         }
     }
 }
예제 #37
0
    /**
     * Updates hands based on tracking data in the specified Leap HandList object.
     * Active HandModel instances are updated if the hand they represent is still
     * present in the Leap HandList; otherwise, the HandModel is removed. If new
     * Leap Hand objects are present in the Leap HandList, new HandModels are
     * created and added to the HandController hand list.
     * @param all_hands The dictionary containing the HandModels to update.
     * @param leap_hands The list of hands from the a Leap Frame instance.
     * @param left_model The HandModel instance to use for new left hands.
     * @param right_model The HandModel instance to use for new right hands.
     */
    protected void UpdateHandModels(Dictionary <int, HandModel> all_hands,
                                    HandList leap_hands,
                                    HandModel left_model, HandModel right_model)
    {
        List <int> ids_to_check = new List <int>(all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;

        for (int h = 0; h < num_hands; ++h)
        {
            Hand leap_hand = leap_hands[h];

            HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

            // If we've mirrored since this hand was updated, destroy it.
            if (all_hands.ContainsKey(leap_hand.Id) &&
                all_hands[leap_hand.Id].IsMirrored() != mirrorZAxis)
            {
                DestroyHand(all_hands[leap_hand.Id]);
                all_hands.Remove(leap_hand.Id);
            }

            // Only create or update if the hand is enabled.
            if (model != null)
            {
                ids_to_check.Remove(leap_hand.Id);

                // Create the hand and initialized it if it doesn't exist yet.
                if (!all_hands.ContainsKey(leap_hand.Id))
                {
                    HandModel new_hand = CreateHand(leap_hand, model);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                    new_hand.transform.localScale = hand_scale * Vector3.one;

                    new_hand.InitHand();
                    new_hand.UpdateHand();
                    all_hands[leap_hand.Id] = new_hand;
                }
                else
                {
                    // Make sure we update the Leap Hand reference.
                    HandModel hand_model = all_hands[leap_hand.Id];
                    hand_model.SetLeapHand(leap_hand);
                    hand_model.MirrorZAxis(mirrorZAxis);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                    hand_model.transform.localScale = hand_scale * Vector3.one;
                    hand_model.UpdateHand();
                }
            }
        }

        // Destroy all hands with defunct IDs.
        for (int i = 0; i < ids_to_check.Count; ++i)
        {
            DestroyHand(all_hands[ids_to_check[i]]);
            all_hands.Remove(ids_to_check[i]);
        }
    }
예제 #38
0
    // Update is called once per frame
    void Update()
    {
        frame    = LeapController.Frame();              //The latest frame
        previous = LeapController.Frame(1);             //The previous frame

        hands     = frame.Hands;
        LeftHand  = hands.Leftmost;
        RightHand = hands.Rightmost;

        LeftPalmPosition  = LeftHand.PalmPosition;
        RightPalmPosition = RightHand.PalmPosition;

        //FingerList allFingers = frame.Fingers;

        // estraggo il contenuto delle stringhe di selezione impostate dalla VRGUI per
        // vedere quali gesture sono attive
        rotationSelection      = PlayerPrefs.GetString("rotation");
        scaleSelection         = PlayerPrefs.GetString("scale");
        pinchRotationSelection = PlayerPrefs.GetString("pinchRotation");
        pinchScaleSelection    = PlayerPrefs.GetString("pinchScale");



        // faccio un controllo sulle stringhe e metto a true le variabili
        // relative alle gesture che l'utente ha deciso di attivare
        if (pinchScaleSelection.Equals("true"))
        {
            PinchScaleBool = true;
        }
        else
        {
            PinchScaleBool = false;
        }

        if (pinchRotationSelection.Equals("true"))
        {
            PinchRotationBool = true;
        }
        else
        {
            PinchRotationBool = false;
        }

        if (rotationSelection.Equals("true"))
        {
            rotationBool = true;
        }
        else
        {
            rotationBool = false;
        }

        if (scaleSelection.Equals("true"))
        {
            scaleBool = true;
        }
        else
        {
            scaleBool = false;
        }



        if (seeHandsBool == true)
        {
            seeHands();
        }

        if (scaleBool == true)
        {
            scale();
        }

        if (translatePinch == true)
        {
            TranslatePinch();
        }


        // quando seleziono la rotazione con il pinch, controllo che sia fatto con la mano destra e sia maggiore di un dato valore
        // chiamo la funzione per la rotazione
        if (PinchRotationBool)
        {
            if (RightHand.PinchStrength > 0.7f)
            {
                renderer.material = ColorBlue;

                if (RightHand.IsValid && LeftHand.IsValid)
                {
                    PinchRotation();
                }
            }
            else
            {
                renderer.material = ColorRed;
            }
        }



        if (RightHand.PinchStrength > 0.7f)
        {
            renderer.material = ColorBlue;

            if (RightHand.IsValid && LeftHand.IsValid)
            {
                TranslatePinch();
            }
        }
        else
        {
            renderer.material = ColorRed;
        }



        //faccio la stessa procedura con la scala
        if (PinchScaleBool)
        {
            if (RightHand.PinchStrength > 0.7f)
            {
                renderer.material = ColorBlue;

                if (RightHand.IsValid && LeftHand.IsValid)
                {
                    PinchScale();
                }
            }
            else
            {
                renderer.material = ColorRed;
            }
        }


        // se seleziono la rotazione normale, chiamo la funzione rotation
        if (rotationBool)
        {
            Rotation();
        }
    }
    bool CheckGesture()
    {
        return(true);        //comment out to enable attempted gesture recognition

        Leap.Frame frame = LeapInputEx.Frame;
        if (frame == null)
        {
            return(false);
        }

        HandList   hands   = frame.Hands;
        FingerList fingers = frame.Fingers;

        Hand    lh    = hands.Leftmost;
        Hand    rh    = hands.Rightmost;
        Vector3 rpos  = rh.PalmPosition.ToUnityScaled();
        Vector3 rdir  = rh.Direction.ToUnity();
        Vector3 rnorm = rh.PalmNormal.ToUnity();

        float farthestZ     = -10000f;
        int   thumbID       = -1;
        int   otherFingerID = -1;
        int   count         = 0;

        bool rightHandMakingGesture = false;


        //if( making gesture)
        GameObject hand = GameObject.Find("right");

        //for(int x = 0; x < m.fin
        //foreach(Finger finger in fingers)
        foreach (Finger finger in rh.Fingers)
        {
            count += 1;
            if (count == 1)
            {
                otherFingerID = finger.Id;
            }
            if (finger.TipPosition.z > farthestZ)
            {
                thumbID   = finger.Id;
                farthestZ = finger.TipPosition.z;
            }
            else
            {
                otherFingerID = finger.Id;
            }
        }

        float palmFingerAngle = frame.Finger(otherFingerID).Direction.AngleTo(rh.Direction);

        //Debug.Log(palmFingerAngle);

        if (palmFingerAngle < .6 && palmFingerAngle > .35)
        {
            return(true);
        }
        else
        {
            return(false);
        }

        /*
         * //frame.Finger(thumbID).TipPosition.ToUnityScaled())
         * //Debug.DrawRay(frame.Finger(thumbID).TipPosition.ToUnityScaled(),Vector3.forward * 1000f, Color.yellow);
         * //Debug.Log(frame.Finger(thumbID).TipPosition.ToUnityScaled());
         *
         * if(Physics.Raycast(rh.Fingers[thumbID].StabilizedTipPosition.ToUnityScaled(),Vector3.forward))
         * {
         *      rightHandMakingGesture = true;
         *      return true;
         * }
         *
         * //if(count == 2 && rh.Fingers[thumbID].StabilizedTipPosition.ToUnityScaled().
         * //Vector3 rightHandPosition = (frame.Finger(thumbID).TipPosition.ToUnityScaled() + frame.Finger (otherFingerID).TipPosition.ToUnityScaled()) /2;
         *
         * foreach(Finger finger in lh.Fingers)
         * {
         *      count+=1;
         *      if(count == 1)
         *      {
         *              otherFingerID = finger.Id;
         *      }
         *      if(finger.TipPosition.z > farthestZ)
         *      {
         *              thumbID = finger.Id;
         *              farthestZ = finger.TipPosition.z;
         *
         *      }
         *      else
         *      {
         *              otherFingerID = finger.Id;
         *      }
         * }
         *
         *      //return true;
         * //else
         *      return false;
         */
    }
예제 #40
0
    /**
      * Updates hands based on tracking data in the specified Leap HandList object.
      * Active HandModel instances are updated if the hand they represent is still
      * present in the Leap HandList; otherwise, the HandModel is removed. If new
      * Leap Hand objects are present in the Leap HandList, new HandModels are
      * created and added to the HandController hand list.
      * @param all_hands The dictionary containing the HandModels to update.
      * @param leap_hands The list of hands from the a Leap Frame instance.
      * @param left_model The HandModel instance to use for new left hands.
      * @param right_model The HandModel instance to use for new right hands.
      */
    protected void UpdateHandModels(Dictionary<int, HandModel> all_hands,
                                  HandList leap_hands,
                                  HandModel left_model, HandModel right_model)
    {
        List<int> ids_to_check = new List<int>(all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;
        //Debug.Log("Active hands: "+num_hands +" / " +all_hands.Count);

        for (int h = 0; h < num_hands; ++h) {
            Hand leap_hand = leap_hands [h];

            HandModel model = (leap_hand.IsLeft) ? left_model : right_model;

            // If we've mirrored since this hand was updated, destroy it.
            /*if (all_hands.ContainsKey(leap_hand.Id) &&
          all_hands[leap_hand.Id].IsMirrored() != mirrorYAxis) {
        DestroyHand(all_hands[leap_hand.Id]);
        all_hands.Remove(leap_hand.Id);
          }*/

            // Only create or update if the hand is enabled.
            if (model != null) {
                ids_to_check.Remove(leap_hand.Id);

                // Create the hand and initialized it if it doesn't exist yet.
                //EDIT BV and if not both hands sets
                if (!all_hands.ContainsKey(leap_hand.Id)) {
                    //Debug.Log("prepare to call CreateHand");
                    HandModel new_hand = CreateHand(model, leap_hand);
                    //if new_hand is null, it means we already have both hands set. Do not add the new hand.
                    if (new_hand != null) {
                        new_hand.SetLeapHand(leap_hand);
                        //new_hand.MirrorYAxis(mirrorYAxis);
                        new_hand.SetController(this);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                        new_hand.transform.localScale = hand_scale * transform.lossyScale;

                        new_hand.InitHand();
                        new_hand.UpdateHand();
                        all_hands [leap_hand.Id] = new_hand;
                    } //else
                        //Debug.Log("can't create hand. States: left " + lefthand + " | right " + righthand);
                } else {
                    // Make sure we update the Leap Hand reference.
                    HandModel hand_model = all_hands [leap_hand.Id];
                    hand_model.SetLeapHand(leap_hand);
                    //hand_model.MirrorYAxis(mirrorYAxis);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                    hand_model.transform.localScale = hand_scale * transform.lossyScale;
                    hand_model.UpdateHand();
                }
            }
        }

        // Destroy all hands with defunct IDs. (hands out)
        for (int i = 0; i < ids_to_check.Count; ++i) {
            //Debug.LogWarning("Destroying hand with defunct ID : " + ((HandModel)all_hands [ids_to_check [i]]));
            //Debug.LogWarning("States: lefthand:"+lefthand +" );

            //try to guess the right slot to free
            if (all_hands [ids_to_check [i]].GetLeapHand().IsLeft)
            {
                if (lefthand == leftGraphicsModel)
                    lefthand = null;
                else
                    righthand = null;
            }
            else
            {
                if (righthand == rightGraphicsModel)
                    righthand = null;
                else
                    lefthand = null;
            }

            DestroyHand(all_hands [ids_to_check [i]]);
            all_hands.Remove(ids_to_check [i]);

        }
    }
    // Update is called once per frame
    void Update()
    {
        Leap.Frame frame = LeapInputEx.Frame;
        if (frame == null)
        {
            return;
        }
        //Debug.Log(frame.Gestures().Count);
        foreach (Gesture gesture in frame.Gestures())
        {
            /*
             * if(gesture.Type == Leap.Gesture.GestureType.TYPESWIPE)
             * {
             *      //frozen = true;
             *
             * //SwipeGesture swipeGesture = SwipeGesture(gesture);
             *      //if this is a new swipe
             *      if(gestureID != gesture.Id)
             *      {
             *              if(frozen)
             *              {
             *                      Destroy(selectionBox);
             *                      selectionBox = null;
             *              }
             *              //frozen = !frozen;
             *              /*
             *              //destroy old box, so if this isn't first box you don't just move old one, creates problems
             *              if(frozen == false)
             *              {
             *                      Destroy(selectionBox);
             *                      selectionBox = null;
             *              }
             *              Debug.Log("Swiper no swiping!");
             *      }
             * }*/

            if (gesture.Type == Leap.Gesture.GestureType.TYPECIRCLE)
            {
                if (gestureID != gesture.Id)
                {
                    CircleGesture circleGesture = new CircleGesture(gesture);
                    if (circleGesture.Progress >= 2)
                    {
                        frozen = !frozen;
                        //destroy old box, so if this isn't first box you don't just move old one, creates problems
                        if (frozen == false)
                        {
                            Destroy(selectionBox);
                            selectionBox = null;
                        }
                        Debug.Log("Circling!");
                    }
                }
            }

            if (gesture.Type == Leap.Gesture.GestureType.TYPESCREENTAP)
            {
                if (gestureID != gesture.Id)
                {
                    ScreenTapGesture screenTapGesture = new ScreenTapGesture(gesture);
//					Debug.Log (screenTapGesture.Direction);
                    //Debug.Log(screenTapGesture.DurationSeconds);
                    if (screenTapGesture.Direction.z < 0)
                    {
                        frozen = !frozen;                         // if frozen, get rid of old box.
                        //destroy old box, so if this isn't first box you don't just move old one, creates problems
                        if (frozen == false)
                        {
                            Destroy(selectionBox);
                            selectionBox = null;
                        }
                        Debug.Log("Tapped!");
                        //Debug.Log (gesture);
                    }
                }
            }
        }

        HandList   hands   = frame.Hands;
        FingerList fingers = frame.Fingers;

        Hand    lh    = hands.Leftmost;
        Hand    rh    = hands.Rightmost;
        Vector3 rpos  = rh.PalmPosition.ToUnityScaled();
        Vector3 rdir  = rh.Direction.ToUnity();
        Vector3 rnorm = rh.PalmNormal.ToUnity();
        Vector3 lpos  = lh.PalmPosition.ToUnityScaled();

        float farthestZ     = -10000f;
        int   thumbID       = -1;
        int   otherFingerID = -1;
        int   count         = 0;

        GameObject hand = GameObject.Find("right");

        #region defining thumb/other fingers
        //for(int x = 0; x < m.fin
        //foreach(Finger finger in fingers)
        foreach (Finger finger in rh.Fingers)
        {
            count += 1;
            if (count == 1)
            {
                otherFingerID = finger.Id;
            }
            if (finger.TipPosition.z > farthestZ)
            {
                thumbID   = finger.Id;
                farthestZ = finger.TipPosition.z;
            }
            else
            {
                otherFingerID = finger.Id;
            }
        }

        Vector3 rightHandPosition = (frame.Finger(thumbID).TipPosition.ToUnityScaled() + frame.Finger(otherFingerID).TipPosition.ToUnityScaled()) / 2;
        count = 0;
        foreach (Finger finger in lh.Fingers)
        {
            count += 1;
            if (count == 1)
            {
                otherFingerID = finger.Id;
            }
            if (finger.TipPosition.z > farthestZ)
            {
                thumbID   = finger.Id;
                farthestZ = finger.TipPosition.z;
            }
            else
            {
                otherFingerID = finger.Id;
            }
        }
        Vector3 leftHandPosition = (frame.Finger(thumbID).TipPosition.ToUnityScaled() + frame.Finger(otherFingerID).TipPosition.ToUnityScaled()) / 2;

        #endregion

        //get positions of left and right hand models
        if (GameObject.Find("RightRiggedHand(Clone)"))
        {
            rpos        = GameObject.Find("RightRiggedHand(Clone)").transform.position;
            handsObject = GameObject.Find("RightRiggedHand(Clone)");
        }
        if (GameObject.Find("LeftRiggedHand(Clone)"))
        {
            lpos = GameObject.Find("LeftRiggedHand(Clone)").transform.position;
        }

        //box position is in the middle of two hand models
        Vector3 boxPosition = Vector3.Lerp(lpos, rpos, 0.5f);

        if (!frozen)
        {
            //Debug.Log ("boxPosition: " + boxPosition);
            if (selectionBox == null && GameObject.Find("RightRiggedHand(Clone)"))
            {
                Transform box = Instantiate(selectionBoxObject, new Vector3(0, 0, 0), Quaternion.identity) as Transform;
                selectionBox = box.gameObject;                //(GameObject)(selectionBox);
                selectionBox.renderer.material.color = Color.blue;
                //GameObject handsObject = GameObject.Find("RightRiggedHand(Clone)");
                //handsObject.transform.position = new Vector3(0,0,0);

                //set position of box
                selectionBox.transform.localPosition = boxPosition;                // + new Vector3(boxPosition.x,0,0);
                //selectionBox.transform.parent = handsObject.transform;


                //don't rotate box based on hands rotation
                selectionBox.transform.rotation = Quaternion.identity;
                //selectionBox.transform.rotation = selectionBox.transform.parent.rotation;
                //selectionBox.transform.Rotate(new Vector3(0,0,90f));
                //selectionBox.AddComponent("BoxCollider");
                //Debug.Log("not frozen, doesn't exist");
            }
            if (selectionBox != null && GameObject.Find("RightRiggedHand(Clone)"))
            {
                /*
                 * Destroy(selectionBox);
                 * selectionBox = null;
                 *
                 * Transform box = Instantiate(selectionBoxObject,new Vector3(0,0,0),Quaternion.identity) as Transform;
                 * selectionBox = box.gameObject;//(GameObject)(selectionBox);
                 * selectionBox.renderer.material.color = Color.blue;
                 * GameObject handsObject = GameObject.Find("Primary Hand");
                 * //handsObject.transform.position = new Vector3(0,0,0);
                 * selectionBox.transform.localPosition = new Vector3(0f,-2f,2.5f) + boxPosition;
                 * selectionBox.transform.parent = handsObject.transform;*/


                //GameObject handsObject = GameObject.Find("RightRiggedHand(Clone)");

                selectionBox.transform.localPosition = boxPosition;                // + new Vector3(boxPosition.x,0,0);
                //selectionBox.transform.parent = handsObject.transform;

                selectionBox.transform.rotation = Quaternion.identity;
                //selectionBox.transform.rotation = selectionBox.transform.parent.rotation;

                Vector3 handDiff = lpos - rpos;
                float   xDiff    = (float)(Math.Sqrt(Math.Pow(handDiff.x, 2f))) / 2f;
                float   yDiff    = (float)(Math.Sqrt(Math.Pow(handDiff.y, 2f))) * .75f;
                float   zDiff    = (float)(Math.Sqrt(Math.Pow(handDiff.z, 2f))) * 1f;


                //limit how small box can be
                float minScale = 0.1f;

                if (xDiff < minScale)
                {
                    xDiff = minScale;
                }
                if (yDiff < minScale)
                {
                    yDiff = minScale;
                }
                if (zDiff < minScale)
                {
                    zDiff = minScale;
                }

                //limit how large box can be
                float maxScale = 1f;

                if (xDiff > maxScale)
                {
                    xDiff = maxScale;
                }
                if (yDiff > maxScale)
                {
                    yDiff = maxScale;
                }
                if (zDiff > maxScale)
                {
                    zDiff = maxScale;
                }


                Vector3 newScale = new Vector3(xDiff, yDiff, zDiff);
                //Debug.Log (newScale);

                selectionBox.transform.localScale = newScale;

                /*
                 * if(xDiff > 1 && yDiff > 1 && zDiff > 1) // minimum scale
                 * {
                 *      selectionBox.transform.localScale = newScale;
                 * }
                 * else
                 * {
                 *      selectionBox.transform.localScale = Vector3.one;
                 * }
                 */
                //Debug.Log("not frozen, but exists");
            }
        }
        else
        {
            if (selectionBox != null)
            {
                selectionBox.renderer.material.color = Color.red;
                Vector3 temp = selectionBox.transform.position;
                selectionBox.transform.parent   = null;
                selectionBox.transform.position = temp;
                //Debug.Log("frozen and exists");
                //Destroy(selectionBox);
                //selectionBox = null;
            }
        }
    }
예제 #42
0
        public void update(ref SLLeapHand h, ref SLLeapHand dh)
        {
            if (!mController.IsConnected)
            {
                return;
            }

            // Get the most recent frame and report some basic information
            Frame         frame      = mController.Frame();
            HandList      hands      = frame.Hands;
            PointableList pointables = frame.Pointables;
            FingerList    fingers    = frame.Fingers;
            ToolList      tools      = frame.Tools;

            for (int ih = 0; ih < 2; ih++)
            {
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        dh.born[ih, i, j] = h.born[ih, i, j];
                    }
                }
            }

            int hi = 0;

            foreach (Hand hand in hands)
            {
                int fi = 0;
                foreach (Finger f in hand.Fingers)
                {
                    Bone b = f.Bone(Bone.BoneType.TYPE_DISTAL);
                    h.born[hi, fi, 0].X = b.NextJoint.x / scale;
                    h.born[hi, fi, 0].Y = b.NextJoint.y / scale - yoffset;
                    h.born[hi, fi, 0].Z = b.NextJoint.z / scale;
                    h.born[hi, fi, 1].X = b.PrevJoint.x / scale;
                    h.born[hi, fi, 1].Y = b.PrevJoint.y / scale - yoffset;
                    h.born[hi, fi, 1].Z = b.PrevJoint.z / scale;
                    b = f.Bone(Bone.BoneType.TYPE_INTERMEDIATE);
                    h.born[hi, fi, 2].X = b.PrevJoint.x / scale;
                    h.born[hi, fi, 2].Y = b.PrevJoint.y / scale - yoffset;
                    h.born[hi, fi, 2].Z = b.PrevJoint.z / scale;
                    b = f.Bone(Bone.BoneType.TYPE_PROXIMAL);
                    h.born[hi, fi, 3].X = b.PrevJoint.x / scale;
                    h.born[hi, fi, 3].Y = b.PrevJoint.y / scale - yoffset;
                    h.born[hi, fi, 3].Z = b.PrevJoint.z / scale;
                    b = f.Bone(Bone.BoneType.TYPE_METACARPAL);
                    h.born[hi, fi, 4].X = b.PrevJoint.x / scale;
                    h.born[hi, fi, 4].Y = b.PrevJoint.y / scale - yoffset;
                    h.born[hi, fi, 4].Z = b.PrevJoint.z / scale;
                    fi++;
                }
                hi++;

                if (hi >= maxhand)
                {
                    break;
                }
            }

            for (int ih = 0; ih < 2; ih++)
            {
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        dh.born[ih, i, j] = h.born[ih, i, j] - dh.born[ih, i, j];
                    }
                }
            }
        }
 public override Task PopulateSaveRootAsync()
 {
     SaveRoot !.Combos   = _model !.ComboHandList !.HandList.GetDeckListFromObjectList();
     SaveRoot.ChanceList = _chanceList.GetDeckListFromObjectList();
     return(base.PopulateSaveRootAsync());
 }
예제 #44
0
    /**
     * Makes sure the physics hands are instantiated or updated as required
     * */
    protected void UpdatePhysicsHandModels(Dictionary <int, HandModel> all_hands,
                                           HandList leap_hands,
                                           HandModel left_model, HandModel right_model)
    {
        List <int> ids_to_check = new List <int>(all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;

        for (int h = 0; h < num_hands; ++h)
        {
            Hand leap_hand = leap_hands[h];

            HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

            // If we've mirrored since this hand was updated, destroy it.
            if (all_hands.ContainsKey(leap_hand.Id) &&
                all_hands[leap_hand.Id].IsMirrored() != mirrorZAxis)
            {
                DestroyHand(all_hands[leap_hand.Id]);
                all_hands.Remove(leap_hand.Id);
            }

            // Only create or update if the hand is enabled.
            if (model != null)
            {
                ids_to_check.Remove(leap_hand.Id);
                // Create the hand and initialized it if it doesn't exist yet.
                if (!all_hands.ContainsKey(leap_hand.Id))
                {
                    HandModel new_hand = CreateHand(model, leap_hand.IsLeft);
                    new_hand.SetLeapHand(leap_hand);
                    new_hand.MirrorZAxis(mirrorZAxis);
                    new_hand.SetController(this);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                    new_hand.transform.localScale = hand_scale * transform.lossyScale;

                    all_hands[leap_hand.Id] = new_hand;                         //bugfix: adding to list before init/update, because if it errors during that process then it'll never get into the list and thus never be removed...
                    new_hand.InitHand();
                    new_hand.UpdateHand();

                    //Debug.Log ("Added " + leap_hand.Id + " to physics list");
                    //Debug.Log ("Created a physics hand and added to active physics hands list, now contains " + all_hands.Count + " hands");
                }
                else
                {
                    //Debug.Log ("Updated a physics hand");
                    // Make sure we update the Leap Hand reference.
                    HandModel hand_model = all_hands[leap_hand.Id];
                    hand_model.SetLeapHand(leap_hand);
                    hand_model.MirrorZAxis(mirrorZAxis);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                    hand_model.transform.localScale = hand_scale * transform.lossyScale;
                    hand_model.UpdateHand();
                }
            }
        }

        // Destroy all hands with defunct IDs.
        for (int i = 0; i < ids_to_check.Count; ++i)
        {
            DestroyHand(all_hands[ids_to_check[i]]);
            //Debug.Log ("Destroyed " + ids_to_check[i] + " from physics list because it was defunct");
            all_hands.Remove(ids_to_check[i]);
        }
    }
        public override void positionDidUpdate(HandList hands)
        {
            this.hands = hands;

            if (this.hands.Count == this.NumberOfHandsRequired)
            {
                if (isDesiredNumberOfFingersPerHand())
                {
                    if (isPinching()) {
                    switch (this.state) {
                        case MotionGestureRecognizerState.MotionGestureRecognizerStatePossible:
                            //Helps with false positives due to change of direction
                            this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateBegan;
                            break;
                        case MotionGestureRecognizerState.MotionGestureRecognizerStateBegan:
                            this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateChanged;
                            break;
                        case MotionGestureRecognizerState.MotionGestureRecognizerStateChanged:
                            this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateChanged;
                            break;
                        case MotionGestureRecognizerState.MotionGestureRecognizerStateEnded:
                            this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateBegan;
                            break;
                        default:
                            break;
                    }
                }
                else {
                    switch (this.state) {
                        case MotionGestureRecognizerState.MotionGestureRecognizerStateBegan:
                            if (decelerationCounter > 1) {
                                decelerationCounter = 0;
                                this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateEnded;
                            }
                            else {
                                decelerationCounter++;
                            }
                            break;
                        case MotionGestureRecognizerState.MotionGestureRecognizerStateChanged:
                            if (decelerationCounter > 1) {
                                decelerationCounter = 0;
                                this.state = MotionGestureRecognizerState.MotionGestureRecognizerStateEnded;
                            }
                            else {
                                decelerationCounter++;
                            }
                            break;
                        case MotionGestureRecognizerState.MotionGestureRecognizerStateEnded:
                            this.state = MotionGestureRecognizerState.MotionGestureRecognizerStatePossible;
                            break;
                        default:
                            break;
                    }
                }
                
                //Call back
                    callback();
                }
            }
        
        }
예제 #46
0
    /**
     * Updates hands based on tracking data in the specified Leap HandList object.
     * Active HandModel instances are updated if the hand they represent is still
     * present in the Leap HandList; otherwise, the HandModel is removed. If new
     * Leap Hand objects are present in the Leap HandList, new HandModels are
     * created and added to the HandController hand list.
     * @param all_hands The dictionary containing the HandModels to update.
     * @param leap_hands The list of hands from the a Leap Frame instance.
     * @param left_model The HandModel instance to use for new left hands.
     * @param right_model The HandModel instance to use for new right hands.
     */
    protected void UpdateHandModels(Dictionary <int, HandModel> all_hands,
                                    HandList leap_hands,
                                    HandModel left_model, HandModel right_model)
    {
        List <int> ids_to_check = new List <int> (all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;

        for (int h = 0; h < num_hands; ++h)
        {
            Hand leap_hand = leap_hands [h];

            //Get the finger_tip location if finger is pinched
            if (leap_hand.PinchStrength > 0.2)
            {
                if (linePoints.Count == 0)
                {
                    lineRenderer.SetVertexCount(0);
                }

                FingerList point   = leap_hand.Fingers.FingerType(Finger.FingerType.TYPE_INDEX);
                Vector3    new_tip = UnityVectorExtension.ToUnity(point [0].TipPosition);
                new_tip.x = new_tip.x * 1.5f;



                lineRenderer.SetPosition(lineRenderer.positionCount - 1, new_tip);

                lineRenderer.positionCount = lineRenderer.positionCount + 1;
                lineRenderer.SetPosition(lineRenderer.positionCount - 1, new_tip);
                linePoints.Add(new_tip);
                Debug.Log("pinching: " + linePoints.Count);
                //Debug.Log (linePoints [linePoints.Count - 1]);
                if (numPoint % 15 == 0)
                {
                    lineRenderer.Simplify(.1f);
                }
                numPoint++;
            }
            else
            {
                //transform.Translate(Vector3.up * Time.deltaTime*50);

                if (linePoints.Count > 0)
                {
                    Debug.Log("not pinching: " + convertVectorListToString(linePoints) + linePoints.Count);
                    StartCoroutine(GetText());
                    //lineRenderer = gameObject.AddComponent<LineRenderer> ();
                    //lineRenderer.positionCount = 100;

                    tex = new Texture2D(128, 128);

                    string fromBase64 = equaIMG;
                    byte[] data       = System.Convert.FromBase64String(fromBase64);
                    tex.LoadImage(data);


                    cube = GameObject.Find("Cube");
                    cube.transform.position   = new Vector3(0, -100, 0);
                    cube.transform.localScale = new Vector3(tex.width * 2, tex.height * 2, 10);
                    //cube.transform.Rotate(new Vector3(0, 0, 180));

                    m_Material             = cube.GetComponent <Renderer> ().material;
                    m_Material.mainTexture = tex;


                    linePoints.Clear();
                    lineRenderer.SetVertexCount(0);

                    //lineRenderer = GetComponent<LineRenderer>();
                    lineRenderer.positionCount = equaPoints.Count;
                    lineRenderer.SetPositions(equaPoints.ToArray());
                }
                else
                {
                }
                int b = checkSwipe(leap_hand);
                if (b != 0)
                {
                    curAngle     = b * 30 * Time.deltaTime;
                    cameraObj    = GameObject.Find("Main Camera");
                    rotateAround = GameObject.Find("HandController").GetComponent <Transform> ();

                    cameraObj.transform.LookAt(rotateAround.position);
                    cameraObj.transform.RotateAround(rotateAround.position, Vector3.up, curAngle);                     //.5f);
                    //lineRenderer.transform.RotateAround(Vector3.zero, Vector3.up, b*30 * Time.deltaTime);
                }



                HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

                // If we've mirrored since this hand was updated, destroy it.
                if (all_hands.ContainsKey(leap_hand.Id) &&
                    all_hands [leap_hand.Id].IsMirrored() != mirrorZAxis)
                {
                    DestroyHand(all_hands [leap_hand.Id]);
                    all_hands.Remove(leap_hand.Id);
                }

                // Only create or update if the hand is enabled.
                if (model != null)
                {
                    ids_to_check.Remove(leap_hand.Id);
                    // Create the hand and initialized it if it doesn't exist yet.
                    if (!all_hands.ContainsKey(leap_hand.Id))
                    {
                        HandModel new_hand = CreateHand(model);
                        new_hand.SetLeapHand(leap_hand);
                        new_hand.MirrorZAxis(mirrorZAxis);
                        new_hand.SetController(this);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                        new_hand.transform.localScale = hand_scale * transform.lossyScale;
                        //new_hand.transform.RotateAround(Vector3.zero, Vector3.up, -curAngle);
                        new_hand.InitHand();

                        new_hand.UpdateHand();
                        all_hands [leap_hand.Id] = new_hand;
                    }
                    else
                    {
                        // Make sure we update the Leap Hand reference.
                        HandModel hand_model = all_hands [leap_hand.Id];
                        hand_model.SetLeapHand(leap_hand);
                        hand_model.MirrorZAxis(mirrorZAxis);

                        // Set scaling based on reference hand.
                        float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                        hand_model.transform.localScale = hand_scale * transform.lossyScale;
                        hand_model.UpdateHand();
                    }
                }
            }

            // Destroy all hands with defunct IDs.
            for (int i = 0; i < ids_to_check.Count; ++i)
            {
                DestroyHand(all_hands [ids_to_check [i]]);
                all_hands.Remove(ids_to_check [i]);
            }
        }
    }
예제 #47
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();
        //set rotation of hand to match myo
        HandList hands = frame.Hands;

        foreach (Hand hand in hands)
        {
            if (hand.IsValid)
            {
                if (left == hand.IsLeft)
                {
                    Vector3 wristPosition    = hand.WristPosition.ToUnity();
                    Vector3 shoulderPosition = transform.position;

                    upperArm.transform.rotation = Quaternion.FromToRotation(
                        new Vector3(-myoUpper.transform.forward.x, -myoUpper.transform.forward.y, myoUpper.transform.forward.z),
                        new Vector3(1, 0, 0)
                        );
                    ThalmicMyo thalmicMyo = myoUpper.GetComponent <ThalmicMyo> ();

                    // The above calculations were done assuming the Myo armbands's +x direction, in its own coordinate system,
                    // was facing toward the wearer's elbow. If the Myo armband is worn with its +x direction facing the other way,
                    // the rotation needs to be updated to compensate.
                    if (thalmicMyo.xDirection == Thalmic.Myo.XDirection.TowardWrist)
                    {
                        // Mirror the rotation around the XZ plane in Unity's coordinate system (XY plane in Myo's coordinate
                        // system). This makes the rotation reflect the arm's orientation, rather than that of the Myo armband.
                        upperArm.transform.rotation = new Quaternion(upperArm.transform.localRotation.x,
                                                                     -upperArm.transform.localRotation.y,
                                                                     upperArm.transform.localRotation.z,
                                                                     -upperArm.transform.localRotation.w);
                    }

                    Vector3 direction = wristPosition - lowerArm.transform.position;
                    direction = Vector3.Normalize(direction);
                    lowerArm.transform.rotation = Quaternion.LookRotation(direction);
                    Vector3 scale = new Vector3(1, 1, 1);
                    //scale.x = Vector3.Distance(lowerArm.transform.position, wristPosition);
                    lowerArm.transform.localScale = scale;

                    /*
                     * // The above calculations were done assuming the Myo armbands's +x direction, in its own coordinate system,
                     * // was facing toward the wearer's elbow. If the Myo armband is worn with its +x direction facing the other way,
                     * // the rotation needs to be updated to compensate.
                     * if (thalmicMyo.xDirection == Thalmic.Myo.XDirection.TowardWrist) {
                     *      // Mirror the rotation around the XZ plane in Unity's coordinate system (XY plane in Myo's coordinate
                     *      // system). This makes the rotation reflect the arm's orientation, rather than that of the Myo armband.
                     *      lowerArm.transform.rotation = new Quaternion(lowerArm.transform.localRotation.x,
                     *                                                   -lowerArm.transform.localRotation.y,
                     *                                                   lowerArm.transform.localRotation.z,
                     *                                                   -lowerArm.transform.localRotation.w);
                     * }
                     */
                    // Access the ThalmicMyo component attached to the Myo object.
                    //updateArmPosition(myoLower, lowerArm, _antiYawLower, _referenceRollLower);
                    //updateArmPosition(myoUpper, upperArm, _antiYawUpper, _referenceRollUpper);
                }
            }
        }
    }
예제 #48
0
    /// </summary>
    ///
    // Update is called once per frame
    void Update()
    {
        float x;

        /*    if (isClient.)
         *  {
         *      float x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
         *      float z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
         *
         *
         *      transform.Rotate(0, x, 0);
         *      transform.Translate(0, 0, z);
         *
         *      if (Input.GetKeyDown(KeyCode.Space))
         *      {
         *          Fire_t();
         *
         *      }
         *      //void Update()
         *
         *      Debug.Log("UPDATE");
         *      //Frame frame = Controller.Frame();
         *      //GestureList gestures = frame.Gestures();
         *
         *
         *
         *  }
         */
        if (!isLocalPlayer)
        {
            return;
        }

        x = Input.GetAxis("Horizontal");
        //Debug.Log(x);
        x = x * Time.deltaTime * 4.0f;

        float z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;

        float x_1 = 2 * Time.deltaTime * 50.0f;
        float z_1 = 8 * Time.deltaTime * 1.0f;

        //Debug.Log(x);

        //transform.Translate(x, 0, 0);

        /*
         * if (x==0.0)
         * {
         *  fuenteAudio.clip = moverse;
         *  fuenteAudio.Play();
         *  Debug.Log(x);
         *
         * }*/

        transform.Translate(x, 0, 0);
        //x = 0;
        //transform.Rotate(0, x, 0);
        //transform.Translate(0, x|, 0);

        Frame frame = Controller.Frame();

        HandList hands  = frame.Hands;
        Hand     hands_ = frame.Hands.Frontmost;

        Hand HandLeft  = frame.Hands.Leftmost;
        Hand HandRight = frame.Hands.Rightmost;

        //HandLeftRot = HandLeft.Direction;
        //Debug.Log("Left rot: " + HandLeftRot);
        HandRightPos = HandRight.PalmPosition;
        Debug.Log("Right pos: " + HandRightPos);
        Debug.Log(HandRightPos.x);
        if (hands_.IsRight)
        {
            Debug.Log("DEEEEEEREEEVHAAAAA");
            //            transform.Translate(-x, 0, 0);
            //transform.Translate(new Vector3(1 * Time.deltaTime * 10.0f, 0, 0));
            if (HandPalmRoll > -2f && HandPalmRoll < 3.5f)
            {
                if (HandRightPos.x < 0)
                {
                    transform.Translate(new Vector3(-1 * Time.deltaTime * 7.0f, 0, 0));
                    //    Debug.Log("DEEEEEEREEEVHAAAAA");
                    fuenteAudio.clip = moverse;
                    fuenteAudio.Play();
                }
                if (HandRightPos.x > 0)
                {
                    transform.Translate(new Vector3(1 * Time.deltaTime * 7.0f, 0, 0));
                    ///  Debug.Log("IZQUIERRRRDAAAAAAAA");
                    fuenteAudio.clip = moverse;
                    fuenteAudio.Play();
                }
            }
            //if (HandPalmYam < -2.2f)
            //{

            //                Fire();
            //          }
        }

        if (hands_.IsLeft)
        {
            //Debug.Log("DEEEEEEREEEVHAAAAA");
            //            transform.Translate(-x, 0, 0);
            //transform.Translate(new Vector3(1 * Time.deltaTime * 10.0f, 0, 0));
            if (HandPalmYam > -2.2f)
            {
                CmdFire();
            }
        }


        if (frame.Hands.Count > 0)
        {
            Hand fristHand = hands[0];
        }
        HandPalmPith = hands[0].PalmNormal.Pitch;
        HandPalmRoll = hands[0].PalmNormal.Roll;
        //       HandPalmRollRight = hand.;
        //            hands[0].PalmNormal.Roll;

        HandPalmYam = hands[0].PalmNormal.Yaw;

        HandWristRot = hands[0].WristPosition.Pitch;

        //Debug.Log("Pitch :" + HandPalmPith);
        Debug.Log("Roll :" + HandPalmRoll);
        //Debug.Log("Yum :" + HandPalmYam);

        //if (HandPalmPith > -2f && HandPalmPith < 3.5f)
        //{
        //  Fire();
        //transform.Translate(new Vector3(-1 * Time.deltaTime * 10.0f, 0, 0));
        //transform.Translate(x, 0, 0);
        //}
        //else if (HandPalmPith < -2.2f) {
        //            transform.Translate(-x, 0, 0);
        //  transform.Translate(new Vector3(1 * Time.deltaTime * 10.0f, 0, 0));

        //}

        /*        else if (HandPalmYam < -2.2f)
         *      {
         *          //            transform.Translate(-x, 0, 0);
         *          transform.Translate(new Vector3(1 * Time.deltaTime * 10.0f, 0, 0));
         *
         */
        if (Input.GetKeyDown(KeyCode.Space))
        {
            //x = 5;
            Debug.Log("entro a espacio");
            CmdFire_friend();
            //CmdFire();
        }
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            //x = 5;
            Debug.Log("entro a espacio");
            CmdFire();
            //CmdFire();
        }
    }
예제 #49
0
 public void CreateSet(IDeckDict <RegularRummyCard> thisList)
 {
     thisList.ForEach(thisCard => UpdateCard(thisCard));
     HandList.ReplaceRange(thisList);
 }
예제 #50
0
    void Update()
    {
        frame = LEAPcontroller.Frame();


        Hands = frame.Hands;
        if (Hands.Count == 0 || Hands.Count > 1)
        {
            return;
        }

        //Vector3 unityPos = Hands[0].PalmPosition.ToUnityScaled(false);
        // Vector3 worldPos = handcontroller.transform.TransformPoint(unityPos);

        // Palm.gameObject.transform.position = worldPos;

        //https://developer.leapmotion.com/documentation/unity/api/Leap_Classes.html?proglang=unity
        float[] arr = Hands[0].PalmPosition.ToFloatArray();
        PalmPosition = new Vector3(arr[0] / 100, arr[1] / 100, -arr[2] / 100 - 8);

        Debug.Log("Palm Position: " + PalmPosition);
        if (-arr[2] / 100 - 8 > -7.0)
        {
            if (arr[0] / 100 < -1.3)
            {
                Debug.Log("Forced Appliedx");
                rb.velocity = new Vector3(-40, 0, 10);
            }

            else if (arr[0] / 100 > 1.1)
            {
                Debug.Log("Forced Reversedx");
                rb.velocity = new Vector3(40, 0, 10);
            }
            else
            {
                Debug.Log("Nullx");

                rb.velocity = new Vector3(0, 0, 40);
            }
        }

        else if (-arr[2] / 100 - 8 < -8.8)
        {
            if (arr[0] / 100 < -1.3)
            {
                Debug.Log("Forced Appliedx");
                rb.velocity = new Vector3(-40, 0, -40);
            }

            else if (arr[0] / 100 > 1.1)
            {
                Debug.Log("Forced Reversedx");
                rb.velocity = new Vector3(40, 0, -40);
            }
            else
            {
                Debug.Log("Nullx");

                rb.velocity = new Vector3(0, 0, -40);
            }
        }
        else
        {
            if (arr[0] / 100 < -1.3)
            {
                Debug.Log("Forced Appliedx");
                rb.velocity = new Vector3(-40, 0, 0);
            }

            else if (arr[0] / 100 > 1.1)
            {
                Debug.Log("Forced Reversedx");
                rb.velocity = new Vector3(40, 0, 0);
            }
            else
            {
                Debug.Log("Nullx");

                rb.velocity = Vector3.zero;
            }
        }



        //Palm.gameObject.transform.position = PalmPosition;

        GestureList gesturesInFrame = frame.Gestures();

        if (!gesturesInFrame.IsEmpty)
        {
            // Debug.Log(gesturesInFrame[0].Type);


            foreach (Gesture gesture in gesturesInFrame)
            {
                if (gesture.Type == Gesture.GestureType.TYPE_CIRCLE)
                {
                    Debug.Log(gesturesInFrame[0].Type);
                    Debug.Log(Hands[0].PalmPosition);
                    // float[] arr = Hands[0].PalmPosition.ToFloatArray();
                    // Debug.Log(PalmPosition);

                    // PalmPosition = new Vector3(arr[0]/100, arr[1]/100, -arr[2]/100-8);
                    // Debug.Log(PalmPosition);


                    // Palm.gameObject.transform.position = PalmPosition;
                }
            }
        }
        //HandModel handModel = GetComponent<HandModel>();
        //PalmPosition  = handModel.transform.TransformPoint(handModel.GetLeapHand().Fingers[0].TipPosition.ToUnityScaled());

        //PalmPosition = Hands[0].PalmPosition.ToUnityScaled();
        //Palm.gameObject.transform.up = PalmPosition*1*Time.deltaTime;
    }
 public override void LoadSet(SavedSet Object)
 {
     WhatSet = Object.WhatSet;
     HandList.ReplaceRange(Object.CardList);
 }
예제 #52
0
    //Gesture Even ZoomInOut
    void ZoomInOut(Gesture gesture, HandList handsForGesture)
    {
        Debug.Log("left zoom");
        SwipeGesture Swipe = new SwipeGesture(gesture);
        Vector swipeDirection = Swipe.Direction;
        float temp = 0;
        if (swipeDirection.x < 0 && handsForGesture[0].IsLeft
            || swipeDirection.x > 0 && handsForGesture[0].IsRight)
        {

            if (leftCamera.GetComponent<Camera>().fieldOfView < maxFov)
            {
                temp = zoomScale;
            }

        }
        else if (swipeDirection.x > 0 && handsForGesture[0].IsLeft
                 || swipeDirection.x < 0 && handsForGesture[0].IsRight)
        {
            if (leftCamera.GetComponent<Camera>().fieldOfView > minFov)
            {
                temp = zoomScale * -1; ;
            }
        }

        leftCamera.GetComponent<Camera>().fieldOfView += temp;
        rightCamera.GetComponent<Camera>().fieldOfView += temp;
    }
예제 #53
0
        /// <summary>
        /// Stop capture.
        /// </summary>
        public void StopSensor()
        {
            this.controller.Dispose();
            this.CurrentFeatures = LeapFeatures.None;
            this.controller = null;
            this.hands = null;
            this.currentFrame = null;

            this.graphicsDevice.Textures.DestroyTexture(this.depthTexture);
        }
예제 #54
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        Debug.Log("Frame Id: " + frame.Id);
        frameCount++;

        HandList hands = frame.Hands;

        for (int i = 0; i < hands.Count; i++)
        {
            Hand        hand         = hands[i];
            Leap.Vector direction    = hand.Direction;
            Leap.Vector palmNormal   = hand.PalmNormal;
            Leap.Vector palmPosition = hand.PalmPosition;
            Leap.Vector handSpeed    = hand.PalmVelocity;


            if (i == 0)
            {
                fdistanceDirection    = direction.DistanceTo(fprevDirection);
                fdistancePalmPosition = palmPosition.DistanceTo(fprevPalmPosition);
                fdistancePalmNormal   = palmNormal.DistanceTo(fprevPalmNormal);
                fdistanceHandVelocity = handSpeed.DistanceTo(fprevHandVelocity);

                fprevDirection    = direction;
                fprevPalmNormal   = palmNormal;
                fprevPalmPosition = palmPosition;
                fprevHandVelocity = handSpeed;
            }
            else if (i == 1)
            {
                sdistanceDirection    = direction.DistanceTo(sprevDirection);
                sdistancePalmPosition = palmPosition.DistanceTo(sprevPalmPosition);
                sdistancePalmNormal   = palmNormal.DistanceTo(sprevPalmNormal);
                sdistanceHandVelocity = handSpeed.DistanceTo(sprevHandVelocity);

                sprevDirection    = direction;
                sprevPalmNormal   = palmNormal;
                sprevPalmPosition = palmPosition;
                sprevHandVelocity = handSpeed;

                Debug.Log("first direction " + fdistanceDirection);
                Debug.Log("second direction " + sdistanceDirection);

                Debug.Log("Direction change = " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("");
                directionFile.WriteLine("frame id: " + frame.Id);
                directionFile.WriteLine("Direction first: " + fdistanceDirection + " second: " + sdistanceDirection + " diff: " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("PalmPosition first: " + fdistancePalmPosition + " second: " + sdistancePalmPosition + " diff: " + (fdistancePalmPosition - sdistancePalmPosition));
                directionFile.WriteLine("PalmNormal first: " + fdistancePalmNormal + " second: " + sdistancePalmNormal + " diff: " + (fdistancePalmNormal - sdistancePalmNormal));
                directionFile.WriteLine("Velocity first: " + fdistanceHandVelocity + " second: " + sdistanceHandVelocity + " diff: " + (fdistanceHandVelocity - sdistanceHandVelocity));

                directionFile.WriteLine("");
                float directionChange    = (fdistanceDirection - sdistanceDirection);
                float palmPositionChange = fdistancePalmPosition - sdistancePalmPosition;
                float palmNormalChange   = fdistancePalmNormal - sdistancePalmNormal;
                float velocityChange     = fdistanceHandVelocity - sdistanceHandVelocity;

                if (directionChange < 0.0f)
                {
                    directionChange *= -1.0f;
                }
                if (palmPositionChange < 0.0f)
                {
                    palmPositionChange *= -1.0f;
                }
                if (palmNormalChange < 0.0f)
                {
                    palmNormalChange *= -1.0f;
                }
                if (velocityChange < 0.0f)
                {
                    velocityChange *= -1.0f;
                }

                totalDistance     += directionChange;
                totalPalmPosition += palmPositionChange;
                totalPalmNormal   += palmNormalChange;
                totalVelocity     += velocityChange;
            }
        }
    }
예제 #55
0
        /// <summary>
        /// Update the service.
        /// </summary>
        /// <param name="gameTime">The current game time.</param>
        public override void Update(TimeSpan gameTime)
        {
            if (this.IsReady)
            {
                this.CurrentFrame = this.controller.Frame();

                if (this.CurrentFeatures.HasFlag(LeapFeatures.Hands))
                {
                    this.hands = this.CurrentFrame.Hands;

                    this.leftHand = null;
                    this.rightHand = null;

                    foreach (var hand in this.hands)
                    {
                        if (hand.IsValid)
                        {
                            if (hand.IsLeft)
                            {
                                if (this.leftHand == null)
                                {
                                    this.leftHand = hand;
                                }
                                else
                                {
                                    this.rightHand = hand;
                                }
                            }
                            else if (hand.IsRight)
                            {
                                if (this.rightHand == null)
                                {
                                    this.rightHand = hand;
                                }
                                else
                                {
                                    this.leftHand = hand;
                                }
                            }
                        }
                    }
                }

                if (this.CurrentFeatures.HasFlag(LeapFeatures.Gestures))
                {
                    foreach (var gesture in this.CurrentFrame.Gestures())
                    {
                        if (gesture.State == Gesture.GestureState.STATESTOP)
                        {
                            switch (gesture.Type)
                            {
                                case Gesture.GestureType.TYPECIRCLE:
                                    if (this.OnGestureCircle != null)
                                    {
                                        this.OnGestureCircle(this.currentFrame, new LeapGestureEventArgs(gesture));
                                    }

                                    break;
                                case Gesture.GestureType.TYPEKEYTAP:
                                    if (this.OnGestureTap != null)
                                    {
                                        this.OnGestureTap(this.currentFrame, new LeapGestureEventArgs(gesture));
                                    }

                                    break;
                                case Gesture.GestureType.TYPESCREENTAP:
                                    if (this.OnGestureScreenTap != null)
                                    {
                                        this.OnGestureScreenTap(this.currentFrame, new LeapGestureEventArgs(gesture));
                                    }

                                    break;
                                case Gesture.GestureType.TYPESWIPE:
                                    if (this.OnGestureSwipe != null)
                                    {
                                        this.OnGestureSwipe(this.currentFrame, new LeapGestureEventArgs(gesture));
                                    }

                                    break;
                                default:
                                    // handle unrecognized gestures
                                    break;
                            }
                        }
                    }
                }

                if (this.CurrentFeatures.HasFlag(LeapFeatures.CameraImages))
                {
                    var image = this.currentFrame.Images[0];

                    if (image.IsValid)
                    {
                        this.graphicsDevice.Textures.SetData(this.depthTexture, image.DataPointer(), image.Width * image.Height);
                    }
                }
            }
        }
예제 #56
0
        public override void OnFrame(Controller controller)
        {
            Frame    frame = controller.Frame();
            HandList hands = frame.Hands;

            //Console.Clear();

            foreach (Hand hand in hands)
            {
                // Ignore other tracked objects that are out of the proper area
                if (Math.Abs(hand.PalmPosition.z) > 150)
                {
                    continue;
                }

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;

                //SafeWriteLine(frame.Timestamp.ToString() + " Hands: " + hands.Count.ToString() + ", Fingers: " + fingers.Count.ToString()+", Tools: " + tools.Count.ToString() );

                if (!fingers.Empty)
                {
                    Vector fingerPos;

                    if (fingers.Count > 1)
                    {
                        // fingerIndex is used to determine which finger's position is used to determine the mouse position... lol

                        // Default: Right Handed: Get the right finger tip
                        int fingerIndex = (fingers[0].TipPosition.x < fingers[1].TipPosition.x) ? 1 : 0;
                        // Left Handed: Get the left finger tip
                        if (isLeftHanded ^ isReversed)
                        {
                            fingerIndex = 1 - fingerIndex;
                        }

                        /*
                         * If you wanna remove the "isReversed" feature, replace the code above with the following one:
                         * if (isLeftHanded) fingerIndex = 1 - fingerIndex;
                         */
                        fingerPos = fingers[fingerIndex].TipPosition;

                        if (isMouseDown)
                        {
                            if (!isClickOnly)
                            {
                                MouseLeftUp();
                            }
                            isMouseDown = false;
                        }
                    }
                    else // Only one finger is tracked
                    {
                        if (!isMouseDown)
                        {
                            if (isClickOnly)
                            {
                                MouseLeftClick();
                            }
                            else
                            {
                                MouseLeftDown();
                            }

                            isMouseDown = true;
                        }

                        fingerPos = fingers[0].TipPosition;
                    }

                    /*
                     * How to get values like -60, 60 ?
                     * Use SafeWriteLine to output the finger tip's position..
                     * and move the finger tip to the leftmost and rightmost sides you want...
                     * then you can decide how wide the x is...
                     */
                    //Device x = -60 ~ 60
                    float cursorX = (fingerPos.x + 60) / 120 * screenWidth * moveScale * (isReversed ? -1 : 1);
                    //Device y = 110 ~ 170
                    float cursorY = (1 - (fingerPos.y - 110) / 70) * screenHeight * moveScale;

                    SetCursorPos((int)cursorX, (int)cursorY);
                }

                break;
            }
        }
예제 #57
0
    /**
      * Updates hands based on tracking data in the specified Leap HandList object.
      * Active HandModel instances are updated if the hand they represent is still
      * present in the Leap HandList; otherwise, the HandModel is removed. If new
      * Leap Hand objects are present in the Leap HandList, new HandModels are
      * created and added to the HandController hand list.
      * @param all_hands The dictionary containing the HandModels to update.
      * @param leap_hands The list of hands from the a Leap Frame instance.
      * @param left_model The HandModel instance to use for new left hands.
      * @param right_model The HandModel instance to use for new right hands.
      */
    protected void UpdateHandModels(Dictionary<int, HandModel> all_hands,
                                  HandList leap_hands,
                                  HandModel left_model, HandModel right_model)
    {
        List<int> ids_to_check = new List<int>(all_hands.Keys);

        // Go through all the active hands and update them.
        int num_hands = leap_hands.Count;
        for (int h = 0; h < num_hands; ++h) {
          Hand leap_hand = leap_hands[h];

          HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

          // If we've mirrored since this hand was updated, destroy it.
          if (all_hands.ContainsKey(leap_hand.Id) &&
          all_hands[leap_hand.Id].IsMirrored() != mirrorZAxis) {
        DestroyHand(all_hands[leap_hand.Id]);
        all_hands.Remove(leap_hand.Id);
          }

          // Only create or update if the hand is enabled.
          if (model != null) {
        ids_to_check.Remove(leap_hand.Id);

        // Create the hand and initialized it if it doesn't exist yet.
        if (!all_hands.ContainsKey(leap_hand.Id)) {
          HandModel new_hand = CreateHand(leap_hand, model);

          // Set scaling based on reference hand.
          float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
          new_hand.transform.localScale = hand_scale * Vector3.one;

          new_hand.InitHand();
          new_hand.UpdateHand();
          all_hands[leap_hand.Id] = new_hand;
        } else {
          // Make sure we update the Leap Hand reference.
          HandModel hand_model = all_hands[leap_hand.Id];
          hand_model.SetLeapHand(leap_hand);
          hand_model.MirrorZAxis(mirrorZAxis);

          // Set scaling based on reference hand.
          float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
          hand_model.transform.localScale = hand_scale * Vector3.one;
          hand_model.UpdateHand();
        }
          }
        }

        // Destroy all hands with defunct IDs.
        for (int i = 0; i < ids_to_check.Count; ++i) {
          DestroyHand(all_hands[ids_to_check[i]]);
          all_hands.Remove(ids_to_check[i]);
        }
    }
예제 #58
0
    /**
     * Updates the graphics hands so that they're drawn properly
     * */
    protected new void UpdateHandModels(Dictionary <int, HandModel> all_hands,
                                        HandList leap_hands,
                                        HandModel left_model, HandModel right_model)
    {
        List <int> ids_to_check = new List <int>(all_hands.Keys);

        // Go through all the active hands in the Leap motion frame and update them.
        int num_hands = leap_hands.Count;

        for (int h = 0; h < num_hands; ++h)
        {
            Hand leap_hand = leap_hands[h];

            HandModel model = (mirrorZAxis != leap_hand.IsLeft) ? left_model : right_model;

            // Only create or update if the hand is enabled.
            if (model != null)
            {
                ids_to_check.Remove(leap_hand.Id);                      //this prevents the hand from being made inactive, since it is active.

                // Create the hand and initialized it if it doesn't exist yet.
                if (!all_hands.ContainsKey(leap_hand.Id))
                {
                    HandModel new_hand = InitializeHand(model);                         //We don't instantiate these ones - they're already on the avatar, so we just init them instead of CreateHand them
                    new_hand.SetLeapHand(leap_hand);
                    new_hand.MirrorZAxis(mirrorZAxis);
                    new_hand.SetController(this);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / new_hand.handModelPalmWidth;
                    new_hand.transform.localScale = hand_scale * transform.lossyScale;

                    new_hand.InitHand();
                    new_hand.UpdateHand();
                    all_hands[leap_hand.Id] = new_hand;

                    if (new_hand.GetLeapHand().IsLeft)
                    {
                        leftActive = true;
                    }
                    else
                    {
                        rightActive = true;
                    }
                    //Debug.Log ("Initialised graphics hand and added to active hands list, now contains " + all_hands.Count + " hands");
                }
                else
                {
                    // Make sure we update the Leap Hand reference.
                    HandModel hand_model = all_hands[leap_hand.Id];
                    hand_model.SetLeapHand(leap_hand);
                    hand_model.MirrorZAxis(mirrorZAxis);

                    // Set scaling based on reference hand.
                    float hand_scale = MM_TO_M * leap_hand.PalmWidth / hand_model.handModelPalmWidth;
                    hand_model.transform.localScale = hand_scale * transform.lossyScale;
                    hand_model.UpdateHand();

                    if (hand_model.GetLeapHand().IsLeft)
                    {
                        leftActive = true;
                    }
                    else
                    {
                        rightActive = true;
                    }
                    //Debug.Log ("Updated graphics hand");
                }
            }
        }

        // flag hands that are no longer active, so IK knows to turn off
        for (int i = 0; i < ids_to_check.Count; ++i)
        {
            if (all_hands[ids_to_check[i]].GetLeapHand().IsLeft)
            {
                leftActive = false;
            }
            else
            {
                rightActive = false;
            }
            all_hands.Remove(ids_to_check[i]);
        }
    }