Esempio n. 1
0
        public static Vector ToEulerianAngle(LeapQuaternion q1)
        {
            float sqw  = q1.w * q1.w;
            float sqx  = q1.x * q1.x;
            float sqy  = q1.y * q1.y;
            float sqz  = q1.z * q1.z;
            float unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor
            float test = q1.x * q1.w - q1.y * q1.z;

            Vector v;

            if (test > 0.4995f * unit)
            { // singularity at north pole
                //v.y = 2f * Mathf.Atan2(q1.y, q1.x);
                v.y = 2f * (float)Math.Atan2(q1.y, q1.x);
                v.x = (float)Math.PI / 2;
                v.z = 0;
                return(NormalizeAngles(v * Rad2Deg));
            }
            if (test < -0.4995f * unit)
            { // singularity at south pole
                v.y = -2f * (float)Math.Atan2(q1.y, q1.x);
                v.x = -(float)Math.PI / 2f;
                v.z = 0;
                return(NormalizeAngles(v * Rad2Deg));
            }

            LeapQuaternion q = new LeapQuaternion(q1.w, q1.z, q1.x, q1.y);


            v.y = (float)Math.Atan2(2f * q.x * q.w + 2f * q.y * q.z, 1 - 2f * (q.z * q.z + q.w * q.w)); // Yaw
            v.x = (float)Math.Asin(2f * (q.x * q.z - q.w * q.y));                                       // Pitch
            v.z = (float)Math.Atan2(2f * q.x * q.y + 2f * q.z * q.w, 1 - 2f * (q.y * q.y + q.z * q.z)); // Roll
            return(NormalizeAngles(v * Rad2Deg));
        }
Esempio n. 2
0
        public double PronoSupra()
        {
            Frame frame = LeapService.GetFrame();

            if (frame.Hands.Count != 0)
            {
                LeapQuaternion q = frame.Hands[0].Rotation;
                if (frame.Hands[0].IsRight)
                {
                    q = new LeapQuaternion(q.x * 1, q.y * 1, q.z * -1, q.w * 1);
                }
                Vector rotation = LeapUtils.ToEulerianAngle(q);
                //Debug.Log(rotation);

                if (rotation.z > 270)
                {
                    rotation.z = 360 - rotation.z;
                }

                if (frame.Hands[0].IsRight)
                {
                    return(Math.Abs(rotation.z) - 90);
                }
                else
                {
                    return(90 - Math.Abs(rotation.z));
                }
                //return Math.Abs(Math.Abs(rotation.z));
            }
            else
            {
                return(0);
            }
        }
Esempio n. 3
0
    //-0.5 Links//-1.0 Rechts
    // Update is called once per frame
    void Update()
    {
        Frame frame = provider.CurrentFrame;

        foreach (Hand hand in frame.Hands)
        {
            float yaw = hand.Direction.Yaw;
            //Debug.Log(yaw);
            // transform.position = hand.PalmPosition.ToVector3() + hand.PalmNormal.ToVector3() * (transform.localScale.y * .5f + .02f);
            // transform.rotation = hand.Basis.rotation.ToQuaternion();
            if (yaw > -1.6f && yaw < 3.5f)
            {
                transform.position += transform.forward * Time.deltaTime * 5;
            }
            else if (yaw < -1.6f)
            {
                transform.position += (transform.forward * -1) * Time.deltaTime * 5;
            }

            //Rotation
            LeapQuaternion rotate = hand.Rotation;

            rotateAngle += rotate.y * rotateSpeed;
            Vector3 targetDirection = new Vector3(Mathf.Sin(rotateAngle), 0, Mathf.Cos(rotateAngle));
            targetRotation     = Quaternion.LookRotation(targetDirection);
            transform.rotation = targetRotation;

            Debug.Log(rotate);
        }
    }
        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;
                }
            }
        }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (Time.timeScale == 1)
        {
            Frame frame = provider.CurrentFrame;
            foreach (Hand hand in frame.Hands)
            {
                LeapQuaternion rotate      = hand.Rotation;
                Quaternion     rotateUnity = rotate.ToQuaternion();
                float          yaw         = hand.Direction.Yaw;
                Debug.Log("Neigung: " + rotateUnity.eulerAngles);

                // transform.position = hand.PalmPosition.ToVector3() + hand.PalmNormal.ToVector3() * (transform.localScale.y * .5f + .02f);
                // transform.rotation = hand.Basis.rotation.ToQuaternion();
                if (rotateUnity.eulerAngles.x < 40 || rotateUnity.eulerAngles.x > 320)
                {
                }
                else if (rotateUnity.eulerAngles.x >= 40 && rotateUnity.eulerAngles.x < 180)
                {
                    transform.position += transform.forward * Time.deltaTime * 5;
                }
                else if (rotateUnity.eulerAngles.x < 320 && rotateUnity.eulerAngles.x >= 180)
                {
                    transform.position += (transform.forward * -1) * Time.deltaTime * 5;
                }


                //Rotation



                //rotateUnity.eulerAngles.y;

                Debug.Log("Rotate: " + rotateUnity.eulerAngles);



                if (!(rotateUnity.eulerAngles.z < 50 || rotateUnity.eulerAngles.z > 310))
                {
                    rotateAngle += -1 * rotate.z * rotateSpeed;
                    Vector3 targetDirection = new Vector3(Mathf.Sin(rotateAngle), 0, Mathf.Cos(rotateAngle));
                    targetRotation = Quaternion.LookRotation(targetDirection);

                    transform.rotation = targetRotation;
                }



                //Jump
                Vector palm = hand.PalmVelocity;

                if (palm.y >= 0.5)
                {
                    rb.AddForce(transform.up * thrust);
                }
                Debug.Log("PalmVelocity: " + palm);
            }
        }
    }
Esempio n. 6
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
 }
Esempio n. 7
0
 public Bone makeBone(ref LEAP_BONE bone, Bone.BoneType type)
 {
     Vector prevJoint = new Vector(bone.prev_joint.x, bone.prev_joint.y, bone.prev_joint.z);
       Vector nextJoint = new Vector(bone.next_joint.x, bone.next_joint.y, bone.next_joint.z);
       Vector center = (nextJoint + prevJoint) * .5f;
       float length = (nextJoint - prevJoint).Magnitude;
       Vector direction = (nextJoint - prevJoint) / length;
       LeapQuaternion rotation = new LeapQuaternion(bone.rotation);
       return new Bone(prevJoint, nextJoint, center, direction, length, bone.width, type, rotation);
 }
Esempio n. 8
0
        // LeapQuaternionを4つのfloat型の変数に分解して変換するメソッドの実装
        static void LeapQuaternionConvertByteAddRange(LeapQuaternion value, List <byte> list)
        {
            list.AddRange(BitConverter.GetBytes(value.x));

            list.AddRange(BitConverter.GetBytes(value.y));

            list.AddRange(BitConverter.GetBytes(value.z));

            list.AddRange(BitConverter.GetBytes(value.w));
        }
