Пример #1
1
        /// <summary>
        /// Write the data of each frame in the file.
        /// </summary>
        /// <param name="controller">Controller that represent the device.</param>
        /// <param name="path">Path of the file where the data will be write.<br/>
        /// If one already exist it will be deleted and a new empty on is created.</param>
        public void RecordData(Controller controller, String path)
        {
            if (Directory.Exists(path) == true)
            {
                String destination = path + "leapMotion.data";
                try
                {
                    if (File.Exists(destination) == true)
                        File.Delete(destination);
                    file = File.Create(destination);
                }
                catch (ArgumentException e)
                {
                    throw e;
                }
            }
            else
                throw new System.ArgumentException("Destination path doesn't exist", "path");

            BinaryWriter writer = new BinaryWriter(file);
            for (int f = 9; f >= 0; f--)
            {
                Frame frameToSerialize = controller.Frame(f);
                byte[] serialized = frameToSerialize.Serialize;
                Int32 length = serialized.Length;
                writer.Write(length);
                writer.Write(serialized);
            }
        }
Пример #2
0
        // 現在のフレームと、直前の5フレームを取得する
        static void GetBeforeFrame()
        {
            Controller leap = new Controller();
            long previousFrameId = -1;

            while ( true ) {
                // 最新のフレームを取得する(leap.Frame( 0 ) と同じ)
                var currentFrame = leap.Frame();
                if ( previousFrameId == currentFrame.Id ) {
                    continue;
                }

                previousFrameId = currentFrame.Id;

                // 直前の5フレームを取得する
                Console.Write( currentFrame.Id + ", " );
                for ( int i = 1; i <= 5; ++i ) {
                    var previousFrame = leap.Frame( i );
                    Console.Write( previousFrame.Id + ", " );
                }

                Console.WriteLine();
            }

            // 終了処理(onExit()相当)
        }
Пример #3
0
	// Use this for initialization
	void Start () {
		Application.runInBackground = true;
		controller = new Leap.Controller ();
		state = State.UP;
		previousFingers = new Vector[4];
		currentFingers = new Vector[4];


		previousFingers [0] = controller.Frame().Hands.Leftmost.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE)[0].StabilizedTipPosition;
		previousFingers [1] = controller.Frame().Hands.Leftmost.Fingers.FingerType(Finger.FingerType.TYPE_INDEX)[0].StabilizedTipPosition;
		previousFingers [2] = controller.Frame().Hands.Rightmost.Fingers.FingerType(Finger.FingerType.TYPE_INDEX)[0].StabilizedTipPosition;
		previousFingers [3] = controller.Frame().Hands.Rightmost.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE)[0].StabilizedTipPosition;
	}
Пример #4
0
    // Use this for initialization
    void Start()
    {
        Application.runInBackground = true;
        controller      = new Leap.Controller();
        state           = State.UP;
        previousFingers = new Vector[4];
        currentFingers  = new Vector[4];


        previousFingers [0] = controller.Frame().Hands.Leftmost.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE)[0].StabilizedTipPosition;
        previousFingers [1] = controller.Frame().Hands.Leftmost.Fingers.FingerType(Finger.FingerType.TYPE_INDEX)[0].StabilizedTipPosition;
        previousFingers [2] = controller.Frame().Hands.Rightmost.Fingers.FingerType(Finger.FingerType.TYPE_INDEX)[0].StabilizedTipPosition;
        previousFingers [3] = controller.Frame().Hands.Rightmost.Fingers.FingerType(Finger.FingerType.TYPE_MIDDLE)[0].StabilizedTipPosition;
    }
Пример #5
0
 // Update on every frame
 void Update()
 {
     if (_leap.IsConnected)
     {
         var frame = _leap.Frame();
         if (frame.Hands.Count > 0)
         {
             // The Leap Motion can see a hand, so get its palm position
             Leap.Vector leapPalmPosition = frame.Hands[0].PalmPosition;
             // Convert to our vector class, and then convert to our coordinate space
             Ultrahaptics.Vector3 uhPalmPosition = _alignment.fromTrackingPositionToDevicePosition(LeapToUHVector(leapPalmPosition));
             // Create a control point object using this position, with full intensity, at 200Hz
             AmplitudeModulationControlPoint point = new AmplitudeModulationControlPoint(uhPalmPosition, 1.0f, 200.0f);
             // Output this point
             _emitter.update(new List <AmplitudeModulationControlPoint> {
                 point
             });
         }
         else
         {
             Debug.LogWarning("No hands detected");
             _emitter.stop();
         }
     }
     else
     {
         Debug.LogWarning("No Leap connected");
         _emitter.stop();
     }
 }
 void FixedUpdate()
 {
     if (inputEnabled)
     {
         activeCursors.Clear();
         Frame    frame = controller.Frame();
         HandList hands = frame.Hands;
         for (int h = 0; h < hands.Count; h++)
         {
             Hand       hand   = hands[h];
             HandCursor cursor = GetCursor();
             cursor.OnFrame(hand);
         }
         //hide all inactive cursors
         foreach (HandCursor cursor in allCursors)
         {
             if (!activeCursors.Contains(cursor))
             {
                 cursor.gameObject.SetActive(false);
                 cursor.Release();
             }
         }
         MoleculeManager.instance.OnFrame(activeCursors);
     }
 }
Пример #7
0
 // Update is called once per frame
 void Update()
 {
     if (placed)
     {
         return;
     }
     frame = leapcontroller.Frame();
     lHand = Hands.Left;
     // if there are hands visible in the view.
     if (lHand != null)
     {
         if (util.IsFlatHand(lHand))
         {
             HUDObject.SetActive(true);
         }
         else
         {
             HUDObject.SetActive(false);
         }
     }
     else
     {
         // if no hands are visible in the view, set the HUD inactive
         HUDObject.SetActive(false);
     }
 }
Пример #8
0
        public void Evaluate(int SpreadMax)
        {
            if (leapcontroller != null && leapcontroller.IsConnected && leapcontroller.IsServiceConnected && leapcontroller.Devices.Count > 0)
            {
                FDevice.SliceCount     = 1;
                FController.SliceCount = 1;
                FFrame.SliceCount      = 1;

                FDevice[0]     = leapdevice;
                FController[0] = leapcontroller;
                FFrame[0]      = leapcontroller.Frame(0);
                leapdevice     = leapcontroller.Devices[0];
            }
            else
            {
                FDevice.SliceCount     = 0;
                FController.SliceCount = 0;
                FFrame.SliceCount      = 0;
            }
            if (FReinit[0] || FirstFrame)
            {
                if (leapcontroller != null)
                {
                    leapcontroller.Dispose();
                }
                leapinit();
                FirstFrame = false;
            }
            GlobalScale            = FScale[0];
            GlobalZMul             = (FMirror[0]) ? -1 : 1;
            AgeCorrectionThreshold = FAgeThreshold[0];
        }
 // Update is called once per frame
 void Update()
 {
     isConnected    = leapController.IsConnected;
     confidenceLeft = confidenceRight = 0.0f;
     if (!isConnected)
     {
         return;
     }
     lastFrame  = leapController.Frame();
     handsCount = lastFrame.Hands.Count;
     if (handsCount != 2)
     {
         return;
     }
     for (int i = 0; i < 2; i++)
     {
         if (lastFrame.Hands[i].IsRight)
         {
             confidenceRight = lastFrame.Hands[i].Confidence;
             rightNormal     = lastFrame.Hands[i].PalmNormal;
             rightPos        = lastFrame.Hands[i].PalmPosition;
         }
         else
         {
             confidenceLeft = lastFrame.Hands[i].Confidence;
             leftNormal     = lastFrame.Hands[i].PalmNormal;
             leftPos        = lastFrame.Hands[i].PalmPosition;
         }
     }
     if (handIndicator != null)
     {
         Transform tr = handIndicator.GetComponent <Transform>();
         tr.position = new Vector3(leftPos.x / 100.0f, leftPos.y / 100.0f, leftPos.z / 100.0f);
     }
 }
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            // Get gestures
            // Only handles swipe gesture for now...
            GestureList gestures = frame.Gestures();
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];

                switch (gesture.Type)
                {
                    case Gesture.GestureType.TYPE_SWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);
                        OnGesture("swipe", swipe.Id, swipe.State.ToString(), swipe.Position.ToFloatArray(), swipe.Direction.ToFloatArray());
                        break;
                    case Gesture.GestureType.TYPECIRCLE:
                        CircleGesture circle = new CircleGesture(gesture);
                        OnCircleGesture("circle", circle.Id, circle.State.ToString(), circle.Progress, circle.Normal, circle.Pointable);
                        break;
                }
            }
        }
