public static PointerType ConvertType(Hand hand, Finger.FingerType fingerType)
	{
		if (hand.IsRight) {
			switch (fingerType) {
			case Finger.FingerType.TYPE_THUMB:
				return PointerType.RightThumb;
			case Finger.FingerType.TYPE_INDEX:
				return PointerType.RightIndex;
			case Finger.FingerType.TYPE_MIDDLE:
				return PointerType.RightMiddle;
			case Finger.FingerType.TYPE_RING:
				return PointerType.RightRing;
			case Finger.FingerType.TYPE_PINKY:
				return PointerType.RightPinky;
			}
		} else if (hand.IsLeft) {
			switch (fingerType) {
			case Finger.FingerType.TYPE_THUMB:
				return PointerType.LeftThumb;
			case Finger.FingerType.TYPE_INDEX:
				return PointerType.LeftIndex;
			case Finger.FingerType.TYPE_MIDDLE:
				return PointerType.LeftMiddle;
			case Finger.FingerType.TYPE_RING:
				return PointerType.LeftRing;
			case Finger.FingerType.TYPE_PINKY:
				return PointerType.LeftPinky;
			}
		}
		
		return PointerType.NULL;
		
	}
 private void TrackIndex(Finger finger, PXCMHandData.IHand handInfo) {
     SetJointdata(handInfo, PXCMHandData.JointType.JOINT_INDEX_BASE, finger.BaseJoint);
     SetJointdata(handInfo, PXCMHandData.JointType.JOINT_INDEX_JT1, finger.FirstJoint);
     SetJointdata(handInfo, PXCMHandData.JointType.JOINT_INDEX_JT2, finger.SecondJoint);
     SetJointdata(handInfo, PXCMHandData.JointType.JOINT_INDEX_TIP, finger);
     SetFingerOpenness(finger, PXCMHandData.FingerType.FINGER_INDEX, handInfo);
 }
Exemple #3
0
    public override void UpdateFinger(Finger finger, Transform deviceTransform,
                                     Vector3 palm_normal, Vector3 palm_direction)
    {
        Vector3 last_bone_normal = palm_normal;
        Vector3 last_bone_direction = palm_direction;

        for (int i = 0; i < NUM_BONES; ++i) {
          // Set velocity.
          Vector3 next_bone_position = deviceTransform.TransformPoint(GetBonePosition(finger, i));
          bones[i].rigidbody.velocity = (next_bone_position - bones[i].transform.position) *
                                    ((1 - easing) / Time.fixedDeltaTime);

          // Set angular velocity.
          Vector3 bone_direction = deviceTransform.rotation * GetBoneDirection(finger, i);
          Vector3 bone_normal = Quaternion.FromToRotation(last_bone_direction, bone_direction) * last_bone_normal;

          Quaternion delta_rotation = Quaternion.LookRotation(bone_direction, -bone_normal) *
                                  Quaternion.Inverse(bones[i].transform.rotation);
          float angle = 0.0f;
          Vector3 axis = Vector3.zero;
          delta_rotation.ToAngleAxis(out angle, out axis);

          if (angle >= 180) {
        angle = 360 - angle;
        axis  = -axis;
          }
          if (angle != 0)
        bones[i].rigidbody.angularVelocity = (1 - easing) * angle * axis;

          last_bone_direction = bone_direction;
          last_bone_normal = bone_normal;
        }
    }
    protected override FingerGestures.FingerPhase GetPhase( Finger finger )
    {
        int button = finger.Index;

        // did we just press it?
        if( Input.GetMouseButtonDown( button ) )
            return FingerPhase.Began;

        // mouse button down?
        if( Input.GetMouseButton( button ) )
        {
            // find out if the mouse has moved since last update
            Vector3 delta = GetPosition( finger ) - finger.Position;

            if( delta.sqrMagnitude < 1.0f )
                return FingerPhase.Stationary;

            return FingerPhase.Moved;
        }

        // did we just release the button?
        if( Input.GetMouseButtonUp( button ) )
            return FingerPhase.Ended;
        
        return FingerPhase.None;
    }
Exemple #5
0
 // Returns the direction the given bone is facing on the finger.
 protected Vector3 GetBoneDirection(Finger finger, int bone)
 {
     Vector3 difference = finger.JointPosition((Finger.FingerJoint)(bone + 1)).ToUnity() -
                      finger.JointPosition((Finger.FingerJoint)(bone)).ToUnity();
     difference.Normalize();
     return difference;
 }
Exemple #6
0
 void OnTriggerEnter(Collider collider)
 {
     if (IsFinger(collider) && gm.getColorChoserActive()) {
         if (!hasSphere)
         {
             fingerModel = collider.gameObject.GetComponentInParent<FingerModel>();
             f = fingerModel.GetLeapFinger();
     //                Debug.Log(f);
             if(fingerModel.fingerType.ToString().Equals("TYPE_INDEX"))
             {
                 col = collider;
                 // Neue Sphere erstellen mit der Farbe vom Bucket
                 QuizManager.setHasColor(true);
                 Destroy(drop);
                 Colors.drop = Instantiate(Resources.Load("Drop")) as GameObject;
                 Colors.drop.transform.position = new Vector3(0, 1.5F, 0);
                 Colors.drop.transform.localScale = new Vector3(0.5F,0.5F,0.5F);
                 Renderer m = Colors.drop.GetComponent<Renderer>();
                 QuizManager.shaderName = bucketMat.name;
                 m.material = bucketMat;
                 Colors.drop.transform.position = fingerModel.GetTipPosition();
                 hasSphere = true;
                 QuizManager.setHasColor(true);
             }
         }
     }
     if (IsHand(collider))
     {
      //           print("Hand berührt");
     }
 }
 public GeneInfo.GeneInfoC_Reflect Finger2C_Reflect(Finger finger)
 {
     Vector3 point = Camera.main.ScreenToWorldPoint (finger.Positions [0]);
     point.z = 0;
     Debug.LogFormat ("Reflet:ScreenPoint {0},{1}", finger.Positions [0].x, finger.Positions [0].y);
     Debug.LogFormat ("Reflet:WorldPoint {0},{1}", point.x, point.y);
     return new GeneInfo.GeneInfoC_Reflect (point);
 }
