コード例 #1
0
        /// <summary>
        /// Get pointing direction if the hand is pointing a direction, relative to the controller.
        /// </summary>
        /// <param name="HandID">Hand ID</param>
        /// <returns>Pointing direction vector for the given hand or null if it does not exist or point in a direction</returns>
        public Vector3?PointingDirection(int HandID = 0)
        {
            int Fingers = ExtendedFingers(HandID);

            if (((Fingers == 1 || Fingers == 2)) && LastFrame.Hands.Count > HandID)
            {
                foreach (Finger CheckedFinger in LastFrame.Hands[HandID].Fingers)
                {
                    if (CheckedFinger.IsExtended)
                    {
                        Vector TipPos  = CheckedFinger.Bone(Bone.BoneType.TYPE_DISTAL).Basis.translation,
                                PreTip = CheckedFinger.Bone(Bone.BoneType.TYPE_INTERMEDIATE).Basis.translation;
                        return(new Vector3(TipPos.x - PreTip.x, TipPos.y - PreTip.y, TipPos.z - PreTip.z).normalized);
                    }
                }
            }
            return(null);
        }
コード例 #2
0
 /// <summary>
 /// Get a hand's rotation by averaging where each finger's base points.
 /// </summary>
 /// <param name="HandID">Hand ID</param>
 /// <returns>Hand rotation</returns>
 public Quaternion?HandRotation(int HandID = 0)
 {
     if (LastFrame.Hands.Count > HandID)
     {
         Vector3 Pointing = Vector3.zero;
         foreach (Finger CheckedFinger in LastFrame.Hands[HandID].Fingers)
         {
             if (CheckedFinger.Type != Finger.FingerType.TYPE_THUMB)
             {
                 Vector Base = CheckedFinger.Bone(CheckedFinger.IsExtended ? Bone.BoneType.TYPE_PROXIMAL : Bone.BoneType.TYPE_METACARPAL).Basis.translation,
                         End = CheckedFinger.Bone(CheckedFinger.IsExtended ? Bone.BoneType.TYPE_INTERMEDIATE : Bone.BoneType.TYPE_PROXIMAL).Basis.translation;
                 Pointing += new Vector3(End.x - Base.x, End.y - Base.y, End.z - Base.z);
             }
         }
         if (Pointing != Vector3.zero)
         {
             Vector  PalmNormal = LastFrame.Hands[HandID].PalmNormal;
             Vector3 Forward    = Quaternion.LookRotation(Pointing, Vector3.up).eulerAngles;
             Vector3 Normal     = Quaternion.FromToRotation(Vector3.up, new Vector3(PalmNormal.x, PalmNormal.y, PalmNormal.z)).eulerAngles;
             return(Quaternion.Euler(-Forward.x, -Forward.y, -Normal.z));
         }
     }
     return(null);
 }