Exemple #1
0
        /**
         * Returns a copy of this Hand object transformed by the specifid transform matrix.
         */
        public Hand TransformedCopy(Matrix trs)
        {
            List <Finger> transformedFingers = new List <Finger>(5);

            for (int f = 0; f < this.Fingers.Count; f++)
            {
                transformedFingers.Add(Fingers[f].TransformedCopy(trs));
            }

            float hScale = trs.xBasis.Magnitude;

            return(new Hand(
                       FrameId,
                       Id,
                       Confidence,
                       GrabStrength,
                       GrabAngle,
                       PinchStrength,
                       PinchDistance,
                       PalmWidth * hScale,
                       IsLeft,
                       TimeVisible,
                       Arm.TransformedCopy(trs),
                       transformedFingers,
                       trs.TransformPoint(PalmPosition),
                       trs.TransformPoint(StabilizedPalmPosition),
                       trs.TransformPoint(PalmVelocity),
                       trs.TransformDirection(PalmNormal).Normalized,
                       trs.TransformDirection(Direction).Normalized,
                       trs.TransformPoint(WristPosition)
                       ));
        }
Exemple #2
0
        public Hand TransformedCopy(Matrix trs)
        {
            FingerList transformedFingers = new FingerList(5);

            for (int f = 0; f < this.Fingers.Count; f++)
            {
                transformedFingers.Add(Fingers[f].TransformedCopy(trs));
            }

            float hScale = trs.xBasis.Magnitude;

            return(new Hand(_frameId,
                            _id,
                            _confidence,
                            _grabStrength,
                            _grabAngle,
                            _pinchStrength,
                            _pinchDistance,
                            _palmWidth * hScale,
                            _isLeft,
                            _timeVisible,
                            _arm.TransformedCopy(trs),
                            transformedFingers,
                            trs.TransformPoint(_palmPosition),
                            trs.TransformPoint(_stabilizedPalmPosition),
                            trs.TransformPoint(_palmVelocity),
                            trs.TransformDirection(_palmNormal).Normalized,
                            trs.TransformDirection(_direction).Normalized,
                            trs.TransformPoint(_wristPosition)
                            ));
        }
Exemple #3
0
 /**
  * Creates a copy of this arm, transformed by the specified transform.
  *
  * @param trs A Matrix containing the desired translation, rotation, and scale
  * of the copied arm.
  * @since 3.0
  */
 public new Arm TransformedCopy(Matrix trs)
 {
   float dScale = trs.zBasis.Magnitude;
   float hScale = trs.xBasis.Magnitude;
   return new Arm(trs.TransformPoint(PrevJoint),
       trs.TransformPoint(NextJoint),
       trs.TransformPoint(Center),
       trs.TransformDirection(Direction),
       Length * dScale,
       Width * hScale,
       trs * Basis);
 }
Exemple #4
0
        /**
         * Creates a copy of this arm, transformed by the specified transform.
         *
         * @param trs A Matrix containing the desired translation, rotation, and scale
         * of the copied arm.
         * @since 3.0
         */
        public new Arm TransformedCopy(Matrix trs)
        {
            float dScale = trs.zBasis.Magnitude;
            float hScale = trs.xBasis.Magnitude;

            return(new Arm(trs.TransformPoint(PrevJoint),
                           trs.TransformPoint(NextJoint),
                           trs.TransformPoint(Center),
                           trs.TransformDirection(Direction),
                           Length * dScale,
                           Width * hScale,
                           trs * Basis));
        }
Exemple #5
0
        public Bone TransformedCopy(Matrix trs)
        {
            float dScale = trs.zBasis.Magnitude;
            float hScale = trs.xBasis.Magnitude;

            return(new Bone(trs.TransformPoint(_prevJoint),
                            trs.TransformPoint(_nextJoint),
                            trs.TransformPoint(_center),
                            trs.TransformDirection(_direction).Normalized,
                            _length * dScale,
                            _width * hScale,
                            _type,
                            trs * _basis));
        }
Exemple #6
0
        /**
         * Creates a copy of this bone, transformed by the specified transform.
         *
         * @param trs A Matrix containing the desired translation, rotation, and scale
         * of the copied bone.
         * @since 3.0
         */
        public Bone TransformedCopy(Matrix trs)
        {
            float dScale = trs.zBasis.Magnitude;
            float hScale = trs.xBasis.Magnitude;

            return(new Bone(trs.TransformPoint(PrevJoint),
                            trs.TransformPoint(NextJoint),
                            trs.TransformPoint(Center),
                            trs.TransformDirection(Direction).Normalized,
                            Length * dScale,
                            Width * hScale,
                            Type,
                            trs * Basis));
        }