Exemple #8
0
 private IKSegment[] makeFinger(Finger finger)
 {
     List<IKSegment> chain = new List<IKSegment>();
     addToChain(ref chain, finger.Base);
     addToChain(ref chain, finger.Mid);
     addToChain(ref chain, finger.End);
     return chain.ToArray();
 }
 public Hand(Side side) {
     Thumb = new Finger();
     Index = new Finger();
     Middle = new Finger();
     Ring = new Finger();
     Pinky = new Finger();
     Side = side;
 }
    UnityEngine.Touch GetTouch( Finger finger )
    {
        int touchIndex = finger2touchMap[finger.Index];

        if( touchIndex == -1 )
            return nullTouch;

        return Input.touches[touchIndex];
    }
 public GeneInfo.GeneInfoC_Curve Finger2C_Curbe(Finger finger)
 {
     List<Vector3> pts = new List<Vector3> ();
     for (int i = 0; i < finger.Positions.Count; i++) {
         Vector3 pt = Camera.main.ScreenToWorldPoint(finger.Positions[i]);
         pt.z = 0;
         pts.Add(pt);
     }
     return new GeneInfo.GeneInfoC_Curve (pts);
 }
Exemple #12
0
    void UpdatePosition()
    {
        #if UNITY_EDITOR
            Finger f = new Finger();
            f.x = Input.mousePosition.x;
            f.y = Input.mousePosition.y;
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(f.x, f.y));
        transform.position=mousePosition;

        #endif
    }
    public GeneInfo.GeneInfoC_Board Finger2C_Borard(Finger finger0, Finger finger1)
    {
        Vector3 p1 = Camera.main.ScreenToWorldPoint (finger0.Positions [0]);
        Vector3 p2 = Camera.main.ScreenToWorldPoint (finger1.Positions [0]);
        p1.z = 0f;
        p2.z = 0f;

        Debug.LogFormat ("Board:ScreenPoint {0},{1},{2},{3}", finger0.Positions [0].x, finger0.Positions [0].y, finger1.Positions [0].x, finger1.Positions [0].y);
        Debug.LogFormat ("Board:WorldPoint {0},{1},{2},{3}", p1.x, p1.y, p2.x, p2.y);
        return new GeneInfo.GeneInfoC_Board (p1, p2);
    }
 public static LEAP_DIGIT CreateDigit(Finger finger) {
   LEAP_DIGIT digit = new LEAP_DIGIT();
   digit.finger_id = finger.Id;
   digit.metacarpal = CreateBone(finger.Bone(Bone.BoneType.TYPE_METACARPAL));
   digit.proximal = CreateBone(finger.Bone(Bone.BoneType.TYPE_PROXIMAL));
   digit.intermediate = CreateBone(finger.Bone(Bone.BoneType.TYPE_INTERMEDIATE));
   digit.distal = CreateBone(finger.Bone(Bone.BoneType.TYPE_DISTAL));
   digit.tip_velocity = new LEAP_VECTOR(finger.TipVelocity);
   digit.stabilized_tip_position = Vector3.zero.ToCVector(); //HACK: stabilized position is sometimes NaN, ignore it
   digit.is_extended = finger.IsExtended ? 1 : 0;
   return digit;
 }
Exemple #15
0
        public TestOSC(IEnumerable<string> args)
        {
            allPixels = new VirtualPixel1D("All Pixels", 28 + 50);

            loopSeq = new Controller.Sequence("Loop Seq");
            fingers = new Finger[10];
            for (int i = 0; i < 10; i++)
                fingers[i] = new Finger();

            testDimmer = new Dimmer("Test");

            this.oscServer = new Expander.OscServer(5555);
        }
 /// <summary>
 /// Determines whether this instance is double tap the specified finger1 finger2.
 /// </summary>
 /// <returns><c>true</c> if this instance is double tap the specified finger1 finger2; otherwise, <c>false</c>.</returns>
 /// <param name="finger1">Finger1.</param>
 /// <param name="finger2">Finger2.</param>
 public bool IsDoubleTap(Finger finger1,Finger finger2)
 {
     if (!IsTap (finger1) || !IsTap (finger2)) {
         return false;
     }
     if (Mathf.Abs (finger1.Times [0] - finger2.Times [0]) > toleranceTime) {
         return false;
     }
     if (Mathf.Abs (finger1.Times [finger1.Times.Count - 1] - finger2.Times [finger2.Times.Count - 1]) > toleranceTime) {
         return false;
     }
     return true;
 }
Exemple #17
0
 void OnTriggerEnter(Collider collider)
 {
     if (IsFinger(collider) && gm.getColorChoserActive() && QuizManager.getHasColor())
     {
         fingerModel = collider.gameObject.GetComponentInParent<FingerModel>();
         f = fingerModel.GetLeapFinger();
         controller = fingerModel.GetController();
         shoeRender.material = QuizManager.getChosenMaterial();
         //shoeRender.material = new Material(Shader.Find(QuizManager.shaderName));
         QuizManager.changedObjects.Add(shoeRender);
         QuizManager.setHasColor(false);
         Destroy(Colors.drop);
     }
 }
 /// <summary>
 /// Determines whether this instance is circle the specified finger.
 /// </summary>
 /// <returns><c>true</c> if this instance is circle the specified finger; otherwise, <c>false</c>.</returns>
 /// <param name="finger">Finger.</param>
 public bool IsCircle(Finger finger)
 {
     bool isLongTrace = false;
     for (int i = 0; i < finger.Positions.Count; i++) {
         if (!isLongTrace) {
             if (Vector2.Distance (finger.Positions [0], finger.Positions [i]) >= toleranceCircleDistance) {
                 isLongTrace = true;
             }
         } else{
             if (Vector2.Distance (finger.Positions [0], finger.Positions [i]) < toleranceCircleDistance) {
                 finger.Positions.RemoveRange (i, finger.Positions.Count - i);
                 return true;
             }
         }
     }
     return false;
 }
 public GeneInfo.GeneInfoC_Jump Finger2C_Jump(Finger finger)
 {
     Vector3 meanPt = Camera.main.ScreenToWorldPoint (finger.Positions [0]);
     float range = 0.0f;
     for (int i = 0; i < finger.Positions.Count; i++) {
         Vector3 pt = Camera.main.ScreenToWorldPoint(finger.Positions[i]);
         meanPt += pt;
     }
     meanPt /= finger.Positions.Count;
     for (int i = 0; i < finger.Positions.Count; i++) {
         float dist = Vector2.Distance(finger.Positions[0],finger.Positions[i]);
         if(range < dist){
             range = dist;
         }
     }
     return new GeneInfo.GeneInfoC_Jump (meanPt, range * JUMP_POWER_MULTIPLIER);
 }
