コード例 #1
0
        protected Bone getBone(Hand hand, Finger.FingerType fingerType, Bone.BoneType boneType)
        {
            if (boneType < 0 || (int)boneType >= 4)
            {
                return(null);
            }

            foreach (Finger finger in hand.Fingers)
            {
                if (finger.Type != fingerType)
                {
                    continue;
                }

                return(finger.Bone(boneType));
            }
            return(null);
        }
コード例 #2
0
ファイル: TestHandFactory.cs プロジェクト: tmokkun/RubiksCube
        static Finger MakeFinger(Finger.FingerType name, Vector position, Vector forward, Vector up, float[] jointLengths,
                                 int frameId, int handId, int fingerId, bool isLeft)
        {
            forward = forward.Normalized;
            up      = up.Normalized;

            Bone[] bones            = new Bone[5];
            float  proximalDistance = -jointLengths[0];
            Bone   metacarpal       = MakeBone(Bone.BoneType.TYPE_METACARPAL, position + forward * proximalDistance, jointLengths[0], 8f, forward, up, isLeft);

            proximalDistance += jointLengths[0];
            bones[0]          = metacarpal;

            Bone proximal = MakeBone(Bone.BoneType.TYPE_PROXIMAL, position + forward * proximalDistance, jointLengths[1], 8f, forward, up, isLeft);

            proximalDistance += jointLengths[1];
            bones[1]          = proximal;

            Bone intermediate = MakeBone(Bone.BoneType.TYPE_INTERMEDIATE, position + forward * proximalDistance, jointLengths[2], 8f, forward, up, isLeft);

            proximalDistance += jointLengths[2];
            bones[2]          = intermediate;

            Bone distal = MakeBone(Bone.BoneType.TYPE_DISTAL, position + forward * proximalDistance, jointLengths[3], 8f, forward, up, isLeft);

            bones[3] = distal;

            return(new Finger(frameId,
                              handId,
                              fingerId,
                              0.0f,
                              position,
                              new Vector(0, 0, 0),
                              forward,
                              position,
                              8f,
                              jointLengths[1] + jointLengths[2] + jointLengths[3],
                              true,
                              name,
                              bones[0],
                              bones[1],
                              bones[2],
                              bones[3]));
        }
コード例 #3
0
        /*--------------------------------------------------------------------------------------------*/
        private void UpdateForFinger(Hand pLeapHand, Finger.FingerType pLeapFingerType)
        {
            Finger leapFinger = pLeapHand.Fingers
                                .FingerType(pLeapFingerType)
                                .FirstOrDefault(f => f.IsValid);

            if (leapFinger == null)
            {
                UpdateForNull();
                return;
            }

            Bone bone = leapFinger.Bone(Bone.BoneType.TYPE_DISTAL);

            IsAvailable = true;
            Position    = leapFinger.TipPosition.ToUnityScaled();
            Rotation    = LeapUtil.CalcQuaternion(bone.Basis);
            Size        = leapFinger.Width * SizeScaleFactor;
        }
コード例 #4
0
        /// <summary>
        /// Fills the Finger object with the provided finger data. You can pass null for
        /// bones; A null bone will not modify the underlying hand's data for that bone.
        /// </summary>
        public static void Fill(this Finger toFill,
                                long frameId,
                                int handId,
                                int fingerId,
                                float timeVisible,
                                Vector tipPosition,
                                Vector direction,
                                float width,
                                float length,
                                bool isExtended,
                                Finger.FingerType type,
                                Bone metacarpal   = null,
                                Bone proximal     = null,
                                Bone intermediate = null,
                                Bone distal       = null)
        {
            toFill.Id          = handId;
            toFill.HandId      = handId;
            toFill.TimeVisible = timeVisible;
            toFill.TipPosition = tipPosition;
            toFill.Direction   = direction;
            toFill.Width       = width;
            toFill.Length      = length;
            toFill.IsExtended  = isExtended;
            toFill.Type        = type;

            if (metacarpal != null)
            {
                toFill.bones[0] = metacarpal;
            }
            if (proximal != null)
            {
                toFill.bones[1] = proximal;
            }
            if (intermediate != null)
            {
                toFill.bones[2] = intermediate;
            }
            if (distal != null)
            {
                toFill.bones[3] = distal;
            }
        }
