Ejemplo n.º 1
0
        public void undateTouches(PointableList fingerlist)
        {
            noOfFinger = 0;

            ScreenList screenList = this.controllerr.CalibratedScreens;

            for (int i = 0; i < fingerlist.Count; i++) {

                Leap.Screen screen = screenList.ClosestScreenHit(fingerlist[i]);
                Vector intersection = screen.Intersect(fingerlist[i], true);
                float screenw = screen.WidthPixels;
                float screenh = screen.HeightPixels;

                int posx = (int)(intersection.x * screenw)  ;    // actual x position on your screen
                int posy = (int)(screenh - intersection.y * screenh) ;     // actual y position on your screen

                //Console.WriteLine(fingerlist[0].TipPosition.z);
                Console.WriteLine(posx+"   "+posy+"  "+i);
                if(fingerlist[i].TipPosition.z < 0)
                {
                    xPos[noOfFinger] = posx;
                    yPos[noOfFinger] = posy;
                    //Console.WriteLine(posx+"   "+posy+"  "+i);
                    noOfFinger++;
                }
                else
                {
                    using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
                    {

                        //		min		max
                        //old	150		0
                        //new	30		2
                        //NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin

                        int radius = ((((int)(fingerlist[i].TipPosition.z) - 150) * (2 - 30)) / (0 - 150)) + 30;

                        //g.DrawRectangle(Pens.Black, posx - (radius/2), posy - (radius/2), radius, radius);

                        //g.DrawEllipse(Pens.Black, posx - (radius/2), posy - (radius/2), radius, radius);
                        //InvalidateRect(IntPtr.Zero, IntPtr.Zero, true);
                    }
                }
            }
            //Console.WriteLine(noOfFinger.ToString()+"    "+noOfTouch.ToString());

            if (noOfFinger != noOfTouch) {
                updateData(fingerlist);
            } else {
                for (int i = 0; i < noOfTouch; i++) {
                    touchPoints[i].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                    touchPoints[i].Move((int)(xPos[i]), (int)(yPos[i]));
                    int moveX = xPos[i] - touchPoints[0].PointerInfo.PtPixelLocation.X;
                    int moveY = yPos[i] - touchPoints[0].PointerInfo.PtPixelLocation.Y;
                    touchPoints[i].Move((int)(moveX), (int)(moveY));
                    //Console.WriteLine(xPos[i]+"   "+yPos[i]);
                }
                TouchInjector.InjectTouchInput(noOfTouch, touchPoints);
            }
        }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Frame          frame          = controller.Frame();
        FingerList     fingers        = frame.Fingers;
        PointableList  pointables     = frame.Pointables;
        InteractionBox interactionBox = frame.InteractionBox;

        foreach (var pointable in frame.Pointables)
        {
            foreach (var finger in frame.Fingers)
            {
                Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                float       tx = normalizedPosition.x * UnityEngine.Screen.width;
                float       ty = UnityEngine.Screen.height - normalizedPosition.y * UnityEngine.Screen.height;

                // 末端骨(指先の骨)
                var bone = finger.Bone(Bone.BoneType.TYPE_METACARPAL);
                if (finger.Type() == Finger.FingerType.TYPE_THUMB)
                {
                    Debug.Log("tx : " + tx + " ty : " + ty + " 距離 : " + pointable.TouchDistance + " 種類 : " + bone.Type);
                }
                int alpha = 255;
                // ホバー状態
                if (pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE)
                {
                    alpha = 255 - (int)(255 * pointable.TouchDistance);
                    //			touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0xff, 0x0);
                }
            }
        }
    }
Ejemplo n.º 3
0
    private static void drawRays(PointableList pointables, float length, float durationSeconds, VectorType vt)
    {
        Vector3 pos, dir;

        foreach (Pointable pointable in pointables)
        {
            if (vt == VectorType.toUnity)
            {
                pos = pointable.TipPosition.ToUnity() / 100;
                dir = pointable.Direction.ToUnity();
            }
            else if (vt == VectorType.toUnityScaled)
            {
                pos = pointable.TipPosition.ToUnityScaled() / 100;
                dir = pointable.Direction.ToUnityScaled();
            }
            else// if (vt == VectorType.Vector3)
            {
                pos = Nastajus.Util.getVector3(pointable.TipPosition) / 100;
                dir = Nastajus.Util.getVector3(pointable.Direction);
            }

            Debug.DrawRay(pos, dir * length, Color.green, durationSeconds, true);
        }
    }
Ejemplo n.º 4
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
            }
Ejemplo n.º 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (controller.IsConnected)
        {
            Debug.Log("CONNECTED");

            // wait until Controller.isConnected() evaluates to true
            //...

            Frame         frame      = controller.Frame();
            HandList      hands      = frame.Hands;
            PointableList pointables = frame.Pointables;
            FingerList    fingers    = frame.Fingers;
            ToolList      tools      = frame.Tools;


            //Alden wrote:
            //Gesture gesture = frame.Gestures;

            //for (int g = 0; g < frame.Gestures().Count; g++)
            //{
            //    switch (frame.Gestures()[g].Type)
            //    {
            //        case Gesture.GestureType.TYPE_CIRCLE:
            //            //Handle circle gestures
            //            Debug.Log("CIRCLE");
            //            break;
            //        case Gesture.GestureType.TYPE_KEY_TAP:
            //            //Handle key tap gestures
            //            Debug.Log("KEY TAP");
            //            break;
            //        case Gesture.GestureType.TYPE_SCREEN_TAP:
            //            //Handle screen tap gestures
            //            Debug.Log("SCREEN TAP");
            //            break;
            //        case Gesture.GestureType.TYPE_SWIPE:
            //            //Handle swipe gestures
            //            Debug.Log("SWIPE");
            //            break;
            //        default:
            //            //Handle unrecognized gestures
            //            Debug.Log("UNRECOGNIZED");
            //            break;
            //    }
            //}

            Debug.Log(checkForSwipe());
        }
        else
        {
            Debug.Log("NOT CONNECTED");
        }
    }