Esempio n. 9
0
    private LeapQuaternion createQuaternion(Vector arm_1, Vector arm_2, Vector arm_3)
    {
        Vector3        arm1_3 = new Vector3(arm_1.x, arm_1.y, arm_1.z);
        Vector3        arm2_3 = new Vector3(arm_2.x, arm_2.y, arm_2.z);
        Vector3        arm3_3 = new Vector3(arm_3.x, arm_3.y, arm_3.z);
        Quaternion     basisQ = Quaternion.LookRotation(arm3_3, arm2_3);
        LeapQuaternion basis  = new LeapQuaternion(basisQ.x, basisQ.y, basisQ.z, basisQ.w);

        return(basis);
    }
        public Bone makeBone(ref LEAP_BONE bone, Bone.BoneType type)
        {
            Vector         prevJoint = new Vector(bone.prev_joint.x, bone.prev_joint.y, bone.prev_joint.z);
            Vector         nextJoint = new Vector(bone.next_joint.x, bone.next_joint.y, bone.next_joint.z);
            Vector         center    = (nextJoint + prevJoint) * .5f;
            float          length    = (nextJoint - prevJoint).Magnitude;
            Vector         direction = (nextJoint - prevJoint) / length;
            LeapQuaternion rotation  = new LeapQuaternion(bone.rotation);

            return(new Bone(prevJoint, nextJoint, center, direction, length, bone.width, type, rotation));
        }
Esempio n. 11
0
 static LeapQuaternion AngleAxis(float angle, Vector axis){
   if(!axis.MagnitudeSquared.NearlyEquals(1.0f)){
     throw new ArgumentException("Axis must be a unit vector.");
   }
   float sineHalfAngle = Mathf.Sin(angle/2.0f);
   LeapQuaternion q = new LeapQuaternion(sineHalfAngle * axis.x,
                                         sineHalfAngle * axis.y,
                                         sineHalfAngle * axis.z,
                                         Mathf.Cos(angle/2.0f));
   return q.Normalized;
 }
Esempio n. 12
0
 public Arm makeArm(ref LEAP_BONE bone)
 {
     Vector prevJoint = new Vector(bone.prev_joint.x, bone.prev_joint.y, bone.prev_joint.z);
       Vector nextJoint = new Vector(bone.next_joint.x, bone.next_joint.y, bone.next_joint.z);
       Vector center = (nextJoint + prevJoint) * .5f;
       float length = (nextJoint - prevJoint).Magnitude;
       Vector direction = Vector.Zero;
       if (length > 0)
     direction = (nextJoint - prevJoint) / length;
       LeapQuaternion rotation = new LeapQuaternion(bone.rotation);
       return new Arm(prevJoint, nextJoint, center, direction, length, bone.width, rotation);
 }
        /**
         * Converts a LeapQuaternion object to a UnityEngine.Quaternion object.
         *
         * @returns The UnityEngine Quaternion object with the same values as the LeapQuaternion.
         */
        public static Quaternion ToQuaternion(this LeapQuaternion q, bool flip = false)
        {
            var ret = new Quaternion(q.x, q.y, q.z, q.w);

            return(ret);

            /*
             * var e = ret.eulerAngles;
             * if (!flip)
             *  return Quaternion.Euler(e.z, e.y, e.x);
             * else {
             *  return Quaternion.Euler(-e.z, -e.y, -e.x);
             * }*/
        }
    private Bone createBone(List <object> basis, Vector start, Vector end, float width, Bone.BoneType type)
    {
        Vector basis_1   = creatVector((List <object>)basis[0]);
        Vector basis_2   = creatVector((List <object>)basis[1]);
        Vector basis_3   = creatVector((List <object>)basis[2]);
        Vector center    = new Vector((end.x + start.x) / 2, (start.y + end.y) / 2, (start.z + end.z) / 2);
        Vector direction = new Vector(end.x - start.x, end.y - start.y, end.z - start.z);
        double length    = Math.Sqrt((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y) + (end.z - start.z) * (end.z - start.z));

        LeapQuaternion orientation = createQuaternion(basis_1, basis_2, basis_3);
        Bone           bone        = new Bone(start, end, center, direction, (float)length, width, type, orientation);

        return(bone);
    }
        public Arm makeArm(ref LEAP_BONE bone)
        {
            Vector prevJoint = new Vector(bone.prev_joint.x, bone.prev_joint.y, bone.prev_joint.z);
            Vector nextJoint = new Vector(bone.next_joint.x, bone.next_joint.y, bone.next_joint.z);
            Vector center    = (nextJoint + prevJoint) * .5f;
            float  length    = (nextJoint - prevJoint).Magnitude;
            Vector direction = Vector.Zero;

            if (length > 0)
            {
                direction = (nextJoint - prevJoint) / length;
            }
            LeapQuaternion rotation = new LeapQuaternion(bone.rotation);

            return(new Arm(prevJoint, nextJoint, center, direction, length, bone.width, rotation));
        }
Esempio n. 16
0
 public void StopRotation()
 {
     for (int i = 0; i < pivots.Length; i++)
     {
         GameObject obj = pivots[i];
         if (obj != null)
         {
             //rightHandGO.transform.GetChild(0).GetComponent<MeshRenderer>().materials[1].SetFloat("_Outline", 0.0f);
             obj.transform.parent.GetComponent <Molecule>().StopRotate();
             break;
         }
     }
     rotating     = false;
     lastRotation = new Leap.LeapQuaternion();
     lastPalmX    = 0;
 }
Esempio n. 17
0
 /// <summary>
 /// Fills the Arm object with the provided arm data.
 /// </summary>
 public static void Fill(this Arm toFill,
                         Vector elbow,
                         Vector wrist,
                         Vector center,
                         Vector direction,
                         float length,
                         float width,
                         LeapQuaternion rotation)
 {
     toFill.PrevJoint = elbow;
     toFill.NextJoint = wrist;
     toFill.Center    = center;
     toFill.Direction = direction;
     toFill.Length    = length;
     toFill.Width     = width;
     toFill.Rotation  = rotation;
 }
Esempio n. 18
0
 /**
  * Constructs a new Arm object.
  *
  * @param elbow The position of the elbow.
  * @param wrist The position of the wrist.
  * @param center The position of the midpoint between the elbow and wrist.
  * @param direction The unit direction vector from elbow to wrist.
  * @param length The distance between elbow and wrist in millimeters.
  * @param width The estimated average width of the arm.
  * @param basis The basis matrix representing the orientation of the arm.
  * @since 3.0
  */
 public Arm(Vector elbow,
     Vector wrist,
     Vector center,
     Vector direction,
     float length,
     float width,
     LeapQuaternion rotation
     )
     : base(elbow,
                 wrist,
                 center,
                 direction,
                 length,
                 width,
                 BoneType.TYPE_METACARPAL, //ignored for arms
                 rotation)
 {
 }