コード例 #5
0
    public void SetData(Hand hand)  //参数为右手
    {
        foreach (Finger finger in hand.Fingers)
        {
            Finger.FingerType fingerType = finger.Type;
            switch (fingerType)
            {
            case Finger.FingerType.TYPE_INDEX:    //食指
                LeftPosition[0]  = finger.TipPosition;
                LeftDirection[0] = finger.Direction;
                LeftRoot[0]      = finger.Bone(Bone.BoneType.TYPE_METACARPAL).Center;
                break;

            case Finger.FingerType.TYPE_MIDDLE:    //中指
                LeftPosition[1]  = finger.TipPosition;
                LeftDirection[1] = finger.Direction;
                LeftRoot[1]      = finger.Bone(Bone.BoneType.TYPE_METACARPAL).Center;
                break;

            case Finger.FingerType.TYPE_PINKY:    //小指
                LeftPosition[2]  = finger.TipPosition;
                LeftDirection[2] = finger.Direction;
                LeftRoot[2]      = finger.Bone(Bone.BoneType.TYPE_METACARPAL).Center;
                break;

            case Finger.FingerType.TYPE_RING:    //无名指
                LeftPosition[3]  = finger.TipPosition;
                LeftDirection[3] = finger.Direction;
                LeftRoot[3]      = finger.Bone(Bone.BoneType.TYPE_METACARPAL).Center;
                break;

            case Finger.FingerType.TYPE_THUMB:    //大拇指
                LeftPosition[4]  = finger.TipPosition;
                LeftDirection[4] = finger.Direction;
                LeftRoot[4]      = finger.Bone(Bone.BoneType.TYPE_PROXIMAL).Center;
                break;

            default:
                break;
            }
        }
    }
コード例 #6
0
        public void JointsMatch([ValueSource(typeof(FrameValidator), "_fingers")] Finger.FingerType fingerType,
                                [ValueSource(typeof(FrameValidator), "_bones")] Bone.BoneType boneType)
        {
            foreach (Hand hand in _frame.Hands)
            {
                Bone prevBone = getBone(hand, fingerType, boneType - 1);
                Bone bone     = getBone(hand, fingerType, boneType);
                Bone nextBone = getBone(hand, fingerType, boneType + 1);

                if (prevBone != null)
                {
                    assertVectorsEqual(prevBone.NextJoint, bone.PrevJoint);
                }

                if (nextBone != null)
                {
                    assertVectorsEqual(nextBone.PrevJoint, bone.NextJoint);
                }
            }
        }
コード例 #7
0
 public SerializableFinger(Finger f)
 {
     Type   = f.Type;
     _bones = new SerializableBone[4];
     for (int i = 0; i < 4; ++i)
     {
         _bones[i] = new Leap.SerializableBone(f.Bone((Bone.BoneType)i));
     }
     _frameId              = 0; //Private
     Id                    = f.Id;
     HandId                = f.HandId;
     TipPosition           = new SerializableVector(f.TipPosition);
     TipVelocity           = new SerializableVector(f.TipVelocity);
     Direction             = new SerializableVector(f.Direction);
     Width                 = f.Width;
     Length                = f.Length;
     IsExtended            = f.IsExtended;
     StabilizedTipPosition = new SerializableVector(f.StabilizedTipPosition);
     TimeVisible           = f.TimeVisible;
 }
コード例 #8
0
    public Vector GetFingerJointPosition(Hand hand, Finger.FingerType fingerType = Finger.FingerType.TYPE_INDEX, Bone.BoneType boneType = Bone.BoneType.TYPE_INTERMEDIATE)
    {
        /*pozice kloubu pozadovaneho prstu*/
        FingerList fingers = hand.Fingers;
        Finger     resFinger;
        Bone       resBone;
        Vector     position = Vector.Zero;

        foreach (Finger finger in fingers)
        {
            if (finger.Type() == fingerType)
            {
                resFinger = finger;
                resBone   = finger.Bone(boneType);
                position  = resBone.Center;
                break;
            }
        }

        return(position);
    }
