/// <summary>
        /// Updates the pitch bend.
        /// </summary>
        /// <param name="pitchBendPointable">The pitch bend pointable.</param>
        private void UpdatePitchBend(Pointable pitchBendPointable)
        {
            // Determine pitch bend by x position of the fingertip relative to the center point (set by last note on event)
            var translation = pitchBendPointable.StabilizedTipPosition - _centerPositionForPitchBend;

            CurrentPitchBend = NormalizeDoubleValue(translation.x, -Config.PitchBendMaxRange / 2, Config.PitchBendMaxRange / 2);
        }
Exemple #2
0
        private void CalulateSlowScreenPosition(Pointable rightFinger)
        {
            CursorPositionX += rightFinger.TipVelocity.x * VelocityPressition;
            CursorPositionX += (1 - rightFinger.TipVelocity.y) * VelocityPressition;

            mouseFacade.SetCursorPosition((int)CursorPositionX, (int)CursorPositionY);
        }
        private void CalulateSlowScreenPosition(Pointable rightFinger)
        {
            CursorPositionX += rightFinger.TipVelocity.x * VelocityPressition;
            CursorPositionX += (1 - rightFinger.TipVelocity.y) * VelocityPressition;

            mouseFacade.SetCursorPosition((int)CursorPositionX, (int)CursorPositionY);
        }
        protected void DrawLeapTouch(Leap.Frame frame)
        {
            InteractionBox interactionBox = frame.InteractionBox;

            if (frame.Pointables.Extended().Count != 1)
            {
                return;
            }

            Pointable pointable = frame.Pointables.Extended()[0];

            // InteractionBox を利用した座標変換
            Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);

            double                tx         = normalizedPosition.x * windowWidth;
            double                ty         = windowHeight - normalizedPosition.y * windowHeight;
            StylusPoint           touchPoint = new StylusPoint(tx, ty);
            StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });

            // タッチ状態
            if (normalizedPosition.z <= TouchBorder)
            {
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                this.InkCanvas_LeapPaintLine.Strokes.Add(touchStroke.Clone());
            }
        }
Exemple #5
0
        /// <summary>
        /// Triggered when the Leap Motion OnFrame event occurs, handles the cursor control and events.
        /// </summary>
        protected void UpdateFrame(Controller con)
        {
            // Grab the frame and the nearest pointer
            Frame     frame     = con.Frame();
            Pointable pointable = frame.Pointables.Frontmost;

            Leap.Vector stabilizedPos = pointable.StabilizedTipPosition;

            // Calculate the position in screen space
            InteractionBox iBox = con.Frame().InteractionBox;

            Leap.Vector normalizedPosition = iBox.NormalizePoint(stabilizedPos);
            double      tx = normalizedPosition.x * screenWidth;
            double      ty = screenHeight - normalizedPosition.y * screenHeight;


            // Allows use of mouse normally
            if (pointable.TouchZone != Pointable.Zone.ZONENONE)
            {
                Mouse.HandleFrame(tx, ty);
            }

            // record current position
            //Win32Services.POINT pt = Win32Services.GetCursorPosition();
            //xPos = pt.x;
            //yPos = pt.y;
        }
Exemple #6
0
    void Update()
    {
        Frame frame = controller.Frame();

        FingerCount = frame.Fingers.Count;

        InteractionBox interactionBox = frame.InteractionBox;
        Pointable      pointable      = frame.Pointables.Frontmost;

        //Debug.Log(interactionBox.NormalizePoint(pointable.TipPosition));

        Vector normalizedPosition = interactionBox.NormalizePoint(pointable.TipPosition);

        normalizedPosition  *= 200;
        normalizedPosition.z = -normalizedPosition.z;
        FrontMost.transform.localPosition = ToVector3(normalizedPosition);

        /*
         * for ( int i = 0; i < FingerObjects.Length; i++ ) {
         * var leapFinger = frame.Fingers[i];
         * var unityFinger = FingerObjects[i];
         * SetVisible( unityFinger, leapFinger.IsValid );
         * if ( leapFinger.IsValid ) {
         *  Vector normalizedPosition = interactionBox.NormalizePoint(leapFinger.TipPosition );
         *  normalizedPosition *= 10;
         *  normalizedPosition.z = -normalizedPosition.z;
         *  unityFinger.transform.localPosition = ToVector3( normalizedPosition );
         * }
         * }
         */
    }
 /// <summary>
 /// Raises the pointable found event.
 /// </summary>
 /// <param name='p'>
 /// P.
 /// </param>
 void OnPointableFound(Pointable p)
 {
     if (m_HandsController != null)
     {
         // In this case we send the event to the Hands controller
         m_HandsController.OnPointableFound(p);
     }
 }
