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

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

            return(new Hand(
                       FrameId,
                       Id,
                       Confidence,
                       GrabStrength,
                       GrabAngle,
                       PinchStrength,
                       PinchDistance,
                       PalmWidth * trs.scale.x,
                       IsLeft,
                       TimeVisible,
                       Arm.TransformedCopy(trs),
                       transformedFingers,
                       trs.TransformPoint(PalmPosition),
                       trs.TransformPoint(StabilizedPalmPosition),
                       trs.TransformVelocity(PalmVelocity),
                       trs.TransformDirection(PalmNormal),
                       trs.TransformDirection(Direction),
                       trs.TransformPoint(WristPosition)
                       ));
        }
        public static LeapTransform GetTestPoseLeftHandTransform(TestHandPose pose)
        {
            LeapTransform transform = LeapTransform.Identity;

            switch (pose)
            {
            case TestHandPose.HeadMountedA:
                transform.rotation    = angleAxis(180 * Constants.DEG_TO_RAD, Vector.Forward);
                transform.translation = new Vector(80f, 120f, 0f);
                break;

            case TestHandPose.HeadMountedB:
                transform.rotation    = Quaternion.Euler(30F, -10F, -20F).ToLeapQuaternion();
                transform.translation = new Vector(220f, 270f, 130f);
                break;

            case TestHandPose.DesktopModeA:
                transform.rotation = angleAxis(0f * Constants.DEG_TO_RAD, Vector.Forward)
                                     .Multiply(angleAxis(-90f * Constants.DEG_TO_RAD, Vector.Right))
                                     .Multiply(angleAxis(180f * Constants.DEG_TO_RAD, Vector.Up));
                transform.translation = new Vector(120f, 0f, -170f);
                break;

            case TestHandPose.ScreenTop:
                transform.rotation = angleAxis(0 * Constants.DEG_TO_RAD, Vector.Forward)
                                     .Multiply(angleAxis(140 * Constants.DEG_TO_RAD, Vector.Right))
                                     .Multiply(angleAxis(0 * Constants.DEG_TO_RAD, Vector.Up));
                transform.translation = new Vector(-120f, 20f, -380f);
                transform.scale       = new Vector(1, 1, 1);
                break;
            }
            return(transform);
        }
Example #3
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);
 }
        /**
         * Does an in-place rigid transformation of a Finger.
         *
         * @param transform A LeapTransform containing the desired translation, rotation, and scale
         * to be applied to the Finger.
         */
        public static Finger Transform(this Finger finger, LeapTransform transform)
        {
            Bone nextBone = finger.bones[3];

            nextBone.NextJoint = transform.TransformPoint(nextBone.NextJoint);

            finger.TipPosition = nextBone.NextJoint;

            for (int i = 3; i-- != 0;)
            {
                Bone bone = finger.bones[i];

                bone.NextJoint = nextBone.PrevJoint = transform.TransformPoint(bone.NextJoint);

                nextBone.TransformGivenJoints(transform);
                nextBone = bone;
            }

            nextBone.PrevJoint = transform.TransformPoint(nextBone.PrevJoint);
            nextBone.TransformGivenJoints(transform);

            finger.TipVelocity           = transform.TransformVelocity(finger.TipVelocity);
            finger.Direction             = finger.bones[2].Direction;
            finger.StabilizedTipPosition = transform.TransformPoint(finger.StabilizedTipPosition);
            finger.Width  *= Math.Abs(transform.scale.x);
            finger.Length *= Math.Abs(transform.scale.z);

            return(finger);
        }
        public static LeapTransform GetLeapTransform(Vector3 position, Quaternion rotation)
        {
            Vector        scale     = new Vector(MM_TO_M, MM_TO_M, MM_TO_M); // Leap units -> Unity units.
            LeapTransform transform = new LeapTransform(position.ToVector(), rotation.ToLeapQuaternion(), scale);

            transform.MirrorZ(); // Unity is left handed.
            return(transform);
        }
        /**
         * Does an in-place rigid transformation of a Bone.
         *
         * @param transform A LeapTransform containing the desired translation, rotation, and scale
         * -    *  to be applied to the bone.
         */
        public static Bone Transform(this Bone bone, LeapTransform transform)
        {
            bone.PrevJoint = transform.TransformPoint(bone.PrevJoint);
            bone.NextJoint = transform.TransformPoint(bone.NextJoint);

            bone.TransformGivenJoints(transform);

            return(bone);
        }
 /// <summary>
 /// This is a special variant of GetInterpolatedFrameFromTime, for use with special
 /// features that only require the position and orientation of the palm positions, and do
 /// not care about pose data or any other data.
 ///
 /// You must specify the id of the hand that you wish to get a transform for.  If you specify
 /// an id that is not present in the interpolated frame, the output transform will be the
 /// identity transform.
 /// </summary>
 public void GetInterpolatedLeftRightTransform(Int64 time,
                                               Int64 sourceTime,
                                               int leftId,
                                               int rightId,
                                               out LeapTransform leftTransform,
                                               out LeapTransform rightTransform)
 {
     _connection.GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, out leftTransform, out rightTransform);
 }
        /**
         * Does an in-place rigid transformation of a Frame.
         *
         * @param transform A LeapTransform containing the desired translation, rotation, and scale
         * to be applied to the Frame.
         */
        public static Frame Transform(this Frame frame, LeapTransform transform)
        {
            for (int i = frame.Hands.Count; i-- != 0;)
            {
                frame.Hands[i].Transform(transform);
            }

            return(frame);
        }
