예제 #1
0
        void _listener_Frame(object sender, ControllerEventArgs e)
        {
            //Todo: Get rid of the dispatcher if possible
            Dispatcher.Invoke((Action)(() =>
            {
                Frame frame = _leap.Frame();

                if (frame.Fingers.Count > 0)
                {
                    Finger finger = frame.Fingers.First();
                    if (finger != null)
                    {
                        Vector vec = finger.Direction;
                        RawRotation = QuaternionHelper.EulerAnglesInRadToQuaternion(
                            RotationFactor * vec.Pitch,
                            RotationFactor * vec.Yaw,
                            0);
                        RawPosition = new Vector3D(
                            finger.TipPosition.x,
                            -finger.TipPosition.y,
                            finger.TipPosition.z
                            );
                    }

                    if (frame.Fingers.Count >= 5)
                    {
                        Calibrate();
                    }

                    UpdatePositionAndRotation();
                }
            }));
        }
예제 #2
0
        private void animateHands(FreeControllerV3 hc, Hand hand, string[] fingerMorphs, float mirror)
        {
            float fx;

            h = hand.PalmPosition;
            r = hand.Rotation;

            Vector3    pos = new Vector3(h[0], h[1], h[2]);
            Quaternion rot = new Quaternion(r.x, r.y, r.z, r.w);

            hc.transform.position = pos;
            hc.transform.rotation = rot;
            hc.transform.Rotate(0, 90 * mirror, 0);
            hc.transform.Translate(xOffsetSlider.val * mirror, 0, 0, Space.Self);

            for (int i = 0; i < hand.Fingers.Count; i++)
            {
                DAZMorph   morph = morphControl.GetMorphByDisplayName(fingerMorphs[i]);
                Quaternion vd    = leapQuaternionToQuaternion(hand.Fingers[i].bones[3].Rotation);
                vd = Quaternion.Inverse(vd * Quaternion.Euler(0, -90 * mirror, 0)) * rot;

                if (i == 0)
                {
                    fx = (0.5f - minMax(0f, 1f, positiveAttitude(vd.x))) * 1.22f;
                }
                else
                {
                    fx = minMax(0f, 1f, correctRotation(vd.x, 0.65f)) * 0.9f;
                }
                if (fx != 0)
                {
                    morph.morphValue = fx / 0.85f;
                }
            }
        }
예제 #3
0
        public string Tremor(Leap.Vector v, Hand hand, int Velocity) // recognize tremor
        {
            //Console.WriteLine("x "+v[0]+" y "+v[1]+" z "+v[2] + " Angle " +hand.Rotation);
            // Console.WriteLine(xyz.Magnitude);

            /*
             * Console.WriteLine(
             *  "  Hand pitch: {0} degrees, roll: {1} degrees, yaw: {2} degrees, x {3} y {4} z{5}",
             *   xyz.Pitch * 180.0f / (float)Math.PI,
             *  xyz.Roll * 180.0f / (float)Math.PI,
             *   xyz.Yaw * 180.0f / (float)Math.PI,
             *   v.x,v.y,v.z
             * );
             */
            if (Math.Abs(v[0]) >= 10 && Math.Abs(v[1]) <= 20)
            {
                return(Emotions[0]);
            }
            else if (Math.Abs(v[0]) > Velocity || Math.Abs(v[1]) > Velocity || Math.Abs(v[2]) >= Velocity)
            {
                return(Emotions[1]);
            }
            else if (v[0] >= -2 || v[0] <= 2 && v.y >= -5 || v.y <= 5)
            {
                return(Emotions[2]);
            }
            else
            {
                return(Emotions[2]);
            }
        }
 Vector Transform(Vector a)
 {
     a.x *= xratio;
     a.z *= zratio;
     a.y *= yratio;
     return(a);
 }
    private byte[] UndistortImage(byte[] imgData, Leap.Image.CameraType type)
    {
        byte[] undistortedImg = new byte[TEX_WIDTH * TEX_HEIGHT];
        for (float row = ROW_OFFSET; row < TEX_HEIGHT - ROW_OFFSET; row++)
        {
            for (float col = COL_OFFSET; col < TEX_WIDTH - COL_OFFSET; col++)
            {
                //Normalize from pixel xy to range [0..1]
                Leap.Vector input = new Leap.Vector();
                input.x = col / TEX_WIDTH;
                input.y = row / TEX_HEIGHT;

                //Convert from normalized [0..1] to ray slopes
                input.x = (input.x - 0.5f) * V_FOV * FOV_MODIFIER;
                input.y = (input.y - 0.5f) * H_FOV * FOV_MODIFIER;


                Leap.Vector pixel  = _currentImage.RectilinearToPixel(type, input);
                int         dindex = (int)Mathf.Floor(row * TEX_WIDTH + col);
                int         pindex = (int)Mathf.Floor(pixel.y) * _currentImage.Width + (int)Mathf.Floor(pixel.x);

                if (pixel.x >= 0 && pixel.x < _currentImage.Width && pixel.y >= 0 && pixel.y < _currentImage.Height)
                {
                    undistortedImg[dindex] = imgData[pindex];
                }
                else
                {
                    undistortedImg[dindex] = 100;
                }
            }
        }
        return(undistortedImg);
    }