Exemple #8
0
    public override void OnFrame(Controller controller)
    {
        Frame currentFrame = controller.Frame();

        currentTime = currentFrame.Timestamp;
        changeTime  = currentTime - prevTime;
        if (changeTime > 5000)
        {
            Hand        hand          = currentFrame.Hands[0];
            FingerList  fingers       = hand.Fingers;
            Pointable   pointable     = currentFrame.Pointables[0];
            Leap.Screen screen        = controller.LocatedScreens.ClosestScreenHit(pointable);
            Frame       prevFrame     = controller.Frame(10);
            Hand        prevhand      = prevFrame.Hands[0];
            FingerList  prevfingers   = prevhand.Fingers;
            Pointable   prevpointable = prevFrame.Pointables[0];
            ScreenList  screenList    = controller.LocatedScreens;
            Leap.Screen prevscreen    = screenList.ClosestScreenHit(prevpointable);

            if (!fingers.IsEmpty)
            {
                float prevwidth  = prevscreen.Intersect(prevpointable, true, 1.0F).x *prevscreen.WidthPixels;
                float prevheight = prevscreen.Intersect(prevpointable, true, 1.0F).y *prevscreen.HeightPixels;
                float width      = screen.Intersect(pointable, true, 1.0F).x *screen.WidthPixels;
                float height     = screen.Intersect(pointable, true, 1.0F).y *screen.HeightPixels;
                float tranX      = currentFrame.Translation(prevFrame).x;
                float tranY      = currentFrame.Translation(prevFrame).y;
                int   fwidth     = (int)((width * 0.2) + (prevwidth * (1.0 - 0.2)));
                int   fheight    = (int)((height * 0.2) + (prevheight * (1.0 - 0.2)));
                fheight = screen.HeightPixels - fheight;
                if (fingers.Count == 2 || fingers.Count == 3)
                {
                    if (changeTime > 5000)
                    {
                        if (fingers.Count == 2)
                        {
                            mouse_event(0x0002 | 0x0004, 0, fwidth, fheight, 0);
                        }
                        else
                        {
                            mouse_event(0x0008 | 0x0010, 0, fwidth, fheight, 0);
                        }

                        Console.Write("Clicked At " + fwidth + " " + fheight);
                    }
                }
                else
                {
                    if (fingers.Count == 1)
                    {
                        Console.Write("TipPosition: " + fingers[0].TipPosition + " Width: " + width + " height: " + height + " tranX: " + tranX + " tranY: " + tranY + "\n");
                        SetCursorPos(fwidth, fheight);
                    }
                }
            }
            prevTime = currentTime;
        }
    }
        public bool Move(Pointable target)
        {
            if (!moveEnabled)
                return false;

            //move the mouse
            Console.WriteLine("Moving mouse to Pointable: {0}", target);
            return accessApi.Move(target.nextPoint().X, target.nextPoint().Y);
        }
Exemple #10
0
    void OnPointableUpdated(Pointable p)
    {
        int index = Array.FindIndex(pointableIDs, id => id == p.Id);

        if (index != -1)
        {
            updatePointable(p, pointables[index]);
        }
    }
 void OnPointableFound( Pointable p )
 {
     int index = Array.FindIndex(m_fingerIDs, id => id == -1);
     if( index != -1 )
     {
         m_fingerIDs[index] = p.Id;
         updatePointable( p, m_fingers[index] );
     }
 }
    //When an object is found, we find our first inactive game object, activate it, and assign it to the found id
    //When lost, we deactivate the object & set it's id to -1
    //When updated, load the new data
    void OnPointableUpdated(Pointable p)
    {
        int index = Array.FindIndex(m_fingerIDs, id => id == p.Id);

        if (index != -1)
        {
            updatePointable(p, m_fingers[index]);
        }
    }
Exemple #13
0
    // Verifica si el dedo esta estirado en comparacion con un minimo, pues depende de la posicion el dedo se ve mas estirado (a lo largo del eje Z)
    public bool stretchedFinger(Pointable finger, float min)
    {
        float fingerDirectionZ = finger.direction[2];

        if (fingerDirectionZ < min)
        {
            return(true);
        }
        return(false);
    }