Пример #11
0
    // Update is called once per frame
    void assignHands()
    {
        Frame       frame = controller.Frame();
        List <Hand> hands = frame.Hands;

        if (hands.Count > 1)
        {
            if (hands[0].IsLeft)
            {
                left  = hands[0];
                right = hands[1];
            }
            else
            {
                right = hands[0];
                left  = hands[1];
            }
        }
        else if (hands.Count > 0)
        {
            if (hands[0].IsLeft)
            {
                left  = hands[0];
                right = null;
            }
            else
            {
                right = hands[0];
                left  = null;
            }
        }
    }
Пример #12
0
    void Update()
    {
        {
            Frame frame = controller.Frame();

            if (frame.Hands.Count == 2)
            {
                List <Hand> hands = frame.Hands;
                Hand        one   = hands[0];
                Hand        two   = hands[1];
                //Debug.Log(one.PinchDistance);
                if (one.PinchDistance < 20 && two.PinchDistance < 20 && !isConjured)
                {
                    GameObject eye  = GameObject.Find("LeapHandController");
                    EyeOfA     eyeA = eye.GetComponent <EyeOfA>();

                    GameObject a = eyeA.eyeOfA;
                    temp = GameObject.Instantiate(a) as GameObject;
                    temp.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f);
                    temp.transform.Rotate(90, 0, 0);
                    temp.transform.position = new Vector3(0, 0, 1);
                    isConjured = true;
                }
                else if (one.PinchDistance < 20 && two.PinchDistance < 20 && isConjured)
                {
                    temp.transform.Rotate(0, 0, 2);
                    if (temp.transform.localScale.x < 0.3f)
                    {
                        temp.transform.localScale += new Vector3(0.002f, 0.002f, 0.002f);
                    }
                    else
                    {
                        if (Time.time > nextFire && counter < 10)
                        {
                            counter++;
                            GameObject clyinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                            clyinder.transform.position.Set(0, 0, 3);
                            clyinder.transform.Rotate(90, 0, 0);
                            Vector3 scale = transform.localScale;
                            scale.x = 0.2f;
                            scale.y = 0.2f;
                            scale.z = 0.2f;
                            clyinder.transform.localScale = scale;
                            Rigidbody clyinderRigid = clyinder.AddComponent <Rigidbody>().GetComponent <Rigidbody>();
                            clyinderRigid.useGravity = false;
                            clyinderRigid.AddForce(transform.forward * 500);
                            Destroy(clyinder, 2f);
                            nextFire = Time.time + 0.2f;
                        }
                    }
                }
                else
                {
                    Destroy(temp);
                    isConjured = false;
                    counter    = 0;
                }
            }
        }
    }
Пример #13
0
        public override void OnFrame(Controller leapController)
        {
            Frame currentFrame = leapController.Frame();

            if (handsLastFrame == 0 && currentFrame.Hands.Count > 0 && LeapRegisterFingers != null)
                LeapRegisterFingers(true);
            else if (handsLastFrame > 0 && currentFrame.Hands.Count == 0 && LeapRegisterFingers != null)
                LeapRegisterFingers(false);
            handsLastFrame = currentFrame.Hands.Count;

            if (currentFrame.Hands.Count > 0 &&
                currentFrame.Hands[0].Fingers.Count > 0 &&
                LeapSwipe != null)
            {
                GestureList gestures = currentFrame.Gestures();
                foreach (Gesture gesture in gestures)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);
                    if (Math.Abs(swipe.Direction.x) > Math.Abs(swipe.Direction.y)) // Horizontal swipe
                    {
                        if (swipe.Direction.x > 0)
                            LeapSwipe(SwipeDirection.Right);
                        else
                            LeapSwipe(SwipeDirection.Left);
                    }
                    else // Vertical swipe
                    {
                        if (swipe.Direction.y > 0)
                            LeapSwipe(SwipeDirection.Up);
                        else
                            LeapSwipe(SwipeDirection.Down);
                    }
                }
            }
        }
Пример #14
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            var frame = controller.Frame();

            try
            {
                // Update all registered items
                lock (_FrameUpdateItems)
                {
                    var item = _FrameUpdateItems.First;
                    while (item != null)
                    {
                        var next = item.Next;
                        if (!item.Value.Update(frame))
                            _FrameUpdateItems.Remove(item);
                        item = next;
                    }
                }
            }
            catch (Exception e)
            {
                _LogAction("Exception: " + e.GetType().FullName + "\n" + e.Message + "\n" + e.StackTrace);
            }
        }
Пример #15
0
    void Update()
    {
        var frame       = controller.Frame();
        var maxDistance = 0.0f;

        transform.position = ConvertVector(frame.Hands [handIndex].PalmPosition) * CoordinateScale;

        for (var i = 0; i < 5; i++)
        {
            var finger = frame.Hands [handIndex].Fingers [i];

            fingers [i].renderer.enabled = finger.IsValid;
            if (!finger.IsValid)
            {
                continue;
            }

            fingers [i].transform.position = ConvertVector(finger.TipPosition) * CoordinateScale;

            var distance = (fingers [i].transform.position - transform.position).magnitude;
            maxDistance = Mathf.Max(maxDistance, distance);
        }

        openness             = Mathf.Lerp(openness, FingerDistanceToOpenness(maxDistance), 0.1f);
        transform.localScale = Vector3.one * openness * 0.5f;

        renderer.enabled = frame.Hands [handIndex].IsValid;
    }
