Beispiel #1
0
        public void OnFrame(object sender, FrameEventArgs args)
        {
            // Get the most recent frame and report some basic information
            Frame frame = args.frame;
            Hand  h;

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

            h = frame.Hands[0];
            Console.WriteLine(string.Format("Velocity is {0}", h.PalmVelocity));
            palm.Move(h.PalmPosition, h.PalmVelocity);
            if (palm.Stopped)
            {
                // check if this is the first time we're reading that the hand is stopped
                if (!handStopped)
                {
                    Console.WriteLine("Beat!");
                    handStopped = true;
                    // possible beat. get volume data, centroid of movement, and append the tempo to the queue
                    TimeSpan dur      = palm.PreviousDuration;
                    Vector   centroid = palm.Centroid;
                    Vector   startPos = palm.StartPosition;
                    Vector   stopPos  = palm.StopPosition;
                    oscHandler = new OSCHandler();
                    float estTempo = 60 * 1000 / dur.Milliseconds;
                    oscHandler.SendTempo((int)Math.Round(estTempo));

                    // X centroid of hand during movement = pan
                    Vector normCentroid = bounder.NormalizePoint(centroid);
                    oscHandler.SendPan((double)normCentroid.x);

                    // get normalized distance by normalizing the points
                    Vector startNorm = bounder.NormalizePoint(startPos);
                    Vector stopNorm  = bounder.NormalizePoint(stopPos);
                    oscHandler.SendVolume(stopNorm.DistanceTo(startNorm));
                }

                // otherwise, check if the hand meets fermata threshold
                else if (palm.DurationStopped > Listener.fermataThreshold)
                {
                    Console.WriteLine(string.Format("Duration stopped is {0}, threshold is {1}", palm.DurationStopped, Listener.fermataThreshold));
                    oscHandler = new OSCHandler();
                    oscHandler.SendFermata();
                }
            }
            else
            {
                // check if it was stopped previously
                if (handStopped)
                {
                    oscHandler = new OSCHandler();
                    oscHandler.SendTempo();
                }

                handStopped = false;
            }
        }
Beispiel #2
0
        protected void DrawLeapLine(Controller leap, Leap.Frame frame)
        {
            FingerList allFingers = frame.Fingers.Extended();

            if (allFingers.Count != 2 || leap.Frame(10).Fingers.Extended().Count != 2)
            {
                return;
            }

            Finger finger1 = allFingers.Leftmost;
            Finger finger2 = allFingers.Rightmost;

            InteractionBox interactionBox = frame.InteractionBox;

            Leap.Vector normalizedPosition1 = interactionBox.NormalizePoint(finger1.StabilizedTipPosition);
            Leap.Vector normalizedPosition2 = interactionBox.NormalizePoint(finger2.StabilizedTipPosition);

            double tx1 = normalizedPosition1.x * windowWidth;
            double ty1 = windowHeight - normalizedPosition1.y * windowHeight;
            double tx2 = normalizedPosition2.x * windowWidth;
            double ty2 = windowHeight - normalizedPosition2.y * windowHeight;

            StylusPointCollection tips = new StylusPointCollection();

            tips.Add(new StylusPoint(tx1, ty1));
            tips.Add(new StylusPoint(tx2, ty2));
            Stroke stroke = new Stroke(tips, lineIndicator);

            this.InkCanvas_LeapPaint.Strokes.Add(stroke);
        }
        private void handDetect(Frame frame)
        {
            Hand hand = frame.Hands[0];

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

            if (!fingers.IsEmpty)
            {
                // Calculate the hand's average finger tip position
                Vector avgPos = Vector.Zero;
                foreach (Finger finger in fingers)
                {
                    avgPos += finger.TipPosition;
                }
                avgPos /= fingers.Count;

                InteractionBox iBox = controller.Frame().InteractionBox;
                Vector         normalizedPosition = iBox.NormalizePoint(avgPos);
                var            screen             = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                var            width  = screen.Width;
                var            height = screen.Height;
                float          x      = normalizedPosition.x * width;
                float          y      = normalizedPosition.y * height;


                int xCoordinate = (int)Math.Round(x);
                int yCoordinate = (int)Math.Round(y);

                Cursor.Position = new Point(xCoordinate, height - yCoordinate);
            }
        }
Beispiel #4
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;
        }
Beispiel #5
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 );
         * }
         * }
         */
    }