Esempio n. 19
0
    public LeapQuaternion CreateLeapQuater(List <List <float> > basis, string handType)
    {
        // Build a Rotation matrix……
        Matrix4x4 rotation = new Matrix4x4();

        if (handType == "right")
        {
            // x-axsis
            rotation[0, 0] = basis[0][0];
            rotation[1, 0] = basis[0][1];
            rotation[2, 0] = basis[0][2];
            // y-axsis
            rotation[0, 1] = basis[1][0];
            rotation[1, 1] = basis[1][1];
            rotation[2, 1] = basis[1][2];
            // z-axsis
            rotation[0, 2] = basis[2][0];
            rotation[1, 2] = basis[2][1];
            rotation[2, 2] = basis[2][2];

            Quaternion     q     = rotation.GetRotation();
            LeapQuaternion Leapq = new LeapQuaternion(q.x, q.y, q.z, q.w);
            return(Leapq);
        }
        else
        {
            // x-axsis
            rotation[0, 0] = basis[0][0];
            rotation[1, 0] = basis[0][1];
            rotation[2, 0] = basis[0][2];
            // y-axsis
            rotation[0, 1] = basis[1][0];
            rotation[1, 1] = basis[1][1];
            rotation[2, 1] = basis[1][2];
            // z-axsis
            rotation[0, 2] = -basis[2][0];
            rotation[1, 2] = -basis[2][1];
            rotation[2, 2] = -basis[2][2];

            Quaternion     q     = rotation.GetRotation();
            LeapQuaternion Leapq = new LeapQuaternion(q.x, q.y, q.z, q.w);
            return(Leapq);
        }
    }
    private Hand CreateHand(long frameId, HandData hand, List <FingerData> fingers)
    {
        bool   isLeft = false;
        Vector arm_1  = creatVector((List <object>)hand.armBasis[0]);
        Vector arm_2  = creatVector((List <object>)hand.armBasis[1]);
        Vector arm_3  = creatVector((List <object>)hand.armBasis[2]);

        Vector direction = creatVector(hand.direction);
        Vector elbow     = creatVector(hand.elbow);

        Vector palmNormal   = creatVector(hand.palmNormal);
        Vector palmPosition = creatVector(hand.palmPosition);
        Vector palmVelocity = creatVector(hand.palmVelocity);

        Vector sphereCenter           = creatVector(hand.sphereCenter);
        Vector stabilizedPalmPosition = creatVector(hand.stabilizedPalmPosition);

        if (hand.type.Equals("left"))
        {
            isLeft = true;
        }
        else
        {
            isLeft = false;
        }

        Vector wrist    = creatVector(hand.wrist);
        Vector midpoint = new Vector((elbow.x + wrist.x) / 2, (elbow.y + wrist.y) / 2, (elbow.z + wrist.z) / 2);

        LeapQuaternion basis = createQuaternion(arm_1, arm_2, arm_3);

        // Note that the armlength and some other data requried form the arm constructor is replaced by a filler 245
        // I couldn't quite how to figure out how to get those data from the leap motion data. I notiecd that the length
        // is usually around 245(which is my hand), so I replaced it with the data.
        Arm arm = new Arm(elbow, wrist, midpoint, direction, 245, (float)hand.armWidth, basis);

        List <Finger> fingerlist = createFingerlist(hand.id, frameId, fingers);

        Hand result = new Hand(frameId, (int)hand.id, (float)hand.confidence, (float)hand.grapStrength, (float)hand.grapAngle, (float)hand.pinchStrength, (float)hand.pinchDistance,
                               (float)hand.s, isLeft, (float)hand.timeVisible, arm, fingerlist, palmPosition,
                               stabilizedPalmPosition, palmVelocity, palmNormal, LeapQuaternion.Identity, direction, wrist);

        return(result);
    }
Esempio n. 21
0
 /// <summary>
 /// Fills the Hand object with the provided hand data. You can pass null for the
 /// fingers input; this will leave the hand's finger data unmodified.
 /// </summary>
 public static void Fill(this Hand toFill,
                         long frameID,
                         int id,
                         float confidence,
                         float grabStrength,
                         float grabAngle,
                         float pinchStrength,
                         float pinchDistance,
                         float palmWidth,
                         bool isLeft,
                         float timeVisible,
                         /* Arm arm,*/
                         List <Finger> fingers,
                         Vector palmPosition,
                         Vector stabilizedPalmPosition,
                         Vector palmVelocity,
                         Vector palmNormal,
                         LeapQuaternion rotation,
                         Vector direction,
                         Vector wristPosition)
 {
     toFill.FrameId       = frameID;
     toFill.Id            = id;
     toFill.Confidence    = confidence;
     toFill.GrabStrength  = grabStrength;
     toFill.GrabAngle     = grabAngle;
     toFill.PinchStrength = pinchStrength;
     toFill.PinchDistance = pinchDistance;
     toFill.PalmWidth     = palmWidth;
     toFill.IsLeft        = isLeft;
     toFill.TimeVisible   = timeVisible;
     if (fingers != null)
     {
         toFill.Fingers = fingers;
     }
     toFill.PalmPosition           = palmPosition;
     toFill.StabilizedPalmPosition = stabilizedPalmPosition;
     toFill.PalmVelocity           = palmVelocity;
     toFill.PalmNormal             = palmNormal;
     toFill.Rotation      = rotation;
     toFill.Direction     = direction;
     toFill.WristPosition = wristPosition;
 }
Esempio n. 22
0
 /// <summary>
 /// Fills the Bone object with the provided bone data.
 /// </summary>
 public static void Fill(this Bone toFill,
                         Vector prevJoint,
                         Vector nextJoint,
                         Vector center,
                         Vector direction,
                         float length,
                         float width,
                         Bone.BoneType type,
                         LeapQuaternion rotation)
 {
     toFill.PrevJoint = prevJoint;
     toFill.NextJoint = nextJoint;
     toFill.Center    = center;
     toFill.Direction = direction;
     toFill.Length    = length;
     toFill.Width     = width;
     toFill.Type      = type;
     toFill.Rotation  = rotation;
 }