Пример #16
0
    // Update is called once per frame
    void Update()
    {
        controller = new Leap.Controller();
        Leap.Frame       frame = controller.Frame();
        List <Leap.Hand> hands = frame.Hands;

        Leap.Hand fristHand = hands[0];
        position = hands[0].PalmPosition;

        pos = Leap.Unity.UnityVectorExtension.ToVector3(position);


        // Attach to the palm
        // Vive Tracker
        //Vector3 pos = new Vector3(ViveHand.transform.position.x - 0.2f, ViveHand.transform.position.y + 1.0f, ViveHand.transform.position.z - 0.5f);

        //Vector3 pos = new Vector3(ViveHand.transform.position.x, ViveHand.transform.position.y, ViveHand.transform.position.z);

        transform.position = pos;

        //if (!pos.Equals(UnityEngine.Vector3.zero))
        //{
        //    // If non-zero, orientate to the hand surface
        //    Vector3 dir = new Vector3(hand.Direction.x, hand.Direction.y, 0.0f);
        //    Vector3 norm =new Vector3(hand.PalmNormal.x, hand.PalmNormal.y, 0.0f);

        //    transform.rotation = Quaternion.LookRotation(dir, norm);
        //}
    }
Пример #17
0
        // Poke gesture
        void PokeGesture(Leap.Controller controller)
        {
            Leap.Frame frame = controller.Frame();
            Hand       hand  = frame.Hands[0];

            // Initiate Poke gesture if Index finger is extended
            if (!poke.gestureOn)
            {
                foreach (Finger finger in hand.Fingers)
                {
                    if (finger.Type == Finger.FingerType.TYPE_INDEX && ((Pointable)finger).IsExtended)
                    {
                        Debug.WriteLine("Poke Started");
                        poke.gestureOn = true;
                    }
                }
            }

            // Perform Poke gesture if Index finger moves forward & back
            if (poke.gestureOn)
            {
                Leap.Vector motion = frame.Translation(controller.Frame(1));

                if (motion.y < -5.0f)
                {
                    poke.forwardMotion++;
                }
                else if (motion.y > 5.0f)
                {
                    poke.backwardMotion++;
                }

                // Turn off gesture and set cooldown timer to .5 sec
                if (poke.forwardMotion > 5 && poke.backwardMotion > 5)
                {
                    Debug.WriteLine("Poke!");
                    poke.forwardMotion   = 0;
                    poke.backwardMotion  = 0;
                    poke.gestureOn       = false;
                    poke.gestureFinished = true;
                    System.Timers.Timer timer = new System.Timers.Timer();
                    timer.Elapsed += new ElapsedEventHandler(PokeSetFinished);
                    timer.Interval = 500;
                    timer.Start();
                }
            }
        }
        public override void OnFrame(Controller controller)
        {
            Frame frame = controller.Frame();
            // Get the first hand
            Hand hand = frame.Hands[0];

            // Check if the hand has any fingers
            FingerList fingers = hand.Fingers;
            if (!fingers.Empty)
            {
                // Calculate the hand's average finger tip position
                Vector avgPos = Vector.Zero;
                Vector avgVelocity = Vector.Zero;
                foreach (Finger finger in fingers)
                {
                    avgPos += finger.TipPosition;
                    avgVelocity += finger.TipVelocity;
                }
                avgPos /= fingers.Count;
                avgVelocity /= fingers.Count;
                List<Gesture.Direction> directions = new List<Gesture.Direction>();

                if (avgVelocity.y > 1500)
                {
                    directions.Add(Gesture.Direction.Up);
                }
                else if (avgVelocity.y < -1500)
                {
                    directions.Add(Gesture.Direction.Down);
                }

                if (avgVelocity.x > 1500)
                {
                    directions.Add(Gesture.Direction.Left);
                }
                else if (avgVelocity.x < -1500)
                {
                    directions.Add(Gesture.Direction.Right);
                }

                if (avgVelocity.z > 1500)
                {
                    directions.Add(Gesture.Direction.Forward);
                }
                else if (avgVelocity.z < -1500)
                {
                    directions.Add(Gesture.Direction.Backward);
                }

                if (directions.Count > 0)
                {
                    Gesture gesture = new Gesture(directions.ToArray(), fingers.Count);
                    onGesture(gesture);
                }

                //Console.WriteLine("Hand has " + fingers.Count
                //            + " fingers, average finger tip Velocity: " + avgVelocity);
            }
        }
Пример #19
0
 public static Frame GetFrame()
 {
     if (leap_controller_ == null)
     {
         CreateController();
     }
     return(leap_controller_.Frame());
 }
Пример #20
0
 // Use this for initialization
 void Start()
 {
     hUtil          = new HandsUtil();
     leapcontroller = new Leap.Controller();
     frame          = leapcontroller.Frame();
     HUDMgr         = GameObject.Find("Managers").GetComponent <HUDManager>();
     dcg            = GameObject.Find("DCG").GetComponent <DCGBase>();
 }
 public override void OnFrame(Controller controller)
 {
     Frame frame = controller.Frame();
     //Console.WriteLine("FRAME");
     foreach (IFrameListener frameListener in frameListeners)
     {
         frameListener.OnFrame(frame);
     }
 }
        public override void OnFrame(Controller controller)
        {
            Frame frame = controller.Frame();

            foreach (IFrameListener frameListener in frameListeners)
            {
                frameListener.OnFrame(frame);
            }
        }