Exemple #14
0
    //------------------------------------------------------------STRETCHED/FLEXED FINGER---------------------------------------------

    // Verifica si el dedo esta flexionado (a lo largo del eje Z)
    public bool flexedFinger(Pointable finger)
    {
        float fingerDirectionZ = finger.direction[2];

        if (fingerDirectionZ > 0.48)
        {
            return(true);
        }
        return(false);
    }
Exemple #15
0
    private void OnPointableUpdated(Pointable p)
    {
        if (!showRefreshPrompt && showTray >= 1f && (selectorPointableId == p.Id || selectorPointableId == -1))
        {
            selectorPointableId = p.Id;
            index = Mathf.RoundToInt((trayOffset + Mathf.InverseLerp(500f, 50f, p.TipPosition.ToUnity().y) * Screen.height) / 75f);
        }

        Debug.DrawRay(p.TipPosition.ToUnityTranslated(), p.Direction.ToUnity() * 0.1f);
    }
Exemple #16
0
    void OnPointableFound(Pointable p)
    {
        int index = Array.FindIndex(pointableIDs, id => id == -1);

        if (index != -1)
        {
            pointableIDs[index] = p.Id;
            updatePointable(p, pointables[index]);
        }
    }
    void OnPointableFound(Pointable p)
    {
        int index = Array.FindIndex(m_fingerIDs, id => id == -1);

        if (index != -1)
        {
            m_fingerIDs[index] = p.Id;
            updatePointable(p, m_fingers[index]);
        }
    }
 void OnPointableFound( Pointable p )
 {
     int index = Array.FindIndex(m_fingerIDs, id => id == -1);
     if( index != -1 )
     {
         m_fingerIDs[index] = p.Id;
         updatePointable( p, m_fingers[index] );
         m_fingers[index].GetComponent<Finger>().Found();
         Main.trackedFingers.Add( m_fingers[index] );
     }
 }
 /// <summary>
 /// Alternative constructor for circle gesture events
 /// <param name="normal">Contains the x, y and z vectors of the gesture</param>
 /// <param name="pointable">The object that is making the gesture</param>
 public GestureEvent(string name, int id, string state, float progress, Vector normal, Pointable pointable)
 {
     this.name      = name;
     this.id        = id;
     this.state     = state;
     this.progress  = progress;
     this.normal    = normal;
     this.position  = null;
     this.direction = null;
     this.pointable = pointable;
 }
 /// <summary>
 /// Alternative constructor for circle gesture events
 /// <param name="normal">Contains the x, y and z vectors of the gesture</param>
 /// <param name="pointable">The object that is making the gesture</param>
 public GestureEvent(string name, int id, string state, float progress, Vector normal, Pointable pointable)
 {
     this.name = name;
     this.id = id;
     this.state = state;
     this.progress = progress;
     this.normal = normal;
     this.position = null;
     this.direction = null;
     this.pointable = pointable;
 }
Exemple #21
0
    void Update()
    {
        prevFingerHeight = fingerHeight;
        Frame frame = controller.Frame();

        Pointable pointable          = frame.Pointables.Frontmost;
        Vector    stabilizedPosition = pointable.StabilizedTipPosition;

//		Debug.Log (stabilizedPosition.y);
        fingerHeight = stabilizedPosition.y;
    }
 // Evaluates the visible fingers and adds them in the FingerTypes dictionary (<int id>: <string type>)
 // [NOT USED]
 void EvaluateNewFinger(Pointable finger)
 {
     Leap.Vector handCenter = finger.Hand.SphereCenter;
     if (Math.Abs(handCenter.x - finger.TipPosition.x) < 40 && Math.Abs(handCenter.z - finger.TipPosition.z) > 15) {
     //			print ("This is the index: "+finger.Id);
         FingerTypes.Add(finger.Id, "index");
     }
     else {
     //			print ("This is the thumb: "+finger.Id);
         FingerTypes.Add(finger.Id, "thumb");
     }
 }
    void OnPointableFound(Pointable p)
    {
        int index = Array.FindIndex(m_fingerIDs, id => id == -1);

        if (index != -1)
        {
            m_fingerIDs[index] = p.Id;
            // set position manually to bypass the raycast.
            m_fingers[index].transform.localPosition = p.TipPosition.ToUnityTranslated();
            updatePointable(p, m_fingers[index]);
        }
    }