예제 #6
0
    //将Leap Motion中获取到的坐标信息转化为Unity的世界坐标
    public static Vector3 leapVectorToUnityVector3(HandController hc, Leap.Vector leapVector)
    {
        Vector3 unityPosition_now = leapVector.ToUnityScaled(false);
        Vector3 worldPosition_now = hc.transform.TransformPoint(unityPosition_now);

        return(worldPosition_now);
    }
예제 #7
0
 public Finger(int frameId,
                    int handId, 
                    int fingerId,
                    float timeVisible,
                    Vector tipPosition,
                    Vector tipVelocity,
                    Vector direction,
                    Vector stabilizedTipPosition,
                    float width,
                    float length,
                    bool isExtended,
                    Finger.FingerType type,
                    Bone metacarpal,
                    Bone proximal,
                    Bone intermediate,
                    Bone distal)
 {
     _type = type;
     _bones [0] = metacarpal;
     _bones [1] = proximal;
     _bones [2] = intermediate;
     _bones [3] = distal;
     _frameId = frameId;
     _id = (handId * 10) + fingerId;
     _handID = handId;
     _tipPosition = tipPosition;
     _tipVelocity = tipVelocity;
     _direction = direction;
     _width = width;
     _length = length;
     _isExtended = isExtended;
     _isValid = false;
     _stabilizedTipPosition = stabilizedTipPosition;
     _timeVisible = timeVisible;
 }
예제 #8
0
 // Constructor for ReplayFrame
 public FingerData(int id, bool isFrontmost, float tipPosition_x, float tipPosition_y, float tipPosition_z, bool isValid)
 {
     m_id = id;
     m_isFrontmost = isFrontmost;
     m_tipPosition = new Vector(tipPosition_x, tipPosition_y, tipPosition_z);
     m_isValid = isValid;
 }
예제 #9
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
 }
 /**
  * Provides the translation matrix to convert Leap transform data to the Unity space of a specific Unity Transform.
  * @param t The Unity Transform to which the Leap transformation data is translated
  */
 public static Matrix GetLeapMatrix(Transform t) {
   Vector xbasis = new Vector(t.right.x, t.right.y, t.right.z) * t.lossyScale.x * MM_TO_M;
   Vector ybasis = new Vector(t.up.x, t.up.y, t.up.z) * t.lossyScale.y * MM_TO_M;
   Vector zbasis = new Vector(t.forward.x, t.forward.y, t.forward.z) * -t.lossyScale.z * MM_TO_M;
   Vector trans = new Vector(t.position.x, t.position.y, t.position.z);
   return new Matrix(xbasis, ybasis, zbasis, trans);
 }
예제 #11
0
 void polyline_points_add(Polyline polyline, Leap.Vector v1, Leap.Vector v2, Leap.Vector v3, Leap.Vector v4)
 {
     polyline.Points.Add(new System.Windows.Point(v1.x * factor, v1.z * factor));
     polyline.Points.Add(new System.Windows.Point(v2.x * factor, v2.z * factor));
     polyline.Points.Add(new System.Windows.Point(v3.x * factor, v3.z * factor));
     polyline.Points.Add(new System.Windows.Point(v4.x * factor, v4.z * factor));
 }
예제 #12
0
    private void Rotate()
    {
        if (currentController != null)
        {
            handPos = currentController.position;
            Leap.Vector indexFinger = currentController.intHand.leapHand.Fingers[1].TipPosition;
        }


        if (!firstTouch)
        {
            previousPosition = handPos;
            currentPosition  = handPos;
            firstTouch       = true;
        }
        else
        {
            previousPosition = currentPosition;
            currentPosition  = handPos;
        }

        if (previousPosition != -currentPosition)
        {
            Vector3 centerToCurrentPos   = currentPosition - viewParent.transform.position;
            Vector3 centerToPrevioustPos = previousPosition - viewParent.transform.position;

            float rotationAmount = Vector3.SignedAngle(centerToPrevioustPos.normalized, centerToCurrentPos.normalized, Vector3.up);
            // Lerp?
            viewParent.transform.RotateAroundLocal(Vector3.up, rotationAmount * rotateFactor);
        }
    }