Пример #23
0
            public override void OnFrame( Controller leap )
            {
                var frame = leap.Frame();

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

                Console.WriteLine( string.Format( "手 : {0} 指 : {1} ツール : {2} ポインタ : {3}",
                    hands.Count, fingers.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
                // 指の情報を表示する
                Finger finger = frame.Fingers[0];
                Console.WriteLine( string.Format( "ID : {0} 位置 : {1} 速度 : {2} 向き : {3}",
                    finger.Id, finger.TipPosition, finger.TipVelocity, finger.Direction ) );
                #endif
            }
Пример #24
0
        // 指のIDとフレーム履歴を利用して、10フレームの指の平均座標を求める
        static void AverageFingerPosition()
        {
            Controller leap = new Controller();
            long previousFrameId = -1;

            // 初期化処理(OnInit()相当)をここに書く
            // 無限ループ内で、前回のフレームのIDと比較して新しいフレームを取得する
            while ( true ) {
                var frame = leap.Frame();
                if ( previousFrameId == frame.Id ) {
                    continue;
                }

                previousFrameId = frame.Id;
                //Console.WriteLine( "Frame ID : " + frame.Id );

                // フレーム更新処理(OnFrame()相当)をここに書く

                //Average a finger position for the last 10 frames
                int count = 0;
                Vector average = new Vector();

                // 最初のに検出された指の平均を取得する
                Finger fingerToAverage = frame.Fingers[0];

                for ( int i = 0; i < 10; i++ ) {
                    // 指定したフレームの、指定した指IDの、指データを取得する
                    Finger fingerFromFrame = leap.Frame( i ).Finger( fingerToAverage.Id );
                    if ( fingerFromFrame.IsValid ) {
                        // 取得した指データが有効であれば平均値の算出に利用する
                        average += fingerFromFrame.TipPosition;
                        count++;
                    }

                    average /= count;
                }

                // 平均値を表示する
                Console.WriteLine( average );
            }

            // 終了処理(OnExit()相当)をここに書く
        }
Пример #25
0
 public override void OnFrame(Controller controller)
 {
     var frame = controller.Frame();
     
     if (frame.Hands.IsEmpty) return;
     var hand = frame.Hands[0];
     var direction = hand.StabilizedPalmPosition;
     var moveDirection = new MoveDirection(hand.StabilizedPalmPosition.x, hand.StabilizedPalmPosition.y, hand.StabilizedPalmPosition.z);
     Task.Factory.StartNew(() => OnHandMoveOn(direction, moveDirection, hand.Fingers.Count));
 }
Пример #26
0
 // Use this for initialization
 void Start()
 {
     this.importButtons = GenerateImportList();
     hUtil          = new HandsUtil();
     leapcontroller = new Leap.Controller();
     frame          = leapcontroller.Frame();
     HUDMgr         = GameObject.Find("Managers").GetComponent <HUDManager>();
     dcg            = GameObject.Find("DCG").GetComponent <DCGBase>();
     base.Start();
 }
Пример #27
0
 // Use this for initialization
 void Start()
 {
     HUD            = GameObject.Find("Managers").GetComponent <HUDManager>();
     controller     = GameObject.Find("LoPoly_Rigged_Hand_Right").GetComponent <handController>();
     hUtil          = new HandsUtil();
     leapcontroller = new Leap.Controller();
     frame          = leapcontroller.Frame();
     HUDMgr         = GameObject.Find("Managers").GetComponent <HUDManager>();
     dcg            = GameObject.Find("DCG").GetComponent <DCGBase>();
     base.Start();
 }
Пример #28
0
 public override void OnFrame(Controller controller)
 {
     var h = FrameArrived;
     if (h != null)
     {
         using (var frame = controller.Frame())
         {
             h(frame);
         }
     }
 }
Пример #29
0
        public override void OnFrame(Controller controller)
        {
            Frame frame = controller.Frame();

            SafeWriteLine("Frame id: " + frame.Id
                     + ", timestamp: " + frame.Timestamp
                     + ", hands: " + frame.Hands.Count
                     + ", fingers: " + frame.Fingers.Count
                     + ", tools: " + frame.Tools.Count
                     + ", gestures: " + frame.Gestures().Count);
        }
Пример #30
0
    // Update is called once per frame
    void Update()
    {
        frame = controller.Frame();
        if (frame.Hands.Count > 0)
        {
            List <Hand> hands = frame.Hands;

            finger = hands[0].Fingers[1];

            Debug.Log(finger.TipPosition);
        }
    }
Пример #31
0
    public static void Update()
    {
        if (m_controller != null)
        {
            Frame lastFrame = m_Frame == null ? Frame.Invalid : m_Frame;
            m_Frame = m_controller.Frame();

            DispatchLostEvents(Frame, lastFrame);
            DispatchFoundEvents(Frame, lastFrame);
            DispatchUpdatedEvents(Frame, lastFrame);
        }
    }
        public override void OnFrame(Controller ctrl)
        {
            //Get the current frame
            Frame currentFrame = ctrl.Frame();

            this.currentTime = currentFrame.Timestamp;
            this.timeChange = currentTime - previousTime;

            if (this.timeChange < 1000 || currentFrame.Hands.IsEmpty)
                return;

            //Get the first finger
            Finger finger = currentFrame.Fingers[0];

            //Get the closest screen that intercepts a ray projected from the finger
            Screen screen = ctrl.LocatedScreens.ClosestScreenHit(finger);

            //Get finger tip's velocity
            float tipVelocity = (int)finger.TipVelocity.Magnitude;

            /*only print info when velocity exceeds a certain threshold,
              so that the slightest movements won't continuously output
              data to the screen*/
            if (screen == null || !screen.IsValid || tipVelocity <= 25)
                return;

            Vector vector = screen.Intersect(finger, true);

            //x and y positions are sometimes returned as NaN (e.g. if hand is partly obscured by screen)
            if (float.IsNaN(vector.x) || float.IsNaN(vector.y))
                return;

            float xScreenIntersect = vector.x;
            float yScreenIntersect = vector.y;

            float x = xScreenIntersect * screen.WidthPixels;
            float y = screen.HeightPixels - (yScreenIntersect * screen.HeightPixels);

            Result result = new Result
            {
                X = (int)x,
                Y = (int)y,
                XIntersect = xScreenIntersect,
                YIntersect = yScreenIntersect,
                ScreenWidth = screen.WidthPixels,
                ScreenHeight = screen.HeightPixels,
                TipVelocity = tipVelocity
            };

            this.reporter.Print(result);
            previousTime = currentTime;
        }
Пример #33
0
    void Update()
    {
        Frame frame = controller.Frame();

        if (frame.Hands.Count > 1)
        {
            List <Hand> hands      = frame.Hands;
            Hand        secondHand = hands[1];
            Finger      thumb      = frame.Hands[1].Fingers
                                     [(int)Finger.FingerType.TYPE_THUMB];
            Finger index = frame.Hands[1].Fingers
                           [(int)Finger.FingerType.TYPE_INDEX];
            Finger middle = frame.Hands[1].Fingers
                            [(int)Finger.FingerType.TYPE_MIDDLE];
            Finger ring = frame.Hands[1].Fingers
                          [(int)Finger.FingerType.TYPE_RING];
            Finger pinky = frame.Hands[1].Fingers
                           [(int)Finger.FingerType.TYPE_PINKY];

            Vector position = secondHand.PalmPosition / 1000;
            bool   extended = !thumb.IsExtended && !index.IsExtended && !middle.IsExtended && !ring.IsExtended && !pinky.IsExtended;
            if (extended && !shielded && secondHand.IsLeft)
            {
                shielded = true;
                cube     = GameObject.CreatePrimitive(PrimitiveType.Cube);
                Vector3 scale = transform.localScale;
                scale.x = 0.6f;
                scale.y = 0.6f;
                scale.z = 0.05f;
                cube.transform.localScale = scale;
            }
            else if (extended && shielded)
            {
                Vector3 direct = new Vector3(secondHand.PalmNormal.ToVector3().x, secondHand.PalmNormal.ToVector3().y, -secondHand.PalmNormal.ToVector3().z);
                //Texture2D blah = Resources.Load("blah.jpg") as Texture2D;
                // cube.transform.Rotate(direct);
                //  cube.GetComponent<Renderer>().material.mainTexture = txture;
                cube.transform.position = position.ToVector3() + new Vector3(-0.2f, 0, 0);
                //cube.GetComponent<Renderer>().material.color = new Color(1, 1, 1, 0.09f);
                //Physics.IgnoreCollision(cube.GetComponent<Collider>(), transform.Find("Spells").GetComponent<Collider>());
            }
            else if (!extended)
            {
                shielded = false;
                Destroy(cube);
            }
            else
            {
                Destroy(cube);
            }
        }
    }
Пример #34
0
        // Wave Gesture
        void WaveGesture(Leap.Controller controller)
        {
            Leap.Frame frame = controller.Frame();
            Hand       hand  = frame.Hands[0];

            // Initiate Wave gesture if all 5 fingers are extended
            if (hand.Pointables.Count == 5 && !wave.gestureOn)
            {
                if (GetNumFingersExtended(hand) == 5)
                {
                    Debug.WriteLine("5 Fingers!");
                    wave.gestureOn = true;
                }
            }

            // Perform wave gesture if hand moves back and forth laterally
            if (wave.gestureOn)
            {
                Leap.Vector motion = frame.Translation(controller.Frame(1));

                if (motion.x > 7.0f)
                {
                    wave.rightMotion++;
                }
                else if (motion.x < -7.0f)
                {
                    wave.leftMotion++;
                }

                if (wave.rightMotion > 5 && wave.leftMotion > 5)
                {
                    Debug.WriteLine("Wave!");
                    wave.rightMotion     = 0;
                    wave.leftMotion      = 0;
                    wave.gestureOn       = false;
                    wave.gestureFinished = true;
                }
            }
        }
Пример #35
0
 public override void OnFrame(Controller controller)
 {
     var frame = controller.Frame();
     
     if (frame.Hands.IsEmpty) return;
     var hand = frame.Hands[0];
     Task.Factory.StartNew(() => OnFingersCount(hand.Fingers.Count));
     var direction = hand.Direction;
     Task.Factory.StartNew(() => OnHandMoveOn(direction));
     CalculateDirectionX(direction);
     CalculateDirectionY(direction);
     CalculateDirectionZ(direction);
 }
        void listener_OnFrameEvent( Controller leap )
        {
            // ここではWPFのUIオブジェクトも触ることができる
            // フレームの処理を行う
            var frame = leap.Frame();

            TextLeap.Text = "Event Frame id: " + frame.Id
                    + ", timestamp: " + frame.Timestamp
                    + ", hands: " + frame.Hands.Count
                    + ", fingers: " + frame.Fingers.Count
                    + ", tools: " + frame.Tools.Count
                    + ", gestures: " + frame.Gestures().Count;
        }
Пример #37
0
        public override void OnFrame(Controller arg)
        {
            // Get the most recent frame and report some basic information
            Frame frame = arg.Frame();
            Console.Clear();
            var pos = (frame.Hands.Leftmost.PalmPosition.x/200);

            if (pos > 1.0)
                pos = 1.0f;
            if (pos < -1.0)
                pos = -1.0f;

            Program.Write(pos);
        }
 public override void OnFrame(Controller controller)
 {
     Frame currentFrame = controller.Frame();
     if (!currentFrame.Hands.Empty)
     {
         //Hand firstHand = currentFrame.Hands[0];
         //FingerList fingers = firstHand.Fingers;
         MotionSubscriberCenter.Instance.positionDidUpdate(currentFrame.Hands);
     }
     else
     {
         MotionSubscriberCenter.Instance.noHands();
     }
 }
Пример #39
0
 /// <summary>
 /// Figures out which is the left and which is the right hand and returns it.
 /// Returns null if the specifik hand isn't there.
 /// </summary>
 /// <param name="frameID"></param>
 /// <param name="leftOrRight"></param>
 /// <returns></returns>
 private Hand getHand(int frameID, string leftOrRight)
 {
     foreach (Hand hand in controller.Frame(frameID).Hands)
     {
         if (hand.IsLeft && leftOrRight == "left")
         {
             return(hand);
         }
         if (hand.IsRight && leftOrRight == "right")
         {
             return(hand);
         }
     }
     return(null);
 }
Пример #40
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            if (!frame.Hands.Empty)
            {
                var pointer = frame.Pointables[0];

                var acceleration = pointer.TipVelocity;

                Gestures.AddData(new double[] { acceleration.x, acceleration.y, acceleration.z });

                lastVelocity = pointer.TipVelocity;
            }
        }
Пример #41
0
        public override void OnFrame(Controller controller)
        {
            if (parent.state != Recorder.RecorderState.Reading) { return; }

            Frame frame = controller.Frame();
            HandList hands = frame.Hands;
            Hand hand = hands.Rightmost;
            if (!hand.IsValid) { return; }
            //if (hands.Count > 1) { Console.WriteLine("MORE THAN 1 HAND"); return; }

            sequence.Add(frame);
            if (sequence.Count >= numOfFramesPerSeq && numOfFramesPerSeq != 0)
            {
                GetSequence();
            }
        }
Пример #42
0
 public override void OnFrame(Controller controller)
 {
     var currentFrame = controller.Frame();
     if (currentFrame.Fingers.IsEmpty == false)
     {
         var fingers = currentFrame.Fingers.Count;
         var velocity = currentFrame.Fingers.Select(f => f.TipVelocity).Average(v => Math.Sqrt(v.MagnitudeSquared));
         fingersSubject.OnNext(fingers);
         velocitySubject.OnNext(velocity);
     }
     else
     {
         fingersSubject.OnNext(0);
         velocitySubject.OnNext(0);
     }
 }
Пример #43
0
        public override void OnFrame(Controller controller)
        {
            //base.OnFrame(controller);
            Frame newFrame = controller.Frame();
            

            int gestureCount = 0;
            if (!newFrame.Hands.IsEmpty)
            {
                mappingCoordinate(newFrame);
                HandList handlist = newFrame.Hands;
                GestureList gestureList = newFrame.Gestures();
                //movingPalm((int)handlist[0].PalmPosition.x, (int)handlist[0].PalmPosition.z);
                //movingPalm((int)handlist[0].StabilizedPalmPosition.x, (int)handlist[0].StabilizedPalmPosition.y);
                

                if (gestureList.IsEmpty)
                {
                    //MessageBox.Show("yaaaaa");
                    gestureCount = gestureList.Count;
                    switch (gestureList[gestureCount - 1].Type)
                    {
                        case Gesture.GestureType.TYPE_SWIPE:
                            MessageBox.Show("Swipe");
                            //Form movieForm = new MovieForm();
                            //movieForm.ShowDialog();

                            break;
                        
                        case Gesture.GestureType.TYPE_CIRCLE:
                            
                            Panel x = targetForm.Controls.Find("mainPanel", true).FirstOrDefault() as Panel;
                            x.VerticalScroll.Value -= 5;
                            
                            x.PerformLayout();
                        //targetForm.VerticalScroll.Value -= targetForm.VerticalScroll.SmallChange;
                            //targetForm.PerformLayout();
                            break;
                        default:
                            //MessageBox.Show("yaaaaa");
                            break;
                    }


                }
            }
        }//end OnFrame
Пример #44
0
    void Update()
    {
        Frame frame = controller.Frame();

        if (frame.Hands.Count > 0)
        {
            List <Hand> hands     = frame.Hands;
            Hand        firstHand = hands[0];
            Finger      thumb     = frame.Hands[0].Fingers
                                    [(int)Finger.FingerType.TYPE_THUMB];
            Finger index = frame.Hands[0].Fingers
                           [(int)Finger.FingerType.TYPE_INDEX];
            Finger middle = frame.Hands[0].Fingers
                            [(int)Finger.FingerType.TYPE_MIDDLE];
            Finger ring = frame.Hands[0].Fingers
                          [(int)Finger.FingerType.TYPE_RING];
            Finger pinky = frame.Hands[0].Fingers
                           [(int)Finger.FingerType.TYPE_PINKY];


            if (Time.time > nextFire && firstHand.IsRight)
            {
                Vector position = firstHand.PalmPosition / 1000;
                bool   extended = thumb.IsExtended && index.IsExtended && middle.IsExtended && ring.IsExtended && pinky.IsExtended;
                if (extended)
                {
                    GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    sphere.GetComponent <Renderer>().material.color = Color.red;
                    sphere.transform.position = position.ToVector3();
                    Vector3 scale = transform.localScale;
                    scale.x = 0.2f;
                    scale.y = 0.2f;
                    scale.z = 0.2f;
                    sphere.transform.localScale = scale;
                    Rigidbody sphereRigid = sphere.AddComponent <Rigidbody>().GetComponent <Rigidbody>();
                    sphereRigid.mass       = 1f;
                    sphereRigid.useGravity = false;
                    Vector3 direct = new Vector3(firstHand.PalmNormal.ToVector3().x, firstHand.PalmNormal.ToVector3().y, -firstHand.PalmNormal.ToVector3().z);
                    sphereRigid.AddForce(transform.TransformVector(direct) * 500);
                    Destroy(sphere, 3f);

                    nextFire = Time.time + 1.0f;
                }
            }
        }
    }
Пример #45
0
 // Update is called once per frame
 void Update()
 {
     frame = leapcontroller.Frame();
     // if there are hands visible in the view.
     if (frame.Hands.Count > 0)
     {
         lHand = frame.Hands[0];
         if (lHand.IsLeft)
         {
             // get the selected prefab from the hud manager and make it appear above the right index finger
             if (this.prefab)
             {
                 prefab.transform.localPosition = new Vector3(rightIndex.transform.position.x, rightIndex.transform.position.y, rightIndex.transform.position.z) + rightIndex.transform.rotation * (new Vector3(0.0f, 0.00f, 0.04f));
             }
         }
     }
 }
Пример #46
0
    // Update is called once per frame
    void Update()
    {
        frame = controller.Frame();
        if (frame.Hands.Count > 0)
        {
            List <Hand> hands = frame.Hands;

            finger  = hands[0].Fingers[0];
            finger1 = hands[0].Fingers[1];
            float a = hands[0].GrabAngle;
            bool  b = finger.IsExtended;
            bool  c = finger1.IsExtended;

            if (a > 2.0 && b && !c)
            {
                if (hands[0].IsLeft)
                {
                    //Debug.Log("left Thumbs up");

                    transform.Rotate(-Vector3.up * 20 * Time.deltaTime);
                }
                else
                {
                    //Debug.Log("Right thumb up");

                    transform.Rotate(Vector3.up * 20 * Time.deltaTime);
                }
            }
            if (a > 2.0 && !b && c)
            {
                if (hands[0].IsLeft)
                {
                    //Debug.Log("left index up");
                    transform.Rotate(Vector3.left, Time.deltaTime * 30);
                }
                else
                {
                    //Debug.Log("Right index up");
                    transform.Rotate(-Vector3.left, Time.deltaTime * 30);
                }
            }
            //Debug.Log(a);
            //Debug.Log(b);
            //Debug.Log(c);
        }
    }
Пример #47
0
        public override void OnFrame(Controller controller)
        {
            var frame = controller.Frame();
            _now = frame.Timestamp;
            _timeDifference = _now - _previous;

            if (frame.Hands.Empty) return;

            _previous = frame.Timestamp;

            if (_timeDifference < 1000) return;
            // Run async
            if (frame.Gestures().Count > 0)
                Task.Factory.StartNew(()=> OnGestureMade(frame.Gestures()));
            if (frame.Fingers.Count > 0)
                Task.Factory.StartNew(() => OnFingersRegistered(frame.Fingers));
        }
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Frame frame = controller.Frame();

            /*SafeWriteLine("Frame id: " + frame.Id
                        + ", timestamp: " + frame.Timestamp
                        + ", hands: " + frame.Hands.Count
                        + ", fingers: " + frame.Fingers.Count
                        + ", tools: " + frame.Tools.Count
                        + ", gestures: " + frame.Gestures().Count);
            */

            pinchStrength = frame.Hands.Count > 0 ? frame.Hands[0].GrabStrength:pinchStrength;
            wristPitch = frame.Hands.Count > 0 ? frame.Hands[0].Direction.Pitch:0;
            wristYaw = frame.Hands.Count > 0 ? frame.Hands[0].Direction.Roll : 0;
        }