Exemple #24
0
    void OnPointableUpdated(Pointable p)
    {
        if (prevLine != null && p.IsValid)
        {
            //Vector3 dir = p.Direction.ToUnity();
            Vector3 pos = p.TipPosition.ToUnityTranslated();
            pos.z -= targetScript.m_LeapOffset.z;

            //transform.localPosition = pos;
            //transform.localRotation = Quaternion.FromToRotation(Vector3.forward, dir);
            prevLine.SetPosition(1, pos);
        }
    }
Exemple #25
0
 private static bool FingerCloseToBoundary(Pointable p)
 {
     if (m_device != null)
     {
         float distanceToBoxWall = m_device.DistanceToBoundary(p.TipPosition);
         // TODO: make this changable through Unity?
         if (distanceToBoxWall < 5.0)
         {
             return(true);
         }
     }
     return(false);
 }
 void OnPointableFound( Pointable p, bool visible )
 {
     int index = Array.FindIndex(m_fingerIDs, id => id == -1);
     if( index != -1 )
     {
         m_fingerIDs[index] = p.Id;
         int fingerHandID = Array.FindIndex(m_handIDs, id => id == p.Hand.Id);
         if (fingerHandID != -1)
         {
             m_fingerHandIDs[index] = fingerHandID;
             LeapInput.NumberOfFingers[fingerHandID]++;
         }
         updatePointable( p, m_fingers[index], visible );
     }
 }
Exemple #27
0
    void OnPointableFound(Pointable p, bool visible)
    {
        int index = Array.FindIndex(m_fingerIDs, id => id == -1);

        if (index != -1)
        {
            m_fingerIDs[index] = p.Id;
            int fingerHandID = Array.FindIndex(m_handIDs, id => id == p.Hand.Id);
            if (fingerHandID != -1)
            {
                m_fingerHandIDs[index] = fingerHandID;
                LeapInput.NumberOfFingers[fingerHandID]++;
            }
            updatePointable(p, m_fingers[index], visible);
        }
    }
Exemple #28
0
    // Update is called once per frame
    void Update()
    {
        if (controller.HasFocus)
        {
            Frame         frame      = controller.Frame();
            HandList      hands      = frame.Hands;
            PointableList pointables = frame.Pointables;
            FingerList    fingers    = frame.Fingers;
            ToolList      tools      = frame.Tools;


            int appWidth  = 20;
            int appHeight = 20;
            int appDepth  = 20;

            InteractionBox iBox      = frame.InteractionBox;
            Pointable      pointable = frame.Pointables.Frontmost;

            Leap.Vector leapPoint       = pointable.StabilizedTipPosition;
            Leap.Vector normalizedPoint = iBox.NormalizePoint(leapPoint, false);

            float appX = normalizedPoint.x * appWidth;
            float appY = (1 - normalizedPoint.y) * appHeight;
            float appZ = normalizedPoint.z * appDepth;



            cubey.transform.position = new Vector3(appX, appY, appZ);


            //logAllPalmPos(hands);
            //logAllFingerDir(fingers, "not leap coords");

            //VectorType vt = VectorType.toUnity;
            //drawRays(pointables, 10, .01f, vt);
            //drawCubes(pointables, cubeScale, vt);


            //drawCylindars(fingers, cylindarScale );

            //drawInteractionBox(frame.InteractionBox);
        }
    }
Exemple #29
0
    //When an object is found, we find our first inactive game object, activate it, and assign it to the found id
    //When lost, we deactivate the object & set it's id to -1
    //When updated, load the new data
    void OnPointableUpdated(Pointable p, bool visible)
    {
        int index = Array.FindIndex(m_fingerIDs, id => id == p.Id);

        if (index != -1)
        {
            for (int i = 0; i < LeapInput.DraggingFingers.Length; i++)
            {
                //if (LeapInput.DraggingFingers[i] != null)
                //{
                //Debug.Log(LeapInput.DraggingFingers[i]);
                //Debug.Log(m_fingers[index]);
                //}
                if (LeapInput.DraggingFingers[i] != null && LeapInput.DraggingFingers[i].Equals(m_fingers[index]))
                {
                    updatePointable(p, m_fingers[index], true);
                    return;
                }
            }
            updatePointable(p, m_fingers[index], visible);
        }
    }
    void Update()
    {
        Frame frame = controller.Frame();

        // Get frontmost pointable
        Pointable pointable = frame.Pointables.Frontmost;

        // Get distance (1 to -1)
        float distance = pointable.TouchDistance;

        // Get position
        Vector stabilizedPosition = pointable.StabilizedTipPosition;

        // Make it useable
        InteractionBox iBox = controller.Frame().InteractionBox;
        Vector         normalizedPosition = iBox.NormalizePoint(stabilizedPosition);
        float          x = normalizedPosition.x * UnityEngine.Screen.width;
        float          y = UnityEngine.Screen.height - normalizedPosition.y * UnityEngine.Screen.height;
        float          z = baseZ - distance * 6;

        // Move it
        this.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(x, UnityEngine.Screen.height - y, z));
    }
