unity远程协同共享leap手势

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

using System.Collections.Generic;
using System;
using UnityEngine;
using Leap;
using Leap.Unity;
using PersonShare;
using ServerCommunication;

public class LocalHands : MonoBehaviour
{
    public int HandID;
    private LeapProvider mProvider;
    public RemoteHand LeftHand = new RemoteHand();
    public RemoteHand RightHand = new RemoteHand();

    private int numL = 0, numR = 0;
    private const int leapHandLen= 44 * 3 * sizeof(double) + 4 * sizeof(double);

    //string path = "D:/Works/DEMO/Hands/Assets/StreamingAssets/";
    private  List<Vector3> Pos_Left = new List<Vector3>();
    private  List<Vector3> Pos_Right = new List<Vector3>();
    private byte[] currentFrameLeft = new byte[leapHandLen];
    private byte[] currentFrameRight = new byte[leapHandLen];
    private byte[] currentFrameHands= new byte[2* leapHandLen];

    //some varibales to send the data of Leap hands

    public ClientManager clientManager;
    void Start()
    {
        mProvider = FindObjectOfType<LeapProvider>() as LeapProvider;
    }
    void LateUpdate()
    {
        //1 Get hand data
        Frame mFrame = mProvider.CurrentFrame;//获取当前帧
        Hands_Model(mFrame);

        // 2 Connect the server
        if (clientManager == null)
            return;
        TCPConnection myTCP = clientManager.TCP;
        MessageIDInfo msgHands = new MessageIDInfo(MessageTypes.MT_SHAREHANDS);
        msgHands.ID = BitConverter.GetBytes(HandID);

        /// 3 Transform  the left hand data to bytes
        if (Pos_Left.Count == 0)
        {
            LeftHand.Arm.Direction = new Quaternion(0,0,0,0);  
            for (int i = 0; i < 44; i++)
            {
                Pos_Left.Add(new Vector3(0, 0, 0));
            }
        }
        currentFrameLeft = EncodeLeftToByteArray();
        currentFrameLeft.CopyTo(currentFrameHands, 0);

        //4 Transform the right hand data to bytes
        if (Pos_Right.Count == 0)
        {
            RightHand.Arm.Direction = new Quaternion(0, 0, 0, 0);
            for (int i = 0; i < 44; i++)
            {
                Pos_Right.Add(new Vector3(0, 0, 0));
            }
        }
        currentFrameRight = EncodeRightToByteArray();
        currentFrameRight.CopyTo(currentFrameHands, leapHandLen);
        msgHands.Info = currentFrameHands;
        //5 send to server
        myTCP.WriteSocket(msgHands.ToByteArray());

        //File.WriteAllBytes(path+"LeftHand.bytes", currentFramesLeft);
        //Debug.Log("左手数据存储成功!");

        //6 clear the list

        if (numL >= 1)
        {
                Pos_Left.Clear();
                numL = 0;
        }

        if (numR >= 1)
        {
            Pos_Right.Clear();
            numR = 0;
        }
    }
    void Hands_Model(Frame mFrame)
    {
        foreach (var itemHands in mFrame.Hands)//遍历左右手
        {
            if (itemHands.IsLeft)
            {
                LeftHand.Wrist= new Vector3(itemHands.WristPosition.x, itemHands.WristPosition.y, itemHands.WristPosition.z);
                LeftHand.Palm = new Vector3(itemHands.PalmPosition.x, itemHands.PalmPosition.y, itemHands.PalmPosition.z);
                LeftHand.Arm.WristPosition = new Vector3(itemHands.Arm.NextJoint.x, itemHands.Arm.NextJoint.y, itemHands.Arm.NextJoint.z);
                LeftHand.Arm.ElbowPosition = new Vector3(itemHands.Arm.PrevJoint.x, itemHands.Arm.PrevJoint.y, itemHands.Arm.PrevJoint.z);
                LeftHand.Arm.Direction= new Quaternion(itemHands.Arm.Rotation.x, itemHands.Arm.Rotation.y, itemHands.Arm.Rotation.z, itemHands.Arm.Rotation.w);
                

                Pos_Left.Add(LeftHand.Wrist);
                Pos_Left.Add(LeftHand.Palm);
                Pos_Left.Add(LeftHand.Arm.WristPosition);
                Pos_Left.Add(LeftHand.Arm.ElbowPosition);
                
                foreach (var itemFingers in itemHands.Fingers)//五个手指,itemHands.Fingers[0]代表大拇指
                {
                    foreach (var itemBones in itemFingers.bones)//骨头的四个骨关节,NextJoint代表靠近指尖的部分,
                                                                //PrevJoint代表靠近手腕的位置
                    {
                        LeftHand.Finger.Bone.PrevJoint = new Vector3(itemBones.PrevJoint.x, itemBones.PrevJoint.y, itemBones.PrevJoint.z);
                        LeftHand.Finger.Bone.NextJoint = new Vector3(itemBones.NextJoint.x, itemBones.NextJoint.y, itemBones.NextJoint.z);
                        Pos_Left.Add(LeftHand.Finger.Bone.PrevJoint);
                        Pos_Left.Add(LeftHand.Finger.Bone.NextJoint);
                    }
                }

                numL++;
            }
            if (itemHands.IsRight)
            {
                RightHand.Wrist = new Vector3(itemHands.WristPosition.x, itemHands.WristPosition.y, itemHands.WristPosition.z);
                RightHand.Palm = new Vector3(itemHands.PalmPosition.x, itemHands.PalmPosition.y, itemHands.PalmPosition.z);
                RightHand.Arm.WristPosition = new Vector3(itemHands.Arm.NextJoint.x, itemHands.Arm.NextJoint.y, itemHands.Arm.NextJoint.z);
                RightHand.Arm.ElbowPosition = new Vector3(itemHands.Arm.PrevJoint.x, itemHands.Arm.PrevJoint.y, itemHands.Arm.PrevJoint.z);
                RightHand.Arm.Direction = new Quaternion(itemHands.Arm.Rotation.x, itemHands.Arm.Rotation.y, itemHands.Arm.Rotation.z, itemHands.Arm.Rotation.w);

                Pos_Right.Add(RightHand.Wrist);
                Pos_Right.Add(RightHand.Palm);
                Pos_Right.Add(RightHand.Arm.WristPosition);
                Pos_Right.Add(RightHand.Arm.ElbowPosition);
                foreach (var itemFingers in itemHands.Fingers)
                {
                    foreach (var itemBones in itemFingers.bones)
                    {
                        RightHand.Finger.Bone.PrevJoint = new Vector3(itemBones.PrevJoint.x, itemBones.PrevJoint.y, itemBones.PrevJoint.z);
                        RightHand.Finger.Bone.NextJoint = new Vector3(itemBones.NextJoint.x, itemBones.NextJoint.y, itemBones.NextJoint.z);
                        Pos_Right.Add(RightHand.Finger.Bone.PrevJoint);
                        Pos_Right.Add(RightHand.Finger.Bone.NextJoint);
                    }
                }
                numR++;
            }
        }
    }
    public byte[] EncodeLeftToByteArray()//编码左手
    {
        int index = 0;
       
        byte[] qua_x = BitConverter.GetBytes((double)LeftHand.Arm.Direction.x);
        qua_x.CopyTo(currentFrameLeft, index);
        index += sizeof(double);
        byte[] qua_y = BitConverter.GetBytes((double)LeftHand.Arm.Direction.y);
        qua_y.CopyTo(currentFrameLeft, index);
        index += sizeof(double);
        byte[] qua_z = BitConverter.GetBytes((double)LeftHand.Arm.Direction.z);
        qua_z.CopyTo(currentFrameLeft, index);
        index += sizeof(double);
        byte[] qua_w = BitConverter.GetBytes((double)LeftHand.Arm.Direction.w);
        qua_w.CopyTo(currentFrameLeft, index);

        index += sizeof(double);
        for (int i = 0; i < 44; i++)
        {
        byte[] pos_x = BitConverter.GetBytes((double)Pos_Left[i].x);
        pos_x.CopyTo(currentFrameLeft, index);
        index += sizeof(double);
        byte[] pos_y = BitConverter.GetBytes((double)Pos_Left[i].y);
        pos_y.CopyTo(currentFrameLeft, index);
        index += sizeof(double);
        byte[] pos_z = BitConverter.GetBytes((double)Pos_Left[i].z);
        pos_z.CopyTo(currentFrameLeft, index);
        index += sizeof(double);
        }
        return currentFrameLeft;
    }
    public byte[] EncodeRightToByteArray()//编码右手
    {
        int index = 0;

        byte[] qua_x = BitConverter.GetBytes((double)RightHand.Arm.Direction.x);
        qua_x.CopyTo(currentFrameRight, index);
        index += sizeof(double);
        byte[] qua_y = BitConverter.GetBytes((double)RightHand.Arm.Direction.y);
        qua_y.CopyTo(currentFrameRight, index);
        index += sizeof(double);
        byte[] qua_z = BitConverter.GetBytes((double)RightHand.Arm.Direction.z);
        qua_z.CopyTo(currentFrameRight, index);
        index += sizeof(double);
        byte[] qua_w = BitConverter.GetBytes((double)RightHand.Arm.Direction.w);
        qua_w.CopyTo(currentFrameRight, index);

        index += sizeof(double);
        for (int i = 0; i < 44; i++)
        {
            byte[] pos_x = BitConverter.GetBytes((double)Pos_Right[i].x);
            pos_x.CopyTo(currentFrameRight, index);
            index += sizeof(double);
            byte[] pos_y = BitConverter.GetBytes((double)Pos_Right[i].y);
            pos_y.CopyTo(currentFrameRight, index);
            index += sizeof(double);
            byte[] pos_z = BitConverter.GetBytes((double)Pos_Right[i].z);
            pos_z.CopyTo(currentFrameRight, index);
            index += sizeof(double);
        }
        return currentFrameRight;
    }
}

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