コード例 #9
0
    Vector GetFingerTipPosition(Hand hand, Finger.FingerType fingerType = Finger.FingerType.TYPE_INDEX)
    {
        /*pozice konecku prstu*/
        FingerList fingers = hand.Fingers;
        Finger     indexFinger;
        Vector     position = Vector.Zero;

        //Vector position = null;

        foreach (Finger finger in fingers)
        {
            if (finger.Type() == fingerType)
            {
                indexFinger = finger;
                position    = indexFinger.TipPosition;
                break;
            }
        }

        return(position);
    }
コード例 #10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public static CursorType GetFingerCursorType(bool pIsLeft, Finger.FingerType pLeapFingerType)
        {
            switch (pLeapFingerType)
            {
            case Finger.FingerType.TYPE_THUMB:
                return(pIsLeft ? CursorType.LeftThumb : CursorType.RightThumb);

            case Finger.FingerType.TYPE_INDEX:
                return(pIsLeft ? CursorType.LeftIndex : CursorType.RightIndex);

            case Finger.FingerType.TYPE_MIDDLE:
                return(pIsLeft ? CursorType.LeftMiddle : CursorType.RightMiddle);

            case Finger.FingerType.TYPE_RING:
                return(pIsLeft ? CursorType.LeftRing : CursorType.RightRing);

            case Finger.FingerType.TYPE_PINKY:
                return(pIsLeft ? CursorType.LeftPinky : CursorType.RightPinky);
            }

            throw new Exception("Unhandled cursor combination: " + pIsLeft + " / " + pLeapFingerType);
        }
コード例 #11
0
    float proximity_pinch_with(Hand hand, Finger.FingerType id = Finger.FingerType.TYPE_INDEX)
    {
        Finger finger;

        switch (id)
        {
        case Finger.FingerType.TYPE_INDEX:

            finger = hand.GetIndex();
            break;

        case Finger.FingerType.TYPE_MIDDLE:

            finger = hand.GetMiddle();
            break;

        case Finger.FingerType.TYPE_RING:

            finger = hand.GetRing();
            break;

        case Finger.FingerType.TYPE_PINKY:
            finger = hand.GetPinky();

            break;

        default:
            finger = hand.GetIndex();
            break;
        }



        Finger  thumb  = hand.GetThumb();
        Vector3 vector = (finger.TipPosition - thumb.TipPosition).ToVector3();

        return(vector.magnitude);
    }
コード例 #12
0
        protected TrackedHandJoint ConvertFingerToTrackedHandJointTip(Finger.FingerType fingerType)
        {
            switch (fingerType)
            {
            case Finger.FingerType.TYPE_THUMB:
                return(TrackedHandJoint.ThumbTip);

            case Finger.FingerType.TYPE_INDEX:
                return(TrackedHandJoint.IndexTip);

            case Finger.FingerType.TYPE_MIDDLE:
                return(TrackedHandJoint.MiddleTip);

            case Finger.FingerType.TYPE_RING:
                return(TrackedHandJoint.RingTip);

            case Finger.FingerType.TYPE_PINKY:
                return(TrackedHandJoint.PinkyTip);

            default:
                return(TrackedHandJoint.None);
            }
        }
コード例 #13
0
        public override void AddHand(Hand hand)
        {
            var newCollection = HandPointCollection.Create(_obj.warper);

            _handIdToPoints[hand.Id] = newCollection;

            for (int f = 0; f < NUM_FINGERS; f++)
            {
                Finger            finger     = hand.Fingers[f];
                Finger.FingerType fingerType = finger.Type;

                for (int j = 0; j < NUM_BONES; j++)
                {
                    Bone.BoneType boneType = (Bone.BoneType)j;
                    Bone          bone     = finger.Bone(boneType);

                    Vector3 bonePos = bone.NextJoint.ToVector3();

                    //Global position of the point is just the position of the joint itself
                    newCollection.SetGlobalPosition(bonePos, fingerType, boneType);
                }
            }
        }
コード例 #14
0
    public int getFingerNum(Finger.FingerType i)
    {
        switch (i)
        {
        case Finger.FingerType.TYPE_THUMB:
            return(1);

        case Finger.FingerType.TYPE_INDEX:
            return(4);

        case Finger.FingerType.TYPE_MIDDLE:
            return(7);

        case Finger.FingerType.TYPE_RING:
            return(10);

        case Finger.FingerType.TYPE_PINKY:
            return(13);

        default:
            return(-1);
        }
    }
