当前位置:   article > 正文

unity远程协同共享leap手势

leap手势

1,本地leap手势数据的获取,并转换成字节码

通过leap获取手势各关节的点坐标时,默认顺序是从大拇指到小拇指为0---4,然后关节从掌心到指尖默认为从0--1--2--3--4

 

 

  1. using System.Collections.Generic;
  2. using System;
  3. using UnityEngine;
  4. using Leap;
  5. using Leap.Unity;
  6. using PersonShare;
  7. using ServerCommunication;
  8. public class LocalHands : MonoBehaviour
  9. {
  10. public int HandID;
  11. private LeapProvider mProvider;
  12. public RemoteHand LeftHand = new RemoteHand();
  13. public RemoteHand RightHand = new RemoteHand();
  14. private int numL = 0, numR = 0;
  15. private const int leapHandLen= 44 * 3 * sizeof(double) + 4 * sizeof(double);
  16. //string path = "D:/Works/DEMO/Hands/Assets/StreamingAssets/";
  17. private List<Vector3> Pos_Left = new List<Vector3>();
  18. private List<Vector3> Pos_Right = new List<Vector3>();
  19. private byte[] currentFrameLeft = new byte[leapHandLen];
  20. private byte[] currentFrameRight = new byte[leapHandLen];
  21. private byte[] currentFrameHands= new byte[2* leapHandLen];
  22. //some varibales to send the data of Leap hands
  23. public ClientManager clientManager;
  24. void Start()
  25. {
  26. mProvider = FindObjectOfType<LeapProvider>() as LeapProvider;
  27. }
  28. void LateUpdate()
  29. {
  30. //1 Get hand data
  31. Frame mFrame = mProvider.CurrentFrame;//获取当前帧
  32. Hands_Model(mFrame);
  33. // 2 Connect the server
  34. if (clientManager == null)
  35. return;
  36. TCPConnection myTCP = clientManager.TCP;
  37. MessageIDInfo msgHands = new MessageIDInfo(MessageTypes.MT_SHAREHANDS);
  38. msgHands.ID = BitConverter.GetBytes(HandID);
  39. /// 3 Transform the left hand data to bytes
  40. if (Pos_Left.Count == 0)
  41. {
  42. LeftHand.Arm.Direction = new Quaternion(0,0,0,0);
  43. for (int i = 0; i < 44; i++)
  44. {
  45. Pos_Left.Add(new Vector3(0, 0, 0));
  46. }
  47. }
  48. currentFrameLeft = EncodeLeftToByteArray();
  49. currentFrameLeft.CopyTo(currentFrameHands, 0);
  50. //4 Transform the right hand data to bytes
  51. if (Pos_Right.Count == 0)
  52. {
  53. RightHand.Arm.Direction = new Quaternion(0, 0, 0, 0);
  54. for (int i = 0; i < 44; i++)
  55. {
  56. Pos_Right.Add(new Vector3(0, 0, 0));
  57. }
  58. }
  59. currentFrameRight = EncodeRightToByteArray();
  60. currentFrameRight.CopyTo(currentFrameHands, leapHandLen);
  61. msgHands.Info = currentFrameHands;
  62. //5 send to server
  63. myTCP.WriteSocket(msgHands.ToByteArray());
  64. //File.WriteAllBytes(path+"LeftHand.bytes", currentFramesLeft);
  65. //Debug.Log("左手数据存储成功!");
  66. //6 clear the list
  67. if (numL >= 1)
  68. {
  69. Pos_Left.Clear();
  70. numL = 0;
  71. }
  72. if (numR >= 1)
  73. {
  74. Pos_Right.Clear();
  75. numR = 0;
  76. }
  77. }
  78. void Hands_Model(Frame mFrame)
  79. {
  80. foreach (var itemHands in mFrame.Hands)//遍历左右手
  81. {
  82. if (itemHands.IsLeft)
  83. {
  84. LeftHand.Wrist= new Vector3(itemHands.WristPosition.x, itemHands.WristPosition.y, itemHands.WristPosition.z);
  85. LeftHand.Palm = new Vector3(itemHands.PalmPosition.x, itemHands.PalmPosition.y, itemHands.PalmPosition.z);
  86. LeftHand.Arm.WristPosition = new Vector3(itemHands.Arm.NextJoint.x, itemHands.Arm.NextJoint.y, itemHands.Arm.NextJoint.z);
  87. LeftHand.Arm.ElbowPosition = new Vector3(itemHands.Arm.PrevJoint.x, itemHands.Arm.PrevJoint.y, itemHands.Arm.PrevJoint.z);
  88. LeftHand.Arm.Direction= new Quaternion(itemHands.Arm.Rotation.x, itemHands.Arm.Rotation.y, itemHands.Arm.Rotation.z, itemHands.Arm.Rotation.w);
  89. Pos_Left.Add(LeftHand.Wrist);
  90. Pos_Left.Add(LeftHand.Palm);
  91. Pos_Left.Add(LeftHand.Arm.WristPosition);
  92. Pos_Left.Add(LeftHand.Arm.ElbowPosition);
  93. foreach (var itemFingers in itemHands.Fingers)//五个手指,itemHands.Fingers[0]代表大拇指
  94. {
  95. foreach (var itemBones in itemFingers.bones)//骨头的四个骨关节,NextJoint代表靠近指尖的部分,
  96. //PrevJoint代表靠近手腕的位置
  97. {
  98. LeftHand.Finger.Bone.PrevJoint = new Vector3(itemBones.PrevJoint.x, itemBones.PrevJoint.y, itemBones.PrevJoint.z);
  99. LeftHand.Finger.Bone.NextJoint = new Vector3(itemBones.NextJoint.x, itemBones.NextJoint.y, itemBones.NextJoint.z);
  100. Pos_Left.Add(LeftHand.Finger.Bone.PrevJoint);
  101. Pos_Left.Add(LeftHand.Finger.Bone.NextJoint);
  102. }
  103. }
  104. numL++;
  105. }
  106. if (itemHands.IsRight)
  107. {
  108. RightHand.Wrist = new Vector3(itemHands.WristPosition.x, itemHands.WristPosition.y, itemHands.WristPosition.z);
  109. RightHand.Palm = new Vector3(itemHands.PalmPosition.x, itemHands.PalmPosition.y, itemHands.PalmPosition.z);
  110. RightHand.Arm.WristPosition = new Vector3(itemHands.Arm.NextJoint.x, itemHands.Arm.NextJoint.y, itemHands.Arm.NextJoint.z);
  111. RightHand.Arm.ElbowPosition = new Vector3(itemHands.Arm.PrevJoint.x, itemHands.Arm.PrevJoint.y, itemHands.Arm.PrevJoint.z);
  112. RightHand.Arm.Direction = new Quaternion(itemHands.Arm.Rotation.x, itemHands.Arm.Rotation.y, itemHands.Arm.Rotation.z, itemHands.Arm.Rotation.w);
  113. Pos_Right.Add(RightHand.Wrist);
  114. Pos_Right.Add(RightHand.Palm);
  115. Pos_Right.Add(RightHand.Arm.WristPosition);
  116. Pos_Right.Add(RightHand.Arm.ElbowPosition);
  117. foreach (var itemFingers in itemHands.Fingers)
  118. {
  119. foreach (var itemBones in itemFingers.bones)
  120. {
  121. RightHand.Finger.Bone.PrevJoint = new Vector3(itemBones.PrevJoint.x, itemBones.PrevJoint.y, itemBones.PrevJoint.z);
  122. RightHand.Finger.Bone.NextJoint = new Vector3(itemBones.NextJoint.x, itemBones.NextJoint.y, itemBones.NextJoint.z);
  123. Pos_Right.Add(RightHand.Finger.Bone.PrevJoint);
  124. Pos_Right.Add(RightHand.Finger.Bone.NextJoint);
  125. }
  126. }
  127. numR++;
  128. }
  129. }
  130. }
  131. public byte[] EncodeLeftToByteArray()//编码左手
  132. {
  133. int index = 0;
  134. byte[] qua_x = BitConverter.GetBytes((double)LeftHand.Arm.Direction.x);
  135. qua_x.CopyTo(currentFrameLeft, index);
  136. index += sizeof(double);
  137. byte[] qua_y = BitConverter.GetBytes((double)LeftHand.Arm.Direction.y);
  138. qua_y.CopyTo(currentFrameLeft, index);
  139. index += sizeof(double);
  140. byte[] qua_z = BitConverter.GetBytes((double)LeftHand.Arm.Direction.z);
  141. qua_z.CopyTo(currentFrameLeft, index);
  142. index += sizeof(double);
  143. byte[] qua_w = BitConverter.GetBytes((double)LeftHand.Arm.Direction.w);
  144. qua_w.CopyTo(currentFrameLeft, index);
  145. index += sizeof(double);
  146. for (int i = 0; i < 44; i++)
  147. {
  148. byte[] pos_x = BitConverter.GetBytes((double)Pos_Left[i].x);
  149. pos_x.CopyTo(currentFrameLeft, index);
  150. index += sizeof(double);
  151. byte[] pos_y = BitConverter.GetBytes((double)Pos_Left[i].y);
  152. pos_y.CopyTo(currentFrameLeft, index);
  153. index += sizeof(double);
  154. byte[] pos_z = BitConverter.GetBytes((double)Pos_Left[i].z);
  155. pos_z.CopyTo(currentFrameLeft, index);
  156. index += sizeof(double);
  157. }
  158. return currentFrameLeft;
  159. }
  160. public byte[] EncodeRightToByteArray()//编码右手
  161. {
  162. int index = 0;
  163. byte[] qua_x = BitConverter.GetBytes((double)RightHand.Arm.Direction.x);
  164. qua_x.CopyTo(currentFrameRight, index);
  165. index += sizeof(double);
  166. byte[] qua_y = BitConverter.GetBytes((double)RightHand.Arm.Direction.y);
  167. qua_y.CopyTo(currentFrameRight, index);
  168. index += sizeof(double);
  169. byte[] qua_z = BitConverter.GetBytes((double)RightHand.Arm.Direction.z);
  170. qua_z.CopyTo(currentFrameRight, index);
  171. index += sizeof(double);
  172. byte[] qua_w = BitConverter.GetBytes((double)RightHand.Arm.Direction.w);
  173. qua_w.CopyTo(currentFrameRight, index);
  174. index += sizeof(double);
  175. for (int i = 0; i < 44; i++)
  176. {
  177. byte[] pos_x = BitConverter.GetBytes((double)Pos_Right[i].x);
  178. pos_x.CopyTo(currentFrameRight, index);
  179. index += sizeof(double);
  180. byte[] pos_y = BitConverter.GetBytes((double)Pos_Right[i].y);
  181. pos_y.CopyTo(currentFrameRight, index);
  182. index += sizeof(double);
  183. byte[] pos_z = BitConverter.GetBytes((double)Pos_Right[i].z);
  184. pos_z.CopyTo(currentFrameRight, index);
  185. index += sizeof(double);
  186. }
  187. return currentFrameRight;
  188. }
  189. }