Beispiel #6
0
        protected void DrawLeapPoint(Leap.Frame frame)
        {
            this.InkCanvas_LeapPaint.Strokes.Clear();
            windowHeight = (float)this.MainWindow1.Height;
            windowWidth  = (float)this.MainWindow1.Width;

            InteractionBox interactionBox = frame.InteractionBox;

            foreach (Pointable pointable in frame.Pointables.Extended())
            {
                // 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, pointIndicator);
                    this.InkCanvas_LeapPaint.Strokes.Add(touchStroke);
                }
            }
        }
Beispiel #7
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);
                }
            }
        }
    }
Beispiel #8
0
        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());
            }
        }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        FingerCount = frame.Fingers.Count;
        //指が有効であればInteractionBoxオブジェクトを使ってLeapMotionの座標系をディスプレイ座標系に変換する
        InteractionBox interactionBox = frame.InteractionBox;

        Hand  hand     = frame.Hands.Rightmost;
        float strength = hand.GrabStrength;

//        Debug.Log (strength);

        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);
            }
        }
    }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>A normalized coordinate to be multiplied with the actual width and height of the screen</returns>
        public float[] getCoordinate()
        {
            float[] coordinates = new float[2];
            Frame   frame       = _controller.Frame();

            if (!frame.Hands.IsEmpty)
            {
                // Get the first hand
                Hand hand = frame.Hands[0];

                // Check if the hand has any fingers
                FingerList fingers = hand.Fingers;
                if (!fingers.IsEmpty)
                {
                    // Calculate the hand's average finger tip position
                    Vector avgPos = Vector.Zero;
                    foreach (Finger finger in fingers)
                    {
                        avgPos += finger.TipPosition;
                    }
                    avgPos /= fingers.Count;

                    InteractionBox iBox = _controller.Frame().InteractionBox;
                    Vector         normalizedPosition = iBox.NormalizePoint(avgPos);

                    coordinates[0] = normalizedPosition.x;
                    coordinates[1] = normalizedPosition.y;

                    return(coordinates);
                }
            }
            return(null);
        }
Beispiel #11
0
 Leap.Vector leapToWorld(Leap.Vector leapPoint, InteractionBox iBox)
 {
     leapPoint.z *= -1.0f;                          //right-hand to left-hand rule
     Leap.Vector normalized = iBox.NormalizePoint(leapPoint, false);
     normalized += new Leap.Vector(0.5f, 0f, 0.5f); //recenter origin
     return(normalized * 100.0f);                   //scale
 }
Beispiel #12
0
        public static Vector3 leapVectorToWorld(Leap.Vector leapPoint, InteractionBox iBox)
        {
            Leap.Vector normalized = iBox.NormalizePoint(leapPoint, false);
            var         v1         = new Vector3(UnityEngine.Screen.width / 2, UnityEngine.Screen.height / 2, Camera.main.nearClipPlane);
            Vector3     v          = Camera.main.ScreenToWorldPoint(v1);

            normalized += new Leap.Vector(v.x, v.y, v.z);              //recenter origin
            return(new Vector3(normalized.x, normalized.y, normalized.z));
        }
Beispiel #13
0
    Leap.Vector LeapToWorld(Leap.Vector lv)
    {
        lv.z *= 0.1f;
        InteractionBox iBox = frame.InteractionBox;

        Leap.Vector normalized = iBox.NormalizePoint(lv);
        normalized += new Leap.Vector(0, 0, 0);
        Debug.Log(normalized);
        return(normalized * leapToWorldMultiplier);
    }