예제 #13
0
 protected override void ApplyPositionUpdate(PersistentHand hand, Vector change, int velocity)
 {
     var linesToScroll = (IsInverted ? -Lines : Lines) * Math.Sign(GetX(change));
     if (IsAccelerated)
         linesToScroll *= Convert.ToInt32(Math.Floor(change.Magnitude / MinDistance));
     InputSimulator.Mouse.VerticalScroll(linesToScroll);
 }
예제 #14
0
        public int angleJ5(Leap.Vector P)
        {
            double sum = Math.Pow(p.x, 2) + Math.Pow(p.y, 2) + Math.Pow(p.z, 2);

            sum = Math.Sqrt(sum);
            double cos, radian, Jfive;
            int    J5;

            cos    = Math.Abs(p.y) / sum;
            radian = Math.Acos(cos);
            double angle_tmp = radian / Math.PI * 180;

            //ElbowZ =(float) angle_tmp;
            if (curr_J3 > 0)
            {
                Jfive = Math.Abs(curr_J2) - curr_J3 - angle_tmp - 90;
                //ElbowY = (float)Jfive;
                J5 = (int)Jfive;
                //ElbowZ = (float)J5;
            }

            else
            {
                Jfive = Math.Abs(curr_J2) + Math.Abs(curr_J3) - 90 - angle_tmp;
                J5    = (int)Jfive;
            }
            return(J5);
        }
예제 #15
0
        public override void OnFrame(Controller controller)
        {
            Pointable pointable = FindPointable(controller);

            // use the pointable movement to move the mouse
            if (null != pointable)
            {
                //SafeWriteLine("pointable: " + pointable.Id + ", " + GetPosition(pointable).ToString());

                if (HasPrevTipPosition)
                {
                    Vector tipMovement = GetPosition(pointable) - PrevTipPosition;
                    //Vector tipMovement = pointable.TipVelocity; // too noisy; need better precision for this

                    Vector mouseMovement = LeapTransform.TransformToScreenSpace(tipMovement);
                    mouseMovement.x *= MouseSensitivityX;
                    mouseMovement.y *= MouseSensitivityY;

                    // there are discontinuities in the data we get back; ignore them and only perform reasonably small movements
                    if (mouseMovement.Magnitude < 300)
                    {
                        MouseWrapper.MoveMouse((int)mouseMovement.x, (int)mouseMovement.y);
                    }
                }

                HasPrevTipPosition = true;
                PrevPointableId = pointable.Id;
                PrevTipPosition = GetPosition(pointable);
            }
            else
            {
                SafeWriteLine("No pointable");

                HasPrevTipPosition = false;
                PrevPointableId = int.MinValue;
                PrevTipPosition = null;
            }

            // convert keyboard presses into mouse clicks. We only want to do this with certain presses,
            // where the key combination would not normally cause anything to happen.  We assume that no
            // one actually presses the right shift key. :)
            if ((KeyboardWrapper.IsKeyDown(Keys.LControlKey)) && (KeyboardWrapper.IsKeyDown(Keys.Space)) && (FrameSinceLastClick > 20))
            {
                MouseWrapper.LeftClick();
                FrameSinceLastClick = 0;
            }
            else if ((KeyboardWrapper.IsKeyDown(Keys.RControlKey)) && (KeyboardWrapper.IsKeyDown(Keys.Space) && (FrameSinceLastClick > 20)))
            {
                MouseWrapper.RightClick();
                FrameSinceLastClick = 0;
            }
            else
            {
                FrameSinceLastClick += 1;
                if (FrameSinceLastClick < 0)
                {
                    FrameSinceLastClick = 20;
                }
            }
        }
예제 #16
0
        protected override void ApplyPositionUpdate(PersistentHand hand, Vector change, int velocity)
        {
            double scaleX;
            double scaleY;
            if (velocity > 150)
            {
                scaleX = _ScaleFactorX;
                scaleY = _ScaleFactorY;
            }
            else if (velocity > 100)
            {
                scaleX = _ScaleFactorX * 2.0 / 3.0;
                scaleY = _ScaleFactorY * 2.0 / 3.0;
            }
            else if (velocity > 50)
            {
                scaleX = _ScaleFactorX * 1.0 / 3.0;
                scaleY = _ScaleFactorY * 1.0 / 3.0;
            }
            else
            {
                scaleX = 1;
                scaleY = 1;
            }
            var x = Convert.ToInt32(GetX(change) * 2 * scaleX);
            var y = Convert.ToInt32(GetY(change) * 2 * scaleY);

            InputSimulator.Mouse.MoveMouseBy(x, -y);
        }
예제 #17
0
        private Point ToScreen(Leap.Vector vector)
        {
            double dX = vector.x * this.CanvasWidth;
            double dY = this.CanvasHeight - vector.y * this.CanvasHeight;

            return(new Point(dX, dY));
        }