Exemple #20
0
    protected void JumpToPosition(Finger finger, Transform deviceTransform,
                                Vector3 palm_normal, Vector3 palm_direction)
    {
        Vector3 last_bone_normal = palm_normal;
        Vector3 last_bone_direction = palm_direction;

        for (int i = 0; i < NUM_BONES; ++i) {
          if (bones[i] != null) {
        // Set position.
        bones[i].transform.position = deviceTransform.TransformPoint(GetBonePosition(finger, i));

        // Set rotation.
        Vector3 bone_direction = deviceTransform.rotation * GetBoneDirection(finger, i);
        last_bone_normal = Quaternion.FromToRotation(last_bone_direction, bone_direction) * last_bone_normal;
        bones[i].transform.rotation = Quaternion.LookRotation(bone_direction, -last_bone_normal);
        last_bone_direction = bone_direction;
          }
        }
    }
    // Use this when the level is loaded
    void Awake()
    {
        m_Instance = this;
        m_Finger = null;
        m_FingerComponent = null;

        // Clamp the score.
        m_Score = 0.0f;
        m_ScoreLastTime = 0.0f;

        // Difficulty initialisation
        m_Difficulty = 1.0f;
        m_DifficultyLastTime = 0.0f;

        // Store initial time
        m_ScoreLastTime = m_DifficultyLastTime = Time.time;

        //SceneManager.LoadSceneByIndex(0, GameSettings.AdditiveSceneLoading, !GameSettings.AsyncSceneLoading);

        Object.DontDestroyOnLoad(this);
    }
Exemple #22
0
        public Vector getFingerVector(Controller controller, Finger finger)
        {
            Vector finger_vector = new Vector();

            // Get the closest screen intercepting a ray projecting from the finger
            Leap.Screen screen = controller.CalibratedScreens.ClosestScreenHit(finger);


            if (screen != null && screen.IsValid)
            {
                Vector screenStabilized = screen.Intersect(finger, true);
                var    xScreenIntersect = screenStabilized.x;
                var    yScreenIntersect = screenStabilized.y;

                if (xScreenIntersect.ToString() != "NaN")
                {
                    finger_vector.x = (int)(xScreenIntersect * screen.WidthPixels);
                    finger_vector.y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels * yAxisMultiplier));
                }
                //SafeWriteLine("yScreenIntersect / HeightPixels" + "/" + yScreenIntersect + "/" + screen.HeightPixels);
            }

            return(finger_vector);
        }
Exemple #23
0
        public static void Run()
        {
            var forearm = new Forearm()
            {
                Description = "Forearm"
            };
            var palm = new Palm()
            {
                Description = "Palm"
            };

            forearm.AddChildren(palm);
            for (int i = 0; i < 5; i++)
            {
                palm.AddChildren(CreateFinger(i));
            }

            Console.Write(forearm.GetStruct());

            Finger CreateFinger(int fingerIndex)
            {
                var finger = new Finger()
                {
                    Description = $"Finger_{fingerIndex}"
                };

                for (int i = 0; i < 3; i++)
                {
                    finger.AddChildren(new Falange()
                    {
                        Description = $"Falange_{i} for {finger.Description}"
                    });
                }
                return(finger);
            }
        }
Exemple #24
0
        /// <summary>
        /// Grip curl is really unreliably tracked, so I don't recommend using it.
        /// </summary>
        private float getGripCurl(Hand h, Finger f)
        {
            var leftPositiveThumbAxis = h.RadialAxis() * (h.IsLeft ? 1f : -1f);
            int baseBoneIdx           = 1;

            if (f.Type == Finger.FingerType.TYPE_THUMB)
            {
                baseBoneIdx = 2;
            }
            var baseDir = f.bones[baseBoneIdx].Direction.ToVector3();

            var gripAngle = baseDir.SignedAngle(
                f.bones[3].Direction.ToVector3(),
                leftPositiveThumbAxis);

            if (gripAngle < -30f)
            {
                gripAngle += 360f;
            }

            var gripCurl = gripAngle.Map(0f, 150f, 0f, 1f);

            return(gripCurl);
        }
Exemple #25
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (handController.GetAllGraphicsHands().Length != 0)
        {
            handModel = handController.GetAllGraphicsHands()[0];
            hand      = handModel.GetLeapHand();
            finger0   = hand.Fingers[0]; //thumb
            finger1   = hand.Fingers[1]; //index
            finger2   = hand.Fingers[2]; //middle finger
            finger3   = hand.Fingers[3]; //ring finger
            pos       = hand.PalmPosition;
            camRot    = this.transform.rotation;
            //movement and rotation speed
            velocity = hand.PalmVelocity;
            speed    = velocity.Magnitude / 50f;

            /* The transformations are based on the palm position and movement.
             * The fingers are used to create new commands */

            Debug.DrawRay(this.GetComponentInChildren <Camera>().transform.position, Vector3.forward);

            //Extend index to activate camera movement
            if (finger1.IsExtended && !finger2.IsExtended && !finger0.IsExtended)
            {
                moveCamera();
            }

            //Extend index and middle finger to activate camera rotation
            if (finger1.IsExtended && finger2.IsExtended && !finger3.IsExtended && !finger0.IsExtended)
            {
                rotateCamera();
            }
            oldPos    = pos;
            oldCamRot = camRot;
        }
    }
Exemple #26
0
    // Update is called once per frame
    void Update()
    {
        if (!GLOBAL.IS_PAUSED)
        {
            if (USE_MOUSE)
            {
                // MOUSE CODE, code to move crosshair
                pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, zDistance);
                pos = Camera.main.ScreenToWorldPoint(pos);
                transform.position = pos;
            }
            else
            {
                // LEAP MOTION, code to move crosshair
                FingerList fl          = hc.GetFrame().Hands[currentHand].Fingers.FingerType(Finger.FingerType.TYPE_INDEX);
                Finger     indexfinger = fl[0];
                fingerpos = indexfinger.StabilizedTipPosition;

                Vector3 indexPostion = fingerpos.ToUnityScaled(false);

                transform.position = hc.transform.TransformPoint(indexPostion.x, indexPostion.y, 1f);
            }
        }
    }
    protected override FingerGestures.FingerPhase GetPhase( Finger finger )
    {
        if( HasValidTouch( finger ) )
        {
            UnityEngine.Touch touch = GetTouch( finger );

            switch( touch.phase )
            {
                case UnityEngine.TouchPhase.Began:
                    return FingerPhase.Began;

                case UnityEngine.TouchPhase.Moved:
                    return FingerPhase.Moved;

                case UnityEngine.TouchPhase.Stationary:
                    return FingerPhase.Stationary;

                default:
                    return FingerPhase.Ended;
            }
        }

        return FingerPhase.None;
    }