Example #9
0
 /**
  * Creates a copy of this arm, transformed by the specified transform.
  *
  * @param trs A LeapTransform containing the desired translation, rotation, and scale
  * of the copied arm.
  * @since 3.0
  */
 public new Arm TransformedCopy(LeapTransform trs)
 {
     return(new Arm(trs.TransformPoint(PrevJoint),
                    trs.TransformPoint(NextJoint),
                    trs.TransformPoint(Center),
                    trs.TransformDirection(Direction),
                    Length * trs.scale.z,
                    Width * trs.scale.x,
                    trs.TransformQuaternion(Rotation)));
 }
Example #10
0
        public static Hand MakeTestHand(int frameId, int handId, bool isLeft)
        {
            List <Finger> fingers = new List <Finger>(5);

            fingers.Add(MakeThumb(frameId, handId, isLeft));
            fingers.Add(MakeIndexFinger(frameId, handId, isLeft));
            fingers.Add(MakeMiddleFinger(frameId, handId, isLeft));
            fingers.Add(MakeRingFinger(frameId, handId, isLeft));
            fingers.Add(MakePinky(frameId, handId, isLeft));

            Vector armWrist = new Vector(-7.05809944059f, 4.0f, 50.0f);
            Vector elbow    = armWrist + 250f * Vector.Backward;

            // Adrian: The previous "armBasis" used "elbow" as a translation component.
            Arm  arm      = new Arm(elbow, armWrist, (elbow + armWrist) / 2, Vector.Forward, 250f, 41f, LeapQuaternion.Identity);
            Hand testHand = new Hand(frameId,
                                     handId,
                                     1.0f,
                                     0.0f,
                                     0.0f,
                                     0.0f,
                                     0.0f,
                                     85f,
                                     isLeft,
                                     0.0f,
                                     arm,
                                     fingers,
                                     new Vector(0, 0, 0),
                                     new Vector(0, 0, 0),
                                     new Vector(0, 0, 0),
                                     Vector.Down,
                                     LeapQuaternion.Identity,
                                     Vector.Forward,
                                     new Vector(-4.36385750984f, 6.5f, 31.0111342526f)
                                     );
            LeapTransform restPosition = LeapTransform.Identity;

            //restPosition.rotation = RotationFromTo(Vector.Up, Vector.Left).Multiply(RotationFromTo(Vector.Up, Vector.Left));
            restPosition.rotation = AngleAxis(180 * Constants.DEG_TO_RAD, Vector.Forward);
            if (isLeft)
            {
                restPosition.translation = new Vector(80f, 120f, 0f);
            }
            else
            {
                restPosition.translation = new Vector(-80f, 120f, 0f);
                restPosition.MirrorX();
            }
            return(testHand.TransformedCopy(restPosition));
        }