Exemple #31
0
 public static bool isForwardRelativeToHand(Pointable item, Hand hand)
 {
     return(Vector3.Dot((item.TipPosition.ToUnity() - hand.PalmPosition.ToUnity()).normalized, hand.Direction.ToUnity()) > _forwardFingerContraint);
 }
Exemple #32
0
 private static bool FingerCloseToBoundary(Pointable p)
 {
     if (m_device != null){
         float distanceToBoxWall = m_device.DistanceToBoundary(p.TipPosition);
         // TODO: make this changable through Unity?
         if (distanceToBoxWall < 5.0){
             return true;
         }
     }
     return false;
 }
    // Update a Unity GameObject that represents a Leap Pointable.
    void updatePointable( Leap.Pointable pointable, GameObject fingerObject )
    {
        // Update the parent object (the hand) of the pointable.
        updateParent( fingerObject, pointable.Hand.Id );

        // Change the pointable's visibility based on whether
        // or not the parent hand is valid.
        SetVisible(fingerObject, pointable.IsValid);
        // Do the same for the collidable property.
        SetCollidable(fingerObject, pointable.IsValid);

        // If the parent hand is valid:
        if ( pointable.IsValid )
        {
            point = pointable;
            // Create vectors for the finger's direction and position with the new
            // direction and position from the Leap, but only after scaling/ofsetting
            // with LeapUnityExtensions.
            Vector3 vFingerDir = pointable.Direction.ToUnity();
            Vector3 vFingerPos = pointable.TipPosition.ToUnityTranslated();

            // Apply the position vector to the Unity finger object.
            fingerObject.transform.localPosition = vFingerPos;
            // Apply the direction vector to the Unity finger object.
            // A Quaternion represents a rotation. For more information, see here:
            // http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.FromToRotation.html
            fingerObject.transform.localRotation = Quaternion.FromToRotation( Vector3.forward, vFingerDir );
            // LIU: get the offset from the forward (pitch) and right (yaw) vectors
        //			if (LeapUnitySelectionController.ActiveMode == "Rotating") {
        //				float offsetY = Vector3.Angle(Vector3.up, vFingerDir);
        //				float offsetX = Vector3.Angle(Vector3.right, vFingerDir);
        //				float pitch = offsetY.ToUnityPitch();
        //				float yaw = offsetX.ToUnityYaw();
                //fingerObject.GetComponent<SpotLight1>().OnLeapRotation(pitch, yaw);
        //				Debug.Log ("Pitch: "+pitch+"  Yaw: "+yaw);
        //				Vector2 rotation = new Vector2 (pitch,yaw);
        //				LeapUnitySelectionController.DoRotation(rotation);
                //fingerObject.transform.RotateAroundLocal(new Vector3(0,1,0),yaw);
                //fingerObject.gameObject.SendMessage(OnLeapRotation, yaw,SendMessageOptions.DontRequireReceiver);
        //			}
        }
    }
    // When an object is found, we find our first inactive game object, activate it, and assign it to the found id.
    // When lost, we deactivate the object & set it's id to -1.
    // When updated, load the new data.
    void OnPointableUpdated( Pointable p )
    {
        // Find the index of p.Id in m_fingerIDs.
        int index = Array.FindIndex(m_fingerIDs, id => id == p.Id);

        // If p.Id exists in m_fingerIDs:
        if( index != -1 )
        {
            // Update the pointable with the data passed from the event.
            updatePointable( p, m_fingers[index] );
        }
    }
 /// <summary>
 /// Method to trigger event for cirle gestures
 /// </summary>
 /// <param name="GestureName">The name of the gesture performed</param>
 /// <param name="GestureId">The ID of the gesture</param>
 /// <param name="GestureState">The state of the gesture in the frame</param>
 /// <param name="GestureNormal">The vector of the gesture</param>
 /// <param name="GesturePointable">The object used to make the gesture</param>
 void OnCircleGesture(string GestureName, int GestureId, string GestureState, float GestureProgress, Vector GestureNormal, Pointable GesturePointable)
 {
     GestureArgs = new GestureEvent(GestureName, GestureId, GestureState, GestureProgress, GestureNormal, GesturePointable);
     if (GestureMade != null)
     {
         GestureMade(this, GestureArgs);
     }
 }