Esempio n. 23
0
 /**
  * Constructs a new Bone object.
  *
  * @param prevJoint The proximal end of the bone (closest to the body)
  * @param nextJoint The distal end of the bone (furthest from the body)
  * @param center The midpoint of the bone
  * @param direction The unit direction vector pointing from prevJoint to nextJoint.
  * @param length The estimated length of the bone.
  * @param width The estimated average width of the bone.
  * @param type The type of finger bone.
  * @param basis The matrix representing the orientation of the bone.
  * @since 3.0
  */
 public Bone(Vector prevJoint,
     Vector nextJoint,
     Vector center,
     Vector direction,
     float length,
     float width,
     Bone.BoneType type,
     LeapQuaternion rotation
     )
 {
     PrevJoint = prevJoint;
       NextJoint = nextJoint;
       Center = center;
       Direction = direction;
       Rotation = rotation;
       Length = length;
       Width = width;
       Type = type;
 }
    void GrabRacket()
    {
        racketposition     = ToVector3(hand.PalmPosition);
        transform.position = camera.transform.position + new Vector3(racketposition.x / 200, 0, -racketposition.z / 50) - new Vector3(0.0f, 0.2f, 0.0f);
        axisofhandrotation = hand.Rotation;
        racketdirection    = Quaternion.LookRotation(ToVector3(hand.PalmNormal), transform.up);
        transform.rotation = racketdirection;
        //transform.rotation = racketdirection;
        //transform.Rotate(xdeg, ydeg, zdeg);
        //rotação

        /* if (hand.GrabStrength == 1)
         * {
         *
         * }*/
        /*if(hand.GrabStrength!=1)
         * {
         *   transform.position = InitialPosition;
         * }*/
    }
    private string GetRotationAngle()
    {
        Hand hand = HandModel.GetLeapHand();
        var  rot  = hand.Rotation;

        Buffer.RemoveAt(0);
        Buffer.Add(rot);
        rot = new LeapQuaternion(
            Buffer.Average(elem => elem.w),
            Buffer.Average(elem => elem.x),
            Buffer.Average(elem => elem.y),
            Buffer.Average(elem => elem.z));

        int decimals = 4;

        return(Math.Round(rot.w, decimals) + " — " +
               Math.Round(rot.x, decimals) + " — " +
               Math.Round(rot.y, decimals) + " — " +
               Math.Round(rot.z, decimals));
    }
Esempio n. 26
0
 //Set angle to rotate from hand current and last rotation, and the axis it must rotate around
 void Rotate(Hand hand)
 {
     if (!hand.IsLeft)
     {
         handRotation = Quaternion.Angle(hand.Rotation.ToQuaternion(), lastRotation.ToQuaternion());
         if (handRotation == 180)
         {
             handRotation = 0;
         }
         if (hand.PalmNormal.x < lastPalmX)// || (hand.PalmNormal.x <0 && lastPalmX <0 && hand.PalmNormal.x > lastPalmX))
         {
             handRotation = -handRotation;
         }
         lastRotation = hand.Rotation;
         lastPalmX    = hand.PalmNormal.x;
     }
     else if (hand.IsLeft)
     {
         pivotRotate.transform.parent.GetComponent <Molecule>().SetAxis(Z, X);
     }
 }
        void SetHandData(Hand hand, int frameID)
        {
            for (int fingerIndex = 0; fingerIndex < hand.Fingers.Count; fingerIndex++)
            {
                Leap.Finger.FingerType fingerType = (Leap.Finger.FingerType)fingerIndex;
                float _fingerWidth = fingerWidth * MM_TO_M;

                Transform metaCarpalTransform = null;

                switch (fingerType)
                {
                case Finger.FingerType.TYPE_THUMB:
                    metaCarpalTransform = thumbMetaCarpal;
                    break;

                case Finger.FingerType.TYPE_INDEX:
                    metaCarpalTransform = indexMetaCarpal;
                    break;

                case Finger.FingerType.TYPE_MIDDLE:
                    metaCarpalTransform = middleMetaCarpal;
                    break;

                case Finger.FingerType.TYPE_RING:
                    metaCarpalTransform = ringMetaCarpal;
                    break;

                case Finger.FingerType.TYPE_PINKY:
                    metaCarpalTransform = pinkyMetaCarpal;
                    break;

                default:
                    Debug.LogError("Invalid finger type for finger index: " + fingerIndex);
                    break;
                }

                // NOTE: if our type is thumb, our 'meta carpal transform' is actually our proximal,
                // and we'll need to generate a zero-length metacarpal for it
                Transform proximalTransform     = (fingerType == Finger.FingerType.TYPE_THUMB) ? metaCarpalTransform : metaCarpalTransform.GetChild(0);
                Transform intermediateTransform = proximalTransform.GetChild(0);
                Transform distalTransform       = intermediateTransform.GetChild(0);
                Transform tip = distalTransform.GetChild(0);

                Finger finger = hand.Fingers[fingerIndex];
                SetBone(ref finger.bones[(int)Bone.BoneType.TYPE_METACARPAL], metaCarpalTransform, proximalTransform, Bone.BoneType.TYPE_METACARPAL, _fingerWidth);
                SetBone(ref finger.bones[(int)Bone.BoneType.TYPE_PROXIMAL], proximalTransform, intermediateTransform, Bone.BoneType.TYPE_PROXIMAL, _fingerWidth);
                SetBone(ref finger.bones[(int)Bone.BoneType.TYPE_INTERMEDIATE], intermediateTransform, distalTransform, Bone.BoneType.TYPE_INTERMEDIATE, _fingerWidth);
                SetBone(ref finger.bones[(int)Bone.BoneType.TYPE_DISTAL], distalTransform, tip, Bone.BoneType.TYPE_DISTAL, _fingerWidth);

                // update the rest of the finger values.
                Vector tipPosition = tip.transform.position.ToVector();
                Vector direction   = new Vector(0, 0, 0);

                float fingerLength =
                    Vector3.Distance(proximalTransform.position, intermediateTransform.position) +
                    Vector3.Distance(intermediateTransform.position, distalTransform.position) +
                    Vector3.Distance(distalTransform.position, tip.position);                     // add up joint lengths for this

                hand.Fingers[fingerIndex].Id          = (int)fingerType;
                hand.Fingers[fingerIndex].HandId      = handID;
                hand.Fingers[fingerIndex].TipPosition = tipPosition;
                hand.Fingers[fingerIndex].Direction   = direction;
                hand.Fingers[fingerIndex].Length      = fingerLength;
            }

            // fill out rest of hand
            // forearm length is 0.27
            // forearm width is 0.09

            Vector forearmStart, forearmEnd;

            forearmStart = GetForearmStart().ToVector();
            forearmEnd   = GetForearmEnd().ToVector();

            Quaternion forearmRotation = GetForearmRotation();

            // might be possible to create this as a bone? Not sure what magic the constructor does.

            /*Arm arm = new Arm(forearmStart, forearmEnd, (forearmStart + forearmEnd) * 0.5f,
             *      (forearmEnd - forearmStart).Normalized, forearmLength, 0.09f,
             *      forearmRotation.ToLeapQuaternion());*/

            hand.Arm.PrevJoint = forearmStart;
            hand.Arm.NextJoint = forearmEnd;
            hand.Arm.Center    = (forearmStart + forearmEnd) * 0.5f;
            hand.Arm.Direction = (forearmEnd - forearmStart).Normalized;
            hand.Arm.Length    = forearmLength;
            hand.Arm.Width     = 0.09f;
            hand.Arm.Rotation  = forearmRotation.ToLeapQuaternion();

            Vector palmPosition = GetPalmPosition().ToVector();
            Vector palmNormal   = GetPalmNormal().ToVector();
            Vector palmVelocity = new Vector(0, 0, 0);

            //palmWidth = 85f * MM_TO_M;

            LeapQuaternion rotation = GetHandRotation().ToLeapQuaternion();

            hand.FrameId                = frameID;
            hand.PalmPosition           = palmPosition;
            hand.PalmVelocity           = palmVelocity;
            hand.PalmNormal             = palmNormal;
            hand.Direction              = wrist.TransformDirection(modelPalmFacing).ToVector();
            hand.Rotation               = rotation;
            hand.PalmWidth              = palmWidth;
            hand.StabilizedPalmPosition = palmPosition;
            hand.WristPosition          = wrist.position.ToVector();
            hand.TimeVisible            = timeVisible;
        }
