예제 #1
0
    void OnDataReceived(object o, LLAPINetworkEventArgs e)
    {
        SimpleBody simpleBody = new SimpleBody();

        string output;
        var    data = e.data;

        using (var inStream = new MemoryStream(data))
            using (var bigStream = new System.IO.Compression.GZipStream(inStream, System.IO.Compression.CompressionMode.Decompress))
                using (var reader = new StreamReader(bigStream))
                {
                    output = reader.ReadToEnd();
                }

        simpleBody = JsonUtility.FromJson <SimpleBody>(output);
//		Debug.Log ("output");
        Debug.Log(DistinguishSimpleBody(simpleBody));
        Debug.Log(output);
//		Debug.Log ("simpleBody");
//		Debug.Log (DistinguishSimpleBody(simpleBody));
//		Debug.Log ("count");
//		Debug.Log (simpleBody.Joints.Count);

        if (DistinguishSimpleBody(tmpBody) == 1)
        {
            simpleBody = CombineSimpleBody(tmpBody, simpleBody);
            Debug.Log("SB1 SB2 combined");
            tmpBody = initSimpleBody();
            //Debug.Log(1);
        }
        else if (DistinguishSimpleBody(tmpBody) == 2)
        {
            simpleBody = CombineSimpleBody(simpleBody, tmpBody);
            Debug.Log("SB1 SB2 combined");
            tmpBody = initSimpleBody();
            //Debug.Log(2);
        }
        else if (DistinguishSimpleBody(tmpBody) == 0)
        {
            tmpBody = simpleBody;
            //Debug.Log(0);
        }
        Debug.Log("Count combine");
        Debug.Log(simpleBody.Joints.Count);

        // localBodyへsimpleBodyの値を代入
        if (simpleBody.Joints.Count == 25)
        {
            for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
            {
                var j  = localBody.Joints[jt];
                var sj = simpleBody.Joints[(int)jt];
                j.Position      = sj.Position;
                j.TrackingState = (Kinect.TrackingState)sj.TrackingState;
                j.Orientation   = ToVector4(sj.X / 10000, sj.Y / 10000, sj.Z / 10000, sj.W / 10000);
            }
        }

        // Bodyデータを取得する
        var joints = localBody.Joints;
        var comp   = Quaternion.FromToRotation(new Vector3(0, 0, 0), Vector3.up);

        Quaternion SpineBase;
        Quaternion SpineMid;
        Quaternion SpineShoulder;
        Quaternion ShoulderLeft;
        Quaternion ShoulderRight;
        Quaternion ElbowLeft;
        Quaternion WristLeft;
        Quaternion HandLeft;
        Quaternion ElbowRight;
        Quaternion WristRight;
        Quaternion HandRight;
        Quaternion KneeLeft;
        Quaternion AnkleLeft;
        Quaternion KneeRight;
        Quaternion AnkleRight;

        // 鏡
        if (IsMirror)
        {
            SpineBase     = joints[Kinect.JointType.SpineBase].Orientation.ToMirror().ToQuaternion(comp);
            SpineMid      = joints[Kinect.JointType.SpineMid].Orientation.ToMirror().ToQuaternion(comp);
            SpineShoulder = joints[Kinect.JointType.SpineShoulder].Orientation.ToMirror().ToQuaternion(comp);
            ShoulderLeft  = joints[Kinect.JointType.ShoulderRight].Orientation.ToMirror().ToQuaternion(comp);
            ShoulderRight = joints[Kinect.JointType.ShoulderLeft].Orientation.ToMirror().ToQuaternion(comp);
            ElbowLeft     = joints[Kinect.JointType.ElbowRight].Orientation.ToMirror().ToQuaternion(comp);
            WristLeft     = joints[Kinect.JointType.WristRight].Orientation.ToMirror().ToQuaternion(comp);
            HandLeft      = joints[Kinect.JointType.HandRight].Orientation.ToMirror().ToQuaternion(comp);
            ElbowRight    = joints[Kinect.JointType.ElbowLeft].Orientation.ToMirror().ToQuaternion(comp);
            WristRight    = joints[Kinect.JointType.WristLeft].Orientation.ToMirror().ToQuaternion(comp);
            HandRight     = joints[Kinect.JointType.HandLeft].Orientation.ToMirror().ToQuaternion(comp);
            KneeLeft      = joints[Kinect.JointType.KneeRight].Orientation.ToMirror().ToQuaternion(comp);
            AnkleLeft     = joints[Kinect.JointType.AnkleRight].Orientation.ToMirror().ToQuaternion(comp);
            KneeRight     = joints[Kinect.JointType.KneeLeft].Orientation.ToMirror().ToQuaternion(comp);
            AnkleRight    = joints[Kinect.JointType.AnkleLeft].Orientation.ToMirror().ToQuaternion(comp);
        }
        // そのまま
        else
        {
            SpineBase     = joints[Kinect.JointType.SpineBase].Orientation.ToQuaternion(comp);
            SpineMid      = joints[Kinect.JointType.SpineMid].Orientation.ToQuaternion(comp);
            SpineShoulder = joints[Kinect.JointType.SpineShoulder].Orientation.ToQuaternion(comp);
            ShoulderLeft  = joints[Kinect.JointType.ShoulderLeft].Orientation.ToQuaternion(comp);
            ShoulderRight = joints[Kinect.JointType.ShoulderRight].Orientation.ToQuaternion(comp);
            ElbowLeft     = joints[Kinect.JointType.ElbowLeft].Orientation.ToQuaternion(comp);
            WristLeft     = joints[Kinect.JointType.WristLeft].Orientation.ToQuaternion(comp);
            HandLeft      = joints[Kinect.JointType.HandLeft].Orientation.ToQuaternion(comp);
            ElbowRight    = joints[Kinect.JointType.ElbowRight].Orientation.ToQuaternion(comp);
            WristRight    = joints[Kinect.JointType.WristRight].Orientation.ToQuaternion(comp);
            HandRight     = joints[Kinect.JointType.HandRight].Orientation.ToQuaternion(comp);
            KneeLeft      = joints[Kinect.JointType.KneeLeft].Orientation.ToQuaternion(comp);
            AnkleLeft     = joints[Kinect.JointType.AnkleLeft].Orientation.ToQuaternion(comp);
            KneeRight     = joints[Kinect.JointType.KneeRight].Orientation.ToQuaternion(comp);
            AnkleRight    = joints[Kinect.JointType.AnkleRight].Orientation.ToQuaternion(comp);
        }

        // 関節の回転を計算する
        Quaternion q = transform.rotation;

        transform.rotation = Quaternion.identity;

        var comp2 = Quaternion.AngleAxis(-90, new Vector3(0, 1, 0)) *
                    Quaternion.AngleAxis(-0, new Vector3(0, 0, 1));

        Spine1.transform.rotation       = SpineMid * comp2;
        RightArm.transform.rotation     = ElbowRight * comp2;
        RightForeArm.transform.rotation = WristRight * Quaternion.AngleAxis(90, new Vector3(0, 1, 0)) *
                                          Quaternion.AngleAxis(-0, new Vector3(0, 0, 1));
        RightHand.transform.rotation = HandRight * comp2;

        LeftArm.transform.rotation     = ElbowLeft * comp2;
        LeftForeArm.transform.rotation = WristLeft * comp2;
        LeftHand.transform.rotation    = HandLeft * comp2;

        RightUpLeg.transform.rotation = KneeRight * comp2;
        RightLeg.transform.rotation   = AnkleRight * comp2;

        RightArm.transform.rotation     = ElbowRight * Quaternion.AngleAxis(90, new Vector3(0, 1, 0));
        RightForeArm.transform.rotation = WristRight * Quaternion.AngleAxis(90, new Vector3(0, 1, 0));

        LeftUpLeg.transform.rotation  = KneeLeft * Quaternion.AngleAxis(0, new Vector3(0, 0, 1));
        LeftLeg.transform.rotation    = AnkleLeft * Quaternion.AngleAxis(0, new Vector3(0, 0, 1));
        LeftUpLeg.transform.rotation  = KneeLeft * Quaternion.AngleAxis(180, new Vector3(0, 1, 0));
        LeftLeg.transform.rotation    = AnkleLeft * Quaternion.AngleAxis(180, new Vector3(0, 1, 0));
        RightUpLeg.transform.rotation = KneeRight * Quaternion.AngleAxis(0, new Vector3(0, 1, 0));
        RightLeg.transform.rotation   = AnkleRight * Quaternion.AngleAxis(0, new Vector3(0, 1, 0));

        // モデルの回転を設定する
        transform.rotation = q;

        // モデルの位置を移動する
        var pos = localBody.Joints[Kinect.JointType.SpineMid].Position;

        Ref.transform.position = new Vector3(-pos.x, pos.y, -pos.z);
    }
예제 #2
0
 void OnDataReceived(object o, LLAPINetworkEventArgs args)
 {
     Debug.Log("texture data received");
     ApplyTextureData(args.data);
 }