예제 #18
0
        public int angleJ3_test3(int J2, Leap.Vector wristVector)
        {
            int J3 = 0;

            if (wristVector.y < 320)
            {
                if (J2 >= -9 && J2 <= 12)
                {
                    J3 = 16 - 21 * (J2 + 9) / 21;
                    return(J3);
                }
                else
                {
                    return(24);
                }
            }
            else
            {
                if (J2 >= -9 && J2 <= 18)
                {
                    J3 = 23 - 28 * (J2 + 9) / 27;
                    return(J3);
                }
                else
                {
                    return(24);
                }
            }
        }
예제 #19
0
    private void Drag()
    {
        if (currentController != null)
        {
            handPos = currentController.position;
            Leap.Vector indexFinger = currentController.intHand.leapHand.Fingers[1].TipPosition;
        }


        if (!firstTouch)
        {
            previousPosition = handPos;
            currentPosition  = handPos;
            firstTouch       = true;
        }
        else
        {
            previousPosition = currentPosition;
            currentPosition  = handPos;
        }
        if (allowDragging)
        {
            viewParent.Translate((currentPosition - previousPosition) * dragFactor, Space.World);
        }
    }
예제 #20
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());
            }
        }
예제 #21
0
        public int angleJ2(Leap.Vector wristVector)
        {
            //  l3
            //  test2_a    放大倍数

            double h0 = test2_a * wristVector.y - h;

            //ElbowY = (float)l3;
            //L4,斜边

            //angle 01
            double radian1;

            radian1 = Math.Atan(h0 / l3);
            ElbowX  = (float)(radian1 / Math.PI * 180);
            //angle 02
            radian2 = Math.Acos(l4 / (2 * a));

            //angle J2
            double Jtwo = (-1) * (Math.PI / 2 - radian1 - radian2) / Math.PI * 180;
            //ElbowY = (float)Jtwo;
            int J2 = (int)Math.Floor(Jtwo);

            //ElbowY = J2;
            return(J2);
        }
예제 #22
0
        string getPinchingFinger(Hand hand)
        {
            string[] fingers = new string[5] {
                "thumb", "index", "middle", "ring", "pinky"
            };

            float  distance = 500;
            Finger pinchingFinger;
            int    index = 0;

            Leap.Vector thumbPos = hand.Fingers[0].TipPosition;

            for (int i = 1; i < hand.Fingers.Count; i++)
            {
                Finger currentFinger   = hand.Fingers[i];
                float  currentDistance = currentFinger.TipPosition.DistanceTo(thumbPos);

                if (currentDistance < distance)
                {
                    distance       = currentDistance;
                    pinchingFinger = currentFinger;
                    index          = i;
                }
            }

            endDistance = distance;

            return(fingers[index]);
        }
예제 #23
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);
                }
            }
        }
        private void CalculateRealScreenPosition(Screen screen, Vector intersection)
        {
            CursorPositionX += (intersection.x * screen.WidthPixels - CursorPositionX) * VelocityResponse;
            CursorPositionY += ((1 - intersection.y) * screen.HeightPixels - CursorPositionY) * VelocityResponse;

            mouseFacade.SetCursorPosition((int)CursorPositionX, (int)CursorPositionY);
        }
예제 #25
0
        public int angerJfive(Leap.Vector p)
        {
            double tan;
            double radian;
            double Jfive;
            int    J5;

            if (p.z >= 0)
            {
                tan = (-1) * p.z / p.x;
                //ElbowX =(float) tan;
                radian = Math.Atan(tan) + Math.PI / 2;
                Jfive  = radian / Math.PI * 180;
                J5     = (int)Math.Floor(Jfive) - curr_J1;
                J5     = (-1) * J5;
                //ElbowX = J5;
                return(J5);
            }
            else
            {
                tan    = p.z / p.x;
                radian = Math.PI / 2 - Math.Atan(tan);
                Jfive  = radian / Math.PI * 180;
                J5     = (int)Math.Floor(Jfive) - curr_J1;
                J5     = (-1) * J5;
                return(J5);
            }
        }
예제 #26
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);
        }
예제 #27
0
    // Update is called once per frame
    void Update()
    {
        if (controller.IsConnected)
        {                                     //controller is a Controller object
            Frame frame = controller.Frame(); //The latest frame
            foreach (Hand hand in frame.Hands)
            {
                if (hand.IsRight)
                {
                    // For Orion, can use leapService and LeapProvider class for quicker operations.
                    //transform.position = hand.PalmPosition.ToVector3() +
                    //hand.PalmNormal.ToVector3() *
                    //(transform.localScale.y * .5f + .02f);
                    //transform.rotation = hand.Basis.Rotation();

                    Leap.Vector position      = hand.PalmPosition;
                    Vector3     unityPosition = position.ToUnityScaled(false);
                    // print(unityPosition);
                    Vector3 worldPosition = hc.transform.TransformPoint(unityPosition);
                    //print(worldPosition);
                    Leap.Vector norm      = hand.PalmNormal;
                    Vector3     unityNorm = norm.ToUnityScaled(false);
                    followTarget.transform.position = worldPosition + unityNorm * (followTarget.transform.localScale.y * .5f + .02f);
                    followTarget.transform.rotation = hand.Basis.Rotation();
                }
            }
        }
    }
 // 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);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="Leap.GestureSpace"/> class
        /// using the predefined constants to define the workspace size.
        /// </summary>
        public GestureSpace()
        {
            Vector topLeft = new Vector(Left, 0, Top);
            Vector bottomRight = new Vector(Right, 0, Bottom);

            xz = new Rectangle((int)topLeft.x, (int)topLeft.z, (int)(bottomRight.x - topLeft.x), (int)Math.Abs(topLeft.z - bottomRight.z));
        }