Example #11
0
        /// <summary>
        /// Returns a test Leap Hand object transformed by the leftHandTransform argument. If the Leap hand is
        /// a right hand, the position and rotation of the Hand will be mirrored along the X axis (so you can provide
        /// LeapTransform to construct both left and right hands.
        /// </summary>
        public static Hand MakeTestHand(bool isLeft, LeapTransform leftHandTransform, int frameId = 0, int handId = 0)
        {
            if (!isLeft)
            {
                leftHandTransform.translation = new Vector(-leftHandTransform.translation.x, leftHandTransform.translation.y, leftHandTransform.translation.z);

                leftHandTransform.rotation = new LeapQuaternion(-leftHandTransform.rotation.x,
                                                                leftHandTransform.rotation.y,
                                                                leftHandTransform.rotation.z,
                                                                -leftHandTransform.rotation.w);

                leftHandTransform.MirrorX();
            }
            return(MakeTestHand(frameId, handId, isLeft).Transform(leftHandTransform));
        }
Example #12
0
        /**
         * Creates a copy of this Frame, transforming all hands, fingers, and bones by the specified transform.
         *
         * @param trs A LeapTransform containing the desired translation, rotation, and scale
         * of the copied Frame.
         * @returns a new Frame object with the transform applied.
         * @since 3.0
         */
        public Frame TransformedCopy(LeapTransform trs)
        {
            Frame transformedFrame = new Frame(
                Id,
                Timestamp,
                CurrentFramesPerSecond,
                new InteractionBox(InteractionBox.Center, InteractionBox.Size),
                new List <Hand>(this.Hands.Count)
                );

            for (int h = 0; h < this.Hands.Count; h++)
            {
                transformedFrame.Hands.Add(this.Hands[h].TransformedCopy(trs));
            }
            return(transformedFrame);
        }
Example #13
0
        public static Matrix4x4 ToMatrix4x4(this Leap.LeapTransform m)
        {
            Matrix4x4 tmp = new Matrix4x4();

            tmp.m11 = m.xBasis.x;
            tmp.m12 = m.yBasis.x;
            tmp.m13 = m.zBasis.x;
            tmp.m21 = m.xBasis.y;
            tmp.m22 = m.yBasis.y;
            tmp.m23 = m.zBasis.y;
            tmp.m31 = m.xBasis.z;
            tmp.m32 = m.yBasis.z;
            tmp.m33 = m.zBasis.z;
            tmp.m44 = 1;
            return(tmp);
        }
        /**
         * Does an in-place rigid transformation of a Bone, assuming the joints have already been transformed.
         *
         * @param transform A LeapTransform containing the desired translation, rotation, and scale
         * -    *  to be applied to the bone.
         */
        internal static void TransformGivenJoints(this Bone bone, LeapTransform transform)
        {
            bone.Length *= Math.Abs(transform.scale.z);
            bone.Center  = (bone.PrevJoint + bone.NextJoint) / 2.0f;

            if (bone.Length < float.Epsilon)
            {
                bone.Direction = Vector.Zero;
            }
            else
            {
                bone.Direction = (bone.NextJoint - bone.PrevJoint) / bone.Length;
            }

            bone.Width   *= Math.Abs(transform.scale.x);
            bone.Rotation = transform.TransformQuaternion(bone.Rotation);
        }