Exemple #36
0
        private Vector GetPosition(Pointable pointable)
        {
            return pointable.StabilizedTipPosition;

            // still janky
            //if (null != pointable.Hand)
            //{
            //    return pointable.Hand.PalmPosition;
            //}
            //else
            //{
            //    return pointable.StabilizedTipPosition;
            //}
        }
Exemple #37
0
 void OnPointableUpdated(Pointable p)
 {
     int index = Array.FindIndex(pointableIDs, id => id == p.Id);
     if( index != -1 )
     {
         updatePointable( p, pointables[index] );
     }
 }
Exemple #38
0
    public override void OnFrame(Controller controller)
    {
        currentFrame = controller.Frame();
        prevFrame    = controller.Frame(10);
        currentTime  = currentFrame.Timestamp;
        changeTime   = currentTime - prevTime;

        if (changeTime > 500)
        {
            Hand       hand             = currentFrame.Hands[0];
            FingerList fingers          = hand.Fingers;
            Hand       prevHand         = prevFrame.Hands[0];
            FingerList prevFingers      = prevHand.Fingers;
            Pointable  currentPointable = currentFrame.Pointables[0];
            Pointable  prevPointable    = prevFrame.Pointables[0];
            // Set Up Screen
            Leap.Screen currentScreen = controller.LocatedScreens.ClosestScreenHit(currentPointable); //CalibratedScreens.ClosestScreenHit(currentPointable);
            Leap.Screen prevScreen    = controller.LocatedScreens.ClosestScreenHit(prevPointable);
            // Set up Display
            float  DisplayHeight = currentScreen.HeightPixels;
            float  DisplayWidth  = currentScreen.WidthPixels;
            double scalingFactor = 1.5;
            // Set up Coordinates
            float CurrentLeapXCoordinate = currentScreen.Intersect(currentPointable, true, 1.0F).x;
            float CurrentLeapYCoordinate = currentScreen.Intersect(currentPointable, true, 1.0F).y;
            int   CurrentyPixel          = (int)(DisplayHeight - (DisplayHeight * (scalingFactor * CurrentLeapYCoordinate)));
            int   CurrentxPixel          = (int)(DisplayWidth * (scalingFactor * CurrentLeapXCoordinate));
            float PrevLeapXCoordinate    = currentScreen.Intersect(prevPointable, true, 1.0F).x;
            float PrevLeapYCoordinate    = currentScreen.Intersect(prevPointable, true, 1.0F).y;
            int   PrevyPixel             = (int)(DisplayHeight - (DisplayHeight * (scalingFactor * PrevLeapYCoordinate)));
            int   PrevxPixel             = (int)(DisplayWidth * (scalingFactor * PrevLeapXCoordinate));
            float changeyPixel           = (PrevyPixel - CurrentyPixel);
            float changexPixel           = (PrevxPixel - CurrentxPixel);
            if (changeyPixel < 0)
            {
                changeyPixel = changeyPixel * -1;
            }
            if (changexPixel < 0)
            {
                changexPixel = changexPixel * -1;
            }
            bool allowfalse = false;
            if (changeyPixel > 10)
            {
                allowfalse = true;
            }
            if (CurrentyPixel < 0)
            {
                CurrentyPixel = 0;
            }
            if (CurrentxPixel < 0)
            {
                CurrentxPixel = 0;
            }
            if (allowfalse)
            {
                if (prevFingers.Count != 2 || prevFingers.Count != 3)
                {
                    if (fingers.Count == 1)
                    {
                        if (changeTime > 500)
                        {
                            UnityEngine.Debug.Log("TipPosition: " + fingers[0].TipPosition + " Width: " + CurrentxPixel + " height: " + CurrentyPixel + "\n");
                            SetCursorPos(CurrentxPixel, CurrentyPixel);
                        }
                    }
                    if (fingers.Count == 2)
                    {
                        if (changeTime > 1000)
                        {
                            mouse_event(0x0002 | 0x0004, 0, CurrentxPixel, CurrentyPixel, 0);
                            UnityEngine.Debug.Log("Clicked At " + CurrentxPixel + " " + CurrentyPixel + "\n");
                        }
                    }
                    if (fingers.Count == 4)
                    {
                        if (changeTime > 10000)
                        {
                            float Translation = currentFrame.Translation(prevFrame).y;
                            Console.WriteLine(Translation);
                            if (Translation < -50)
                            {
                                //SendKeys.SendWait("{LEFT}");
                                System.Threading.Thread.Sleep(700);
                            }
                            if (Translation > 50)
                            {
                                //SendKeys.SendWait("{Right}");
                                System.Threading.Thread.Sleep(700);
                            }
                        }
                    }
                }
            }
        }
        prevTime = currentTime;
    }