Esempio n. 28
0
 public LeapTransform(Vector translation, LeapQuaternion rotation)
     : this(translation, rotation, Vector.Ones)
 {
 }
Esempio n. 29
0
        void SetHandData(Hand hand, int frameID)
        {
            // fill out palm and hand
            // forearm length is 0.27
            // forearm width is 0.09

            Vector forearmStart, forearmEnd;

            forearmStart = GetForearmStart().ToVector();
            forearmEnd   = GetForearmEnd().ToVector();

            Quaternion forearmRotation = GetForearmRotation();

            arm.PrevJoint = forearmStart;
            arm.NextJoint = forearmEnd;
            arm.Center    = (forearmStart + forearmEnd) * 0.5f;
            arm.Direction = (forearmEnd - forearmStart).Normalized;
            arm.Length    = forearmLength;
            arm.Width     = 0.09f;
            arm.Rotation  = forearmRotation.ToLeapQuaternion();

            Vector palmPosition = GetPalmPosition().ToVector();
            Vector palmNormal   = GetPalmNormal().ToVector();
            Vector palmVelocity = (visibleTime != 0 &&
                                   (visibleTime - previousHand.TimeVisible != 0)) ? (previousHand.PalmPosition - palmPosition).Normalized / (visibleTime - previousHand.TimeVisible) :
                                  new Vector(0, 0, 0);
            Vector handDirection = wrist.TransformDirection(modelFingerPointing).ToVector();

            LeapQuaternion rotation = GetHandRotation().ToLeapQuaternion();

            fingers = hand.Fingers;

            // fingers
            for (int fingerIndex = 0; fingerIndex < 5; fingerIndex++)
            {
                Leap.Finger.FingerType fingerType = (Leap.Finger.FingerType)fingerIndex;

                Transform metaCarpalTransform = null;

                // set up our bones
                Bone[] bones = null;

                switch (fingerType)
                {
                case Finger.FingerType.TYPE_THUMB:
                    metaCarpalTransform = thumbMetaCarpal;
                    bones = thumbBones;
                    break;

                case Finger.FingerType.TYPE_INDEX:
                    metaCarpalTransform = indexMetaCarpal;
                    bones = indexBones;
                    break;

                case Finger.FingerType.TYPE_MIDDLE:
                    metaCarpalTransform = middleMetaCarpal;
                    bones = middleBones;
                    break;

                case Finger.FingerType.TYPE_RING:
                    metaCarpalTransform = ringMetaCarpal;
                    bones = ringBones;
                    break;

                case Finger.FingerType.TYPE_PINKY:
                    metaCarpalTransform = pinkyMetaCarpal;
                    bones = pinkyBones;
                    break;

                default:
                    Debug.LogError("Invalid finger type for finger index: " + fingerIndex);
                    break;
                }

                // NOTE: if our type is thumb, our 'meta carpal transform' is actually our proximal,
                // and we'll need to generate a zero-length metacarpal for it
                Transform proximalTransform     = (fingerType == Finger.FingerType.TYPE_THUMB) ? metaCarpalTransform : metaCarpalTransform.GetChild(0);
                Transform intermediateTransform = proximalTransform.GetChild(0);
                Transform distalTransform       = intermediateTransform.GetChild(0);
                Transform tip         = distalTransform.GetChild(0);
                Vector    tipPosition = tip.transform.position.ToVector();
                Vector    direction   = distalTransform.TransformVector(modelFingerPointing).ToVector();

                float fingerLength =
                    Vector3.Distance(proximalTransform.position, intermediateTransform.position) +
                    Vector3.Distance(intermediateTransform.position, distalTransform.position) +
                    Vector3.Distance(distalTransform.position, tip.position);                     // add up joint lengths for this
                float fingerDot = Vector3.Dot(direction.ToVector3(), handDirection.ToVector3());
                fingerDots[fingerIndex] = fingerDot;
                bool isExtended = fingerDot > 0.5f;

                SetBone(bones[(int)Bone.BoneType.TYPE_METACARPAL], metaCarpalTransform, proximalTransform, Bone.BoneType.TYPE_METACARPAL, fingerWidth[fingerIndex]);
                SetBone(bones[(int)Bone.BoneType.TYPE_PROXIMAL], proximalTransform, intermediateTransform, Bone.BoneType.TYPE_PROXIMAL, fingerWidth[fingerIndex]);
                SetBone(bones[(int)Bone.BoneType.TYPE_INTERMEDIATE], intermediateTransform, distalTransform, Bone.BoneType.TYPE_INTERMEDIATE, fingerWidth[fingerIndex]);
                SetBone(bones[(int)Bone.BoneType.TYPE_DISTAL], distalTransform, tip, Bone.BoneType.TYPE_DISTAL, fingerWidth[fingerIndex]);

                fingers[fingerIndex].bones       = bones;
                fingers[fingerIndex].HandId      = handID;
                fingers[fingerIndex].TimeVisible = visibleTime;
                fingers[fingerIndex].TipPosition = tipPosition;
                fingers[fingerIndex].Direction   = direction;
                fingers[fingerIndex].Width       = fingerWidth[fingerIndex];
                fingers[fingerIndex].Length      = fingerLength;
                fingers[fingerIndex].IsExtended  = isExtended;
                fingers[fingerIndex].Type        = (Finger.FingerType)fingerIndex;
                fingers[fingerIndex].Id          = fingerIndex;
                fingers[fingerIndex].HandId      = handID;
            }

            hand.FrameId                = frameID;
            hand.PalmPosition           = palmPosition;
            hand.PalmVelocity           = palmVelocity;
            hand.PalmNormal             = palmNormal;
            hand.Direction              = handDirection;
            hand.Rotation               = rotation;
            hand.PalmWidth              = palmWidth;
            hand.StabilizedPalmPosition = palmPosition;
            hand.WristPosition          = wrist.position.ToVector();
            hand.GrabAngle              = 0;
            hand.GrabStrength           = gripStrength;
            hand.TimeVisible            = visibleTime;
            hand.Confidence             = confidence;
            hand.PinchStrength          = pinchStrength;
            hand.PinchDistance          = (fingers[(int)Finger.FingerType.TYPE_INDEX].TipPosition.ToVector3() -
                                           fingers[(int)Finger.FingerType.TYPE_THUMB].TipPosition.ToVector3()).magnitude;
            hand.Arm     = arm;
            hand.Fingers = fingers;
            hand.IsLeft  = isLeft;
        }