using System;
using UnityEngine;
using PersonShare;
using System.IO;
using System.Collections;

class RemoteHands : MonoBehaviour
{
    private const int leapHandLen = 44 * 3 * sizeof(double) + 4 * sizeof(double);
    public int HandID;
    public byte[] remoteFrameHands = new byte[2 * leapHandLen+sizeof(Int32)];

    private byte[] currentFramesLeft = new byte[leapHandLen];
    private byte[] currentFramesRight = new byte[leapHandLen];

    public RemoteHand Hand = new RemoteHand();
    string Leftpath = "D:/Works/DEMO/Hands/Assets/StreamingAssets/LeftHand.bytes";
    string Rightpath = "D:/Works/DEMO/Hands/Assets/StreamingAssets/RightHand.bytes";
    public const int NUM_Wrist = 1;
    public const int NUM_Palm = 1;
    public const int NUM_BONES = 20;
    public const int NUM_JOINTS = 42;
    public const int NUM_META = 12;
    public const int NUM_ARM = 4;

    public GameObject[] L_Wrist = new GameObject[NUM_Wrist];
    public GameObject[] L_Palm = new GameObject[NUM_Palm];
    public GameObject[] L_Bones = new GameObject[NUM_BONES];
    public GameObject[] L_Joints = new GameObject[NUM_JOINTS];
    public GameObject[] L_Meta = new GameObject[NUM_META];
    public GameObject[] L_Arm = new GameObject[NUM_ARM];