2, 远程接收字节码后,解析并赋给自己绘制的手势

 

  1. using System;
  2. using UnityEngine;
  3. using PersonShare;
  4. using System.IO;
  5. using System.Collections;
  6. class RemoteHands : MonoBehaviour
  7. {
  8. private const int leapHandLen = 44 * 3 * sizeof(double) + 4 * sizeof(double);
  9. public int HandID;
  10. public byte[] remoteFrameHands = new byte[2 * leapHandLen+sizeof(Int32)];
  11. private byte[] currentFramesLeft = new byte[leapHandLen];
  12. private byte[] currentFramesRight = new byte[leapHandLen];
  13. public RemoteHand Hand = new RemoteHand();
  14. string Leftpath = "D:/Works/DEMO/Hands/Assets/StreamingAssets/LeftHand.bytes";
  15. string Rightpath = "D:/Works/DEMO/Hands/Assets/StreamingAssets/RightHand.bytes";
  16. public const int NUM_Wrist = 1;
  17. public const int NUM_Palm = 1;
  18. public const int NUM_BONES = 20;
  19. public const int NUM_JOINTS = 42;
  20. public const int NUM_META = 12;
  21. public const int NUM_ARM = 4;
  22. public GameObject[] L_Wrist = new GameObject[NUM_Wrist];
  23. public GameObject[] L_Palm = new GameObject[NUM_Palm];
  24. public GameObject[] L_Bones = new GameObject[NUM_BONES];
  25. public GameObject[] L_Joints = new GameObject[NUM_JOINTS];
  26. public GameObject[] L_Meta = new GameObject[NUM_META];
  27. public GameObject[] L_Arm = new GameObject[NUM_ARM];
  28. public GameObject[] R_Wrist = new GameObject[NUM_Wrist];
  29. public GameObject[] R_Palm = new GameObject[NUM_Palm];
  30. public GameObject[] R_Bones = new GameObject[NUM_BONES];
  31. public GameObject[] R_Joints = new GameObject[NUM_JOINTS];
  32. public GameObject[] R_Meta = new GameObject[NUM_META];
  33. public GameObject[] R_Arm = new GameObject[NUM_ARM];
  34. IEnumerator Loadlefthandbyte(string path)
  35. {
  36. WWW www = new WWW(path);
  37. yield return www;
  38. LoadRemoteLeftHand(www.bytes);
  39. }
  40. IEnumerator Loadrighthandbyte(string path)
  41. {
  42. WWW www = new WWW(path);
  43. yield return www;
  44. LoadRemoteRightHand(www.bytes);
  45. }
  46. private void LateUpdate()
  47. {
  48. Buffer.BlockCopy(remoteFrameHands,0, currentFramesLeft,0, leapHandLen);
  49. Buffer.BlockCopy(remoteFrameHands, leapHandLen, currentFramesRight, 0, leapHandLen);
  50. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.L))
  51. {
  52. StartCoroutine(Loadlefthandbyte(Leftpath));
  53. Debug.Log("左手数据加载成功!");
  54. }
  55. else
  56. {
  57. LoadRemoteLeftHand(currentFramesLeft);
  58. //LoadRemoteLeftHand(LocalHands.currentFramesLeft);
  59. }
  60. if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.R))
  61. {
  62. StartCoroutine(Loadrighthandbyte(Rightpath));
  63. Debug.Log("右手数据加载成功!");
  64. }
  65. else
  66. {
  67. //LoadRemoteRightHand(LocalHands.currentFramesRight);
  68. LoadRemoteRightHand(currentFramesRight);
  69. }
  70. AddDataToJoins();
  71. }
  72. private void AddDataToJoins()
  73. {
  74. #region LeftHand
  75. #region Thumb
  76. BoneLenth(L_Joints[0], L_Joints[0], L_Bones[0]);
  77. BoneLenth(L_Joints[1], L_Joints[3], L_Bones[1]);
  78. BoneLenth(L_Joints[3], L_Joints[5], L_Bones[2]);
  79. BoneLenth(L_Joints[5], L_Joints[7], L_Bones[3]);
  80. #endregion
  81. #region Index
  82. BoneLenth(L_Joints[0], L_Joints[9], L_Bones[4]);
  83. BoneLenth(L_Joints[9], L_Joints[11], L_Bones[5]);
  84. BoneLenth(L_Joints[11], L_Joints[13], L_Bones[6]);
  85. BoneLenth(L_Joints[13], L_Joints[15], L_Bones[7]);
  86. #endregion
  87. #region Middle
  88. BoneLenth(L_Joints[16], L_Joints[17], L_Bones[8]);
  89. BoneLenth(L_Joints[17], L_Joints[19], L_Bones[9]);
  90. BoneLenth(L_Joints[19], L_Joints[21], L_Bones[10]);
  91. BoneLenth(L_Joints[21], L_Joints[23], L_Bones[11]);
  92. #endregion
  93. #region Ring
  94. BoneLenth(L_Joints[24], L_Joints[25], L_Bones[12]);
  95. BoneLenth(L_Joints[25], L_Joints[27], L_Bones[13]);
  96. BoneLenth(L_Joints[27], L_Joints[29], L_Bones[14]);
  97. BoneLenth(L_Joints[29], L_Joints[31], L_Bones[15]);
  98. #endregion
  99. #region Pinky
  100. BoneLenth(L_Joints[32], L_Joints[33], L_Bones[16]);
  101. BoneLenth(L_Joints[33], L_Joints[35], L_Bones[17]);
  102. BoneLenth(L_Joints[35], L_Joints[37], L_Bones[18]);
  103. BoneLenth(L_Joints[27], L_Joints[29], L_Bones[19]);
  104. #endregion
  105. #region Palm
  106. BoneLenth(L_Joints[0], L_Joints[8], L_Meta[0]);
  107. BoneLenth(L_Joints[8], L_Joints[16], L_Meta[1]);
  108. BoneLenth(L_Joints[16], L_Joints[24], L_Meta[2]);
  109. BoneLenth(L_Joints[24], L_Joints[32], L_Meta[3]);
  110. BoneLenth(L_Joints[9], L_Joints[17], L_Meta[4]);
  111. BoneLenth(L_Joints[17], L_Joints[25], L_Meta[5]);
  112. BoneLenth(L_Joints[25], L_Joints[33], L_Meta[6]);
  113. BoneLenth(L_Joints[0], L_Joints[32], L_Meta[7]);
  114. #endregion
  115. #region Arm
  116. BoneLenth(L_Arm[0], L_Arm[1], L_Meta[8]);
  117. BoneLenth(L_Arm[0], L_Arm[2], L_Meta[10]);
  118. BoneLenth(L_Arm[2], L_Arm[3], L_Meta[9]);
  119. BoneLenth(L_Arm[1], L_Arm[3], L_Meta[11]);
  120. #endregion
  121. #endregion
  122. #region RightHand
  123. #region Thumb
  124. BoneLenth(R_Joints[0], R_Joints[0], R_Bones[0]);
  125. BoneLenth(R_Joints[1], R_Joints[3], R_Bones[1]);
  126. BoneLenth(R_Joints[3], R_Joints[5], R_Bones[2]);
  127. BoneLenth(R_Joints[5], R_Joints[7], R_Bones[3]);
  128. #endregion
  129. #region Index
  130. BoneLenth(R_Joints[0], R_Joints[9], R_Bones[4]);
  131. BoneLenth(R_Joints[9], R_Joints[11], R_Bones[5]);
  132. BoneLenth(R_Joints[11], R_Joints[13], R_Bones[6]);
  133. BoneLenth(R_Joints[13], R_Joints[15], R_Bones[7]);
  134. #endregion
  135. #region Middle
  136. BoneLenth(R_Joints[16], R_Joints[17], R_Bones[8]);
  137. BoneLenth(R_Joints[17], R_Joints[19], R_Bones[9]);
  138. BoneLenth(R_Joints[19], R_Joints[21], R_Bones[10]);
  139. BoneLenth(R_Joints[21], R_Joints[23], R_Bones[11]);
  140. #endregion
  141. #region Ring
  142. BoneLenth(R_Joints[24], R_Joints[25], R_Bones[12]);
  143. BoneLenth(R_Joints[25], R_Joints[27], R_Bones[13]);
  144. BoneLenth(R_Joints[27], R_Joints[29], R_Bones[14]);
  145. BoneLenth(R_Joints[29], R_Joints[31], R_Bones[15]);
  146. #endregion
  147. #region Pinky
  148. BoneLenth(R_Joints[32], R_Joints[33], R_Bones[16]);
  149. BoneLenth(R_Joints[33], R_Joints[35], R_Bones[17]);
  150. BoneLenth(R_Joints[35], R_Joints[37], R_Bones[18]);
  151. BoneLenth(R_Joints[27], R_Joints[29], R_Bones[19]);
  152. #endregion
  153. #region Palm
  154. BoneLenth(R_Joints[0], R_Joints[8], R_Meta[0]);
  155. BoneLenth(R_Joints[8], R_Joints[16], R_Meta[1]);
  156. BoneLenth(R_Joints[16], R_Joints[24], R_Meta[2]);
  157. BoneLenth(R_Joints[24], R_Joints[32], R_Meta[3]);
  158. BoneLenth(R_Joints[9], R_Joints[17], R_Meta[4]);
  159. BoneLenth(R_Joints[17], R_Joints[25], R_Meta[5]);
  160. BoneLenth(R_Joints[25], R_Joints[33], R_Meta[6]);
  161. BoneLenth(R_Joints[0], R_Joints[32], R_Meta[7]);
  162. #endregion
  163. #region Arm
  164. BoneLenth(R_Arm[0], R_Arm[1], R_Meta[8]);
  165. BoneLenth(R_Arm[0], R_Arm[2], R_Meta[10]);
  166. BoneLenth(R_Arm[2], R_Arm[3], R_Meta[9]);
  167. BoneLenth(R_Arm[1], R_Arm[3], R_Meta[11]);
  168. #endregion
  169. #endregion
  170. }
  171. private void BoneLenth(GameObject J0, GameObject J1, GameObject Bone)
  172. {
  173. Vector3 from = new Vector3(0.0f, 1.0f, 0.0f);//开始轴线的方向
  174. Vector3 to = (J0.transform.position - J1.transform.position);//读取轴线的方向
  175. Vector3 zhou = Vector3.Cross(from, to);//两个向量的叉积
  176. float angle = Vector3.Angle(from, to);//默认夹角为0-180
  177. // b 到 a 的夹角
  178. float sign = Mathf.Sign(Vector3.Dot(zhou.normalized, Vector3.Cross(to.normalized, from.normalized)));//判断夹角的正负
  179. float signed_angle = angle * sign;
  180. Bone.transform.rotation = Quaternion.AngleAxis(angle, zhou);
  181. double distance = (Vector3.Distance(J0.transform.position, J1.transform.position)) / 2.0;
  182. float Dis = (float)distance;
  183. Bone.transform.localScale
  184. = new Vector3(Bone.transform.localScale.x, Dis, Bone.transform.localScale.z);
  185. Bone.transform.position = (J0.transform.position + J1.transform.position) / 2;
  186. }
  187. private void LoadRemoteLeftHand(byte[] frame)//左手解码,赋值
  188. {
  189. int index = 0;
  190. Hand.Arm.Direction.x= (float)BitConverter.ToDouble(frame, index);
  191. index += sizeof(double);
  192. Hand.Arm.Direction.y = (float)BitConverter.ToDouble(frame, index);
  193. index += sizeof(double);
  194. Hand.Arm.Direction.z = (float)BitConverter.ToDouble(frame, index);
  195. index += sizeof(double);
  196. Hand.Arm.Direction.w = (float)BitConverter.ToDouble(frame, index);
  197. index += sizeof(double);
  198. Hand.Wrist.x = (float)BitConverter.ToDouble(frame, index);
  199. index += sizeof(double);
  200. Hand.Wrist.y = (float)BitConverter.ToDouble(frame, index);
  201. index += sizeof(double);
  202. Hand.Wrist.z = (float)BitConverter.ToDouble(frame, index);
  203. L_Wrist[0].transform.position = new Vector3(Hand.Wrist.x, Hand.Wrist.y, Hand.Wrist.z);
  204. index += sizeof(double);
  205. Hand.Palm.x = (float)BitConverter.ToDouble(frame, index);
  206. index += sizeof(double);
  207. Hand.Palm.y = (float)BitConverter.ToDouble(frame, index);
  208. index += sizeof(double);
  209. Hand.Palm.z = (float)BitConverter.ToDouble(frame, index);
  210. L_Palm[0].transform.position = new Vector3(Hand.Palm.x, Hand.Palm.y, Hand.Palm.z);
  211. index += sizeof(double);
  212. Hand.Arm.WristPosition.x = (float)BitConverter.ToDouble(frame, index);
  213. index += sizeof(double);
  214. Hand.Arm.WristPosition.y = (float)BitConverter.ToDouble(frame, index);
  215. index += sizeof(double);
  216. Hand.Arm.WristPosition.z = (float)BitConverter.ToDouble(frame, index);
  217. L_Joints[40].transform.position = new Vector3(Hand.Arm.WristPosition.x, Hand.Arm.WristPosition.y, Hand.Arm.WristPosition.z);
  218. L_Joints[40].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);
  219. index += sizeof(double);
  220. Hand.Arm.ElbowPosition.x = (float)BitConverter.ToDouble(frame, index);
  221. index += sizeof(double);
  222. Hand.Arm.ElbowPosition.y = (float)BitConverter.ToDouble(frame, index);
  223. index += sizeof(double);
  224. Hand.Arm.ElbowPosition.z = (float)BitConverter.ToDouble(frame, index);
  225. L_Joints[41].transform.position = new Vector3(Hand.Arm.ElbowPosition.x, Hand.Arm.ElbowPosition.y, Hand.Arm.ElbowPosition.z);
  226. L_Joints[41].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);
  227. for (int i = 0; i < 40; i++)
  228. {
  229. float point_x=0, point_y=0, point_z=0;
  230. index += sizeof(double);
  231. point_x = (float)BitConverter.ToDouble(frame, index);
  232. index += sizeof(double);
  233. point_y = (float)BitConverter.ToDouble(frame, index);
  234. index += sizeof(double);
  235. point_z = (float)BitConverter.ToDouble(frame, index);
  236. L_Joints[i].transform.position = new Vector3(point_x, point_y, point_z);
  237. }
  238. }
  239. private void LoadRemoteRightHand(byte[] frame)//右手解码,赋值
  240. {
  241. int index = 0;
  242. Hand.Arm.Direction.x = (float)BitConverter.ToDouble(frame, index);
  243. index += sizeof(double);
  244. Hand.Arm.Direction.y = (float)BitConverter.ToDouble(frame, index);
  245. index += sizeof(double);
  246. Hand.Arm.Direction.z = (float)BitConverter.ToDouble(frame, index);
  247. index += sizeof(double);
  248. Hand.Arm.Direction.w = (float)BitConverter.ToDouble(frame, index);
  249. index += sizeof(double);
  250. Hand.Wrist.x = (float)BitConverter.ToDouble(frame, index);
  251. index += sizeof(double);
  252. Hand.Wrist.y = (float)BitConverter.ToDouble(frame, index);
  253. index += sizeof(double);
  254. Hand.Wrist.z = (float)BitConverter.ToDouble(frame, index);
  255. R_Wrist[0].transform.position = new Vector3(Hand.Wrist.x, Hand.Wrist.y, Hand.Wrist.z);
  256. index += sizeof(double);
  257. Hand.Palm.x = (float)BitConverter.ToDouble(frame, index);
  258. index += sizeof(double);
  259. Hand.Palm.y = (float)BitConverter.ToDouble(frame, index);
  260. index += sizeof(double);
  261. Hand.Palm.z = (float)BitConverter.ToDouble(frame, index);
  262. R_Palm[0].transform.position = new Vector3(Hand.Palm.x, Hand.Palm.y, Hand.Palm.z);
  263. index += sizeof(double);
  264. Hand.Arm.WristPosition.x = (float)BitConverter.ToDouble(frame, index);
  265. index += sizeof(double);
  266. Hand.Arm.WristPosition.y = (float)BitConverter.ToDouble(frame, index);
  267. index += sizeof(double);
  268. Hand.Arm.WristPosition.z = (float)BitConverter.ToDouble(frame, index);
  269. R_Joints[40].transform.position = new Vector3(Hand.Arm.WristPosition.x, Hand.Arm.WristPosition.y, Hand.Arm.WristPosition.z);
  270. R_Joints[40].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);
  271. index += sizeof(double);
  272. Hand.Arm.ElbowPosition.x = (float)BitConverter.ToDouble(frame, index);
  273. index += sizeof(double);
  274. Hand.Arm.ElbowPosition.y = (float)BitConverter.ToDouble(frame, index);
  275. index += sizeof(double);
  276. Hand.Arm.ElbowPosition.z = (float)BitConverter.ToDouble(frame, index);
  277. R_Joints[41].transform.position = new Vector3(Hand.Arm.ElbowPosition.x, Hand.Arm.ElbowPosition.y, Hand.Arm.ElbowPosition.z);
  278. R_Joints[41].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);
  279. for (int i = 0; i < 40; i++)
  280. {
  281. float point_x = 0, point_y = 0, point_z = 0;
  282. index += sizeof(double);
  283. point_x = (float)BitConverter.ToDouble(frame, index);
  284. index += sizeof(double);
  285. point_y = (float)BitConverter.ToDouble(frame, index);
  286. index += sizeof(double);
  287. point_z = (float)BitConverter.ToDouble(frame, index);
  288. R_Joints[i].transform.position = new Vector3(point_x, point_y, point_z);
  289. }
  290. }
  291. }

手势一个关节一个小球,中间用杆相连。

以上完成了手势数据的共享,但在远程端需要自己建手的三维模型

分为两步,一个是各关节点,一个是关节点的连杆。

两个关节点构成中间的连杆,连杆的

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/128029
推荐阅读
相关标签
  

闽ICP备14008679号