Esempio n. 30
0
 public Quaternion ConvertQ(LeapQuaternion q)
 {
     return(new Quaternion(q.x, q.y, q.z, q.w));
 }
    private Hand creatHand(long frameId, object hand, object pointables_object)
    {
        bool isLeft = false;
        Dictionary <string, object> handsobject = (Dictionary <string, object>)hand;
        List <object> pointables_list           = (List <object>)pointables_object;
        List <object> armbasislist = (List <object>)handsobject["armBasis"];
        Vector        arm_1        = creatVector((List <object>)armbasislist[0]);
        Vector        arm_2        = creatVector((List <object>)armbasislist[1]);
        Vector        arm_3        = creatVector((List <object>)armbasislist[2]);

        //arm_1 = normalizeVector(arm_1);
        //arm_1 = normalizeVector(arm_2);
        //arm_1 = normalizeVector(arm_3);

        double armWidth = (double)handsobject["armWidth"];

        double confidence = (double)handsobject["confidence"];

        List <object> direction_list = (List <object>)handsobject["direction"];
        Vector        direction      = creatVector((List <object>)direction_list);

        List <object> elbow_list = (List <object>)handsobject["elbow"];
        Vector        elbow      = creatVector((List <object>)elbow_list);

        double grabStrength = (double)handsobject["grabStrength"];

        long Handid = (long)handsobject["id"];

        List <object> palmNormal_list = (List <object>)handsobject["palmNormal"];
        Vector        palmNormal      = creatVector((List <object>)palmNormal_list);

        List <object> palmPosition_list = (List <object>)handsobject["palmPosition"];
        Vector        palmPosition      = creatVector((List <object>)palmPosition_list);

        List <object> palmVelocity_list = (List <object>)handsobject["palmVelocity"];
        Vector        palmVelocity      = creatVector((List <object>)palmVelocity_list);

        double pinchStrength = (double)handsobject["pinchStrength"];

        List <object> r_list = (List <object>)handsobject["r"];

        Matrix4x4             rotationMatrix = new Matrix4x4();
        List <List <object> > r = new List <List <object> >();
        int i = 0;

        foreach (var item in r_list)
        {
            List <object> current = new List <object>();
            foreach (var array in current)
            {
                rotationMatrix.SetRow(i, creatVector4((List <object>)array));
            }
        }

        double s = (double)handsobject["s"];

        List <object> sphereCenter_list = (List <object>)handsobject["sphereCenter"];
        Vector        sphereCenter      = creatVector((List <object>)sphereCenter_list);

        double sphereRadius = (double)handsobject["sphereRadius"];

        List <object> stabilizedPalmPosition_list = (List <object>)handsobject["stabilizedPalmPosition"];
        Vector        stabilizedPalmPosition      = creatVector((List <object>)stabilizedPalmPosition_list);

        List <object> t_list = (List <object>)handsobject["t"];
        Vector        t      = creatVector((List <object>)t_list);

        double timeVisible = (double)handsobject["timeVisible"];

        string type = (string)handsobject["type"];

        if (type.Equals("left"))
        {
            isLeft = true;
        }
        else
        {
            isLeft = false;
        }

        List <object> wrist_list = (List <object>)handsobject["wrist"];
        Vector        wrist      = creatVector((List <object>)wrist_list);
        Vector        midpoint   = new Vector((elbow.x + wrist.x) / 2, (elbow.y + wrist.y) / 2, (elbow.z + wrist.z) / 2);

        //Debug.Log("Handdddddd");
        //Debug.Log(armWidth);


        LeapQuaternion basis = createQuaternion(arm_1, arm_2, arm_3);
        //LeapQuaternion basis = createQuaternion(arm_1, arm_2, arm_3);

        Arm arm = new Arm(elbow, wrist, midpoint, direction, 245, (float)armWidth, basis);
        // public Hand(long frameID, int id, float confidence, float grabStrength, float grabAngle, float pinchStrength, float pinchDistance, float palmWidth, bool isLeft, float timeVisible, Arm arm, List<Finger> fingers, Vector palmPosition, Vector stabilizedPalmPosition, Vector palmVelocity, Vector palmNormal, Vector direction, Vector wristPosition);

        List <Finger> fingerlist = createFingerlist(Handid, frameId, pointables_list);
        //Debug.Log(fingerlist.Count);
        Hand result = new Hand(frameId, (int)Handid, (float)confidence, (float)grabStrength, 0, (float)pinchStrength, 0, (float)s, isLeft, (float)timeVisible, arm, fingerlist, palmPosition, stabilizedPalmPosition, palmVelocity, palmNormal, direction, wrist);

        return(result);
    }
 /**
  * Converts a LeapQuaternion object to a UnityEngine.Quaternion object.
  *
  * @returns The UnityEngine Quaternion object with the same values as the LeapQuaternion.
  */
 public static Quaternion ToQuaternion(this LeapQuaternion q)
 {
     return(new Quaternion(q.x, q.y, q.z, q.w));
 }
Esempio n. 33
0
 public static Quaternion GetQuaternion(LeapQuaternion q)
 {
     return(new Quaternion(q.x, q.y, q.z, q.w));
 }