Beispiel #14
0
        private void DrawFingerBones(Leap.Finger oFinger, InteractionBox interactionBox,
                                     DrawingContext drawingContext)
        {
            Bone bone;

            foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
            {
                bone = oFinger.Bone(boneType);
                Leap.Vector startPosition = interactionBox.NormalizePoint(bone.PrevJoint);
                Leap.Vector endPosition   = interactionBox.NormalizePoint(bone.NextJoint);

                Point  posStart = this.ToScreen(startPosition);
                Point  posEnd   = this.ToScreen(endPosition);
                double dX1      = posStart.X;
                double dY1      = posStart.Y;
                double dX2      = posEnd.X;
                double dY2      = posEnd.Y;
                drawingContext.DrawLine(new Pen()
                {
                    Brush = new SolidColorBrush(Colors.Blue), Thickness = 1
                },
                                        new Point(dX1, dY1), new Point(dX2, dY2));

                Pen oPen = new Pen();
                if (boneType == Bone.BoneType.TYPE_PROXIMAL)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Gold), oPen, new Point(dX1, dY1), 6, 6);
                }
                else if (boneType == Bone.BoneType.TYPE_METACARPAL)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Black), oPen, new Point(dX1, dY1), 6, 6);
                }
                else if (boneType == Bone.BoneType.TYPE_INTERMEDIATE)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.DarkGreen), oPen, new Point(dX1, dY1), 6, 6);
                }
                else if (boneType == Bone.BoneType.TYPE_DISTAL)
                {
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX1, dY1), 6, 6);
                    drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX2, dY2), 12, 12);
                }
            }
        }
Beispiel #15
0
    void Hand()
    {
        InteractionBox iBox = controller.Frame().InteractionBox;

        frame = controller.Frame();
        List <Hand> handlist = new List <Hand>();

        for (int h = 0; h < frame.Hands.Count; h++)
        {
            Hand leapHand = frame.Hands[h];
            handlist.Add(leapHand);
        }
        index = frame.Hands[0].Fingers[(int)Finger.FingerType.TYPE_INDEX];
        if (index.IsExtended)
        {
            Vector fingPos = index.StabilizedTipPosition;
            Vector norm    = iBox.NormalizePoint(fingPos, false);
            appX   = norm.x * appWidth;
            appY   = -1 * (1 - norm.y) * appHeight;
            imageX = t.transform.position.x;
            imageY = t.transform.position.y;
            ballX  = ball.transform.position.x;
            ballY  = ball.transform.position.y;
            float distanceX = ballX - imageX;
            float distanceY = ballY - imageY;
            if (Mathf.Abs(distanceX) < 50 && Mathf.Abs(distanceY) < 50)
            {
                //moveCheck = true;
                countBegining = 1;
                //ballX = imageX;
                //ballY = imageY;
                //ball.transform.position = t.transform.position;
                //ball.transform.parent = t.transform;
            }
            //if (Mathf.Abs (distanceX) < 100 && Mathf.Abs (distanceY) < 100) {
            //}
            Vector3 fPos     = new Vector3(appX, appY);
            Plane   objPlane = new Plane(Camera.main.transform.forward * -1, ball.transform.position);
            Ray     mRay     = Camera.main.ScreenPointToRay(fPos);
            float   rayDistance;
            if (objPlane.Raycast(mRay, out rayDistance))
            {
                ball.transform.position = mRay.GetPoint(rayDistance);
                float d = Vector3.Distance(t.transform.position, ball.transform.position);
                if (d < 50)
                {
                    ball.transform.position = t.transform.position;
                    GoodCount++;
                }
            }
        }
    }
Beispiel #16
0
        protected void Update(object sender, EventArgs e)
        {
            paintCanvas.Strokes.Clear();
            windowWidth  = (float)this.Width;
            windowHeight = (float)this.Height;

            Frame          frame          = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;


            Debug.WriteLine("Count = " + leap.Frame().Pointables.Count);
            ioControl(leap.Frame().Pointables.Count);

            //String str = "";
            //foreach (Pointable pointable in leap.Frame().Pointables)
            //{
            //    str = str + " " + pointable.Id;
            //}
            //Debug.WriteLine(str);

            foreach (Pointable pointable in leap.Frame().Pointables)
            {
                Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                float       tx = normalizedPosition.x * windowWidth;
                float       ty = windowHeight - normalizedPosition.y * windowHeight;

                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);
                }
                // タッチ状態
                else if (pointable.TouchDistance <= 0)
                {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                }
                // タッチ対象外
                else
                {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                }

                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                paintCanvas.Strokes.Add(touchStroke);
            }
        }