Пример #49
0
 // Update is called once per frame
 void Update()
 {
     mFrame = leapController.Frame();
     if (mFrame.Hands.Count >= 1)
     {
         // deal with position
         float       sphereRadius = mFrame.Hands[0].SphereRadius;
         Leap.Vector sphereCentre = mFrame.Hands[0].StabilizedPalmPosition;
         transform.position   = Vector3.Slerp(transform.position, new Vector3(-sphereCentre.x, sphereCentre.y, sphereCentre.z), Time.deltaTime * 10f);
         transform.localScale = Vector3.one * sphereRadius;
         //Deal with rotation
         Leap.Vector forward  = mFrame.Hands[0].Direction;
         Leap.Vector up       = mFrame.Hands[0].PalmNormal;
         Vector3     rotation = new Vector3(forward.Pitch * Mathf.Rad2Deg, forward.Yaw * Mathf.Rad2Deg, -up.Roll * Mathf.Rad2Deg);
         transform.localEulerAngles = Vector3.Slerp(transform.localEulerAngles, rotation, Time.deltaTime * 80f);
     }
 }
Пример #50
0
    // Update is called once per frame
    void Update()
    {
        if (LeapUnityBridge == null)
        {
            Debug.LogError("There is no LeapUnityBridge component in the scene!");
            return;
        }

        UpdateFromUnityBridge();


        Frame currentFrame = LeapController.Frame();

        DebugDrawHands(currentFrame);
        DebugDrawFingers(currentFrame);
        DebugDrawPalms(currentFrame);
    }