Exemple #7
0
        /**
         * Creates a copy of this finger, transformed by the specified transform.
         *
         * @param trs A Matrix containing the desired translation, rotation, and scale
         * of the copied finger.
         * @since 3.0
         */
        public Finger TransformedCopy(Matrix trs)
        {
            float dScale = trs.zBasis.Magnitude;
            float hScale = trs.xBasis.Magnitude;

            return(new Finger(_frameId,
                              HandId,
                              Id,
                              TimeVisible,
                              trs.TransformPoint(TipPosition),
                              trs.TransformPoint(TipVelocity),
                              trs.TransformDirection(Direction).Normalized,
                              trs.TransformPoint(StabilizedTipPosition),
                              Width * hScale,
                              Length * dScale,
                              IsExtended,
                              Type,
                              _bones[0].TransformedCopy(trs),
                              _bones[1].TransformedCopy(trs),
                              _bones[2].TransformedCopy(trs),
                              _bones[3].TransformedCopy(trs)));
        }
Exemple #8
0
        public Finger TransformedCopy(Matrix trs)
        {
            float dScale = trs.zBasis.Magnitude;
            float hScale = trs.xBasis.Magnitude;

            return(new Finger(_frameId,
                              _handID,
                              _id,
                              _timeVisible,
                              trs.TransformPoint(_tipPosition),
                              trs.TransformPoint(_tipVelocity),
                              trs.TransformDirection(_direction).Normalized,
                              trs.TransformPoint(_stabilizedTipPosition),
                              _width * hScale,
                              _length * dScale,
                              _isExtended,
                              _type,
                              _bones[0].TransformedCopy(trs),
                              _bones[1].TransformedCopy(trs),
                              _bones[2].TransformedCopy(trs),
                              _bones[3].TransformedCopy(trs)));
        }
    /// <summary>
    /// Update joint positions based on finger positions
    /// </summary>
    void UpdateJoints()
    {
        Vector3 angle;
        float seekSpeed = Time.deltaTime * 20;
        float returnSpeed = Time.deltaTime * 4;
        Vector3 rotation;
        List<int> fingerIDs = new List<int>(unityHand.leapFingers.Keys);

        handTransform = unityHand.detectedFingers.handTransform;

        // Update Visible Fingers
        foreach (int i in fingerIDs)
        {
            Vector3 transformedPosition = handTransform.TransformPoint(unityHand.leapFingers[i].TipPosition).ToUnityScaled();
            Vector basePosition = -unityHand.leapFingers[i].Direction * unityHand.leapFingers[i].Length;
            basePosition += unityHand.leapFingers[i].TipPosition;

            //angle = Quaternion.FromToRotation(Vector3.forward + baseTransformedPosition, transformedPosition).eulerAngles;
            angle = Quaternion.FromToRotation(Vector3.forward, transformedPosition).eulerAngles;
            rotation = joints[i].localEulerAngles;

            rotation.x = Mathf.LerpAngle(rotation.x, angle.x, seekSpeed);
            rotation.y = Mathf.LerpAngle(rotation.y, angle.y, seekSpeed);
            rotation.z = Mathf.LerpAngle(rotation.z, angle.z, seekSpeed);
            joints[i].localEulerAngles = rotation;
        }

        // Update Missing Fingers
        for (int i = 0; i < 5; i++)
        {
            if (!unityHand.leapFingers.ContainsKey(i))
            {
                rotation = joints[i].localEulerAngles;
                rotation.x = Mathf.LerpAngle(rotation.x, 90, returnSpeed);
                rotation.y = Mathf.LerpAngle(rotation.y, 0, returnSpeed);
                rotation.z = Mathf.LerpAngle(rotation.z, 0, returnSpeed);
                joints[i].localEulerAngles = rotation;
            }
        }
    }
Exemple #10
0
 public Bone TransformedCopy(Matrix trs)
 {
     float dScale = trs.zBasis.Magnitude;
     float hScale = trs.xBasis.Magnitude;
     return new Bone(trs.TransformPoint(_prevJoint),
         trs.TransformPoint(_nextJoint),
         trs.TransformPoint(_center),
         trs.TransformDirection(_direction).Normalized,
         _length * dScale,
         _width * hScale,
         _type,
         trs * _basis);
 }