Beispiel #17
0
        public Point toScreenCoor(Leap.Vector LVector)
        {
            ibox = controller.Frame().InteractionBox;

            Leap.Vector normalizedPoint = ibox.NormalizePoint(LVector, true);
            float       appX            = normalizedPoint.x * (float)(Image.Width);
            float       appY            = (1 - normalizedPoint.y) * (float)(Image.Height);
            float       appX2           = LVector.x;
            float       appY2           = LVector.y;

            return(new Point(appX, appY));

            // return new Point(appX2, appY2);
        }
        protected void Update(object sender, EventArgs e)
        {
            paintCanvas.Strokes.Clear();
            windowWidth  = (float)this.Width;
            windowHeight = (float)this.Height;

            Frame          frame          = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            foreach (Pointable pointable in leap.Frame().Pointables)
            {
                // InteractionBox を利用した座標変換
                Leap.Vector normalizedPosition = interactionBox.NormalizePoint(pointable.StabilizedTipPosition);

                // Intersect Point を利用した座標変換
                //Leap.Vector normalizedPosition = locatedScreen.Intersect( pointable, true );

                // Projection Point を利用した座標変換
                //Leap.Vector normalizedPosition = locatedScreen.Project( pointable.TipPosition, false );

                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                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);
                }
                // タッチ状態
                else if (pointable.TouchDistance <= 0)
                {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                }
                // タッチ対象外
                else
                {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                }

                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       = new StylusPointCollection(new StylusPoint[] { touchPoint });
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                paintCanvas.Strokes.Add(touchStroke);
            }
        }
        protected void Update(object sender, EventArgs e)
        {
            paintCanvas.Strokes.Clear();

            windowWidth  = (float)this.Width;
            windowHeight = (float)this.Height;

            Leap.Frame     frame          = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            try
            {
                Leap.Image image = frame.Images[0];
                this.DrawRawImages_WriteableBitmap(image.Data, image.Width, image.Height);
            }
            catch { }

            foreach (Pointable pointable in leap.Frame().Pointables)
            {
                Finger      oFinger            = new Finger(pointable);
                Leap.Vector normalizedPosition =
                    interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                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);
                }
                else if (pointable.TouchDistance <= 0)
                {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                }
                else
                {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                }
                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       =
                    new StylusPointCollection(new StylusPoint[] { touchPoint });
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                paintCanvas.Strokes.Add(touchStroke);
            }
        }
    void Update()
    {
        if (collisionFlag && collisionCounter > 0)
        {
            collisionCounter--;
        }
        Frame frame = controller.Frame();

        FingerCount = frame.Fingers.Count;

        InteractionBox interactionBox = frame.InteractionBox;

        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;

                //オキュラス合体用座標変換

                float theta = 2 * Mathf.PI / 8;
                normalizedPosition.y = -normalizedPosition.y;
                float Y = Mathf.Cos(theta) * normalizedPosition.y - Mathf.Sin(theta) * normalizedPosition.z;
                float Z = Mathf.Sin(theta) * normalizedPosition.y + Mathf.Cos(theta) * normalizedPosition.z;
                normalizedPosition.x = -normalizedPosition.x;
                normalizedPosition.z = Z;


                GameObject v = GameObject.Find("OVRCameraController");

                float beta = 2 * Mathf.PI * (v.transform.eulerAngles.y + 70) / 360;

                float X = Mathf.Cos(beta) * normalizedPosition.x - Mathf.Sin(beta) * normalizedPosition.z;
                Z = Mathf.Sin(beta) * normalizedPosition.x + Mathf.Cos(beta) * normalizedPosition.z;

                normalizedPosition.x = X;
                normalizedPosition.y = Y + 8;
                normalizedPosition.z = -Z;
                //合体用終了
                unityFinger.transform.position = ToVector3(normalizedPosition);
            }
        }
    }
        protected void Update(object sender, EventArgs e)
        {
            paintCanvas.Strokes.Clear();
            windowWidth  = (float)this.Width;
            windowHeight = (float)this.Height;

            Leap.Frame     frame          = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            foreach (Pointable pointable in leap.Frame().Pointables)
            {
                // ここから追加
                // 伸びている指、ツール以外は無視する
                //if ( !pointable.IsExtended ) {
                //    continue;
                //}
                // ここまで追加

                Leap.Vector normalizedPosition =
                    interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                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);
                }
                else if (pointable.TouchDistance <= 0)
                {
                    alpha = -(int)(255 * pointable.TouchDistance);
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                }
                else
                {
                    alpha = 50;
                    touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                }

                StylusPoint           touchPoint = new StylusPoint(tx, ty);
                StylusPointCollection tips       =
                    new StylusPointCollection(new StylusPoint[] { touchPoint });
                Stroke touchStroke = new Stroke(tips, touchIndicator);
                paintCanvas.Strokes.Add(touchStroke);
            }
        }