コード例 #15
0
    static public Vector3 positionTipFingerRight(Finger.FingerType id = Finger.FingerType.TYPE_INDEX)
    {
        if (right_hand != null)
        {
            Finger finger;
            switch (id)
            {
            case Finger.FingerType.TYPE_INDEX:

                finger = right_hand.GetIndex();
                break;

            case Finger.FingerType.TYPE_MIDDLE:

                finger = right_hand.GetMiddle();
                break;

            case Finger.FingerType.TYPE_RING:

                finger = right_hand.GetRing();
                break;

            case Finger.FingerType.TYPE_PINKY:
                finger = right_hand.GetPinky();

                break;

            default:
                finger = right_hand.GetThumb();
                break;
            }


            return(finger.TipPosition.ToVector3());
        }
        return(Vector3.one * float.MaxValue);
    }
コード例 #16
0
    public void tips(Vector fpos, Finger.FingerType i)
    {
        int j = getFingerNum(i);

        if (j != -1)
        {
            data [j]     = fpos.x;
            data [j + 1] = fpos.y;
            data [j + 2] = fpos.z;
        }

        switch (j)
        {
        case 1:
            thumb = fpos;
            break;

        case 4:
            index = fpos;
            break;

        case 7:
            middle = fpos;
            break;

        case 10:
            ring = fpos;
            break;

        case 13:
            pinky = fpos;
            break;

        default:
            break;
        }
    }
コード例 #17
0
    /// <summary>
    /// 保存指定的手指到指定的位置中
    /// </summary>
    /// <param name="handNumber">索引号 0表示左手</param>
    ///
    /// <param name="finger">手指信息</param>
    void SaveFingerData(int handIndex,
                        Finger.FingerType fingerType,
                        FingerData fingerData)
    {
        //将data保存或者覆盖到m_FingerDatas中
        if (m_FingerDatas[handIndex].ContainsKey(fingerType))
        {
            m_FingerDatas[handIndex][fingerType] = fingerData;
        }
        else
        {
            m_FingerDatas[handIndex].Add(fingerType, fingerData);
        }

        //保存或者覆盖到buffer中
        if (m_FingerDatasBuffer[handIndex, m_CurBufIndex].ContainsKey(fingerType))
        {
            m_FingerDatasBuffer[handIndex, m_CurBufIndex][fingerType] = fingerData;
        }
        else
        {
            m_FingerDatasBuffer[handIndex, m_CurBufIndex].Add(fingerType, fingerData);
        }
    }
コード例 #18
0
    /// <summary>
    /// 保存手的信息到指定的缓存中,也保存在当前数据中
    /// </summary>
    /// <param name="handIndex">Hand index.</param>
    /// <param name="hand">Hand.</param>
    /// <param name="curBufIndex">Current buffer index.</param>
    void SaveFingerDataWithHandIndex(Hand hand)
    {
        //做空判断好恶心,既然要求传入一个Hand,为什么你要传入一个null呢。
        //这里不做null的判断也不会有问题
        //if (hand != null)
        //{
        bool isLeft    = hand.IsLeft;
        int  handIndex = isLeft ? 0 : 1;

        foreach (Finger finger in hand.Fingers)
        {
            Finger.FingerType fingerType = finger.Type();

            Vector fingerDir = finger.Direction;

            // Bone bone = finger.Bone(Bone.BoneType.TYPE_DISTAL);
            // Vector distalPos = bone.Center;
            Vector distalPos = finger.TipPosition;
            //记录根骨位置
            Vector metacarpalPos = finger.Bone(Bone.BoneType.TYPE_METACARPAL).Center;

            //如果是拇指,用近端骨指的位置代替
            if (finger.Type() == Finger.FingerType.TYPE_THUMB)
            {
                metacarpalPos = finger.Bone(Bone.BoneType.TYPE_PROXIMAL).Center;
            }

            //将数据保存到m_FingerDatas中,以及buffer中。
            FingerData fingerData = new FingerData(distalPos, fingerDir, metacarpalPos);

            //Vector3 fingerPos = VectorTrans.ToUnityVector3(fingerData.m_Position);
            //s Vector3 fingerDistalPos = VectorTrans.ToUnityVector3(fingerData.m_Point.m_Position);
            SaveFingerData(handIndex, fingerType, fingerData);
        }
        //}
    }