Exemple #39
0
    private void OnPointableUpdated(Pointable p)
    {
        if (!showRefreshPrompt && showTray >= 1f && (selectorPointableId == p.Id || selectorPointableId == -1))
        {
            selectorPointableId = p.Id;
            index = Mathf.RoundToInt((trayOffset + Mathf.InverseLerp(500f, 50f, p.TipPosition.ToUnity().y) * Screen.height) / 75f);
        }

        Debug.DrawRay(p.TipPosition.ToUnityTranslated(), p.Direction.ToUnity() * 0.1f);
    }
 //When an object is found, we find our first inactive game object, activate it, and assign it to the found id
 //When lost, we deactivate the object & set it's id to -1
 //When updated, load the new data
 void OnPointableUpdated( Pointable p, bool visible )
 {
     int index = Array.FindIndex(m_fingerIDs, id => id == p.Id);
     if( index != -1 )
     {
         for (int i = 0; i < LeapInput.DraggingFingers.Length; i++)
         {
             //if (LeapInput.DraggingFingers[i] != null)
             //{
                 //Debug.Log(LeapInput.DraggingFingers[i]);
                 //Debug.Log(m_fingers[index]);
             //}
             if (LeapInput.DraggingFingers[i] != null && LeapInput.DraggingFingers[i].Equals(m_fingers[index]))
             {
                 updatePointable( p, m_fingers[index], true );
                 return;
             }
         }
         updatePointable( p, m_fingers[index], visible );
     }
 }
Exemple #41
0
    private bool isForwardRelativeToHand(Pointable item, Hand hand)
    {
        Vector3 vHandToFinger = (LeapToUnity(item.TipPosition, true) - LeapToUnity(hand.PalmPosition, true)).normalized;
        float fDotProduct = Vector3.Dot(vHandToFinger, LeapToUnity(hand.Direction, false));

        return fDotProduct > 0.7f;
    }
	void OnPointableFound( Pointable p )
	{
		int index = Array.FindIndex(m_fingerIDs, id => id == -1);
		if( index != -1 )
		{
			m_fingerIDs[index] = p.Id;
			// set position manually to bypass the raycast.
			m_fingers[index].transform.localPosition = p.TipPosition.ToUnityTranslated();
			updatePointable( p, m_fingers[index] );
		}
	}
Exemple #43
0
 public static bool openRelativeHand(Pointable pointFinger, Hand hand)
 {
     return(Vector3.Dot(pointFinger.TipPosition.ToUnity() - hand.PalmPosition.ToUnity().normalized,
                        hand.Direction.ToUnity()) > forwardFingerContraint);
 }
 void OnPointableFound( Pointable p )
 {
     // Find the first instance of -1 in m_fingerIDs
     // (the first unused index).
     int index = Array.FindIndex(m_fingerIDs, id => id == -1);
     // Allow only two fingers to be visible
     // if this is there are less than 2 fingers check which type is the new: thumb or index
     if (index >= GetAllowableFingers()) {
         return;
     //			EvaluateNewFinger (p);
     //			// and change the interaciton mode accordingly
     //			SetInteractionMode();
     }
     //		else {
     //			return;
     //		}
     // If there is an available slot in the array:
     if( index != -1 )
     {
         LeapUnitySelectionController.OnFound(m_fingers[index]);
         // Change the index to match p.Id.
         m_fingerIDs[index] = p.Id;
         // Update the pointable with the data passed from the event.
         updatePointable( p, m_fingers[index] );
     }
 }
 //When an object is found, we find our first inactive game object, activate it, and assign it to the found id
 //When lost, we deactivate the object & set it's id to -1
 //When updated, load the new data
 public void OnPointableUpdated(Pointable p)
 {
 }
 //When an object is found, we find our first inactive game object, activate it, and assign it to the found id
 //When lost, we deactivate the object & set it's id to -1
 //When updated, load the new data
 void OnPointableUpdated( Pointable p )
 {
     int index = Array.FindIndex(m_fingerIDs, id => id == p.Id);
     if( index != -1 )
     {
         updatePointable( p, m_fingers[index] );
     }
 }
 /// <summary>
 /// Resets the pitch bend center point.
 /// </summary>
 /// <param name="pitchBendPointable">The pitch bend pointable.</param>
 private void ResetPitchBend(Pointable pitchBendPointable)
 {
     _centerPositionForPitchBend = pitchBendPointable.StabilizedTipPosition;
 }