Beispiel #22
0
    public override void UpdateHand()
    {
        if (palm != null)
        {
            palm.position = GetPalmPosition();
            palm.rotation = GetPalmRotation() * Reorientation();
            InteractionBox interactionBox = controller_.GetFrame().InteractionBox;
            int            count          = 0;
            foreach (Finger finger in controller_.GetFrame().Hands[0].Fingers)
            {
                if (finger.IsExtended)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                Vector normalPoint = interactionBox.NormalizePoint(controller_.GetFrame().Hands[0].PalmPosition);
                if (normalPoint.y > 0.75f)
                {
                    GameObject canvasCube = GameObject.Find("EaselCube");
                    //print(canvasCube.transform.position);
                }
            }

            //print(controller_.GetFrame().Hands[0].Fingers[0].TipPosition);
            RaycastHit rayHit;
            if (Physics.Raycast(controller_.transform.TransformPoint(controller_.GetFrame().Hands[0].Fingers[0].TipPosition.ToUnityScaled()), controller_.transform.TransformDirection(controller_.GetFrame().Hands[0].Fingers[0].Direction.ToUnity()), out rayHit))
            {
                UnityStandardAssets.Characters.FirstPerson.HandleInput.drawBrush(rayHit);
            }
        }

        if (forearm != null)
        {
            forearm.rotation = GetArmRotation() * Reorientation();
        }

        for (int i = 0; i < fingers.Length; ++i)
        {
            if (fingers[i] != null)
            {
                fingers[i].fingerType = (Finger.FingerType)i;
                fingers[i].UpdateFinger();
            }
        }
    }
Beispiel #23
0
    void Update()
    {
        frame          = controller.Frame();
        interactionBox = frame.InteractionBox;
        Hand hand = frame.Hands[0];

        plamCount        = frame.Hands.Count;
        debugFingerCount = frame.Fingers.Count;
        Vector plamPos = interactionBox.NormalizePoint(hand.PalmPosition);
        int    scale   = 4;   //感知する領域を広げる

        x = scale * (plamPos.x - 0.5f);
        y = 7 * plamPos.y;
        z = scale * (plamPos.z - 0.5f);
        if (plamCount <= 1)        //片手の場合
        {
            if (hand.IsValid == false && existPlamFlag)
            {
                existPlamFlag = false;
                Destroy(plam);
            }
            if (!existPlamFlag)
            {
                if (hand.IsValid)
                {
                    existPlamFlag = true;
                    plam          = (GameObject)Instantiate(Resources.Load("Title/Plam"), ToVector3(new Vector(x, y, -z)), Quaternion.identity);
                    plam.transform.SetParent(GameObject.Find("MainCamera/LeapPos").transform);
                    plam.GetComponent <Renderer>().enabled = hand.IsValid;
                    plam.GetComponent <Collider>().enabled = hand.IsValid;
                }
            }
            else
            {
                plam.transform.localPosition = ToVector3(new Vector(x, y, -z));
            }
            HoldDecision(hand);
        }
        else if (plamCount >= 2)        //両手の場合
        {
            existPlamFlag = false;
            Destroy(plam);
            BothHandsGesture();
        }
    }
Beispiel #24
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);
        }
    }
        void listener_OnFrameEvent( Controller leap )
        {
            CanvasPaint.Children.Clear();
            var windowWidth = (float)ActualWidth;
            var windowHeight = (float)ActualHeight;

            Leap.Frame frame = leap.Frame();
            InteractionBox interactionBox = leap.Frame().InteractionBox;

            foreach ( Pointable pointable in leap.Frame().Pointables ) {
                Leap.Vector normalizedPosition = interactionBox.NormalizePoint( pointable.StabilizedTipPosition );
                float tx = normalizedPosition.x * windowWidth;
                float ty = windowHeight - normalizedPosition.y * windowHeight;

                Color color = Color.FromArgb( 0, 0, 0, 0 );
                if ( pointable.TouchDistance > 0 && pointable.TouchZone != Pointable.Zone.ZONENONE ) {
                    var alpha = 255 - (int)(255 * pointable.TouchDistance);
                    color = Color.FromArgb( (byte)alpha, 0x0, 0xff, 0x0 );
                }
                else if ( pointable.TouchDistance <= 0 ) {
                    var alpha = -(int)(255 * pointable.TouchDistance);
                    color = Color.FromArgb( (byte)alpha, 0xff, 0x0, 0x0 );
                }
                else {
                    var alpha = 50;
                    color = Color.FromArgb( (byte)alpha, 0x0, 0x0, 0xff );
                }

                // 点を表示する
                var ellipse  = new Ellipse()
                {
                    Width = 40,
                    Height = 40,
                    Fill = new SolidColorBrush( color ),
                };

                Canvas.SetLeft( ellipse, tx );
                Canvas.SetTop( ellipse, ty );

                CanvasPaint.Children.Add( ellipse );
            }
        }