예제 #30
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;
        }
예제 #31
0
 /**
    * Constructs a transformation matrix from the specified basis and translation vectors.
    *
    * \include Matrix_Matrix_basis_origin.txt
    *
    * @param xBasis A Vector specifying rotation and scale factors for the x-axis.
    * @param yBasis A Vector specifying rotation and scale factors for the y-axis.
    * @param zBasis A Vector specifying rotation and scale factors for the z-axis.
    * @param origin A Vector specifying translation factors on all three axes.
    * @since 1.0
    */
 public Matrix(Vector xBasis, Vector yBasis, Vector zBasis, Vector origin)
 {
     this._xBasis = xBasis;
     this._yBasis = yBasis;
     this._zBasis = zBasis;
     this._origin = origin;
 }
예제 #32
0
 public GestureDetectedEventArgs(GestureType type, float speed, Vector direction, long timestamp)
 {
     m_type = type;
     m_speed = speed;
     m_direction = direction;
     m_timestamp = timestamp;
 }
예제 #33
0
 /**
    * Constructs a copy of the specified Matrix object.
    *
    * \include Matrix_Matrix_copy.txt
    *
    * @since 1.0
    */
 public Matrix(Matrix other)
 {
     this._xBasis = other.xBasis;
     this._yBasis = other.yBasis;
     this._zBasis = other.zBasis;
     this._origin = other.origin;
 }
예제 #34
0
 /**
    * Constructs a transformation matrix from the specified basis vectors.
    *
    * \include Matrix_Matrix_basis.txt
    *
    * @param xBasis A Vector specifying rotation and scale factors for the x-axis.
    * @param yBasis A Vector specifying rotation and scale factors for the y-axis.
    * @param zBasis A Vector specifying rotation and scale factors for the z-axis.
    * @since 1.0
    */
 public Matrix(Vector xBasis, Vector yBasis, Vector zBasis)
 {
     this._xBasis = xBasis;
     this._yBasis = yBasis;
     this._zBasis = zBasis;
     this._origin = Vector.Zero;
 }
예제 #35
0
 public Vector TransformToScreenSpace(Vector leapVector)
 {
     if (Orientation.Equals(SensorOrientation.DesktopLeftward))
     {
         return new Vector(leapVector.x, -leapVector.y, 0);
     }
     else if (Orientation.Equals(SensorOrientation.MonitorLeftward))
     {
         return new Vector(leapVector.x, leapVector.z, 0);
     }
     else if (Orientation.Equals(SensorOrientation.MonitorRightward))
     {
         return new Vector(leapVector.x, -leapVector.z, 0);
     }
     else if (Orientation.Equals(SensorOrientation.MonitorSkyward))
     {
         return new Vector(-leapVector.z, leapVector.x, 0);
     }
     else if (Orientation.Equals(SensorOrientation.MonitorEarthward))
     {
         return new Vector(-leapVector.z, -leapVector.x, 0);
     }
     else
     {
         Debug.Assert(false);
         return new Vector();
     }
 }
예제 #36
0
    /// <summary>
    /// Processes the swipe gesture.
    /// </summary>
    private void processSwipeGesture()
    {
        // Gets the final direction
        Leap.Vector finalDirection = m_FinalSwipeGestureValues.Direction;        // - m_InitialSwipeGestureValues.Direction;

        // Checks if the swipe direction is horizontal or vertical
        if (Mathf.Abs(finalDirection.x) > Mathf.Abs(finalDirection.y))
        {
            if (finalDirection.x > 0)
            {
//				Debug.Log("Swipe right" );
            }
            else
            {
//				Debug.Log("Swipe left" );
            }
        }
        else
        {
            if (finalDirection.y > 0)
            {
//				Debug.Log("Swipe up");
            }
            else
            {
//				Debug.Log("Swipe down ");
            }
        }
    }
예제 #37
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);
        //}
    }