Example #15
0
        public static LeapTransform GetTestPoseLeftHandTransform(TestHandPose pose)
        {
            LeapTransform transform = LeapTransform.Identity;

            switch (pose)
            {
            case TestHandPose.PoseA:
                transform.rotation    = AngleAxis(180 * Constants.DEG_TO_RAD, Vector.Forward);
                transform.translation = new Vector(80f, 120f, 0f);
                break;

            case TestHandPose.PoseB:
                transform.rotation    = Quaternion.Euler(30F, -10F, -20F).ToLeapQuaternion();
                transform.translation = new Vector(220f, 270f, 130f);
                break;
            }
            return(transform);
        }
Example #16
0
 /**
  * Creates a copy of this finger, transformed by the specified transform.
  *
  * @param trs A LeapTransform containing the desired translation, rotation, and scale
  * of the copied finger.
  * @since 3.0
  */
 public Finger TransformedCopy(LeapTransform trs)
 {
     return(new Finger(_frameId,
                       HandId,
                       Id % 10, //remove hand portion of finger Id
                       TimeVisible,
                       trs.TransformPoint(TipPosition),
                       trs.TransformVelocity(TipVelocity),
                       trs.TransformDirection(Direction),
                       trs.TransformPoint(StabilizedTipPosition),
                       Width * trs.scale.x,
                       Length * trs.scale.z,
                       IsExtended,
                       Type,
                       _bones[0].TransformedCopy(trs),
                       _bones[1].TransformedCopy(trs),
                       _bones[2].TransformedCopy(trs),
                       _bones[3].TransformedCopy(trs)));
 }
        /**
         * Does an in-place rigid transformation of a Hand.
         *
         * @param transform A LeapTransform containing the desired translation, rotation, and scale
         * to be applied to the Hand.
         */
        public static Hand Transform(this Hand hand, LeapTransform transform)
        {
            hand.PalmPosition           = transform.TransformPoint(hand.PalmPosition);
            hand.StabilizedPalmPosition = transform.TransformPoint(hand.StabilizedPalmPosition);
            hand.PalmVelocity           = transform.TransformVelocity(hand.PalmVelocity);
            hand.PalmNormal             = transform.TransformDirection(hand.PalmNormal);
            hand.Direction     = transform.TransformDirection(hand.Direction);
            hand.WristPosition = transform.TransformPoint(hand.WristPosition);
            hand.PalmWidth    *= Math.Abs(transform.scale.x);
            hand.Rotation      = transform.TransformQuaternion(hand.Rotation);

            hand.Arm.Transform(transform);

            for (int i = 5; i-- != 0;)
            {
                hand.Fingers[i].Transform(transform);
            }

            return(hand);
        }
        /// <summary>
        /// Returns a test Leap Hand object transformed by the leftHandTransform argument.
        /// If the Leap hand is a right hand, the position and rotation of the Hand will be
        /// mirrored along the X axis (so you can provide LeapTransform to construct both
        /// left and right hands.
        /// </summary>
        public static Hand MakeTestHand(bool isLeft, LeapTransform leftHandTransform,
                                        int frameId       = 0, int handId = 0,
                                        UnitType unitType = UnitType.LeapUnits)
        {
            // Apply the appropriate mirroring if this is a right hand.
            if (!isLeft)
            {
                leftHandTransform.translation = new Vector(-leftHandTransform.translation.x,
                                                           leftHandTransform.translation.y, leftHandTransform.translation.z);

                leftHandTransform.rotation = new LeapQuaternion(-leftHandTransform.rotation.x,
                                                                leftHandTransform.rotation.y,
                                                                leftHandTransform.rotation.z,
                                                                -leftHandTransform.rotation.w);

                leftHandTransform.MirrorX();
            }

            // Leap space is oriented differently than Unity space, so correct for this here.
            var hand = makeLeapSpaceTestHand(frameId, handId, isLeft)
                       .Transform(leftHandTransform);
            var correctingQuaternion     = Quaternion.Euler(90f, 0f, 180f);
            var correctingLeapQuaternion = new LeapQuaternion(correctingQuaternion.x,
                                                              correctingQuaternion.y,
                                                              correctingQuaternion.z,
                                                              correctingQuaternion.w);

            var transformedHand = hand.Transform(new LeapTransform(Vector.Zero,
                                                                   correctingLeapQuaternion));

            if (unitType == UnitType.UnityUnits)
            {
                transformedHand.TransformToUnityUnits();
            }

            return(transformedHand);
        }
 /**
  * Returns a new frame that is a copy of a frame, with an additional rigid
  * transformation applied to it.
  *
  * @param transform The transformation to be applied to the copied frame.
  */
 public static Frame TransformedCopy(this Frame frame, LeapTransform transform)
 {
     return(new Frame().CopyFrom(frame).Transform(transform));
 }