Ejemplo n.º 6
0
    void Start()
    {
        Controller controller = new Controller();
        // wait until Controller.isConnected() evaluates to true
        //...

        Frame         frame      = controller.Frame();
        HandList      hands      = frame.Hands;
        PointableList pointables = frame.Pointables;
        FingerList    fingers    = frame.Fingers;
        ToolList      tools      = frame.Tools;
    }
Ejemplo n.º 7
0
    private void drawCubes(PointableList pointables, Vector3 cubeScale, VectorType vt)
    {
        int whichFinger = 0;

        foreach (Pointable pointable in pointables)
        {
            //Vector3 pos = Nastajus.Util.getVector3(finger.TipPosition);
            //Vector3 pos = finger.TipPosition.ToUnityScaled();
            //drawingCylindars[whichFinger].transform.position = pos;

            //Vector3 dir = Nastajus.Util.getVector3(finger.Direction);
            //drawingCylindars[whichFinger].transform.rotation = Quaternion.Euler(dir);
            //drawingCylindars[whichFinger].transform.eulerAngles = finger.Direction.ToUnity();

            whichFinger++;
        }
    }
Ejemplo n.º 8
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);
        }
    }
Ejemplo n.º 9
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;

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

            drawRays(fingers, 10, 1);


            //drawCylindars(fingers, cylindarScale );

            drawInteractionBox(frame.InteractionBox);
        }
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();
        // do something with the tracking data in the frame...
        HandList      hands      = frame.Hands;
        PointableList pointables = frame.Pointables;
        FingerList    fingers    = frame.Fingers;
        ToolList      tools      = frame.Tools;

//		foreach (Hand hand in hands) {
//			Debug.Log (hand.ToString ());
//		}
        if (hands.Count >= 1)
        {
            Hand firstHand = hands[0];
            Debug.Log(firstHand.IsRight);
            foreach (Finger finger in firstHand.Fingers)
            {
                Debug.Log(finger.TipPosition.z);
            }
        }
    }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            using (var controller = new Controller())
            {
                // Calling controller.IsConnected immediately fails (well, other than in console apps you wouldn't access it immediately anyways)
                Thread.Sleep(1000);

                if (controller.IsConnected)
                {
                    Frame frame   = controller.Frame();
                    var   frameId = frame.Id; // in polling used for checking "Did I see that frame already?"

                    HandList      hands      = frame.Hands;
                    PointableList pointables = frame.Pointables;
                    FingerList    fingers    = frame.Fingers;
                    ToolList      tools      = frame.Tools;

                    Console.WriteLine("# of fingers " + fingers.Count);

                    if (fingers.Count > 0)
                    {
                        Finger farLeft = frame.Fingers.Leftmost;

                        float x = farLeft.TipPosition.x;
                        float y = farLeft.TipPosition.y;
                        float z = farLeft.TipPosition.z;

                        Console.WriteLine("x: {0} y: {1} z: {2}", x, y, z);
                    }
                }
                else
                {
                    Console.WriteLine("No controller detected");
                }

                Console.ReadLine();
            }
        }
Ejemplo n.º 12
0
        private void updateData(PointableList fingerlist)
        {
            for (int i = 0; i < noOfTouch; i++) {
                touchPoints[i].PointerInfo.PointerFlags = PointerFlags.UP;
            }

            TouchInjector.InjectTouchInput(noOfTouch, touchPoints);

            for(int i = 0; i < noOfFinger; i++)
            {
                touchPoints[i] = MakePointerTouchInfo(xPos[i], yPos[i], 10, (uint)(i+1));
            }

            TouchInjector.InjectTouchInput(noOfFinger, touchPoints);

            noOfTouch = noOfFinger;
            //Console.WriteLine(noOfTouch.ToString());
        }
Ejemplo n.º 13
0
            public override void OnFrame(Controller leap)
            {
                var frame = leap.Frame();

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

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

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

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

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

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

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

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

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

#if true
                // 親指の定義を確認する
                foreach (var finger in frame.Fingers)
                {
                    if (finger.Type == Finger.FingerType.TYPE_THUMB)
                    {
                        for (int t = (int)Bone.BoneType.TYPE_METACARPAL; t <= (int)Bone.BoneType.TYPE_DISTAL; t++)
                        {
                            var bone = finger.Bone((Bone.BoneType)t);
                            Console.WriteLine(string.Format("種類 : {0} 長さ : {1}", bone.Type, bone.Length));
                        }
                    }
                }
#endif
            }
Ejemplo n.º 14
0
        public void update(ref SLLeapHand h, ref SLLeapHand dh)
        {
            if (!mController.IsConnected)
            {
                return;
            }

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

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

            int hi = 0;

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

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

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