예제 #38
0
 /**
  * Constructs a finger.
  *
  * Generally, you should not create your own finger objects. Such objects will not
  * have valid tracking data. Get valid finger objects from a hand in a frame
  * received from the service.
  *
  * @param frameId The id of the frame this finger appears in.
  * @param handId The id of the hand this finger belongs to.
  * @param fingerId The id of this finger (handId + 0-4 for finger position).
  * @param timeVisible How long this instance of the finger has been visible.
  * @param tipPosition The position of the finger tip.
  * @param tipVelocity The velocity of the finger tip.
  * @param direction The pointing direction of the finger.
  * @param stabilizedTipPosition The stabilized tip position.
  * @param width The average width of the finger.
  * @param length The length of the finger.
  * @param isExtended Whether the finger is more-or-less straight.
  * @param type The finger name.
  * @param metacarpal The first bone of the finger (inside the hand).
  * @param proximal The second bone of the finger
  * @param intermediate The third bone of the finger.
  * @param distal The end bone.
  * @since 3.0
  */
 public Finger(long frameId,
               int handId,
               int fingerId,
               float timeVisible,
               Vector tipPosition,
               Vector tipVelocity,
               Vector direction,
               Vector stabilizedTipPosition,
               float width,
               float length,
               bool isExtended,
               Finger.FingerType type,
               Bone metacarpal,
               Bone proximal,
               Bone intermediate,
               Bone distal)
 {
   Type = type;
   _bones[0] = metacarpal;
   _bones[1] = proximal;
   _bones[2] = intermediate;
   _bones[3] = distal;
   _frameId = frameId;
   Id = (handId * 10) + fingerId;
   HandId = handId;
   TipPosition = tipPosition;
   TipVelocity = tipVelocity;
   Direction = direction;
   Width = width;
   Length = length;
   IsExtended = isExtended;
   StabilizedTipPosition = stabilizedTipPosition;
   TimeVisible = timeVisible;
 }
예제 #39
0
 public void DrawBasis(Vector position, LeapTransform basis, float scale)
 {
     Vector3 origin = position.ToVector3();
       Debug.DrawLine(origin, origin + basis.xBasis.ToVector3() * scale, Color.red);
       Debug.DrawLine(origin, origin + basis.yBasis.ToVector3() * scale, Color.green);
       Debug.DrawLine(origin, origin + basis.zBasis.ToVector3() * scale, Color.blue);
 }
예제 #40
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();
     }
 }
예제 #41
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);
                }
            }
        }
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="Leap.GestureSpace"/> class
        /// using the given boundaries.
        /// </summary>
        /// <param name="left">Left edge of the workspace, defined in mm relative to Leap.</param>
        /// <param name="top">Top edge of the workspace, defined in mm relative to Leap.</param>
        /// <param name="right">Right edge of the workspace, defined in mm relative to Leap.</param>
        /// <param name="bottom">Bottom edge of the workspace, defined in mm relative to Leap.</param>
        public GestureSpace(int left, int top, int right, int bottom)
        {
            Vector topLeft = new Vector(left, 0, top);
            Vector bottomRight = new Vector(right, 0, bottom);

            xz = new Rectangle((int)topLeft.x, (int)topLeft.z, (int)(bottomRight.x - topLeft.x), (int)Math.Abs(topLeft.z - bottomRight.z));
        }
예제 #43
0
 public PositionTracker(PersistentHand hand, Func<PersistentHand, Vector> positionGetter, Func<PersistentHand, int> velocityGetter)
 {
     Hand = hand;
     PositionGetter = positionGetter;
     VelocityGetter = velocityGetter;
     _CurrentPosition = PositionGetter(Hand);
 }
예제 #44
0
        private long TimeDifference; // difference between time stamps

        #endregion Fields

        #region Methods

        public double cursorFingerVelocity(Vector pos1, Vector pos2, Vector pos3, Vector pos4)
        {
            double fingerVelocity = 0;

            fingerVelocity = (pos1.y - pos2.y) / 0.1;

            return fingerVelocity;
        }
예제 #45
0
파일: HandData.cs 프로젝트: intuilab/LeapIA
 // Constructor for ReplayFrame
 public HandData(int id, int nbOfFingers, bool isFrontmost, float palmPosition_x, float palmPosition_y, float palmPosition_z, bool isValid)
 {
     m_id = id;
     m_nbOfFingers = nbOfFingers;
     m_isFrontmost = isFrontmost;
     m_palmPosition = new Vector(palmPosition_x, palmPosition_y, palmPosition_z);
     m_isValid = isValid;
 }
예제 #46
0
  static Finger MakeIndexFinger(int frameId, int handId){
     //Index Finger
     Vector position = new Vector(23.1812851873f, 2.0f, -23.1493459317f);
     Vector forward = new Vector(0.166044313785f, -0.14834045293f, -0.974897120667f);
     Vector up = new Vector(0.0249066470677f, 0.988936352868f, -0.1462345681f);
     float[]  jointLengths = {68.12f, 39.78f, 22.38f, 15.82f};
     return MakeFinger (Finger.FingerType.TYPE_INDEX, position, forward, up, jointLengths, frameId, handId, handId + 1);
 }