Пример #51
0
        //Method called for each frame captured by the leap motion
        public override void OnFrame(Controller cntrlr)
        {
            //Increment the number of frames
            NbFrame++;

            // Get the current frame.
            Frame currentFrame = cntrlr.Frame();

            //get the list of hands in the frame
            ListeMain = currentFrame.Hands;

            NombreMain = ListeMain.Count;

            FingerList fingers = ListeMain[0].Fingers;

            DebutPosition = false;
            foreach (Hand hand in ListeMain)
            {
                FingerList doigts = hand.Fingers;
                if (doigts[1].IsExtended && doigts[2].IsExtended && !doigts[3].IsExtended && !doigts[4].IsExtended)
                {
                    DebutPosition = true;
                }
                Vector vecteur = doigts[1].Bone(Bone.BoneType.TYPE_DISTAL).Center;
                ValeurX = vecteur.x;
                ValeurY = vecteur.y;
                ValeurZ = hand.PalmPosition.z;

                DeplacementDroite = false;
                DeplacementGauche = false;
                Saut = false;
                rightMove.TestGesture(hand);
                leftMove.TestGesture(hand);
                saut.TestGesture(hand);
            }
            OnPropertyChanged("Saut");
            OnPropertyChanged("DeplacementGauche");
            OnPropertyChanged("DeplacementDroite");
            OnPropertyChanged("NbFrame");
            OnPropertyChanged("DebutPosition");
            OnPropertyChanged("NombreMain");
            OnPropertyChanged("ValeurX");
            OnPropertyChanged("ValeurY");
            OnPropertyChanged("ValeurZ");
        }
