Ejemplo n.º 1
0
        // Convert Leap Matrix into Unity Quaternion.
        public static Quaternion Rotation(this Matrix matrix)
        {
            Vector3 up      = matrix.TransformDirection(LEAP_UP).ToUnity();
            Vector3 forward = matrix.TransformDirection(LEAP_FORWARD).ToUnity();

            return(Quaternion.LookRotation(forward, up));
        }
Ejemplo n.º 2
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)
                       ));
        }
Ejemplo n.º 3
0
		////////////////////////////////////////////////////////////////////////////////////////////////
		/*--------------------------------------------------------------------------------------------*/
		public static Quaternion CalcQuaternion(Matrix pBasis) {
			//Adapted from "LeapUnityExtensions.cs" in the Leap Motion SDK
			//Smaller GC allocations than the previous "ToMatrix4x4()" approach
			Vector3 up = pBasis.TransformDirection(LeapUp).ToUnity(); //GC_ALLOC
			Vector3 forward = pBasis.TransformDirection(LeapForward).ToUnity(); //GC_ALLOC
			return Quaternion.LookRotation(forward, up);
		}
Ejemplo n.º 4
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)
                            ));
        }
Ejemplo n.º 5
0
        /**
         * Performs a matrix inverse if the matrix consists entirely of rigid
         * transformations (translations and rotations).  If the matrix is not rigid,
         * this operation will not represent an inverse.
         *
         * \include Matrix_rigidInverse.txt
         *
         * Note that all matrices that are directly returned by the API are rigid.
         *
         * @returns The rigid inverse of the matrix.
         * @since 1.0
         */
        public Matrix RigidInverse()
        {
            Matrix rotInverse = new Matrix(new Vector(xBasis[0], yBasis[0], zBasis[0]),
                                           new Vector(xBasis[1], yBasis[1], zBasis[1]),
                                           new Vector(xBasis[2], yBasis[2], zBasis[2]));

            rotInverse.origin = rotInverse.TransformDirection(-origin);
            return(rotInverse);
        }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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)));
        }
Ejemplo n.º 11
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)));
        }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
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));
 }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
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)
      );
    }
Ejemplo n.º 16
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)
            );
        }
Ejemplo n.º 17
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));
 }
Ejemplo n.º 18
0
 /**
    * Performs a matrix inverse if the matrix consists entirely of rigid
    * transformations (translations and rotations).  If the matrix is not rigid,
    * this operation will not represent an inverse.
    *
    * \include Matrix_rigidInverse.txt
    *
    * Note that all matrices that are directly returned by the API are rigid.
    *
    * @returns The rigid inverse of the matrix.
    * @since 1.0
    */
 public Matrix RigidInverse()
 {
     Matrix rotInverse = new Matrix(new Vector(xBasis[0], yBasis[0], zBasis[0]),
                                    new Vector(xBasis[1], yBasis[1], zBasis[1]),
                                    new Vector(xBasis[2], yBasis[2], zBasis[2]));
     rotInverse.origin = rotInverse.TransformDirection( -origin );
     return rotInverse;
 }