コード例 #19
0
    /**
     * Copies the data from an internal finger definition into a finger.
     *
     * @param leapBone The internal finger definition to be copied into this finger.
     * @param type The finger type of this finger.
     * @param frameId The frame id of the frame this finger belongs to.
     * @param handId The hand id of the hand this finger belongs to.
     * @param timeVisible The time in seconds that this finger has been visible.
     */
    public static Finger CopyFrom(this Finger finger, LEAP_DIGIT leapBone, Finger.FingerType type, int handId, float timeVisible) {
      finger.Id = (handId * 10) + leapBone.finger_id;
      finger.HandId = handId;
      finger.TimeVisible = timeVisible;

      Bone metacarpal = finger.bones[0];
      Bone proximal = finger.bones[1];
      Bone intermediate = finger.bones[2];
      Bone distal = finger.bones[3];

      metacarpal.CopyFrom(leapBone.metacarpal, Leap.Bone.BoneType.TYPE_METACARPAL);
      proximal.CopyFrom(leapBone.proximal, Leap.Bone.BoneType.TYPE_PROXIMAL);
      intermediate.CopyFrom(leapBone.intermediate, Leap.Bone.BoneType.TYPE_INTERMEDIATE);
      distal.CopyFrom(leapBone.distal, Leap.Bone.BoneType.TYPE_DISTAL);

      finger.TipPosition = distal.NextJoint;
      finger.Direction = intermediate.Direction;
      finger.Width = intermediate.Width;
      finger.Length = (leapBone.finger_id == 0 ? 0.0f : 0.5f * proximal.Length) + intermediate.Length + 0.77f * distal.Length; //The values 0.5 for proximal and 0.77 for distal are used in platform code for this calculation
      finger.IsExtended = leapBone.is_extended != 0;
      finger.Type = type;

      return finger;
    }
コード例 #20
0
  /**
   * Returns Mecanim spread angle, which only applies to joint_type = 0
   * NOTE: Positive spread is towards thumb for index and middle,
   * but is in the opposite direction for the ring and pinky.
   * For the thumb negative spread rotates the thumb in to the palm.
   * */
  public float GetFingerJointSpreadMecanim() {
    // The successive actions of local rotations on a vector yield the global rotation,
    // so the inverse of the parent rotation appears on the left.
    Quaternion jointRotation = Quaternion.identity;
    if (finger_ != null) {
      jointRotation = Quaternion.Inverse (finger_.Bone ((Bone.BoneType)(0)).Basis.Rotation ()) 
        * finger_.Bone ((Bone.BoneType)(1)).Basis.Rotation ();
    } else if (bones [0] && bones [1]) {
      jointRotation = Quaternion.Inverse (GetBoneRotation (0)) * GetBoneRotation (1);
    }
    // Spread is a rotation around the Y axis of the base bone when joint_type = 0
    float spreadAngle = 0f;
    Finger.FingerType fType = fingerType;
    if (finger_ != null) { 
      fingerType = finger_.Type;
    }

    if (fType == Finger.FingerType.TYPE_INDEX ||
      fType == Finger.FingerType.TYPE_MIDDLE) {
      spreadAngle = jointRotation.eulerAngles.y;
      if (spreadAngle > 180f) {
        spreadAngle -= 360f;
      }
      // NOTE: eulerAngles range is [0, 360) so spreadAngle <= -180f will not occur.
    }
    if (fType == Finger.FingerType.TYPE_THUMB ||
      fType == Finger.FingerType.TYPE_RING ||
      fType == Finger.FingerType.TYPE_PINKY) {
      spreadAngle = -jointRotation.eulerAngles.y;
      if (spreadAngle <= -180f) {
        spreadAngle += 360f;
      }
      // NOTE: eulerAngles range is [0, 360) so spreadAngle > +180f will not occur.
    }
    return spreadAngle;
  }