Пример #52
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        foreach (Gesture gesture in frame.Gestures())
        {
            switch (gesture.Type)
            {
            case (Gesture.GestureType.TYPECIRCLE):
            {
                Debug.Log("Circle gesture recognized.");
                break;
            }

            case (Gesture.GestureType.TYPEINVALID):
            {
                Debug.Log("Invalid gesture recognized.");
                break;
            }

            case (Gesture.GestureType.TYPEKEYTAP):
            {
                Debug.Log("Key Tap gesture recognized.");
                break;
            }

            case (Gesture.GestureType.TYPESCREENTAP):
            {
                Debug.Log("Screen tap gesture recognized.");
                break;
            }

            case (Gesture.GestureType.TYPESWIPE):
            {
                Debug.Log("Swipe gesture recognized.");
                break;
            }

            default:
            {
                break;
            }
            }
        }
    }
Пример #53
0
        public override void OnFrame(Controller controller)
        {
            Frame frame = controller.Frame();

            foreach (Gesture gesture in frame.Gestures())
            {
                if (gesture.Type == KeyTapGesture.ClassType())
                {
                    Tap();
                }
                if (gesture.Type == SwipeGesture.ClassType())
                {
                    SwipeGesture swipeGesture = new SwipeGesture(gesture);
                    if (swipeGesture.Direction.x > 0) SwipeRight();
                    else SwipeLeft();
                }
            }
        }
Пример #54
0
 // Update is called once per frame
 void Update()
 {
     base.Update();
     frame = leapcontroller.Frame();
     // if there are hands visible in the view.
     if (frame.Hands.Count > 0)
     {
         lHand = frame.Hands[0];
         // If it is the left hand, make the position of the HUD relative to the local position of the right index(bone3).
         if (lHand.IsLeft)
         {
             // get the selected prefab from the hud manager and make it appear above the right index finger
             // if (this.prefab)
             //{
             //   prefab.transform.localPosition = new Vector3(rightIndex.transform.position.x, rightIndex.transform.position.y, rightIndex.transform.position.z) + rightIndex.transform.rotation * (new Vector3(0.0f, 0.00f, 0.04f));
             // }
         }
     }
 }
Пример #55
0
 private void Update()
 {
     if (_controller != null)
     {
         _frame = _controller.Frame();
         if (_frame != null)
         {
             Debug.Log("frame!=null");
             if (_frame.Hands.Count > 0)
             {
                 _hand = _frame.Hands[0];
             }
             else
             {
                 _hand = null;
             }
         }
     }
 }
Пример #56
0
        public override void OnFrame(Controller controller)
        {
            using (var frame = controller.Frame())
            {
                Vector A = new Vector(2, 0, 0);
                Vector B = new Vector(4, 2, 0);
                double rads = Math.Round(A.AngleTo(B), 2);
                Console.WriteLine("Radians " + rads);
                Console.WriteLine("Degrees " + Math.Round(rads*180/Math.PI, 2));

                //Console.WriteLine("Thumb: " + Math.Round(frame.Fingers[0].Length / 10, 2) + "cm");
                //Console.WriteLine("Index: " + Math.Round(frame.Fingers[1].Length / 10, 2) + "cm");
                //Console.WriteLine("Middle: " + Math.Round(frame.Fingers[2].Length / 10, 2) + "cm");
                //Console.WriteLine("Ring: " + Math.Round(frame.Fingers[3].Length / 10, 2) + "cm");
                //Console.WriteLine("Pinky: " + Math.Round(frame.Fingers[4].Length / 10, 2) + "cm\n");
            }
            Console.ReadLine();

            //Thread.Sleep(2000);

            //using (var frame = controller.Frame())
            //{
            //    _now = frame.Timestamp;
            //    _timeDifference = _now - _previous;

            //    if (frame.Hands.IsEmpty || _timeDifference < 5000)
            //    {
            //        return;
            //    }

            //    _previous = frame.Timestamp;

            //    if (frame.Gestures().Count > 0 && OnGesturesMade != null)
            //    {
            //        OnGesturesMade(frame.Gestures());
            //    }

            //    if (frame.Fingers.Count > 0 && OnFingersRegistered != null)
            //    {
            //        OnFingersRegistered(frame.Fingers);
            //    }
            //}
        }
Пример #57
0
    // Update is called once per frame
    void Update()
    {
        frame = leapcontroller.Frame();

        // if there are hands visible in the view.
        if (frame.Hands.Count > 0 && !placed)
        {
            lHand = frame.Hands[0];
            // If it is the left hand, make the position of the HUD relative to the local position of the palm.
            if (lHand.IsLeft)
            {
                // WORKS ON TESTSCENE
                transform.localPosition = new Vector3(lHand.PalmPosition.x, lHand.PalmPosition.y, -lHand.PalmPosition.z) / 1000f + new Vector3(-0.0f, -1.05f, -1.20f);
                //transform.rotation = Quaternion.FromToRotation(Vector3.up, lHand.PalmNormal.ToVector3);

                // THIS ONE WORKS ON THE CLOCK SCENE
                //transform.localPosition = new Vector3(lHand.PalmPosition.x, lHand.PalmPosition.y, -lHand.PalmPosition.z) / 1000f + new Vector3(-0.0f, -1.15f, -1.15f);
            }
        }
    }
Пример #58
0
        /* React to the New Frame Received from the Leap Motion */
        public override void OnFrame(Leap.Controller controller)
        {
            // Get Hand from this current Frame
            InputManager IM = _instance;

            Leap.HandList hands = controller.Frame().Hands;
            // Restrict to One Hand Detection
            if (hands.Count == 1)
            {
                // Call Leap Motion Update
                try
                {
                    OnLeapMotionUpdate(hands.Frontmost);
                    Debug.Log("Hand Detected");
                }
                catch (Exception e)
                {
                    Debug.Log(e.ToString());
                    Debug.Log(e.ToString());
                }
            }
            else if (IM.currentSimilarity != ASLTest.INVALID_ASL_TEST)
            {
                IM.UpdateCurrentSimilarity(ASLTest.INVALID_ASL_TEST);
                IM.UpdateCurrentLetter(INVALID_ASL_LETTER);

                /*
                 * //Handle case of Leap Motion with no more detection
                 * IM.currentLetter = INVALID_ASL_LETTER;
                 * IM.similarityHandler(ASLTest.INVALID_ASL_TEST);
                 * IM.letterHandler(INVALID_ASL_LETTER);
                 * IM.currentLetter = INVALID_ASL_LETTER;*/
            }

            // For Debugging Purposes only
            if (updateDebugLogOnFrame)
            {
                Debug.Log("New Frame available");
                updateDebugLogOnFrame = false;
            }
        }