Example #20
0
 /**
  * Returns the Frame at the specified time, interpolating the data between existing frames, if necessary,
  * and transforms the data using the specified transform matrix.
  *
  *
  */
 public Frame GetTransformedInterpolatedFrame(LeapTransform trs, Int64 time)
 {
     //return _connection.GetInterpolatedFrame(time).TransformedCopy(trs);
     return(null);
 }
Example #21
0
 /**
  * Creates a copy of this arm, transformed by the specified transform.
  *
  * @param trs A LeapTransform containing the desired translation, rotation, and scale
  * of the copied arm.
  * @since 3.0
  */
 public new Arm TransformedCopy(LeapTransform trs)
 {
     return new Arm(trs.TransformPoint(PrevJoint),
       trs.TransformPoint(NextJoint),
       trs.TransformPoint(Center),
       trs.TransformDirection(Direction),
       Length * trs.scale.z,
       Width * trs.scale.x,
       trs.TransformQuaternion(Rotation));
 }
Example #22
0
 /**
  * Creates a copy of this finger, transformed by the specified transform.
  *
  * @param trs A LeapTransform containing the desired translation, rotation, and scale
  * of the copied finger.
  * @since 3.0
  */
 public Finger TransformedCopy(LeapTransform trs)
 {
     return new Finger(_frameId,
                 HandId,
                 Id % 10, //remove hand portion of finger Id
                 TimeVisible,
                 trs.TransformPoint(TipPosition),
                 trs.TransformVelocity(TipVelocity),
                 trs.TransformDirection(Direction),
                 trs.TransformPoint(StabilizedTipPosition),
                 Width * trs.scale.x,
                 Length * trs.scale.z,
                 IsExtended,
                 Type,
                 _bones[0].TransformedCopy(trs),
                 _bones[1].TransformedCopy(trs),
                 _bones[2].TransformedCopy(trs),
                 _bones[3].TransformedCopy(trs));
 }
Example #23
0
    public void DrawBasis(RuntimeGizmoDrawer gizmoDrawer, Vector3 origin, LeapTransform basis, float scale) {
      gizmoDrawer.color = Color.red;
      gizmoDrawer.DrawLine(origin, origin + basis.xBasis.ToVector3() * scale);
      gizmoDrawer.color = Color.green;
      gizmoDrawer.DrawLine(origin, origin + basis.yBasis.ToVector3() * scale);
      gizmoDrawer.color = Color.blue;
      gizmoDrawer.DrawLine(origin, origin + basis.zBasis.ToVector3() * scale);

      //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);
    }
        protected Frame getTransformedFrame(Frame source)
        {
            LeapTransform leapTransform;
              if (_temporalWarping != null) {
            Vector3 warpedPosition;
            Quaternion warpedRotation;
            _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp);

            warpedRotation = warpedRotation * transform.localRotation;

            leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f);
            leapTransform.MirrorZ();
              } else {
            leapTransform = transform.GetLeapMatrix();
              }

              return source.TransformedCopy(leapTransform);
        }