Exemple #48
0
    // Update is called once per frame
    void Update()
    {
        float     percent;
        Frame     frame     = controller.Frame();
        Pointable pointable = frame.Pointables.Frontmost;
        //Vector direction = pointable.Direction;
        //float length = pointable.Length;
        //float width = pointable.Width;
        //Vector stabilizedPosition = pointable.StabilizedTipPosition;
        Vector position = pointable.TipPosition;

        //Vector speed = pointable.TipVelocity;
        //float touchDistance = pointable.TouchDistance;
        Pointable.Zone zone = pointable.TouchZone;

        Vector3 pointerPos     = gameObject.transform.position + _leapManager.pointerPositionWorld + (gameObject.transform.rotation * Vector3.forward * 10.0f);
        Vector2 screenPosition = myCam.WorldToScreenPoint(pointerPos);

        Ray clicker = myCam.ScreenPointToRay(screenPosition);

        if (Physics.Raycast(clicker, out hit, float.MaxValue, hitMask))
        {
            if (hit.collider.gameObject.name == "Restart")
            {
                if (lastHover != "Restart")
                {
                    lastHover = "Restart";
                    timer     = 0f;
                }

                else
                {
                    timer += Time.deltaTime;
                    if (timer >= 3f)
                    {
                        Application.LoadLevel("Map");
                    }

                    else
                    {
                        percent = timer / 3f;
                        cursor.renderer.material.color = Color.Lerp(startcolor, endcolor, percent);
                    }
                }
            }

            else if (hit.collider.gameObject.name == "Menu")
            {
                if (lastHover != "Menu")
                {
                    lastHover = "Menu";
                    timer     = 0f;
                }

                else
                {
                    timer += Time.deltaTime;

                    if (Time.time + timer >= Time.time + 3f)
                    {
                        Application.LoadLevel("Startscreen");
                    }

                    else
                    {
                        percent = timer / 3f;
                        cursor.renderer.material.color = Color.Lerp(startcolor, endcolor, percent);
                    }
                }
            }

            else if (hit.collider.gameObject.name == "Next")
            {
                if (lastHover != "Next")
                {
                    lastHover = "Next";
                    timer     = 0f;
                }

                else
                {
                    timer += Time.deltaTime;

                    if (Time.time + timer >= Time.time + 3f)
                    {
                        Application.LoadLevel("Level 2");
                    }

                    else
                    {
                        percent = timer / 3f;
                        cursor.renderer.material.color = Color.Lerp(startcolor, endcolor, percent);
                    }
                }
            }
            else
            {
                timer     = 0f;
                lastHover = "";
                percent   = timer / 3f;
                cursor.renderer.material.color = startcolor;
            }
        }

        else
        {
            cursor.renderer.material.color = startcolor;
        }
    }
 public static bool isForwardRelativeToHand(Pointable item, Hand hand)
 {
     return Vector3.Dot((item.TipPosition.ToUnity() - hand.PalmPosition.ToUnity()).normalized, hand.Direction.ToUnity()) > _forwardFingerContraint;
 }
 /// <summary>
 /// Raises the pointable found event.
 /// </summary>
 /// <param name='p'>
 /// P.
 /// </param>
 public void OnPointableFound(Pointable p)
 {
 }
Exemple #51
0
 void OnPointableFound( Pointable p )
 {
     int index = Array.FindIndex(pointableIDs, id => id == -1);
     if( index != -1 )
     {
         pointableIDs[index] = p.Id;
         updatePointable( p, pointables[index] );
     }
 }