Beispiel #26
0
        private void ShowFingerPoints(Leap.Frame frame)
        {
            Dispatcher.BeginInvoke(new Action(delegate()
            {
                this.InkCanvasPnl.Strokes.Clear();

                InteractionBox interactionBox = frame.InteractionBox;

                foreach (Pointable pointable in frame.Pointables)
                {
                    Leap.Vector normalizedPosition =
                        interactionBox.NormalizePoint(pointable.StabilizedTipPosition);
                    double tx = normalizedPosition.x * this.InkCanvasPnl.Width;
                    double ty = this.InkCanvasPnl.Height - normalizedPosition.y * this.InkCanvasPnl.Height;

                    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);
                    }
                    else if (pointable.TouchDistance <= 0)
                    {
                        alpha = -(int)(255 * pointable.TouchDistance);
                        touchIndicator.Color = Color.FromArgb((byte)alpha, 0xff, 0x0, 0x0);
                    }
                    else
                    {
                        alpha = 50;
                        touchIndicator.Color = Color.FromArgb((byte)alpha, 0x0, 0x0, 0xff);
                    }
                    StylusPoint touchPoint     = new StylusPoint(tx, ty);
                    StylusPointCollection tips =
                        new StylusPointCollection(new StylusPoint[] { touchPoint });
                    Stroke touchStroke = new Stroke(tips, touchIndicator);
                    this.InkCanvasPnl.Strokes.Add(touchStroke);
                }
            }));
        }
    void Update()
    {
        Frame frame = controller.Frame();

        FingerCount = frame.Fingers.Count;

        InteractionBox interactionBox = frame.InteractionBox;

        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);
            }
        }
    }
Beispiel #28
0
    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));
    }