예제 #47
0
 private static IJoint CreateFinger(Vector position, Vector normal, JointType jt)
 {
     var finger = new OrientedJoint();
     finger.JointType = jt;
     finger.Point = new Vector3(position.x, position.y, position.z);
     finger.Orientation = new Vector4(10 * normal.x, 10 * normal.y, 10 * normal.z, 0);
     return finger;
 }
예제 #48
0
  static Finger MakeThumb(int frameId, int handId){
     //Thumb
     Vector position = new Vector(19.3382610281f, -6.0f, 53.168484654f);
     Vector forward = new Vector(0.436329113772f, 0.0f, -0.899787143982f);
     Vector up = new Vector(0.804793943718f, 0.447213915513f, 0.390264553767f);
     float[] jointLengths = {0.0f, 46.22f, 31.57f, 21.67f};
     return MakeFinger (Finger.FingerType.TYPE_THUMB, position, forward, up, jointLengths, frameId, handId, handId + 0);
 }
예제 #49
0
 public LeapTransform(Vector translation, LeapQuaternion rotation, Vector scale)
     : this()
 {
     _scale = scale;
       // these are non-trival setters.
       this.translation = translation;
       this.rotation = rotation; // Calls validateBasis
 }
예제 #50
0
  static Finger MakeMiddleFinger(int frameId, int handId){
     //Middle Finger
     Vector position = new Vector(2.78877821918f, 4.0f, -23.252105626f);
     Vector forward = new Vector(0.0295207858556f, -0.148340452932f, -0.988495641481f);
     Vector up = new Vector(-0.145765270107f, 0.977715980076f, -0.151075968756f);
     float[]  jointLengths = {64.60f, 44.63f, 26.33f, 17.40f};
     return MakeFinger (Finger.FingerType.TYPE_MIDDLE, position, forward, up, jointLengths, frameId, handId, handId + 2);
 }
 public static bool DirectTo(Vector position, Vector normal, Vector target, double threshold = 15.0)
 {
     return DirectTo(
         new Vector3(position.x, position.y, position.z),
         new Vector3(normal.y, normal.y, normal.z),
         new Vector3(target.x, target.y, target.z),
         threshold);
 }
예제 #52
0
 public override bool IsAcceptableDirection(Vector direction)
 {
     if (Math.Abs (direction.x) > Math.Abs (direction.z)) {
         Debug.Log ("horizontal");
         return true;
     }
     return false;
 }
예제 #53
0
        public double L3(Leap.Vector wristVector)
        {
            double x_m    = wristVector.x - M;
            double l3_tmp = Math.Pow((l2 + test2_a * x_m), 2) + Math.Pow(test2_a * wristVector.z, 2);

            l3_tmp = Math.Sqrt(l3_tmp);
            return(l3_tmp);
        }
 public static Vector3 Vec3(this Leap.Vector vec)
 {
     return(new Vector3(
                vec.x,
                vec.y,
                -vec.z
                ));
 }
예제 #55
0
 //Constructor for LeapFrame
 public FingerData(Finger finger)
 {
     m_id = finger.Id;
     m_isFrontmost = (finger.Id == finger.Frame.Fingers.Frontmost.Id);
     m_tipPosition = finger.TipPosition;
     m_length = finger.Length;
     m_isValid = finger.IsValid;
 }
예제 #56
0
        void newFrameHandler(object sender, FrameEventArgs eventArgs)
        {
            Frame frame = eventArgs.frame;

            fpsDisplay.Content = frame.CurrentFramesPerSecond.ToString();
            if (frame.Hands.Count > 0)
            {
                Hand hand = frame.Hands[0];

                string handType = hand.IsLeft ? "Left" : "Right";


                // fingers
                Finger thumb   = hand.Fingers[0];
                Finger pointer = hand.Fingers[1];
                Finger middle  = hand.Fingers[2];
                Finger ring    = hand.Fingers[3];
                Finger pinky   = hand.Fingers[4];

                handTypeDisplay.Content = hand.IsLeft ? "left" : "right";

                Arm         arm           = hand.Arm;
                Leap.Vector armDirection  = arm.Direction;
                Leap.Vector handDirection = hand.Direction;

                double angleRadians = armDirection.AngleTo(handDirection);
                double angleDegrees = Math.Round(angleRadians * 180 / Math.PI);
                currentAngle = angleDegrees;
                calculateAverageAngle();
                this.angleDisplay.Content = currentAverageAngle.ToString();

                if (recording == true)
                {
                    DateTime currentTime = DateTime.Now;
                    int      elapsedTime = Convert.ToInt32(((TimeSpan)(currentTime - startRecording)).TotalMilliseconds);
                    timeDisplay.Content = elapsedTime.ToString();
                    string line = "timestamp: " + elapsedTime.ToString() + " | hand: " + handType + " | angle: " + currentAverageAngle.ToString();
                    if (firstFrame == true)
                    {
                        using (StreamWriter recordFile = new StreamWriter(@"C:\Users\casch\Documents\Work\Uni\Studienarbeit\Implementierung\C#\wfe.txt"))
                        {
                            recordFile.WriteLine(line);
                        };

                        firstFrame = false;
                    }
                    else
                    {
                        using (StreamWriter recordFile = new StreamWriter(@"C:\Users\casch\Documents\Work\Uni\Studienarbeit\Implementierung\C#\wfe.txt", true))
                        {
                            recordFile.WriteLine(line);
                        };
                    }
                }
            }

            controller.RequestImages(frame.Id, Leap.Image.ImageType.DEFAULT, imagedata);
        }