    public GameObject[] R_Wrist = new GameObject[NUM_Wrist];
    public GameObject[] R_Palm = new GameObject[NUM_Palm];
    public GameObject[] R_Bones = new GameObject[NUM_BONES];
    public GameObject[] R_Joints = new GameObject[NUM_JOINTS];
    public GameObject[] R_Meta = new GameObject[NUM_META];
    public GameObject[] R_Arm = new GameObject[NUM_ARM];
    IEnumerator Loadlefthandbyte(string path)
    {
        WWW www = new WWW(path);
        yield return www;
        LoadRemoteLeftHand(www.bytes);
    }
    IEnumerator Loadrighthandbyte(string path)
    {
        WWW www = new WWW(path);
        yield return www;
        LoadRemoteRightHand(www.bytes);
    }
    private void LateUpdate()
    {

        Buffer.BlockCopy(remoteFrameHands,0, currentFramesLeft,0, leapHandLen);
        Buffer.BlockCopy(remoteFrameHands, leapHandLen, currentFramesRight, 0, leapHandLen);
        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.L))
        {
            StartCoroutine(Loadlefthandbyte(Leftpath));
            Debug.Log("左手数据加载成功!");
        }
        else
        {
            LoadRemoteLeftHand(currentFramesLeft);
            //LoadRemoteLeftHand(LocalHands.currentFramesLeft);

        }
        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(KeyCode.R))
        {
            StartCoroutine(Loadrighthandbyte(Rightpath));
            Debug.Log("右手数据加载成功!");
        }
        else
        {
            //LoadRemoteRightHand(LocalHands.currentFramesRight);
            LoadRemoteRightHand(currentFramesRight);
        }
        AddDataToJoins();
    }
    private void AddDataToJoins()
    {
        #region LeftHand
        #region Thumb
        BoneLenth(L_Joints[0], L_Joints[0], L_Bones[0]);
        BoneLenth(L_Joints[1], L_Joints[3], L_Bones[1]);
        BoneLenth(L_Joints[3], L_Joints[5], L_Bones[2]);
        BoneLenth(L_Joints[5], L_Joints[7], L_Bones[3]);
        #endregion

        #region Index
        BoneLenth(L_Joints[0], L_Joints[9], L_Bones[4]);
        BoneLenth(L_Joints[9], L_Joints[11], L_Bones[5]);
        BoneLenth(L_Joints[11], L_Joints[13], L_Bones[6]);
        BoneLenth(L_Joints[13], L_Joints[15], L_Bones[7]);
        #endregion

        #region Middle
        BoneLenth(L_Joints[16], L_Joints[17], L_Bones[8]);
        BoneLenth(L_Joints[17], L_Joints[19], L_Bones[9]);
        BoneLenth(L_Joints[19], L_Joints[21], L_Bones[10]);
        BoneLenth(L_Joints[21], L_Joints[23], L_Bones[11]);
        #endregion

        #region Ring
        BoneLenth(L_Joints[24], L_Joints[25], L_Bones[12]);
        BoneLenth(L_Joints[25], L_Joints[27], L_Bones[13]);
        BoneLenth(L_Joints[27], L_Joints[29], L_Bones[14]);
        BoneLenth(L_Joints[29], L_Joints[31], L_Bones[15]);
        #endregion

        #region Pinky
        BoneLenth(L_Joints[32], L_Joints[33], L_Bones[16]);
        BoneLenth(L_Joints[33], L_Joints[35], L_Bones[17]);
        BoneLenth(L_Joints[35], L_Joints[37], L_Bones[18]);
        BoneLenth(L_Joints[27], L_Joints[29], L_Bones[19]);
        #endregion

        #region Palm
        BoneLenth(L_Joints[0], L_Joints[8], L_Meta[0]);
        BoneLenth(L_Joints[8], L_Joints[16], L_Meta[1]);
        BoneLenth(L_Joints[16], L_Joints[24], L_Meta[2]);
        BoneLenth(L_Joints[24], L_Joints[32], L_Meta[3]);
        BoneLenth(L_Joints[9], L_Joints[17], L_Meta[4]);
        BoneLenth(L_Joints[17], L_Joints[25], L_Meta[5]);
        BoneLenth(L_Joints[25], L_Joints[33], L_Meta[6]);
        BoneLenth(L_Joints[0], L_Joints[32], L_Meta[7]);
        #endregion

        #region Arm
        BoneLenth(L_Arm[0], L_Arm[1], L_Meta[8]);
        BoneLenth(L_Arm[0], L_Arm[2], L_Meta[10]);
        BoneLenth(L_Arm[2], L_Arm[3], L_Meta[9]);
        BoneLenth(L_Arm[1], L_Arm[3], L_Meta[11]);
        #endregion

        #endregion

        #region RightHand
        #region Thumb
        BoneLenth(R_Joints[0], R_Joints[0], R_Bones[0]);
        BoneLenth(R_Joints[1], R_Joints[3], R_Bones[1]);
        BoneLenth(R_Joints[3], R_Joints[5], R_Bones[2]);
        BoneLenth(R_Joints[5], R_Joints[7], R_Bones[3]);
        #endregion

        #region Index
        BoneLenth(R_Joints[0], R_Joints[9], R_Bones[4]);
        BoneLenth(R_Joints[9], R_Joints[11], R_Bones[5]);
        BoneLenth(R_Joints[11], R_Joints[13], R_Bones[6]);
        BoneLenth(R_Joints[13], R_Joints[15], R_Bones[7]);
        #endregion

        #region Middle
        BoneLenth(R_Joints[16], R_Joints[17], R_Bones[8]);
        BoneLenth(R_Joints[17], R_Joints[19], R_Bones[9]);
        BoneLenth(R_Joints[19], R_Joints[21], R_Bones[10]);
        BoneLenth(R_Joints[21], R_Joints[23], R_Bones[11]);
        #endregion

        #region Ring
        BoneLenth(R_Joints[24], R_Joints[25], R_Bones[12]);
        BoneLenth(R_Joints[25], R_Joints[27], R_Bones[13]);
        BoneLenth(R_Joints[27], R_Joints[29], R_Bones[14]);
        BoneLenth(R_Joints[29], R_Joints[31], R_Bones[15]);
        #endregion

        #region Pinky
        BoneLenth(R_Joints[32], R_Joints[33], R_Bones[16]);
        BoneLenth(R_Joints[33], R_Joints[35], R_Bones[17]);
        BoneLenth(R_Joints[35], R_Joints[37], R_Bones[18]);
        BoneLenth(R_Joints[27], R_Joints[29], R_Bones[19]);
        #endregion

        #region Palm
        BoneLenth(R_Joints[0], R_Joints[8], R_Meta[0]);
        BoneLenth(R_Joints[8], R_Joints[16], R_Meta[1]);
        BoneLenth(R_Joints[16], R_Joints[24], R_Meta[2]);
        BoneLenth(R_Joints[24], R_Joints[32], R_Meta[3]);
        BoneLenth(R_Joints[9], R_Joints[17], R_Meta[4]);
        BoneLenth(R_Joints[17], R_Joints[25], R_Meta[5]);
        BoneLenth(R_Joints[25], R_Joints[33], R_Meta[6]);
        BoneLenth(R_Joints[0], R_Joints[32], R_Meta[7]);
        #endregion

        #region Arm
        BoneLenth(R_Arm[0], R_Arm[1], R_Meta[8]);
        BoneLenth(R_Arm[0], R_Arm[2], R_Meta[10]);
        BoneLenth(R_Arm[2], R_Arm[3], R_Meta[9]);
        BoneLenth(R_Arm[1], R_Arm[3], R_Meta[11]);
        #endregion

        #endregion
    }
    private void BoneLenth(GameObject J0, GameObject J1, GameObject Bone)
    {
        Vector3 from = new Vector3(0.0f, 1.0f, 0.0f);//开始轴线的方向
        Vector3 to = (J0.transform.position - J1.transform.position);//读取轴线的方向
        Vector3 zhou = Vector3.Cross(from, to);//两个向量的叉积
        float angle = Vector3.Angle(from, to);//默认夹角为0-180
        // b 到 a 的夹角
        float sign = Mathf.Sign(Vector3.Dot(zhou.normalized, Vector3.Cross(to.normalized, from.normalized)));//判断夹角的正负
        float signed_angle = angle * sign;
        Bone.transform.rotation = Quaternion.AngleAxis(angle, zhou);
        double distance = (Vector3.Distance(J0.transform.position, J1.transform.position)) / 2.0;
        float Dis = (float)distance;
        Bone.transform.localScale
            = new Vector3(Bone.transform.localScale.x, Dis, Bone.transform.localScale.z);
        Bone.transform.position = (J0.transform.position + J1.transform.position) / 2;
    }
    private void LoadRemoteLeftHand(byte[] frame)//左手解码,赋值
    {
        int index = 0;

        Hand.Arm.Direction.x= (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.Direction.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.Direction.z = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.Direction.w = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        
        Hand.Wrist.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Wrist.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Wrist.z = (float)BitConverter.ToDouble(frame, index);
        L_Wrist[0].transform.position = new Vector3(Hand.Wrist.x, Hand.Wrist.y, Hand.Wrist.z);

        index += sizeof(double);
        Hand.Palm.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Palm.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Palm.z = (float)BitConverter.ToDouble(frame, index);
        L_Palm[0].transform.position = new Vector3(Hand.Palm.x, Hand.Palm.y, Hand.Palm.z);

        index += sizeof(double);
        Hand.Arm.WristPosition.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.WristPosition.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.WristPosition.z = (float)BitConverter.ToDouble(frame, index);
        L_Joints[40].transform.position = new Vector3(Hand.Arm.WristPosition.x, Hand.Arm.WristPosition.y, Hand.Arm.WristPosition.z);
        L_Joints[40].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);

        index += sizeof(double);
        Hand.Arm.ElbowPosition.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.ElbowPosition.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.ElbowPosition.z = (float)BitConverter.ToDouble(frame, index);
        L_Joints[41].transform.position = new Vector3(Hand.Arm.ElbowPosition.x, Hand.Arm.ElbowPosition.y, Hand.Arm.ElbowPosition.z);
        L_Joints[41].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);

        for (int i = 0; i < 40; i++)
        {
        float point_x=0, point_y=0, point_z=0;

        index += sizeof(double);
        point_x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        point_y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        point_z = (float)BitConverter.ToDouble(frame, index);
        L_Joints[i].transform.position = new Vector3(point_x, point_y, point_z);
        }
    }
    private void LoadRemoteRightHand(byte[] frame)//右手解码,赋值
    {
        int index = 0;

        Hand.Arm.Direction.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.Direction.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.Direction.z = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.Direction.w = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);

        Hand.Wrist.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Wrist.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Wrist.z = (float)BitConverter.ToDouble(frame, index);
        R_Wrist[0].transform.position = new Vector3(Hand.Wrist.x, Hand.Wrist.y, Hand.Wrist.z);

        index += sizeof(double);
        Hand.Palm.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Palm.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Palm.z = (float)BitConverter.ToDouble(frame, index);
        R_Palm[0].transform.position = new Vector3(Hand.Palm.x, Hand.Palm.y, Hand.Palm.z);

        index += sizeof(double);
        Hand.Arm.WristPosition.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.WristPosition.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.WristPosition.z = (float)BitConverter.ToDouble(frame, index);
        R_Joints[40].transform.position = new Vector3(Hand.Arm.WristPosition.x, Hand.Arm.WristPosition.y, Hand.Arm.WristPosition.z);
        R_Joints[40].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);

        index += sizeof(double);
        Hand.Arm.ElbowPosition.x = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.ElbowPosition.y = (float)BitConverter.ToDouble(frame, index);
        index += sizeof(double);
        Hand.Arm.ElbowPosition.z = (float)BitConverter.ToDouble(frame, index);
        R_Joints[41].transform.position = new Vector3(Hand.Arm.ElbowPosition.x, Hand.Arm.ElbowPosition.y, Hand.Arm.ElbowPosition.z);
        R_Joints[41].transform.rotation = new Quaternion(Hand.Arm.Direction.x, Hand.Arm.Direction.y, Hand.Arm.Direction.z, Hand.Arm.Direction.w);

        for (int i = 0; i < 40; i++)
        {
            float point_x = 0, point_y = 0, point_z = 0;

            index += sizeof(double);
            point_x = (float)BitConverter.ToDouble(frame, index);
            index += sizeof(double);
            point_y = (float)BitConverter.ToDouble(frame, index);
            index += sizeof(double);
            point_z = (float)BitConverter.ToDouble(frame, index);
            R_Joints[i].transform.position = new Vector3(point_x, point_y, point_z);
        }
    }
}

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

猜你喜欢

转载自blog.csdn.net/moonlightpeng/article/details/85173582