Esempio n. 34
0
        private void updateHandPosition()
        {
            if (!GestureProvider.UpdatedInThisFrame)
            {
                return;
            }

            var hand = _HandDataSide == HandDataSide.PlayerLeft ? GestureProvider.LeftHand : GestureProvider.RightHand;

            if (hand == null)
            {
                _hand = null;
                return;
            }

            // finger roots
            Vector3 index = hand.points[5], middle = hand.points[9], ring = hand.points[13], pinky = hand.points[17];
            Vector3 vec1     = (index + middle) / 2 - hand.points[0];
            Vector3 vec2     = (ring + pinky) / 2 - hand.points[0];
            Vector3 forward  = hand.isLeft ? Vector3.Cross(vec1, vec2) : Vector3.Cross(vec2, vec1);
            Vector3 upDir    = -forward;
            Vector3 rightDir = Vector3.Cross(upDir, vec1);

            // Leap hand general options
            // TODO: Review this values
            long  frameID       = 1;
            int   id            = hand.isLeft ? 0 : 1;
            float confidence    = 1;
            float grabStrength  = 0;
            float grabAngle     = 0;
            float pinchStrength = 0;
            float pinchDistance = 1;
            float palmWidth     = (index - pinky).magnitude;
            bool  isLeft        = hand.isLeft;
            float timeVisible   = 1;

            // Setup fingers and bones
            float         fingerWidth = 0.02f;
            bool          isExtended  = false;
            List <Finger> fingers     = new List <Finger> {
            };

            Finger.FingerType[] fingerTypeList = { Finger.FingerType.TYPE_THUMB, Finger.FingerType.TYPE_INDEX, Finger.FingerType.TYPE_MIDDLE, Finger.FingerType.TYPE_RING, Finger.FingerType.TYPE_PINKY };
            int fingerCount = 0;

            foreach (Finger.FingerType fingerType in fingerTypeList)
            {
                float       fingerLength      = 0.0f;
                List <Bone> bones             = new List <Bone> {
                };
                Bone.BoneType[] boneTypesList = { Bone.BoneType.TYPE_METACARPAL, Bone.BoneType.TYPE_PROXIMAL, Bone.BoneType.TYPE_INTERMEDIATE, Bone.BoneType.TYPE_DISTAL };
                float           boneWidth     = 0.018f;
                int             fingerRoot    = 0;
                switch (fingerType)
                {
                case Finger.FingerType.TYPE_THUMB:
                    fingerRoot = 1;
                    break;

                case Finger.FingerType.TYPE_INDEX:
                    fingerRoot = 5;
                    break;

                case Finger.FingerType.TYPE_MIDDLE:
                    fingerRoot = 9;
                    break;

                case Finger.FingerType.TYPE_RING:
                    fingerRoot = 13;
                    break;

                case Finger.FingerType.TYPE_PINKY:
                    fingerRoot = 17;
                    break;
                }

                // Calculate xDir(perpendicular vector to finger's right side) for set rotation
                Vector3 secondBoneDir = hand.points[fingerRoot + 2] - hand.points[fingerRoot + 1];
                secondBoneDir = secondBoneDir.normalized;
                Vector3 xDir = Vector3.Cross(secondBoneDir, rightDir);
                xDir = Vector3.Cross(secondBoneDir, xDir);
                Vector3 xDirR = xDir;
                if (fingerType == Finger.FingerType.TYPE_THUMB)
                {
                    xDirR = Quaternion.AngleAxis(-90, secondBoneDir) * xDir;
                }


                int boneIndex = 0;
                foreach (Bone.BoneType boneType in boneTypesList)
                {
                    Vector  prevJoint;
                    Vector  nextJoint;
                    Vector3 boneDir;
                    if (boneType == Bone.BoneType.TYPE_METACARPAL)
                    {
                        Vector3 handDownDirection = hand.position - middle;
                        handDownDirection = handDownDirection.normalized;
                        Vector3 rootThumb = hand.points[1] + handDownDirection * 0.025f;
                        Vector3 jointRoot = Vector3.Lerp(rootThumb, hand.points[0], (float)(fingerRoot - 1) / 16);
                        jointRoot = Vector3.Lerp(jointRoot, hand.points[fingerRoot + 1], 0.2f);
                        prevJoint = new Vector(jointRoot.x, jointRoot.y, jointRoot.z);
                        nextJoint = new Vector(hand.points[fingerRoot + boneIndex].x, hand.points[fingerRoot + boneIndex].y, hand.points[fingerRoot + boneIndex].z);
                        boneDir   = hand.points[fingerRoot + boneIndex] - jointRoot;
                        boneDir   = boneDir.normalized;
                        if (fingerType == Finger.FingerType.TYPE_THUMB)
                        {
                            prevJoint = nextJoint;
                        }
                    }
                    else
                    {
                        prevJoint = new Vector(hand.points[fingerRoot + boneIndex].x, hand.points[fingerRoot + boneIndex].y, hand.points[fingerRoot + boneIndex].z);
                        boneIndex++;
                        nextJoint = new Vector(hand.points[fingerRoot + boneIndex].x, hand.points[fingerRoot + boneIndex].y, hand.points[fingerRoot + boneIndex].z);
                        boneDir   = hand.points[fingerRoot + boneIndex] - hand.points[fingerRoot + boneIndex - 1];
                        boneDir   = boneDir.normalized;
                    }

                    float boneLength = (nextJoint - prevJoint).Magnitude;
                    fingerLength += boneLength;
                    Vector center        = (nextJoint + prevJoint) / 2;
                    Vector boneDirection = nextJoint - prevJoint;
                    boneDirection = boneDirection.Normalized;

                    Vector3 boneUpDir = Vector3.Cross(xDirR, boneDir);
                    if (fingerType == Finger.FingerType.TYPE_THUMB && boneType == Bone.BoneType.TYPE_METACARPAL)
                    {
                        boneUpDir = Vector3.Cross((Quaternion.AngleAxis(70, secondBoneDir) * xDir), boneDir);
                    }
                    Quaternion     boneRotationUnity = Quaternion.LookRotation(boneDir, boneUpDir);
                    LeapQuaternion boneRotation      = new LeapQuaternion(boneRotationUnity.x, boneRotationUnity.y, boneRotationUnity.z, boneRotationUnity.w);
                    bones.Add(new Bone(prevJoint,
                                       nextJoint,
                                       center,
                                       boneDirection,
                                       boneLength,
                                       boneWidth,
                                       boneType,
                                       boneRotation));
                }

                Vector fingerTipPosition = bones[3].NextJoint;
                Vector fingerDirection   = bones[3].NextJoint - bones[3].PrevJoint;
                fingerDirection = fingerDirection.Normalized;
                fingers.Add(new Finger(0,
                                       id,
                                       fingerCount,
                                       timeVisible,
                                       fingerTipPosition,
                                       fingerDirection,
                                       fingerWidth,
                                       fingerLength,
                                       isExtended,
                                       fingerType,
                                       bones[0],
                                       bones[1],
                                       bones[2],
                                       bones[3]));
                fingerCount++;
            }


            Vector palmPosition           = new Vector(hand.position.x, hand.position.y, hand.position.z);
            Vector stabilizedPalmPosition = new Vector(hand.position.x, hand.position.y, hand.position.z);
            Vector palmVelocity           = new Vector(0, 0, 0);
            Vector palmNormal             = new Vector(forward.x, forward.y, forward.z);

            palmNormal = palmNormal.Normalized;

            Vector3        midDir          = (middle + ring) / 2 - hand.points[0];
            Quaternion     m_NewRot        = Quaternion.LookRotation(midDir, upDir);
            LeapQuaternion palmOrientation = new LeapQuaternion(m_NewRot.x, m_NewRot.y, m_NewRot.z, m_NewRot.w);

            Vector direction = new Vector((middle - hand.position).x, (middle - hand.position).y, (middle - hand.position).z);

            direction = direction.Normalized;
            Vector wristPosition = new Vector(hand.points[0].x, hand.points[0].y, hand.points[0].z);

            Vector         elbow        = wristPosition - direction * 0.1f;
            Vector         wrist        = wristPosition;
            Vector         armCenter    = (elbow + wristPosition) / 2;
            float          length       = 0.1f;
            float          width        = palmWidth;
            Vector         armDirection = direction;
            LeapQuaternion armRotation  = palmOrientation;
            Arm            arm          = new Arm(elbow, wrist, armCenter, armDirection, length, width, armRotation);

            _hand = new Hand(frameID,
                             id,
                             confidence,
                             grabStrength,
                             grabAngle,
                             pinchStrength,
                             pinchDistance,
                             palmWidth,
                             isLeft,
                             timeVisible,
                             arm,
                             fingers,
                             palmPosition,
                             stabilizedPalmPosition,
                             palmVelocity,
                             palmNormal,
                             palmOrientation,
                             direction,
                             wristPosition);

            _handData.CopyFrom(_hand);
            _unwarpedHandData.CopyFrom(_handData);

            refreshPointDataFromHand();
            _lastCustomHandWasLeft = _unwarpedHandData.IsLeft;
        }
