예제 #1
0
        public HandOffset GetHandOffset(ExternHandState other, float scale, int[] bonesParent, string[] boneMapping)
        {
            HandOffset handOffset = new HandOffset();

            handOffset.rootPositionOffset = (this.rootPosition - other.rootPosition) * scale;

            handOffset.rootRotationOffset = (rootRotation * Quaternion.Inverse(other.rootRotation)).eulerAngles;
            //handOffset.rootRotationOffset = (Quaternion.LookRotation(forward, up) * Quaternion.Inverse(Quaternion.LookRotation(other.forward,other.up))).eulerAngles;

            Dictionary <string, Vector3> childrenRotationOffset = new Dictionary <string, Vector3>();

            Quaternion[] offsets = new Quaternion[localBoneDirections.Length];
            for (int i = 0; i < localBoneDirections.Length; i++)
            {
                offsets[i] = Quaternion.FromToRotation(other.localBoneDirections[i], this.localBoneDirections[i]);
            }
            for (int i = 0; i < localBoneDirections.Length; i++)
            {
                Quaternion relativeOffset;
                if (bonesParent[i] == -1)
                {
                    relativeOffset = offsets[i];
                }
                else
                {
                    relativeOffset = offsets[i] * Quaternion.Inverse(offsets[bonesParent[i]]);
                }
                //childrenRotationOffset.Add(boneMapping[i],  relativeOffset.eulerAngles);
                childrenRotationOffset.Add(boneMapping[i], (relativeOffset * other.rootRotation).eulerAngles);
            }
            handOffset.childrenRotationOffset = childrenRotationOffset;
            return(handOffset);
        }
예제 #2
0
 /***
  * if handState is null, return false
  */
 public bool SetHandState(HandOffset handOffset)
 {
     if (handOffset == null)
     {
         return(false);
     }
     this.Reset();
     rootNode.localPosition += handOffset.rootPositionOffset;
     rootNode.Rotate(handOffset.rootRotationOffset);
     foreach (KeyValuePair <string, Vector3> childRotationOffse in handOffset.childrenRotationOffset)
     {
         if (!handBones.ContainsKey(childRotationOffse.Key))
         {
             Console.WriteLine("Wrong bone name: " + childRotationOffse.Key + "in input hand state!");
             continue;
         }
         handBones[childRotationOffse.Key].Rotate(childRotationOffse.Value);
     }
     return(true);
 }