Example #25
0
 /**
 * Returns the Frame at the specified time, interpolating the data between existing frames, if necessary,
 * and transforms the data using the specified transform matrix.
 *
 *
 */
 public Frame GetTransformedInterpolatedFrame(LeapTransform trs, Int64 time)
 {
     return _connection.GetInterpolatedFrame(time).TransformedCopy(trs);
 }
Example #26
0
 /**
  * Returns the frame object with all hands transformed by the specified
  * transform matrix.
  * @param trs a LeapTransform containing translation, rotation, and scale.
  * @param history The age of the frame to return, counting backwards from
  * the most recent frame (0) into the past and up to the maximum age (59).
  */
 public Frame GetTransformedFrame(LeapTransform trs, int history = 0)
 {
     return Frame(history).TransformedCopy(trs);
 }
 /**
  * Returns a new finger that is a copy of a finger, with an additional rigid
  * transformation applied to it.
  *
  * @param transform The transformation to be applied to the copied finger.
  */
 public static Finger TransformedCopy(this Finger finger, LeapTransform transform)
 {
     return(new Finger().CopyFrom(finger).Transform(transform));
 }
 /**
  * Returns a new bone that is a copy of a bone, with an additional rigid
  * transformation applied to it.
  *
  * @param transform The transformation to be applied to the copied bone.
  */
 public static Bone TransformedCopy(this Bone bone, LeapTransform transform)
 {
     return(new Bone().CopyFrom(bone).Transform(transform));
 }
Example #29
0
 /**
  * Returns the frame object with all hands transformed by the specified
  * transform matrix.
  * @param trs a LeapTransform containing translation, rotation, and scale.
  * @param history The age of the frame to return, counting backwards from
  * the most recent frame (0) into the past and up to the maximum age (59).
  */
 public Frame GetTransformedFrame(LeapTransform trs, int history = 0)
 {
     return(new Frame().CopyFrom(Frame(history)).Transform(trs));
 }
 /**
  * Returns a new hand that is a copy of a hand, with an additional rigid
  * transformation applied to it.
  *
  * @param transform The transformation to be applied to the copied hand.
  */
 public static Hand TransformedCopy(this Hand hand, LeapTransform transform)
 {
     return(new Hand().CopyFrom(hand).Transform(transform));
 }
Example #31
0
 /**
  * Returns the frame object with all hands transformed by the specified
  * transform matrix.
  * @param trs a LeapTransform containing translation, rotation, and scale.
  * @param history The age of the frame to return, counting backwards from
  * the most recent frame (0) into the past and up to the maximum age (59).
  */
 public Frame GetTransformedFrame(LeapTransform trs, int history = 0)
 {
     return(Frame(history).TransformedCopy(trs));
 }
Example #32
0
 public void GetInterpolatedLeftRightTransform(long time, long sourceTime, int leftId, int rightId, out LeapTransform leftTransform, out LeapTransform rightTransform)
 {
     this._connection.GetInterpolatedLeftRightTransform(time, sourceTime, (long)leftId, (long)rightId, out leftTransform, out rightTransform);
 }
        protected void updateIfTransformMoved(Frame source, ref Frame toUpdate)
        {
            if (transform.hasChanged) {
            _transformedFixedFrame = null;
            _transformedUpdateFrame = null;
            transform.hasChanged = false;
              }

              if (toUpdate == null) {
            LeapTransform leapTransform;
            if (_temporalWarping != null) {
              Vector3 warpedPosition;
              Quaternion warpedRotation;
              _temporalWarping.TryGetWarpedTransform(LeapVRTemporalWarping.WarpedAnchor.CENTER, out warpedPosition, out warpedRotation, source.Timestamp);

              warpedRotation = warpedRotation * transform.localRotation;

              leapTransform = new LeapTransform(warpedPosition.ToVector(), warpedRotation.ToLeapQuaternion(), transform.lossyScale.ToVector() * 1e-3f);
              leapTransform.MirrorZ();
            } else {
              leapTransform = transform.GetLeapMatrix();
            }

            toUpdate = source.TransformedCopy(leapTransform);
              }
        }