Пример #59
0
        public override void OnFrame(Controller controller)
        {
            // Get the most recent frame and report some basic information
            Leap.Frame frame = controller.Frame();

            if (!frame.Hands.Empty)
            {
                if (frame.Hands.Count==2&&frame.Fingers.Count>=2&&LeapFingerReady!=null)
                {
                    Finger first, second;
                    if (frame.Fingers[0].Length > frame.Fingers[1].Length)
                    {
                        first = frame.Fingers[0];
                        second = frame.Fingers[1];
                    }
                    else
                    {
                        first = frame.Fingers[1];
                        second = frame.Fingers[0];
                    }
                    for (int i = 2; i < frame.Fingers.Count;i++ )
                    {
                        if (frame.Fingers[i].Length > second.Length && frame.Fingers[i].Length < first.Length)
                        {
                            second = frame.Fingers[i];
                        }
                        else if (frame.Fingers[i].Length > second.Length && frame.Fingers[i].Length > first.Length)
                        {
                            first = frame.Fingers[i];
                        }
                    }
                    if (first.Length>30&&second.Length>30)
                        LeapFingerReady(this,frame.Fingers[0],frame.Fingers[1]);
                }

            }

            // Get gestures

            GestureList gestures = frame.Gestures();
            for (int i = 0; i < gestures.Count; i++)
            {
                Gesture gesture = gestures[i];

                switch (gesture.Type)
                {
                    case Gesture.GestureType.TYPECIRCLE:
                        CircleGesture circle = new CircleGesture(gesture);

                        // Calculate clock direction using the angle between circle normal and pointable
                        if (circle.State == Gesture.GestureState.STATESTOP&&circle.Radius>15&&circle.Progress>0.5)
                        {
                            if(DateTime.Now-lastTime>TimeSpan.FromMilliseconds(1000))
                            {
                                LeapCircleReady(this);
                                lastTime = DateTime.Now;
                            }
                        }

                        break;
                    case Gesture.GestureType.TYPESWIPE:
                        SwipeGesture swipe = new SwipeGesture(gesture);

                        if (swipe.State == Gesture.GestureState.STATESTART&&LeapSwipeReady!=null)
                        {
                           // if (DateTime.Now - lastTime > TimeSpan.FromMilliseconds(600))
                            //{
                                if (swipe.Direction.x < -0.5)
                                {
                                    LeapSwipeReady(this, SwipeType.SwipeLeft);
                                    //lastTime = DateTime.Now;
                                }
                                else if (swipe.Direction.x > 0.5)
                                {
                                    LeapSwipeReady(this, SwipeType.SwipeRight);
                                    //lastTime = DateTime.Now;
                                }
                            //}

                            //else if (swipe.Direction.z < -0.2)
                            //{
                            //    LeapSwipeReady(this, SwipeType.SwpieIn);
                            //}
                            //else if (swipe.Direction.z > 0.2)
                            //{
                            //    Thread.Sleep(300);
                            //    LeapSwipeReady(this, SwipeType.SwipeOut);
                            //}

                        }
                        break;
                    case Gesture.GestureType.TYPEKEYTAP:
                        KeyTapGesture keytap = new KeyTapGesture(gesture);
                        SafeWriteLine("Tap id: " + keytap.Id
                                       + ", " + keytap.State
                                       + ", position: " + keytap.Position
                                       + ", direction: " + keytap.Direction);

                        break;
                    case Gesture.GestureType.TYPESCREENTAP:
                        ScreenTapGesture screentap = new ScreenTapGesture(gesture);
                        Finger first = screentap.Frame.Fingers[0];
                        for (int j = 1; j < frame.Fingers.Count; j++)
                        {
                            if ( frame.Fingers[j].Length > first.Length)
                            {
                                first = frame.Fingers[j];
                            }
                        }
                        if ( LeapTapScreenReady!=null&&screentap.State==Gesture.GestureState.STATESTOP&&first.Length>15)
                        {
                            if (DateTime.Now - lastTime > TimeSpan.FromMilliseconds(600))
                            {
                               LeapTapScreenReady(this);
                                lastTime = DateTime.Now;
                            }
                        }
                        break;
                }
            }
        }
Пример #60
0
        public override void OnFrame(Controller cntrlr)
        {
            // Get the current frame.
            Frame currentFrame = cntrlr.Frame();

            currentTime = currentFrame.Timestamp;
            timeChange = currentTime - previousTime;
            if (timeChange > FramePause)
            {

                //pointable jari
                if (!currentFrame.Hands.IsEmpty)
                {
                    // Get the first finger in the list of fingers
                    Pointable finger = currentFrame.Pointables[0];
                    // Get the closest screen intercepting a ray projecting from the finger
                    Screen screen = cntrlr.LocatedScreens.ClosestScreenHit(finger);

                    if (screen != null && screen.IsValid)
                    {
                        // Get the velocity of the finger tip
                        //var tipVelocity = (int)finger.TipVelocity.Magnitude;
                        Hand hand = currentFrame.Hands.Frontmost;
                        // Use tipVelocity to reduce jitters when attempting to hold
                        // the cursor steady
                        //if (tipVelocity > 25)
                        if (finger.TipVelocity.Magnitude > 25)
                        {
                            float xScreenIntersect = (float)screen.Intersect(finger, true).x;
                            float yScreenIntersect = (float)(1 - screen.Intersect(finger, true).y);
                            //float zScreenIntersect = finger.TipPosition.z;
                            float zScreenIntersect = screen.DistanceToPoint(finger.TipPosition);

                            if (xScreenIntersect.ToString() != "NaN")
                            {
                                //var x = (int)(xScreenIntersect * screen.WidthPixels);
                                //var y = (int)(screen.HeightPixels - (yScreenIntersect * screen.HeightPixels));

                                if (fingerPoint.Count <= 0)
                                {
                                    fingerPoint.Add(new FingerPointStorage(xScreenIntersect, yScreenIntersect, zScreenIntersect, false,0,0));
                                }
                                else
                                {

                                    ////////////////////gesture
                                    if (currentFrame.Pointables.Count > 2)
                                    {

                                        //Console.WriteLine("embuh: " + currentFrame.Gestures().Count);
                                        // Console.WriteLine("pinch: " + hand.PinchStrength);

                                        if (currentFrame.Gestures().Count > 0)
                                        {
                                            //debugbox1.Text = "Gesture" + frame.Gestures()[0].ToString();
                                            int numGestures = currentFrame.Gestures().Count;
                                            if (numGestures > 0)
                                            {
                                                for (int i = 0; i < numGestures; i++)
                                                {
                                                    if (currentFrame.Gestures()[i].Type == Leap.Gesture.GestureType.TYPESCREENTAP)
                                                    {
                                                        ScreenTapGesture tap = new ScreenTapGesture(currentFrame.Gestures()[i]);

                                                        //Console.WriteLine("position z: " + tap.Position.z);
                                                        //System.Diagnostics.Process.Start(@"D:\465097.jpg");
                                                        // System.Diagnostics.Process.Start(@"D:\KULIAH_NGAJAR\Daspro\C++\GettingStartedCpp_001.pptx");
                                                        // PlayFile(@"D:\a.mp3");

                                                    }
                                                    else if (currentFrame.Gestures()[i].Type == Leap.Gesture.GestureType.TYPECIRCLE)
                                                    {
                                                        CircleGesture circle = new CircleGesture(currentFrame.Gestures()[i]);
                                                        fingerPoint[0].g_circle = circle.Progress;

                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ///////////////////////////////////
                                    fingerPoint[0].g_Pinch = hand.PinchStrength;
                                    fingerPoint[0].g_X = xScreenIntersect;
                                    fingerPoint[0].g_Y = yScreenIntersect;
                                    fingerPoint[0].g_Z = zScreenIntersect;
                                    fingerPoint[0].isActive = true;
                                    if (hand.IsLeft)
                                        fingerPoint[0].numHand = true;
                                    else
                                        fingerPoint[0].numHand = false;
                                    //Console.WriteLine("leap x-axis: {0},y-axis: {1},z-axis: {2}", fingerPoint[0].g_X, fingerPoint[0].g_Y, fingerPoint[0].g_Z);
                                }
                            }
                        }
                    }
                }
                previousTime = currentTime;
            }
        }