コード例 #21
0
    public float AngleBetweenFingers(Hand hand, Finger.FingerType fingerType1 = Finger.FingerType.TYPE_THUMB, Finger.FingerType fingerType2 = Finger.FingerType.TYPE_INDEX)
    {
        /*zjisti uhel mezi dvema prsty*/
        Finger finger1 = null;
        Finger finger2 = null;

        foreach (Finger finger in hand.Fingers)
        {
            if (finger.Type() == fingerType1)
            {
                finger1 = finger;
            }
            else if (finger.Type() == fingerType2)
            {
                finger2 = finger;
            }
        }

        if (finger1 == null || finger2 == null)
        {
            return(-1);
        }

        float angle = finger1.Direction.AngleTo(finger2.Direction);

        return(angle * 180 / Mathf.PI);
    }
コード例 #22
0
        public Finger makeFinger(Frame owner, ref LEAP_HAND hand, ref LEAP_DIGIT digit, Finger.FingerType type)
        {
            Bone metacarpal   = makeBone(ref digit.metacarpal, Bone.BoneType.TYPE_METACARPAL);
            Bone proximal     = makeBone(ref digit.proximal, Bone.BoneType.TYPE_PROXIMAL);
            Bone intermediate = makeBone(ref digit.intermediate, Bone.BoneType.TYPE_INTERMEDIATE);
            Bone distal       = makeBone(ref digit.distal, Bone.BoneType.TYPE_DISTAL);

            return(new Finger((int)owner.Id,
                              (int)hand.id,
                              (int)digit.finger_id,
                              hand.visible_time,
                              distal.NextJoint,
                              new Vector(digit.tip_velocity.x, digit.tip_velocity.y, digit.tip_velocity.z),
                              intermediate.Direction,
                              new Vector(digit.stabilized_tip_position.x, digit.stabilized_tip_position.y, digit.stabilized_tip_position.z),
                              intermediate.Width,
                              proximal.Length + intermediate.Length + (distal.Length * 0.77f), //0.77 is used in platform code for this calculation
                              digit.is_extended != 0,
                              type,
                              metacarpal,
                              proximal,
                              intermediate,
                              distal
                              ));
        }
コード例 #23
0
    public void KeyBehaviour(Hand hand, Finger.FingerType fingerType)
    {
        Debug.Log(hand);
        if (hand.IsLeft && !GameManagerPiano.gm.leftFingers.Contains(fingerType))
        {
            return;
        }
        else if (hand.IsRight && !GameManagerPiano.gm.rightFingers.Contains(fingerType))
        {
            return;
        }

        int index = 0;

        if (hand.IsLeft)
        {
            index = leftKeysDic[fingerType];
        }
        else if (hand.IsRight)
        {
            index = rightKeysDic[fingerType];
        }

        if (keys[index])
        {
            if (keys[index].GetComponent <Animator>().GetBool("Blinking"))
            {
                keys[index].GetComponent <Animator>().SetBool("Blinking", false);
                keys[index].GetComponent <Animator>().Play("KeyPressed");
                keys[index].GetComponent <KeyBehaviourPiano>().PlayGoodSound();
                keys[index].GetComponentInChildren <ScoreFeedbackPiano>().ShowGreen();
                OkPinch(hand, fingerType);

                GameManagerPiano.gm.UpdateScore(1);
                if (GameManagerPiano.gm.useSimultaneous)
                {
                    if (index < 4)
                    {
                        StartCoroutine(DelayedNextLeftKey());
                    }
                    else
                    {
                        StartCoroutine(DelayedNextRightKey());
                    }
                }
                else if (GameManagerPiano.gm.useLeftHand && GameManagerPiano.gm.useRightHand)
                {
                    StartCoroutine(DelayedNextAnyKey());
                }
                else if (GameManagerPiano.gm.useLeftHand)
                {
                    StartCoroutine(DelayedNextLeftKey());
                }
                else if (GameManagerPiano.gm.useRightHand)
                {
                    StartCoroutine(DelayedNextRightKey());
                }
            }
            else
            {
                keys[index].GetComponent <Animator>().Play("KeyPressed");
                keys[index].GetComponent <KeyBehaviourPiano>().PlayBadSound();
                keys[index].GetComponentInChildren <ScoreFeedbackPiano>().ShowRed();
                GameManagerPiano.gm.UpdateScore(-1);
            }
        }
    }
コード例 #24
0
 public void SetFinger(Finger a_Finger)
 {
     m_Type   = a_Finger.Type;
     m_Finger = a_Finger;
 }
