private void Awake()
 {
     for (int i = 0; i < _Avatars.Count; i++)
     {
         Debug.Log(i);
         localBodies.Add(CreateBody());
     }
     tmpBody = initSimpleBody();
 }
Exemplo n.º 2
0
    SimpleBody CombineSimpleBody(SimpleBody sb1, SimpleBody sb2)
    {
        for (int jt = 0; jt < sb2.Joints.Count; jt++)
        {
            sb1.Joints.Add(sb2.Joints[jt]);
        }

        return(sb1);
    }
Exemplo n.º 3
0
    // 受け取ったSimpleBodyを判別
    int DistinguishSimpleBody(SimpleBody sb)
    {
//		Debug.Log ("disting");
//		Debug.Log (sb.Joints.Count);
        if (sb.Joints.Count == 13)              // 13 = SimpleBody1の関節の数
        {
            return(1);
        }
        else if (sb.Joints.Count == 12)         // 12 = SimpleBody2の関節の数
        {
            return(2);
        }
        else
        {
            return(0);
        }
    }
Exemplo n.º 4
0
        }//end method

        private SimpleBody UpdateJoints(Body b) // COORDINATE MAPPING
        {
            var jointList = new SimpleBody();

            foreach (var joint in b.Joints.Values)
            {
                //if joint isnt tracked ignore
                if (joint.TrackingState != TrackingState.Tracked)
                {
                    continue;
                }

                // 3D space point
                var jointPosition = joint.Position;

                // 2D space point
                var point      = new Point();
                var colorPoint = _sensor.CoordinateMapper.MapCameraPointToColorSpace(jointPosition);

                point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
                point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;

                var simJoint = new SimpleJoint()
                {
                    Point = new Vector2((float)point.X / 16, (float)((-1.0 * point.Y) / 9)), //conversion to 16:9 ratio
                    Type  = joint.JointType
                };

                // Draw
                var ellipse = new Ellipse
                {
                    Fill   = Brushes.Blue,
                    Width  = Settings.Default.JointSize,
                    Height = Settings.Default.JointSize
                };

                Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
                Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);

                canvas.Children.Add(ellipse);
                jointList.Joints.Add(simJoint);
            }
            return(jointList);
        }
Exemplo n.º 5
0
    SimpleBody initSimpleBody()
    {
        var sb     = new SimpleBody();
        var joints = new List <SimpleJoint>();

        for (int jt = 0; jt <= 24; jt++)
        {
            var joint = new SimpleJoint();
            joint.Position      = Vector3.zero;
            joint.TrackingState = (int)Kinect.TrackingState.NotTracked;
            joint.X             = 0.0f;
            joint.Y             = 0.0f;
            joint.Z             = 0.0f;
            joint.W             = 0.0f;
            joints.Add(joint);
        }
        sb.Joints = joints;
        return(sb);
    }
Exemplo n.º 6
0
 private void Awake()
 {
     localBody = CreateBody();
     tmpBody   = initSimpleBody();
 }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
0
 void Awake()
 {
     body = GetComponent<SimpleBody>();
     time = GetComponent<SubjectiveTime>();
 }
    void Update()
    {
        if (BodySourceManager == null)
        {
            return;
        }

        _BodyManager = BodySourceManager.GetComponent <BodySourceManager>();
        if (_BodyManager == null)
        {
            return;
        }

        Kinect.Body[] data = _BodyManager.GetData();
        if (data == null)
        {
            return;
        }

        // 人数分の関節情報を送信
        SimpleBody simpleBody1 = new SimpleBody();              // Position, TrackingState
        SimpleBody simpleBody2 = new SimpleBody();              // Orientation

        byte[] sendData1;
        byte[] sendData2;
        for (int i = 0; i < Number; i++)
        {
            //if (data[i].IsTracked) {
            simpleBody1 = GenerateSimpleBody1(data[i]);
            simpleBody2 = GenerateSimpleBody2(data[i]);

            string serialisedMsg1 = JsonUtility.ToJson(simpleBody1);
            string serialisedMsg2 = JsonUtility.ToJson(simpleBody2);
            Debug.Log(serialisedMsg1 + serialisedMsg2);

            using (var memoryStream = new MemoryStream())
            {
                using (var gzipStream = new Unity.IO.Compression.GZipStream(memoryStream, Unity.IO.Compression.CompressionMode.Compress))
                    using (var writer = new StreamWriter(gzipStream))
                    {
                        writer.Write(serialisedMsg1);
                    }
                sendData1 = memoryStream.ToArray();
            }
            NetworkManager.SendPacketData(sendData1, UnityEngine.Networking.QosType.Unreliable);
            using (var memoryStream = new MemoryStream())
            {
                using (var gzipStream = new Unity.IO.Compression.GZipStream(memoryStream, Unity.IO.Compression.CompressionMode.Compress))
                    using (var writer = new StreamWriter(gzipStream))
                    {
                        writer.Write(serialisedMsg2);
                    }
                sendData2 = memoryStream.ToArray();
            }


            NetworkManager.SendPacketData(sendData2, UnityEngine.Networking.QosType.Unreliable);
            Debug.Log("sender update()");
            //}
        }
    }