예제 #57
0
    // Update is called once per frame
    void Update()
    {
        HandList hands = controller.Frame().Hands;


        for (int i = 0; i < hands.Count; i++)
        {
            Hand hand = controller.Frame().Hands[i];
            //Leap.Vector rawTp = controller.Frame().Hand(hand.Id).Fingers[1].TipPosition;
            Leap.Vector rawTp = controller.Frame().Hand(hand.Id).PalmPosition;
            Vector3     tp    = TipPosToVector(rawTp);
            if ((tp.x < 0 && color == "blue") || (tp.x > 0 && color == "red"))
            {
                this.transform.position = tp;
                lastDrawingState        = drawing;
                Debug.Log(hand.PalmNormal.Pitch);
                if (hand.PalmNormal.Pitch < activationPitch && !bar.GetComponent <BarController>().gameEnded)
                {
                    drawing   = false;
                    mat.color = movingColor;

                    if (lastDrawingState == true)
                    {
                        Cucumber line = CreateShapeFromPoints(pathX, pathZ);
                        pathX.Clear();
                        pathZ.Clear();
                        if (line.length > 0.25f && line.length < 1.4f)
                        {
                            bar.GetComponent <BarController>().changeChalk(0.1f * line.length, color);
                            if (line.vigor)
                            {
                                Transform newLine = Instantiate(vigor, line.position, Quaternion.Euler(0, -(float)(line.angle * 180 / Math.PI), 90));
                                newLine.GetComponent <VigorController>().init(line.length, color, line.angle);
                                newLine.GetComponent <VigorController>().bar = bar;
                                BarController.toDestroy.Add(newLine.gameObject);
                            }
                            else
                            {
                                Transform newLine = Instantiate(forbiddance, line.position, Quaternion.Euler(0, -(float)(line.angle * 180 / Math.PI), 90));
                                newLine.GetComponent <ForbiddanceController>().init(line.length, color, line.angle);
                                BarController.toDestroy.Add(newLine.gameObject);
                            }
                        }
                    }
                }
                else
                {
                    drawing   = true;
                    mat.color = drawingColor;
                    pathX.Add(tp.x);
                    pathZ.Add(tp.z);
                }
            }
        }
        //string hand = controller.Frame().Hand(0).ToString();
        //Debug.Log(hand);
    }
예제 #58
0
 /**
  * Constructs an invalid Bone object.
  *
  * \include Bone_invalid.txt
  *
  * Get valid Bone objects from a Finger object.
  *
  * @since 2.0
  */
 public Bone()
 {
     _prevJoint = Vector.Zero;
     _nextJoint = Vector.Zero;
     _basis = Matrix.Identity;
     _center = Vector.Zero;
     _direction = Vector.Zero;
     _type = BoneType.TYPE_METACARPAL; //There is no invalid BoneType
 }
예제 #59
0
        public void check_IsAMatch_failsifyvalueoutsideparameters()
        {
            Vector newposition = new Vector(100, 100, 0);
            Vector originalposition = new Vector(200, 201, 0);

            Boolean isamatch = TestListener.IsAMatch(newposition, originalposition);

            Assert.AreEqual(false, isamatch, "IsAMatch does not fail when y value outside parameter");
        }
 /// <summary>
 /// Constructor to create a swipe event object
 /// </summary>
 /// <param name="name">Name of the gesture</param>
 /// <param name="id">ID of the gesture</param>
 /// <param name="state">State of the gesture in the frame</param>
 /// <param name="position">Position of the gesture in the frame</param>
 /// <param name="direction">Direction of the gesture in the frame</param>
 public GestureEvent(string name, int id, string state, float[] position, float[] direction)
 {
     this.name = name;
     this.id = id;
     this.state = state;
     this.position = position;
     this.direction = direction;
     this.progress = 0F;
     this.normal = null;
 }