コード例 #25
0
    // Update is called once per frame
    void Update()
    {
        bool lefthandexit  = false;
        bool righthandexit = false;
        //Debug.Log ("Update");
        Vector3 fwd       = new Vector3(0, 0, 10);
        Frame   frame     = hc.GetFrame();
        Frame   lastframe = hc.getlastframe();

        apply_color = color_apply.gameObject.GetComponent <RGB> ().rgb;


        foreach (Hand hand in frame.Hands)
        {
            if (hand.IsLeft)
            {
                lefthandexit = true;
                lefthand     = hand;
            }

            if (hand.IsRight)
            {
                righthandexit = true;
                righthand     = hand;


                foreach (Finger finger in righthand.Fingers)
                {
                    Finger.FingerType type = finger.Type();
                    if (type == Finger.FingerType.TYPE_INDEX)
                    {
                        dx = finger.Direction.x;
                        dy = finger.Direction.y;
                        dz = finger.Direction.z;
                        hx = finger.TipPosition.x;
                        hy = finger.TipPosition.y;
                        hz = finger.TipPosition.z;
                    }
                }
                //dx = hand.Direction.x;
                //dy = hand.Direction.y;
                //dz = hand.Direction.z;
                handdir = new Vector3(dx * index, dy * index, -dz * index);

                //				----------------------------------------------------------------------


                //hx = hand.PalmPosition.x;
                //hy = hand.PalmPosition.y;
                //hz = hand.PalmPosition.z;
                handpos = new Vector3(hx * index, hy * index, -hz * index);

                //				----------------------------------------------------------
                //Debug.Log ("righthand_position is " + handpos + "righthand dir is " + handdir);
                //Debug.Log ("reall date is" + hand.PalmPosition + " /// " + hand.Direction);
                xr = hand.RotationAngle(lastframe, Vector.XAxis);
                yr = hand.RotationAngle(lastframe, Vector.YAxis);
                zr = hand.RotationAngle(lastframe, Vector.ZAxis);
            }
        }
        //cube.transform.Rotate (new Vector3(xr*index,yr*index,-zr*index),Space.World);


        /*
         * float x = this.transform.rotation.x;
         * float y = this.transform.rotation.y;
         * float z = this.transform.rotation.z;
         * Vector3 rota = new Vector3 (x, y, z);
         * Debug.Log ("this.position=" + this.transform.position);
         * dx = this.transform.position.x;
         * dy = this.transform.position.y;
         * dz = this.transform.position.z;
         * Vector3 position = new Vector3 (dx,dy+100,dz);
         *
         */



        if (squize(lefthand.SphereRadius) && (!squize(righthand.SphereRadius)))
        {
            //bool Physics.Raycast(Ray ray, Vector3 direction, RaycastHit out hit, float distance, int layerMask)
            if (Physics.Raycast(handpos, handdir, out hit, 10000, 1))
            {
                particle_light.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z - 2);


                if ((highlight.gameObject.name.ToString() != hit.collider.gameObject.name.ToString()) &&
                    origin == Color.black &&
                    (!IsHand(hit.collider)) &&
                    (hit.collider.gameObject.GetComponent <Renderer>() != null))
                {
                    Debug.Log("first");
                    highlight = hit.collider.gameObject;
                    control_script.main_son = hit.collider.gameObject;

                    origin = highlight.gameObject.GetComponent <Renderer> ().material.color;
                    highlight.gameObject.GetComponent <Renderer> ().material.color = Color.gray;
                }

                if ((highlight.gameObject.name.ToString() != hit.collider.gameObject.name.ToString()) &&
                    origin != Color.black &&
                    (!IsHand(hit.collider)) &&
                    ((hit.collider.gameObject.GetComponent <Renderer>() != null)))
                {
                    Debug.Log("change");
                    control_script.main_son = hit.collider.gameObject;

                    highlight.gameObject.GetComponent <Renderer> ().material.color = origin;
                    highlight = hit.collider.gameObject;
                    origin    = highlight.gameObject.GetComponent <Renderer> ().material.color;
                    highlight.gameObject.GetComponent <Renderer> ().material.color = Color.gray;
                }

                /*
                 * if((highlight.gameObject.name.ToString()==hit.collider.gameObject.name.ToString())&&origin!=Color.black)
                 * {
                 *      highlight = hit.collider.gameObject;
                 *      highlight.gameObject.GetComponent<Renderer> ().material.color = Color.red;
                 * }
                 */


                //hit.collider.gameObject.GetComponent<Renderer> ().material.color = Color.red;
                Debug.Log("OBJ-name is " + hit.collider.gameObject);
                //Debug.Log ("hit point is " + hit.point + " distance = " + hit.distance);
                //Debug.Log ("Success");
                Debug.DrawLine(handpos, hit.point, Color.red);
                Debug.Break();
            }



            if (lefthandexit == true)
            {
                Debug.Log("________________");
                //Debug.Break();
            }
        }
    }