Esempio n. 35
0
    private Hand creatHand(long frameId, object hand, object pointables_object)
    {
        bool isLeft = false;
        Dictionary <string, object> handsobject = (Dictionary <string, object>)hand;
        List <object> pointables_list           = (List <object>)pointables_object;
        List <object> armbasislist = (List <object>)handsobject["armBasis"];
        Vector        arm_1        = creatVector((List <object>)armbasislist[0]);
        Vector        arm_2        = creatVector((List <object>)armbasislist[1]);
        Vector        arm_3        = creatVector((List <object>)armbasislist[2]);

        double armWidth = (double)handsobject["armWidth"];

        double confidence = (double)handsobject["confidence"];

        List <object> direction_list = (List <object>)handsobject["direction"];
        Vector        direction      = creatVector((List <object>)direction_list);

        List <object> elbow_list = (List <object>)handsobject["elbow"];
        Vector        elbow      = creatVector((List <object>)elbow_list);

        double grabStrength = (double)handsobject["grabStrength"];

        long Handid = (long)handsobject["id"];

        List <object> palmNormal_list = (List <object>)handsobject["palmNormal"];
        Vector        palmNormal      = creatVector((List <object>)palmNormal_list);

        palmNormal_list_global = palmNormal_list;

        List <object> palmPosition_list = (List <object>)handsobject["palmPosition"];
        Vector        palmPosition      = creatVector((List <object>)palmPosition_list);

        palmPosition_list_global = palmPosition_list;

        List <object> palmVelocity_list = (List <object>)handsobject["palmVelocity"];
        Vector        palmVelocity      = creatVector((List <object>)palmVelocity_list);

        double pinchStrength = (double)handsobject["pinchStrength"];

        List <object> r_list = (List <object>)handsobject["r"];

        Matrix4x4             rotationMatrix = new Matrix4x4();
        List <List <object> > r = new List <List <object> >();
        int i = 0;

        foreach (var item in r_list)
        {
            List <object> current = new List <object>();
            foreach (var array in current)
            {
                rotationMatrix.SetRow(i, creatVector4((List <object>)array));
            }
        }

        double s = (double)handsobject["s"];

        List <object> sphereCenter_list = (List <object>)handsobject["sphereCenter"];
        Vector        sphereCenter      = creatVector((List <object>)sphereCenter_list);

        double sphereRadius = (double)handsobject["sphereRadius"];

        List <object> stabilizedPalmPosition_list = (List <object>)handsobject["stabilizedPalmPosition"];
        Vector        stabilizedPalmPosition      = creatVector((List <object>)stabilizedPalmPosition_list);

        List <object> t_list = (List <object>)handsobject["t"];
        Vector        t      = creatVector((List <object>)t_list);

        double timeVisible = (double)handsobject["timeVisible"];

        string type = (string)handsobject["type"];

        if (type.Equals("left"))
        {
            isLeft = true;
        }
        else
        {
            isLeft = false;
        }

        List <object> wrist_list = (List <object>)handsobject["wrist"];
        Vector        wrist      = creatVector((List <object>)wrist_list);
        Vector        midpoint   = new Vector((elbow.x + wrist.x) / 2, (elbow.y + wrist.y) / 2, (elbow.z + wrist.z) / 2);



        LeapQuaternion basis = createQuaternion(arm_1, arm_2, arm_3);

        // Note that the armlength and some other data requried form the arm constructor is replaced by a filler 245
        // I couldn't quite how to figure out how to get those data from the leap motion data. I notiecd that the length
        // is usually around 245(which is my hand), so I replaced it with the data.
        Arm arm = new Arm(elbow, wrist, midpoint, direction, 245, (float)armWidth, basis);

        List <Finger> fingerlist = createFingerlist(Handid, frameId, pointables_list);

        //Same with the arm object, I couldn't figure out the grablength from the leap motion. This may be causing some of the perfromace issues that I have with
        // the hand model in real time.
        Hand result = new Hand(frameId, (int)Handid, (float)confidence, (float)grabStrength, 0, (float)pinchStrength, 0, (float)s, isLeft, (float)timeVisible, arm, fingerlist, palmPosition, stabilizedPalmPosition, palmVelocity, palmNormal, direction, wrist);

        return(result);
    }
Esempio n. 36
0
 public static Quaternion ToQuaternion(this LeapQuaternion leapQuaternion)
 {
     return(new Quaternion(leapQuaternion.x, leapQuaternion.y, leapQuaternion.z, leapQuaternion.w));
 }
Esempio n. 37
0
        public static Quaternion ToHMDQuaternion(this LeapQuaternion leapQuaternion)
        {
            Vector3 eulur = leapQuaternion.ToQuaternion().eulerAngles;

            return(Quaternion.Euler(eulur.x, -eulur.y, -eulur.z));
        }
Esempio n. 38
0
        // This is only usable when the basis vectors have not been modified directly.
        public LeapQuaternion TransformQuaternion(LeapQuaternion rhs)
        {
            if (_quaternionDirty)
            throw new InvalidOperationException("Calling TransformQuaternion after Basis vectors have been modified.");

              if (_flip)
              {
            // Mirror the axis of rotation accross the flip axis.
            rhs.x *= _flipAxes.x;
            rhs.y *= _flipAxes.y;
            rhs.z *= _flipAxes.z;
              }

              LeapQuaternion t = _quaternion.Multiply(rhs);
              return t;
        }
 private static SerializableQuaternion ToSerializableQuaternion(LeapQuaternion quaternion)
 {
     return new SerializableQuaternion
     {
         x = quaternion.x,
         y = quaternion.y,
         z = quaternion.z,
         w = quaternion.w
     };
 }