Beispiel #29
0
        protected void Update(object sender, EventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(delegate()
            {
                DrawingVisual drawingVisual   = new DrawingVisual();
                DrawingContext drawingContext = drawingVisual.RenderOpen();
                Pen oPen = new Pen()
                {
                    Brush = new SolidColorBrush(Colors.Blue), Thickness = 3
                };

                Leap.Frame frame = leap.Frame();
                InteractionBox interactionBox = frame.InteractionBox;
                foreach (Hand hand in frame.Hands)
                {
                    foreach (Finger finger in hand.Fingers)
                    {
                        Bone bone;
                        foreach (Bone.BoneType boneType in (Bone.BoneType[])Enum.GetValues(typeof(Bone.BoneType)))
                        {
                            bone = finger.Bone(boneType);
                            Leap.Vector startPosition = interactionBox.NormalizePoint(bone.PrevJoint);
                            Leap.Vector endPosition   = interactionBox.NormalizePoint(bone.NextJoint);

                            double dX1 = startPosition.x * this.CanvasWidth;
                            double dY1 = this.CanvasHeight - startPosition.y * this.CanvasHeight;
                            double dX2 = endPosition.x * this.CanvasWidth;
                            double dY2 = this.CanvasHeight - endPosition.y * this.CanvasHeight;

                            drawingContext.DrawLine(oPen, new Point(dX1, dY1), new Point(dX2, dY2));

                            if (boneType == Bone.BoneType.TYPE_PROXIMAL)
                            {
                                drawingContext.DrawEllipse(new SolidColorBrush(Colors.Gold), oPen, new Point(dX1, dY1), 6, 6);
                            }
                            else if (boneType == Bone.BoneType.TYPE_METACARPAL)
                            {
                                drawingContext.DrawEllipse(new SolidColorBrush(Colors.Black), oPen, new Point(dX1, dY1), 6, 6);
                            }
                            else if (boneType == Bone.BoneType.TYPE_INTERMEDIATE)
                            {
                                drawingContext.DrawEllipse(new SolidColorBrush(Colors.DarkGreen), oPen, new Point(dX1, dY1), 6, 6);
                            }
                            else if (boneType == Bone.BoneType.TYPE_DISTAL)
                            {
                                drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX1, dY1), 6, 6);
                                // Finger Tip
                                drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), oPen, new Point(dX2, dY2), 12, 12);
                            }
                        }
                    }
                }

                drawingContext.Close();

                RenderTargetBitmap rtb = new RenderTargetBitmap((int)CvMain.ActualWidth,
                                                                (int)this.CvMain.ActualHeight, 96, 96, PixelFormats.Pbgra32);
                rtb.Render(drawingVisual);

                this.ImgMain.Source = rtb;
            }));
        }
        /// <summary>
        /// Event responder to receiving a new frame
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void OnFrame(object sender, FrameEventArgs args)
        {
            // Get the most recent frame and report some basic information
            Frame          frame   = args.frame;
            InteractionBox box     = frame.InteractionBox;
            double         xBounds = frame.InteractionBox.Width;
            Hand           h;

            // search through detected hands
            int matchIndex = -1;

            for (int i = 0; i < frame.Hands.Count; i++)
            {
                if (frame.Hands[i].IsRight && UseRightHand)
                {
                    matchIndex = i;
                    break;
                }
                else if (frame.Hands[i].IsLeft && !UseRightHand)
                {
                    matchIndex = i;
                    break;
                }
            }

            if (matchIndex < 0)
            {
                // no matching hands were detected. just send the last played tempo
                oscHandler.SendTempo();
                return;
            }

            h = frame.Hands[matchIndex];

            // further stabilize this position by adding the average of the last three points
            xPositions.EnqueueMovingAverage(h.StabilizedPalmPosition.x, 3);
            lastTwoBeatsPositions.Add(h.StabilizedPalmPosition.x);
            //allPositions.Add(h.StabilizedPalmPosition);
            double xBackAvg    = xPositions.BackAverage(.8);
            double xFrontAvg   = xPositions.FrontAverage(.2);
            double averageXpos = 0;

            if ((xBackAvg * xFrontAvg < 0 && xPositions.Length() > 20))
            {
                BeatAmt++;
                Console.WriteLine("Beat!");
                if (BeatAmt % 2 == 0)
                {
                    averageXpos = lastTwoBeatsPositions.Average();
                    lastTwoBeatsPositions.Clear();
                }

                xPositions.Clear();
                if (firstBeat)
                {
                    // not enough data to create a tempo. we will use this as a starting point
                    startTime       = DateTime.Now;
                    initialPosition = h.PalmPosition;
                    firstBeat       = false;
                    return;
                }
                else
                {
                    TimeSpan span = DateTime.Now - startTime;
                    startTime = DateTime.Now;

                    double durSeconds = span.Seconds + (span.Milliseconds / 1000.0);
                    int    estTempo   = (int)Math.Round(60 / durSeconds);
                    estimatedTempos.Enqueue(estTempo);



                    var   initialNorm = box.NormalizePoint(initialPosition);
                    var   currentNorm = box.NormalizePoint(h.StabilizedPalmPosition);
                    float dist        = initialNorm.DistanceTo(currentNorm);
                    Console.WriteLine(string.Format("Actual 3D normalized dist {0}", dist));
                    double xDist = Math.Abs(currentNorm.x - initialNorm.x);

                    var nonNormDist = initialPosition.DistanceTo(h.StabilizedPalmPosition);
                    Console.WriteLine(string.Format("Non normalized dist {0}", nonNormDist));
                    dist = nonNormDist / 100;
                    // reset initial position
                    initialPosition = h.StabilizedPalmPosition;
                    // send volume based on scale of distance
                    if (BeatAmt % 2 == 0)
                    {
                        Vector avgXPosition = new Vector((float)averageXpos, 0, 0);
                        Vector normX        = box.NormalizePoint(avgXPosition);
                        oscHandler.SendPan(normX.x);
                        oscHandler.SendVolume(dist * 2 > 1 ? 1 : dist * 2);
                        // round the average to the nearest 5 to prevent too many changes
                        oscHandler.SendTempo((int)Math.Round(estimatedTempos.Average() / 5) * 5);
                    }

                    Console.WriteLine("-----");
                }
            }
            else
            {
                // check if the time between the last beat time and the current time is greater than the threshold for a fermata
            }
        }