Exemple #28
0
    /**
    * Draws lines from elbow to wrist, wrist to palm, and normal to the palm.
    * Also draws the orthogonal basis vectors for the pinch and grab points.
    */
    public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer gizmoDrawer) {
      if (DrawHand) {
        Hand hand = GetLeapHand();
        gizmoDrawer.color = Color.red;
        gizmoDrawer.DrawLine(hand.Arm.ElbowPosition.ToVector3(), hand.Arm.WristPosition.ToVector3());
        gizmoDrawer.color = Color.white;
        gizmoDrawer.DrawLine(hand.WristPosition.ToVector3(), hand.PalmPosition.ToVector3()); //Wrist to palm line
        gizmoDrawer.color = Color.black;
        gizmoDrawer.DrawLine(hand.PalmPosition.ToVector3(), (hand.PalmPosition + hand.PalmNormal * hand.PalmWidth / 2).ToVector3()); //Hand Normal
        if (PinchPoint != null)
          DrawBasis(gizmoDrawer, PinchPoint.position, PinchPoint.GetLeapMatrix(), .01f); //Pinch basis
        if (GrabPoint != null)
          DrawBasis(gizmoDrawer, GrabPoint.position, GrabPoint.GetLeapMatrix(), .01f); //Grab basis

        for (int f = 0; f < 5; f++) { //Fingers
          Finger finger = hand.Fingers[f];
          for (int i = 0; i < 4; ++i) {
            Bone bone = finger.Bone((Bone.BoneType)i);
            gizmoDrawer.color = colors[i];
            gizmoDrawer.DrawLine(bone.PrevJoint.ToVector3(), bone.PrevJoint.ToVector3() + bone.Direction.ToVector3() * bone.Length);
          }
        }
      }
    }
    protected override FingerGestures.FingerPhase GetPhase(Finger finger)
    {
        if (HasValidTouch(finger))
        {
            UnityEngine.Touch touch = GetTouch(finger);

            switch (touch.phase)
            {
            case UnityEngine.TouchPhase.Began:
                return(FingerPhase.Began);

            case UnityEngine.TouchPhase.Moved:
                return(FingerPhase.Moved);

            case UnityEngine.TouchPhase.Stationary:
                return(FingerPhase.Stationary);

            default:
                return(FingerPhase.Ended);
            }
        }

        return(FingerPhase.None);
    }
Exemple #30
0
    public bool Pinching()
    {
        HandModel hand_model = GetComponent <HandModel>();
        Hand      leap_hand  = hand_model.GetLeapHand();

        Vector leap_thumb_tip   = leap_hand.Fingers[0].TipPosition;
        float  closest_distance = Mathf.Infinity;

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

            for (int j = 0; j < FingerModel.NUM_BONES; ++j)
            {
                Vector leap_joint_position = finger.Bone((Bone.BoneType)j).NextJoint;

                float thumb_tip_distance = leap_joint_position.DistanceTo(leap_thumb_tip);
                closest_distance = Mathf.Min(closest_distance, thumb_tip_distance);
            }
        }

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

        if (closest_distance <= trigger_distance)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
        //Transform updating methods

        private void updateSpheres()
        {
            //Update all spheres
            List <Finger> fingers = hand_.Fingers;

            for (int i = 0; i < fingers.Count; i++)
            {
                Finger finger = fingers[i];
                for (int j = 0; j < 4; j++)
                {
                    int       key    = getFingerJointIndex((int)finger.Type, j);
                    Transform sphere = _jointSpheres[key];
                    sphere.position = finger.Bone((Bone.BoneType)j).NextJoint.ToVector3();
                    if (_showHand == false)
                    {
                        sphere.GetComponent <Renderer>().enabled = false;
                    }
                    else
                    {
                        sphere.GetComponent <Renderer>().enabled = true;
                    }
                }
            }

            palmPositionSphere.position = hand_.PalmPosition.ToVector3();

            Vector3 wristPos = hand_.PalmPosition.ToVector3();

            wristPositionSphere.position = wristPos;

            Transform thumbBase = _jointSpheres[THUMB_BASE_INDEX];

            Vector3 thumbBaseToPalm = thumbBase.position - hand_.PalmPosition.ToVector3();

            mockThumbJointSphere.position = hand_.PalmPosition.ToVector3() + Vector3.Reflect(thumbBaseToPalm, hand_.Basis.xBasis.ToVector3());
        }
Exemple #32
0
    IEnumerator KeepTouchpoint(Finger finger)
    {
        //checke id:
        if ((1 << finger.index & mask_id) > 0)
        {
            yield break;
        }
        mask_id |= 1 << finger.index;

        //Positioniere Touchpoint:
        GameObject touchSensor = Instantiate(touchPrefab, PixelToWorld(finger.screenPosition), Quaternion.identity);

        touchSensor.GetComponent <TouchSensor>().Initialize(finger.index);
        while (finger.isActive)
        {
            touchSensor.transform.position = PixelToWorld(finger.screenPosition);
            yield return(new WaitForEndOfFrame());
        }

        Destroy(touchSensor);
        mask_id ^= 1 << finger.index;

        yield break;
    }
Exemple #33
0
    /**
     * Copies the data from an internal finger definition into a finger.
     *
     * @param leapBone The internal finger definition to be copied into this finger.
     * @param type The finger type of this finger.
     * @param frameId The frame id of the frame this finger belongs to.
     * @param handId The hand id of the hand this finger belongs to.
     * @param timeVisible The time in seconds that this finger has been visible.
     */
    public static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type, int handId, float timeVisible) {
      finger.Id = (handId * 10) + leapBone.finger_id;
      finger.HandId = handId;
      finger.TimeVisible = timeVisible;

      Bone metacarpal = finger.bones[0];
      Bone proximal = finger.bones[1];
      Bone intermediate = finger.bones[2];
      Bone distal = finger.bones[3];

      metacarpal.CopyFrom(leapBone.metacarpal, Leap.Bone.BoneType.TYPE_METACARPAL);
      proximal.CopyFrom(leapBone.proximal, Leap.Bone.BoneType.TYPE_PROXIMAL);
      intermediate.CopyFrom(leapBone.intermediate, Leap.Bone.BoneType.TYPE_INTERMEDIATE);
      distal.CopyFrom(leapBone.distal, Leap.Bone.BoneType.TYPE_DISTAL);

      finger.TipPosition = distal.NextJoint;
      finger.Direction = intermediate.Direction;
      finger.Width = intermediate.Width;
      finger.Length = (leapBone.finger_id == 0 ? 0.0f : 0.5f * proximal.Length) + intermediate.Length + 0.77f * distal.Length; //The values 0.5 for proximal and 0.77 for distal are used in platform code for this calculation
      finger.IsExtended = leapBone.is_extended != 0;
      finger.Type = type;

      return finger;
    }
