Guest User

Untitled

a guest
May 25th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1.         public int ID;
  2.         public int Parent;
  3.         public Quaternion Direction;
  4.         public Vector3 Translation;
  5. //seems to work
  6.         public Bone(int id, int parent, Quaternion direction, Vector3 translation)
  7.         {
  8.             ID = id;
  9.             Parent = parent;
  10.             Direction = direction;
  11.             Translation = translation;
  12.         }
  13. //not so much
  14.         public Bone(Bone[] bones, int id, int parent, Vector3 dest)
  15.         {
  16.             ID = id;
  17.             Parent = parent;      
  18.             Vector3 bonepos = dest;
  19.             Vector3 parentbonepos = bones[parent].GetBindTranslation(bones);
  20.             //(length)
  21.             Translation = new Vector3(0,0, (bonepos - parentbonepos).Length());
  22.             Vector3 notneeded;
  23.             Vector3 alsonotneeded;
  24.             Matrix.CreateLookAt(bonepos,parentbonepos,  Vector3.Up).Decompose(out notneeded, out Direction, out alsonotneeded);
  25.         }
  26.         public Matrix GetBindPose(Bone[] bones)
  27.         {
  28.             if(Parent == -1)
  29.                 return Matrix.CreateTranslation(Translation)*Matrix.CreateFromQuaternion(Direction);
  30.             return Matrix.CreateTranslation(Translation) * Matrix.CreateFromQuaternion(Direction) * bones[Parent].GetBindPose(bones);
  31.         }
  32.         public Vector3 GetBindTranslation(Bone[] bones)
  33.         {
  34.                 return Vector3.Transform(Vector3.Zero, GetBindPose(bones));
  35.          
  36.         }
Add Comment
Please, Sign In to add comment