コード例 #26
0
 private int getIndex(Finger.FingerType fingerType, Bone.BoneType boneType)
 {
     return((int)fingerType * 4 + (int)boneType);
 }
コード例 #27
0
 public Vector3 GetLocalPosition(Finger.FingerType fingerType, Bone.BoneType boneType)
 {
     return(_localPositions[getIndex(fingerType, boneType)]);
 }
コード例 #28
0
 public void SetGlobalPosition(Vector3 globalPosition, Finger.FingerType fingerType, Bone.BoneType boneType)
 {
     _localPositions[getIndex(fingerType, boneType)] = _inverseTransformMatrix.MultiplyPoint3x4(globalPosition);
 }
コード例 #29
0
 public void fillFinger(Finger toFill, long frameId, int handId, int fingerId, float timeVisible, Vector tipPosition, Vector tipVelocity, Vector direction, Vector stabilizedTipPosition, float width, float length, bool isExtended, Finger.FingerType type, Bone metacarpal, Bone proximal, Bone intermediate, Bone distal)
 {
     toFill.Id          = handId;
     toFill.HandId      = handId;
     toFill.TimeVisible = timeVisible;
     toFill.TipPosition = tipPosition;
     //toFill.TipVelocity = tipVelocity;                     // deprecated as of
     //toFill.StabilizedTipPosition = stabilizedTipPosition; // Core 4.4
     toFill.Direction  = direction;
     toFill.Width      = width;
     toFill.Length     = length;
     toFill.IsExtended = isExtended;
     toFill.Type       = type;
     toFill.bones[0]   = metacarpal;
     toFill.bones[1]   = proximal;
     toFill.bones[2]   = intermediate;
     toFill.bones[3]   = distal;
 }
コード例 #30
0
ファイル: HandBinderEditor.cs プロジェクト: LABSIM/APOLLON
 private SerializedProperty FingerOffsetPropertyFromLeapTypes(Finger.FingerType fingerType, Bone.BoneType boneType)
 {
     return(boundHand.FindPropertyRelative("fingers").GetArrayElementAtIndex((int)fingerType).FindPropertyRelative("boundBones").GetArrayElementAtIndex((int)boneType).FindPropertyRelative("offset"));
 }
コード例 #31
0
    void SaveData(Hand hand)
    {
        if (hand != null)
        {
            if (hand.IsRight)                           //右手
            {
                foreach (Finger finger in hand.Fingers) ///有可能有手指没有检测到·
                {
                    Finger.FingerType fingerType = finger.Type;
                    switch (fingerType)
                    {
                    case Finger.FingerType.TYPE_INDEX:
                        rightPosition[indexNow, 0] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_MIDDLE:
                        rightPosition[indexNow, 1] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_PINKY:
                        rightPosition[indexNow, 2] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_RING:
                        rightPosition[indexNow, 3] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_THUMB:
                        rightPosition[indexNow, 4] = finger.TipPosition;
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                foreach (Finger finger in hand.Fingers)  ///有可能有手指没有检测到·
                {
                    Finger.FingerType fingerType = finger.Type;
                    switch (fingerType)
                    {
                    case Finger.FingerType.TYPE_INDEX:
                        leftPosition[indexNow, 0] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_MIDDLE:
                        leftPosition[indexNow, 1] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_PINKY:
                        leftPosition[indexNow, 2] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_RING:
                        leftPosition[indexNow, 3] = finger.TipPosition;
                        break;

                    case Finger.FingerType.TYPE_THUMB:
                        leftPosition[indexNow, 4] = finger.TipPosition;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
    }