Exemple #34
0
    /// <summary>
    /// Processes the leap input.
    /// </summary>
    public override void processLeapInput()
    {
        // Gets the current frame leap data
        Frame m_currentFrame = LeapInput.Frame;

        // Checks that the current frame is valid
        if (!m_currentFrame.IsValid)
        {
            return;
        }

        // Gets a list of fingers
        FingerList m_fingersList = m_currentFrame.Fingers;

        // Verifies that there is at least one finger in the list
        if (m_fingersList.Count > 0)
        {
            // Gets the first finger in the list since it's only one pointer object
            Finger activeFinger = m_fingersList[0];

            // In this sample we only care for the tip Position of the first finger
            m_ActiveFinger.M_TipPosition = new Vector3(activeFinger.TipPosition.x, activeFinger.TipPosition.y, activeFinger.TipPosition.z);
        }
    }
Exemple #35
0
 private void OnDrawGizmos()
 {
     if (ShowGizmos && HandModel != null && HandModel.IsTracked)
     {
         Color innerColor;
         if (IsActive)
         {
             innerColor = OnColor;
         }
         else
         {
             innerColor = OffColor;
         }
         Finger  finger          = HandModel.GetLeapHand().Fingers[selectedFingerOrdinal()];
         Vector3 fingerDirection = finger.Bone(Bone.BoneType.TYPE_DISTAL).Direction.ToVector3();
         Utils.DrawCone(finger.TipPosition.ToVector3(), fingerDirection, OnAngle, finger.Length, innerColor);
         Utils.DrawCone(finger.TipPosition.ToVector3(), fingerDirection, OffAngle, finger.Length, LimitColor);
         Gizmos.color = DirectionColor;
         //Gizmos.DrawRay(finger.TipPosition.ToVector3(), selectedDirection(finger.TipPosition.ToVector3())*500);
         Vector3 Direction = finger.Direction.ToVector3();
         Gizmos.DrawRay(finger.TipPosition.ToVector3(), Direction * 500);
         //cylinder.transform.position = finger.TipPosition.ToVector3();
     }
 }
        //Geometry creation methods

        private void createSpheres()
        {
            //Create spheres for finger joints
            List <Finger> fingers = hand_.Fingers;

            for (int i = 0; i < fingers.Count; i++)
            {
                Finger finger = fingers[i];
                for (int j = 0; j < 4; j++)
                {
                    int key = getFingerJointIndex((int)finger.Type, j);
                    _jointSpheres[key] = createSphere("Joint", SPHERE_RADIUS);
                }
            }

            mockThumbJointSphere = createSphere("MockJoint", SPHERE_RADIUS);
            palmPositionSphere   = createSphere("PalmPosition", PALM_RADIUS);
            wristPositionSphere  = createSphere("WristPosition", SPHERE_RADIUS);

            armFrontLeft  = createSphere("ArmFrontLeft", SPHERE_RADIUS, true);
            armFrontRight = createSphere("ArmFrontRight", SPHERE_RADIUS, true);
            armBackLeft   = createSphere("ArmBackLeft", SPHERE_RADIUS, true);
            armBackRight  = createSphere("ArmBackRight", SPHERE_RADIUS, true);
        }
            public static T FindOrCreate <T>(ref List <T> links, Finger finger)
                where T : Link, new()
            {
                if (links == null)
                {
                    links = new List <T>();
                }

                foreach (var link in links)
                {
                    if (link.Finger == finger)
                    {
                        return(link);
                    }
                }

                var newLink = new T();

                newLink.Finger = finger;

                links.Add(newLink);

                return(newLink);
            }
        /** Updates the position and rotation for each non-null attachment transform. */
        public override void UpdateHand()
        {
            if (Palm != null)
            {
                Palm.position = _hand.PalmPosition.ToVector3();
                Palm.rotation = _hand.Basis.rotation.ToQuaternion();
            }
            if (Arm != null)
            {
                Arm.position = _hand.Arm.Center.ToVector3();
                Arm.rotation = _hand.Arm.Basis.rotation.ToQuaternion();
            }
            if (Thumb != null)
            {
                Thumb.position = _hand.Fingers[0].Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();
                Thumb.rotation = _hand.Fingers[0].Bone(Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion();
            }
            if (Index != null)
            {
                Index.position = _hand.Fingers[1].Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();
                Index.rotation = _hand.Fingers[1].Bone(Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion();
            }
            if (Middle != null)
            {
                Middle.position = _hand.Fingers[2].Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();
                Middle.rotation = _hand.Fingers[2].Bone(Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion();
            }
            if (Ring != null)
            {
                Ring.position = _hand.Fingers[3].Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();
                Ring.rotation = _hand.Fingers[3].Bone(Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion();
            }
            if (Pinky != null)
            {
                Pinky.position = _hand.Fingers[4].Bone(Bone.BoneType.TYPE_DISTAL).NextJoint.ToVector3();
                Pinky.rotation = _hand.Fingers[4].Bone(Bone.BoneType.TYPE_DISTAL).Rotation.ToQuaternion();
            }
            if (PinchPoint != null)
            {
                Vector thumbTip   = _hand.Fingers[0].TipPosition;
                Vector indexTip   = _hand.Fingers[1].TipPosition;
                Vector pinchPoint = Vector.Lerp(thumbTip, indexTip, 0.5f);
                PinchPoint.position = pinchPoint.ToVector3();

                Vector forward = pinchPoint - _hand.Fingers[1].Bone(Bone.BoneType.TYPE_PROXIMAL).PrevJoint;
                Vector up      = _hand.Fingers[1].Bone(Bone.BoneType.TYPE_PROXIMAL).Direction.Cross(forward);
                PinchPoint.rotation = Quaternion.LookRotation(forward.ToVector3(), up.ToVector3());
            }
            if (GrabPoint != null)
            {
                var     fingers     = _hand.Fingers;
                Vector3 GrabCenter  = _hand.WristPosition.ToVector3();
                Vector3 GrabForward = Vector3.zero;
                for (int i = 0; i < fingers.Count; i++)
                {
                    Finger finger = fingers[i];
                    GrabCenter += finger.TipPosition.ToVector3();
                    if (i > 0) //don't include thumb
                    {
                        GrabForward += finger.TipPosition.ToVector3();
                    }
                }
                GrabPoint.position = GrabCenter / 6.0f; //average between wrist and fingertips
                GrabForward        = (GrabForward / 4 - _hand.WristPosition.ToVector3()).normalized;
                Vector3 thumbToPinky = fingers[0].TipPosition.ToVector3() - fingers[4].TipPosition.ToVector3();
                Vector3 GrabNormal   = Vector3.Cross(GrabForward, thumbToPinky).normalized;
                GrabPoint.rotation = Quaternion.LookRotation(GrabForward, GrabNormal);
            }
        }
Exemple #39
0
    // Update is called once per frame
    void Update()
    {
        //score = GameObject.Find ("Managers").GetComponent<ScoreManager> ().score;


        RaycastHit hit;

        Controller controller = new Controller();
        Frame      frame      = controller.Frame(); // controller is a Controller object

        if (frame.Hands.Count > 0)
        {
            List <Hand> hands = frame.Hands;
            Hand        hand;
            int         extendedFingers = 0;
            foreach (Hand h in hands)
            {
                if (h.IsLeft)
                {
                    hand = h;
                    for (int f = 0; f < hand.Fingers.Count; f++)
                    {
                        Finger digit = hand.Fingers[f];
                        if (digit.IsExtended)
                        {
                            extendedFingers++;
                        }
                    }
                }
            }

            if (extendedFingers == 5)
            {
                try
                {
                    line.enabled = true;
                }
                catch (UnassignedReferenceException e)
                {
                    print("Line Enable Error");
                }
                Vector3 rayDirection = transform.TransformDirection(Vector3.down);
                if (Physics.Raycast(transform.position, rayDirection, out hit))
                {
                    if (hit.collider)
                    {
                        //t = 0f;
                        target = hit.transform.gameObject;
                        line.SetPosition(1, new Vector3(0, -hit.distance, 0));

                        if (target.tag == "Enemy")
                        {
                            //ps = target.GetComponent<ParticleSystem>();
                            //ps.Play();
                            audio.Play();
                            //Destroy (target/*, ps.duration*/);

                            e.updateEnemy((Object)target);
                            GameObject.Find("Managers").GetComponent <ScoreManager>().score++;

                            scoreLabel.text = "SCORE : " + GameObject.Find("Managers").GetComponent <ScoreManager>().score.ToString();
                        }
                    }
                }
                else
                {
                    //t = 0f;
                    line.SetPosition(1, new Vector3(0, -5000000, 0));
                }
            }
            else
            {
                try {
                    line.enabled = false;
                } catch (UnassignedReferenceException e) {
                    print("Game End");
                }
            }
        }
    }
Exemple #40
0
    private bool CreateGesture(EventName message,Finger finger,float actionTime, SwipeType swipe, float swipeLength, Vector2 swipeVector)
    {
        //Creating the structure with the required information
        Gesture gesture = new Gesture();

        gesture.fingerIndex = finger.fingerIndex;
        gesture.touchCount = finger.touchCount;
        gesture.startPosition = finger.startPosition;
        gesture.position = finger.position;
        gesture.deltaPosition = finger.deltaPosition;

        gesture.actionTime = actionTime;
        gesture.deltaTime = finger.deltaTime;

        gesture.swipe = swipe;
        gesture.swipeLength = swipeLength;
        gesture.swipeVector = swipeVector;

        gesture.deltaPinch = 0;
        gesture.twistAngle = 0;
        gesture.pickObject = finger.pickedObject;
        gesture.otherReceiver = receiverObject;

        if (useBroadcastMessage){
            SendGesture(message,gesture);
        }
        if (!useBroadcastMessage || joystickAddon){
            RaiseEvent(message, gesture);
        }

        return true;
    }
Exemple #41
0
 static float GetFingerDistanceFromStart(Finger finger)
 {
     return(finger.DistanceFromStart);
 }
Exemple #42
0
 static Vector2 GetFingerStartPosition(Finger finger)
 {
     return(finger.StartPosition);
 }
Exemple #43
0
 public bool Remove(Finger touch)
 {
     return(list.Remove(touch));
 }
Exemple #44
0
    /// <summary>
    /// Check if the input fingers are moving in opposite direction
    /// </summary>
    public static bool FingersMovedInOppositeDirections(Finger finger0, Finger finger1, float minDOT)
    {
        float dot = Vector2.Dot(finger0.DeltaPosition.normalized, finger1.DeltaPosition.normalized);

        return(dot < minDOT);
    }
 protected override Vector2 GetPosition( Finger finger )
 {
     return Input.mousePosition;
 }
Exemple #46
0
	/// \}


	// -----------------
	// Hide documentation
	///	\cond 
	// ------------------


	// ---------------------
	override public void Init(TouchController joy)
		{	
		base.Init(joy);

		this.joy = joy;
		this.fingerA = new Finger(this);
		this.fingerB = new Finger(this);	
		

		this.AnimateParams(
			(this.overrideScale ? this.releasedScale : this.joy.releasedZoneScale), 	
			(this.overrideColors ? this.releasedColor : this.joy.defaultReleasedZoneColor), 
			0);


		this.OnReset();

		if (this.initiallyDisabled) 
			this.Disable(true);
		if (this.initiallyHidden) 
			this.Hide(true);

		}
Exemple #47
0
 public FingerSql(MySqlConnection msconnection)
 {
     mscon  = msconnection;
     finger = new Finger();
 }
Exemple #48
0
	private bool GetPickedGameObject(Finger finger, bool isTowFinger=false){

		if (finger == null){
			return false;
		}

		pickedObject.isGUI = false;
		pickedObject.pickedObj = null;
		pickedObject.pickedCamera = null;
		
		if (touchCameras.Count>0){
			for (int i=0;i<touchCameras.Count;i++){
				if (touchCameras[i].camera!=null && touchCameras[i].camera.enabled){

					Vector2 pos=Vector2.zero;
					if (!isTowFinger){
						pos = finger.position;
					}
					else{
						pos = twoFinger.position;
					}

			        Ray ray = touchCameras[i].camera.ScreenPointToRay( pos );
			        RaycastHit hit;

					if (enable2D){

						LayerMask mask2d = pickableLayers2D;
						RaycastHit2D[] hit2D = new RaycastHit2D[1];
						if (Physics2D.GetRayIntersectionNonAlloc( ray,hit2D,float.PositiveInfinity,mask2d)>0){
							pickedObject.pickedCamera = touchCameras[i].camera;
							pickedObject.isGUI = touchCameras[i].guiCamera;
							pickedObject.pickedObj = hit2D[0].collider.gameObject;
							return true;
						}
					}

					LayerMask mask = pickableLayers3D;
						
			        if( Physics.Raycast( ray, out hit,float.MaxValue,mask ) ){
						pickedObject.pickedCamera = touchCameras[i].camera;
						pickedObject.isGUI = touchCameras[i].guiCamera;
						pickedObject.pickedObj = hit.collider.gameObject;
			            return true;
					}
				}
			}
		}
		else{
			Debug.LogWarning("No camera is assigned to EasyTouch");	
		}
        return false;     
	}
Exemple #49
0
 public PhalangeData(Finger finger, int Index, device_type_t DeviceTypeT)
 {
     this.Finger      = finger;
     this.Index       = Index;
     this.DeviceTypeT = DeviceTypeT;
 }
Exemple #50
0
	private bool FingerInTolerance(Finger finger ){

		if ((finger.position-finger.startPosition).sqrMagnitude <= (StationaryTolerance*StationaryTolerance)){
			return true;
		}
		else{
			return false;
		}
	}
Exemple #51
0
 public void Add(Finger touch)
 {
     list.Add(touch);
 }
Exemple #52
0
	void UpdateTouches(bool realTouch, int touchCount){
		 
		fingers.CopyTo( tmpArray,0);
		
		if (realTouch || enableRemote){
			ResetTouches();
			for (var i = 0; i < touchCount; ++i) {
				Touch touch = Input.GetTouch(i);
				
				int t=0;
				while (t < 100 && fingers[i]==null){	
					if (tmpArray[t] != null){
						if ( tmpArray[t].fingerIndex == touch.fingerId){								
							fingers[i] = tmpArray[t];
						}
					}
					t++;	
				}
				
				if (fingers[i]==null){
					fingers[i]= new Finger();
					fingers[i].fingerIndex = touch.fingerId;
					fingers[i].gesture = GestureType.None;
					fingers[i].phase = TouchPhase.Began;
				}
				else{
					fingers[i].phase = touch.phase;
				}

				if ( fingers[i].phase!= TouchPhase.Began){
					fingers[i].deltaPosition = touch.position - fingers[i].position;
				}
				else{
					fingers[i].deltaPosition = Vector2.zero;
				}

				fingers[i].position = touch.position;
				//fingers[i].deltaPosition = touch.deltaPosition;
				fingers[i].tapCount = touch.tapCount;
				fingers[i].deltaTime = touch.deltaTime;
				
				fingers[i].touchCount = touchCount;					
			}
		}
		else{
			int i=0;
			while (i<touchCount){
				fingers[i] = input.GetMouseTouch(i,fingers[i]) as Finger;
				fingers[i].touchCount = touchCount;
				i++;
			}			
		}
		
	}
Exemple #53
0
 public bool Contains(Finger touch)
 {
     return(list.Contains(touch));
 }
Exemple #54
0
	private void CreateGesture(int touchIndex,EventName message,Finger finger, SwipeDirection swipe, float swipeLength, Vector2 swipeVector){

		bool firingEvent = true;

		if (autoUpdatePickedUI && allowUIDetection){
			finger.isOverGui = IsScreenPositionOverUI( finger.position );
			finger.pickedUIElement = GetFirstUIElementFromCache();
		}

		// NGui
		if (enabledNGuiMode  && message == EventName.On_TouchStart){
			finger.isOverGui = finger.isOverGui || IsTouchOverNGui(finger.position);
		}

		// firing event ?
		if ((enableUIMode || enabledNGuiMode)){
			firingEvent = !finger.isOverGui;
		}

		// The new gesture
		Gesture gesture = finger.GetGesture();

		// Auto update picked object
		if (autoUpdatePickedObject && autoSelect){
			if (message != EventName.On_Drag && message != EventName.On_DragEnd && message != EventName.On_DragStart){
				if (GetPickedGameObject(finger)){
					gesture.pickedObject = pickedObject.pickedObj;
					gesture.pickedCamera = pickedObject.pickedCamera;
					gesture.isGuiCamera = pickedObject.isGUI;
				}
				else{
					gesture.pickedObject = null;
					gesture.pickedCamera = null;
					gesture.isGuiCamera = false;
				}
			}
		}

		gesture.swipe = swipe;
		gesture.swipeLength = swipeLength;
		gesture.swipeVector = swipeVector;

		gesture.deltaPinch = 0;
		gesture.twistAngle = 0;


		// Firing event
		if ( firingEvent){
			RaiseEvent(message, gesture);
		}
		else if (finger.isOverGui){
			if (message == EventName.On_TouchUp){
				RaiseEvent(EventName.On_UIElementTouchUp, gesture);
			}
			else{
				RaiseEvent(EventName.On_OverUIElement, gesture);
			}
		}

	}	
Exemple #55
0
 static Vector2 GetFingerPreviousPosition(Finger finger)
 {
     return(finger.PreviousPosition);
 }
Exemple #56
0
 public FingerPosition(Canvas canvas, Dispatcher dispatcher, FrameworkElement uiElement, Finger finger)
 {
     this.Canvas     = canvas;
     this.Dispatcher = dispatcher;
     this.Finger     = finger;
     this.UIElement  = uiElement;
 }
Exemple #57
0
    //Create bone objects and fingers from the leap motion pointalbes data.
    private List <Finger> createFingerlist(long Handid, long frameId, List <object> pointables_list)
    {
        List <Finger> result = new List <Finger>();

        foreach (var item in pointables_list)
        {
            Dictionary <string, object> pointables = (Dictionary <string, object>)item;

            List <object> btipPosition_list = (List <object>)pointables["btipPosition"];
            Vector        btipPosition      = creatVector((List <object>)btipPosition_list);

            List <object> carpPosition_list = (List <object>)pointables["carpPosition"];
            Vector        carpPosition      = creatVector((List <object>)carpPosition_list);

            List <object> dipPosition_list = (List <object>)pointables["dipPosition"];
            Vector        dipPosition      = creatVector((List <object>)dipPosition_list);

            List <object> direction_list = (List <object>)pointables["direction"];
            Vector        direction      = creatVector((List <object>)direction_list);

            bool extended = (bool)pointables["extended"];

            long handId = (long)pointables["handId"];

            long id = (long)pointables["id"];

            double length = (double)pointables["length"];
            //Debug.Log(length);

            List <object> mcpPosition_list = (List <object>)pointables["mcpPosition"];
            Vector        mcpPosition      = creatVector((List <object>)mcpPosition_list);

            List <object> pipPosition_list = (List <object>)pointables["pipPosition"];
            Vector        pipPosition      = creatVector((List <object>)pipPosition_list);

            List <object> stabilizedTipPosition_list = (List <object>)pointables["stabilizedTipPosition"];
            Vector        stabilizedTipPosition      = creatVector((List <object>)stabilizedTipPosition_list);

            double timeVisible = (double)pointables["timeVisible"];

            List <object> tipPosition_list = (List <object>)pointables["tipPosition"];
            Vector        tipPosition      = creatVector((List <object>)tipPosition_list);

            List <object> tipVelocity_list = (List <object>)pointables["tipVelocity"];
            Vector        tipVelocity      = creatVector((List <object>)tipVelocity_list);

            bool tool = (bool)pointables["tool"];

            double touchDistance = (double)pointables["touchDistance"];

            String touchZone = (String)pointables["touchZone"];

            long type_index = (long)pointables["type"];
            Finger.FingerType type;
            switch (type_index)
            {
            case 0: type = Finger.FingerType.TYPE_THUMB; break;

            case 1: type = Finger.FingerType.TYPE_INDEX; break;

            case 2: type = Finger.FingerType.TYPE_MIDDLE; break;

            case 3: type = Finger.FingerType.TYPE_RING; break;

            case 4: type = Finger.FingerType.TYPE_PINKY; break;

            default: type = Finger.FingerType.TYPE_UNKNOWN; break;
            }

            double width = (double)pointables["width"];

            float fingerId = handId + type_index;

            List <object> boneBasis = (List <object>)pointables["bases"];
            //Debug.Log(boneBasis.Count);
            List <object> bonelist_1 = (List <object>)boneBasis[0];
            List <object> bonelist_2 = (List <object>)boneBasis[1];
            List <object> bonelist_3 = (List <object>)boneBasis[2];
            List <object> bonelist_4 = (List <object>)boneBasis[3];

            Bone metacarpal   = createBone(bonelist_1, carpPosition, mcpPosition, (float)width, Bone.BoneType.TYPE_METACARPAL);
            Bone proximal     = createBone(bonelist_2, mcpPosition, pipPosition, (float)width, Bone.BoneType.TYPE_PROXIMAL);
            Bone intermediate = createBone(bonelist_3, pipPosition, dipPosition, (float)width, Bone.BoneType.TYPE_INTERMEDIATE);
            Bone distal       = createBone(bonelist_4, dipPosition, btipPosition, (float)width, Bone.BoneType.TYPE_DISTAL);

            Finger finger = new Finger(id, (int)frameId, (int)fingerId, (float)timeVisible, tipPosition, tipVelocity, direction, stabilizedTipPosition, (float)width, (float)length, extended, type, metacarpal, proximal, intermediate, distal);
            //Finger finger = new Finger();
            result.Add(finger);
        }
        return(result);
    }
Exemple #58
0
    public Finger GetMouseTouch(int fingerIndex, Finger myFinger)
    {
        Finger finger;

        if (myFinger != null)
        {
            finger = myFinger;
        }
        else
        {
            finger         = new Finger();
            finger.gesture = EasyTouch.GestureType.None;
        }
        if (fingerIndex == 1 && (Input.GetKeyUp(KeyCode.LeftAlt) || Input.GetKeyUp(EasyTouch.instance.twistKey) || Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(EasyTouch.instance.swipeKey)))
        {
            finger.fingerIndex   = fingerIndex;
            finger.position      = oldFinger2Position;
            finger.deltaPosition = finger.position - oldFinger2Position;
            finger.tapCount      = tapCount[fingerIndex];
            finger.deltaTime     = Time.realtimeSinceStartup - deltaTime[fingerIndex];
            finger.phase         = TouchPhase.Ended;
            return(finger);
        }
        if (Input.GetMouseButton(0))
        {
            finger.fingerIndex = fingerIndex;
            finger.position    = GetPointerPosition(fingerIndex);
            if ((double)(Time.realtimeSinceStartup - tapeTime[fingerIndex]) > 0.5)
            {
                tapCount[fingerIndex] = 0;
            }
            if (Input.GetMouseButtonDown(0) || (fingerIndex == 1 && (Input.GetKeyDown(KeyCode.LeftAlt) || Input.GetKeyDown(EasyTouch.instance.twistKey) || Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(EasyTouch.instance.swipeKey))))
            {
                finger.position      = GetPointerPosition(fingerIndex);
                finger.deltaPosition = Vector2.zero;
                tapCount[fingerIndex]++;
                finger.tapCount = tapCount[fingerIndex];
                startActionTime[fingerIndex] = Time.realtimeSinceStartup;
                deltaTime[fingerIndex]       = startActionTime[fingerIndex];
                finger.deltaTime             = 0f;
                finger.phase = TouchPhase.Began;
                if (fingerIndex == 1)
                {
                    oldFinger2Position = finger.position;
                }
                else
                {
                    ref Vector2 reference = ref oldMousePosition[fingerIndex];
                    reference = finger.position;
                }
                if (tapCount[fingerIndex] == 1)
                {
                    tapeTime[fingerIndex] = Time.realtimeSinceStartup;
                }
                return(finger);
            }
            finger.deltaPosition = finger.position - oldMousePosition[fingerIndex];
            finger.tapCount      = tapCount[fingerIndex];
            finger.deltaTime     = Time.realtimeSinceStartup - deltaTime[fingerIndex];
            if (finger.deltaPosition.sqrMagnitude < 1f)
            {
                finger.phase = TouchPhase.Stationary;
            }
            else
            {
                finger.phase = TouchPhase.Moved;
            }
            ref Vector2 reference2 = ref oldMousePosition[fingerIndex];
Exemple #59
0
 internal TouchProcessor(Arm arm, Finger finger)
 {
     m_arm    = arm;
     m_finger = finger;
 }
Exemple #60
0
    private void CreateGesture(int touchIndex,EventName message,Finger finger,float actionTime, SwipeType swipe, float swipeLength, Vector2 swipeVector)
    {
        if (message == EventName.On_TouchStart || message == EventName.On_TouchUp){
            isStartHoverNGUI = IsTouchHoverNGui(touchIndex);
        }

        //if (message == EventName.On_Cancel || message == EventName.On_TouchUp){
        //	isStartHoverNGUI = false;
        //}

        if (!isStartHoverNGUI){
            //Creating the structure with the required information
            Gesture gesture = new Gesture();

            gesture.fingerIndex = finger.fingerIndex;
            gesture.touchCount = finger.touchCount;
            gesture.startPosition = finger.startPosition;
            gesture.position = finger.position;
            gesture.deltaPosition = finger.deltaPosition;

            gesture.actionTime = actionTime;
            gesture.deltaTime = finger.deltaTime;

            gesture.swipe = swipe;
            gesture.swipeLength = swipeLength;
            gesture.swipeVector = swipeVector;

            gesture.deltaPinch = 0;
            gesture.twistAngle = 0;
            gesture.pickObject = finger.pickedObject;
            gesture.otherReceiver = receiverObject;

            gesture.isHoverReservedArea = IsTouchReservedArea( touchIndex);

            gesture.pickCamera = finger.pickedCamera;
            gesture.isGuiCamera = finger.isGuiCamera;

            gesture.hitPoint = finger.hitPoint;         //zs

            if (useBroadcastMessage){
                SendGesture(message,gesture);
            }
            if (!useBroadcastMessage || isExtension){
                RaiseEvent(message, gesture);
            }
        }
    }