Exemple #11
0
 /**
  * Creates a copy of this finger, transformed by the specified transform.
  *
  * @param trs A Matrix containing the desired translation, rotation, and scale
  * of the copied finger.
  * @since 3.0
  */
 public Finger TransformedCopy(Matrix trs)
 {
   float dScale = trs.zBasis.Magnitude;
   float hScale = trs.xBasis.Magnitude;
   return new Finger(_frameId,
                     HandId,
                     Id,
                     TimeVisible,
                     trs.TransformPoint(TipPosition),
                     trs.TransformPoint(TipVelocity),
                     trs.TransformDirection(Direction).Normalized,
                     trs.TransformPoint(StabilizedTipPosition),
                     Width * hScale,
                     Length * dScale,
                     IsExtended,
                     Type,
                     _bones[0].TransformedCopy(trs),
                     _bones[1].TransformedCopy(trs),
                     _bones[2].TransformedCopy(trs),
                     _bones[3].TransformedCopy(trs));
 }
 /**
  * Converts a Leap Matrix object representing a translation to a
  * Unity Vector3 object.
  *
  * @param matrix The Leap.Matrix to convert.
  * @param mirror If true, the operation is reflected along the z axis.
  */
 public static Vector3 Translation(this Matrix matrix, bool mirror = false)
 {
     return(matrix.TransformPoint(LEAP_ORIGIN).ToUnityScaled(mirror));
 }
Exemple #13
0
    public Hand TransformedCopy(Matrix trs)
    {
      List<Finger> transformedFingers = new List<Finger>(5);
      for (int f = 0; f < this.Fingers.Count; f++)
        transformedFingers.Add(Fingers[f].TransformedCopy(trs));

      float hScale = trs.xBasis.Magnitude;
      return new Hand(
        FrameId,
        Id,
        Confidence,
        GrabStrength,
        GrabAngle,
        PinchStrength,
        PinchDistance,
        PalmWidth * hScale,
        IsLeft,
        TimeVisible,
        Arm.TransformedCopy(trs),
        transformedFingers,
        trs.TransformPoint(PalmPosition),
        trs.TransformPoint(StabilizedPalmPosition),
        trs.TransformPoint(PalmVelocity),
        trs.TransformDirection(PalmNormal).Normalized,
        trs.TransformDirection(Direction).Normalized,
        trs.TransformPoint(WristPosition)
      );
    }
Exemple #14
0
        public Hand TransformedCopy(Matrix trs)
        {
            FingerList transformedFingers = new FingerList(5);
            for(int f = 0; f < this.Fingers.Count; f++)
                transformedFingers.Add(Fingers[f].TransformedCopy(trs));

            float hScale = trs.xBasis.Magnitude;
            return new Hand(_frameId,
                _id,
                _confidence,
                _grabStrength,
                _grabAngle,
                _pinchStrength,
                _pinchDistance,
                _palmWidth * hScale,
                _isLeft,
                _timeVisible,
                _arm.TransformedCopy(trs),
                transformedFingers,
                trs.TransformPoint(_palmPosition),
                trs.TransformPoint(_stabilizedPalmPosition),
                trs.TransformPoint(_palmVelocity),
                trs.TransformDirection(_palmNormal).Normalized,
                trs.TransformDirection(_direction).Normalized,
                trs.TransformPoint(_wristPosition)
            );
        }
Exemple #15
0
 // Convert Leap Matrix into Unity Translation.
 public static Vector3 Translation(this Matrix matrix)
 {
     return(matrix.TransformPoint(LEAP_ORIGIN).ToUnityScaled());
 }
Exemple #16
0
 public Finger TransformedCopy(Matrix trs)
 {
     float dScale = trs.zBasis.Magnitude;
     float hScale = trs.xBasis.Magnitude;
     return new Finger(_frameId,
                       _handID,
                       _id,
                       _timeVisible,
                       trs.TransformPoint(_tipPosition),
                       trs.TransformPoint(_tipVelocity),
                       trs.TransformDirection(_direction).Normalized,
                       trs.TransformPoint(_stabilizedTipPosition),
                       _width * hScale,
                       _length * dScale,
                       _isExtended,
                       _type,
                       _bones[0].TransformedCopy(trs),
                       _bones[1].TransformedCopy(trs),
                       _bones[2].TransformedCopy(trs),
                       _bones[3].TransformedCopy(trs));
 }
Exemple #17
0
 /**
  * Creates a copy of this bone, transformed by the specified transform.
  *
  * @param trs A Matrix containing the desired translation, rotation, and scale
  * of the copied bone.
  * @since 3.0
  */
 public Bone TransformedCopy(Matrix trs)
 {
   float dScale = trs.zBasis.Magnitude;
   float hScale = trs.xBasis.Magnitude;
   return new Bone(trs.TransformPoint(PrevJoint),
       trs.TransformPoint(NextJoint),
       trs.TransformPoint(Center),
       trs.TransformDirection(Direction).Normalized,
       Length * dScale,
       Width * hScale,
       Type,
       trs * Basis);
 }