Esempio n. 1
0
    public GameObject CreateBodyObject(Kinect.Body kinectBody)
    {
        GameObject body = new GameObject("Body:" + kinectBody.TrackingId);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = new GameObject();
            if (ShowSkeleton)
            {
                jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                LineRenderer lr = jointObj.AddComponent <LineRenderer>();
                lr.SetVertexCount(2);
                lr.material = BoneMaterial;
                lr.SetWidth(0.05f, 0.05f);
            }

            jointObj.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        Kinect.Joint Neck        = kinectBody.Joints[Kinect.JointType.Neck];
        Kinect.Joint SpineMid    = kinectBody.Joints[Kinect.JointType.SpineMid];
        float        TorsoLength = GetBoneSize(Neck, SpineMid);

        // TorsoLength is .30 (about a foot) for me (6'1").
        transform.parent.localScale = new Vector3(TorsoLength * BODY_SCALE, TorsoLength * BODY_SCALE, TorsoLength * BODY_SCALE);

        return(body);
    }
    void SetBoneTransform(GameObject obj, Kinect.JointType type, Kinect.Body _body)
    {
        obj.transform.position = KPos2Vec3(type, _body);
        obj.transform.rotation = Vec4ToQ(type, _body);

        obj.name = type.ToString();
    }
Esempio n. 3
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        // Vector3 sizeAdjust = new Vector3(5f, 5f, 5f);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.positionCount = 2;
            lr.material      = BoneMaterial;
            lr.startWidth    = 0.05f;
            lr.endWidth      = 0.05f;

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name = jt.ToString();

            jointObj.transform.parent = body.transform;

            /*
             * Vector3 currentPos = jointObj.transform.parent.position;
             * currentPos = Vector3.Scale(currentPos, sizeAdjust);
             * jointObj.transform.parent.position = currentPos;
             */
        }

        return(body);
    }
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);


            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            jointObj.transform.localScale = new Vector3(0, 0, 0);
            if (DrawSkeleton)
            {
                lr.SetWidth(0.05f, 0.05f);
            }
            else
            {
                lr.SetWidth(0, 0);
            }

            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 5
0
    // Create a new game object containing a marker for every joint as children
    private GameObject CreateBody(ulong id)
    {
        GameObject body = new GameObject();

        body.name             = "Body:" + id;
        body.transform.parent = transform;

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject joint = (GameObject)Object.Instantiate(marker);
            joint.name             = jt.ToString();
            joint.transform.parent = body.transform;
        }

        // Text boxes for some body joints
        // ---> Spine
        GameObject spineBox = (GameObject)Object.Instantiate(textBox);

        spineBox.name             = "Spine angles";
        spineBox.transform.parent = body.transform;

        // ---> Right shoulder
        GameObject rightShoulderBox = (GameObject)Object.Instantiate(textBox);

        rightShoulderBox.name             = "Right shoulder angles";
        rightShoulderBox.transform.parent = body.transform;

        return(body);
    }
Esempio n. 6
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj;
            if (jt == Kinect.JointType.Head || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight)
            {
                jointObj = GameObject.Instantiate(jointPrefab);
            }
            else if (jt == Kinect.JointType.SpineMid)
            {
                jointObj = GameObject.Instantiate(bodyPrefab);
            }
            else
            {
                jointObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            }

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);


            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }
        return(body);
    }
    void SetBoneTransform(GameObject bone, Kinect.JointType type)
    {
        bone.transform.position      = kinectPos2Vec3(type);
        bone.transform.localRotation = Vec4toQuaternion(type);

        bone.name = type.ToString();
    }
Esempio n. 8
0
    public Vector3 mirrorSpaceTransform(Body body, Windows.Kinect.JointType joint)
    {
        //Caculate MirrorSpace points
        Vector3    realHeadPos        = kinectPossitionTransforms(body, JointType.Head);
        Vector3    reflectionJointPos = reflectionTransform(body, joint);
        RaycastHit hit;

        Vector3 dir = (reflectionJointPos - realHeadPos).normalized;

        //Debug.Log("HeadRayDIR:: " + dir.ToString());

        Ray r = new Ray(realHeadPos, dir);

        //TODO should take into acount the rotation of the head - the direction should be betwwen the head and where the look ray intersects with the reflection plane
        //TODO should do this with line intersects plane not raycasting
        if (Physics.Raycast(r, out hit, 4.0f, layerMask))
        {
            if (hit.collider.tag == "Mirror")
            {
                //Debug.Log("HitPoint1::" + hit.point.ToString());
                return((Vector3)hit.point);
            }
        }

        return(Vector3.zero);
    }
Esempio n. 9
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        body.transform.localScale = new Vector3(12.0f, 12.0f, 12.0f);

        int i = 0;

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            if (jt.ToString() == "HandLeft" || jt.ToString() == "HandRight")
            {
                GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Capsule);

                jointObj.transform.localScale = new Vector3(50.0f, 25.0f, 50.0f);
                jointObj.name             = jt.ToString();
                jointObj.transform.parent = body.transform;

                Renderer rend = jointObj.GetComponent <Renderer>();
                rend.enabled = false;

                // add our colliders to the cloth gameobject as defined above
                cap[i]             = jointObj.GetComponent <CapsuleCollider>();
                c.capsuleColliders = cap;
                i++;
            }
        }

        return(body);
    }
Esempio n. 10
0
    public Quaternion kinectRotationTransform(Body body, Windows.Kinect.JointType joint)
    {
        //Correct for kinect rotation
        Quaternion rot = new Quaternion(body.JointOrientations[joint].Orientation.X, body.JointOrientations[joint].Orientation.Y, body.JointOrientations[joint].Orientation.Z, body.JointOrientations[joint].Orientation.W);

        return(_kinectRotation * rot);
    }
Esempio n. 11
0
    public Vector3 reflectionTransform(Body body, Windows.Kinect.JointType joint)
    {
        //Caculate Vertual reflected points
        Vector3 pos = kinectPossitionTransforms(body, joint);

        return(new Vector3(pos.x, pos.y, -1.0f * pos.z));
    }
Esempio n. 12
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //unrender cubes
            jointObj.GetComponent <Renderer>().enabled = false;

            /*
             * LineRenderer lr = jointObj.AddComponent<LineRenderer>();
             * lr.SetVertexCount(2);
             * lr.material = BoneMaterial;
             * lr.SetWidth(0.05f, 0.05f);
             */

            jointObj.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }
        body.transform.SetParent(this.transform);
        body.transform.localPosition = Vector3.zero;
        body.transform.localRotation = Quaternion.identity;
        return(body);
    }
Esempio n. 13
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        TrackingPoints tracker = new TrackingPoints();

        _TrackerMap[body] = tracker;

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            if (jt == Kinect.JointType.WristLeft || jt == Kinect.JointType.WristRight)
            {
                GameObject cube = Instantiate(HandTracker);
                tracker.TrackerMap[jt] = cube;
            }
            lr.SetWidth(SIZE_BONE, SIZE_BONE);

            jointObj.transform.localScale = new Vector3(SIZE_JOINT, SIZE_JOINT, SIZE_JOINT);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 14
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);

            /*
             * //影の影響を受けないようにする
             * var meshRenderer = jointObj.GetComponent<MeshRenderer>();
             * meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
             * meshRenderer.receiveShadows = false;
             */
            //可視オブジェクトはこちらで用意する
            jointObj.GetComponent <MeshRenderer>().enabled = false;

            //位置だけ見れればいい
            jointObj.GetComponent <BoxCollider>().enabled = false;


            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 15
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            // 関節のCubeを生成する
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            jointObj.transform.tag = "Body";
            jointObj.AddComponent <bodyScript> ();
            jointObj.GetComponent <Renderer> ().enabled = false;
            Vector3 v = jointObj.transform.position;
            jointObj.transform.position = new Vector3(v.x, v.y, 0);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(1f, 1f);

            jointObj.transform.localScale = new Vector3(1, 1, 1);
            //jointObj.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 16
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        filter.UpdateFilter(ref body);
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.HandRight; jt++)
        {
            //Kinect.Joint sourceJoint = body.Joints [jt];
            GameObject avatarSpineBase            = GameObject.FindGameObjectsWithTag(Kinect.JointType.SpineBase.ToString())[0];
            Transform  jointObj                   = bodyObject.transform.FindChild(jt.ToString());
            Kinect.CameraSpacePoint jointPosition = filter.FilteredJoints[jt].Position;
            jointPosition.Z = -jointPosition.Z;
            jointDataRecorder.Append(string.Format("{0},{1},{2},{3}", System.DateTime.Now, jointPosition.X, jointPosition.Y, jointPosition.Z));

            if (jt == Kinect.JointType.SpineBase)
            {
                transformDistance = new Vector3(jointPosition.X - avatarSpineBase.transform.position.x,
                                                jointPosition.Y - avatarSpineBase.transform.position.y,
                                                jointPosition.Z - avatarSpineBase.transform.position.z);
            }

            jointObj.position = new Vector3((jointPosition.X - transformDistance.x),
                                            (jointPosition.Y - transformDistance.y),
                                            (jointPosition.Z - transformDistance.z));

            /*if (jt <= Kinect.JointType.ShoulderLeft || jt == Kinect.JointType.ShoulderRight) {
             *                  GameObject avatarJoint = GameObject.FindGameObjectsWithTag (jt.ToString ()) [0];
             *                  avatarJoint.transform.position = jointObj.transform.position;
             *          }*/
        }
        jointDataRecorder.Append("\n");
    }
Esempio n. 17
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        float scale      = 0.1f;
        int   scale_line = 2;
        float line_width = 0.1f;

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(scale_line);
            lr.material = BoneMaterial;
            lr.SetWidth(line_width, line_width);

            jointObj.transform.localScale = new Vector3(scale, scale, scale);

            jointObj.transform.position = jointObj.transform.position;
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 18
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            if (jt == Kinect.JointType.Head)
            {
                jointObj.SetActive(false);
            }

            if (jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight)
            {
                jointObj.SetActive(false);
            }

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);

            jointObj.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;

            jointObj.transform.position = new Vector3(0.0f, 0.0f, 0.0f);
        }

        return(body);
    }
Esempio n. 19
0
    private void RefreshBodyObject(EmitBody body, GameObject bodyObject)
    {
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint?targetJoint = null;

            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints[_BoneMap[jt]];
            }

            Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint, groundPosition);
            jointObj.RotateAround(RotationPivot, transform.up, RotationCoef);

            LineRenderer lr = jointObj.GetComponent <LineRenderer>();
            if (targetJoint.HasValue)
            {
                lr.SetPosition(0, jointObj.localPosition);

                Vector3 endpoint = RotateAroundPoint(GetVector3FromJoint(targetJoint.Value, groundPosition), RotationPivot, Quaternion.Euler(0, RotationCoef, 0));
                lr.SetPosition(1, endpoint);
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Esempio n. 20
0
 //更新所有骨架物件的位置與關節之間的連線。
 private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
 {
     //以迴圈的方式將所有的骨骼一個一個的去計算。
     for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
     {
         //抓取到來源關節,以及重置目標關節為空物件。
         Kinect.Joint sourceJoint = body.Joints[jt];
         Kinect.Joint?targetJoint = null;
         //運用Key和Velue的關係讀取目標關節。
         if (_BoneMap.ContainsKey(jt))
         {
             targetJoint = body.Joints[_BoneMap[jt]];
         }
         //讀取出骨頭線段的出發點,也就是目前關節的位置。
         Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
         jointObj.localPosition = GetVector3FromJoint(sourceJoint);
         //讀取關節的LineRenderer,如果有目標關節的話,賦予其座標0和座標1的位置,同時設定骨頭線段的顏色。
         LineRenderer lr = jointObj.GetComponent <LineRenderer>();
         if (targetJoint.HasValue)
         {
             lr.SetPosition(0, jointObj.localPosition);
             lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
             lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
         }
         //如果沒有目標關節的話,代表此為末端關節,不需要LineRenderer,將其關閉。
         else
         {
             lr.enabled = false;
         }
     }
 }
Esempio n. 21
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body");

        body.transform.position += Vector3.down * 100;
        body.transform.SetParent(FindObjectOfType <GameControl>().transform); ///Body is singleton


        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);

            lr.enabled = false;

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            if (jt == Kinect.JointType.Head)
            {
                Debug.Log(jt);

                // プレハブに置き換える
                GameObject jointObj = Instantiate(jointBall);

                //GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);//Cube

                LineRenderer lr = jointObj.AddComponent <LineRenderer>();
                lr.SetVertexCount(2);
                lr.material = BoneMaterial;
                lr.SetWidth(0.05f, 0.05f);

                jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
                jointObj.name             = jt.ToString();
                jointObj.transform.parent = body.transform;
            }
        }
        return(body);
    }
Esempio n. 23
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            Destroy(jointObj.GetComponent <Rigidbody>());
            Destroy(jointObj.GetComponent <MeshFilter>());
            Destroy(jointObj.GetComponent <MeshRenderer>());

            if (jt == Kinect.JointType.HandRight)
            {
                Instantiate(handPrefab, jointObj.transform).GetComponent <Rigidbody2D>();
            }
            else if (jt == Kinect.JointType.HandLeft)
            {
                Instantiate(handPrefab, jointObj.transform).GetComponent <Rigidbody2D>();
            }

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 24
0
        private void AddMapping(Kinect.JointType type, Transform bone)
        {
            if (bone == null)
            {
                return;
            }

            // check for existing mapping for type and bone
            Map foundMapping     = GetMapFromJointType(type);
            Map foundBoneMapping = GetMapFromBone(bone);

            if (foundBoneMapping != null)
            {
                UpdateMapping(foundBoneMapping, null); // reset the bone to null
            }

            if (foundMapping == null && bone != null)
            {
                // wasn't found, so create one
                foundMapping = new Map(type, bone);

                // add the entry to the mapping
                this.MappedList.Add(foundMapping);
            }
            else
            {
                UpdateMapping(foundMapping, bone);
            }
        }
Esempio n. 25
0
    // Refresh the body game object
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyobject)
    {
        //loop over each joint type
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints [jt];        // Current joint in loop is source joint
            Kinect.Joint?targetJoint = null;                    // Target joint

            // if bonemap contains joint --> it is the targetjoint
            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints [_BoneMap [jt]];      // Target joint is next joint
            }

            Transform jointObj = bodyobject.transform.FindChild(jt.ToString());         // Transform of child joint of bodyobject through string
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);                  // Position of transform joint is position of sourceJoint

            LineRenderer lr = jointObj.GetComponent <LineRenderer> ();
            // Draw line from source to target if targetJoint is present
            if (targetJoint.HasValue)
            {
                lr.SetPosition(0, jointObj.localPosition);                                                                    // current join position
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));                                                    // position of target join
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState)); // color line regarding state
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Esempio n. 26
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);


            if (jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
            {
                //jointObj.AddComponent<CustomCollider1>();
                jointObj.AddComponent <Rigidbody>().isKinematic = true;
            }
            else
            {
                jointObj.GetComponent <BoxCollider>().enabled = false;
            }

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        return(body);
    }
Esempio n. 27
0
        internal static KinectSkeleton.SegmentType GetSegmentType(Kinect.JointType type)
        {
            KinectSkeleton.SegmentType segment = KinectSkeleton.SegmentType.Body;

            if (type == Kinect.JointType.Neck || type == Kinect.JointType.Head)
            {
                segment = KinectSkeleton.SegmentType.Head;
            }
            else if (type == Kinect.JointType.ShoulderLeft || type == Kinect.JointType.ElbowLeft || type == Kinect.JointType.WristLeft || type == Kinect.JointType.HandLeft)
            {
                segment = KinectSkeleton.SegmentType.LeftArm;
            }
            else if (type == Kinect.JointType.HandLeft || type == Kinect.JointType.ThumbLeft || type == Kinect.JointType.HandTipLeft)
            {
                segment = KinectSkeleton.SegmentType.LeftHand;
            }
            else if (type == Kinect.JointType.ShoulderRight || type == Kinect.JointType.ElbowRight || type == Kinect.JointType.WristRight)
            {
                segment = KinectSkeleton.SegmentType.RightArm;
            }
            else if (type == Kinect.JointType.HandRight || type == Kinect.JointType.ThumbRight || type == Kinect.JointType.HandTipRight)
            {
                segment = KinectSkeleton.SegmentType.RightHand;
            }
            else if (type == Kinect.JointType.HipLeft || type == Kinect.JointType.KneeLeft || type == Kinect.JointType.AnkleLeft || type == Kinect.JointType.FootLeft)
            {
                segment = KinectSkeleton.SegmentType.LeftLeg;
            }
            else if (type == Kinect.JointType.HipRight || type == Kinect.JointType.KneeRight || type == Kinect.JointType.AnkleRight || type == Kinect.JointType.FootRight)
            {
                segment = KinectSkeleton.SegmentType.RightLeg;
            }

            return(segment);
        }
Esempio n. 28
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            if (jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight)
            {
                GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

                LineRenderer lr = jointObj.AddComponent <LineRenderer>();
                lr.SetVertexCount(2);
                lr.material = BoneMaterial;
                lr.SetWidth(0.05f, 0.05f);



                jointObj.transform.localScale = new Vector3(0.025f, 0.025f, 0.025f); //KinectBodyの大きさを設定できる 0.3f, 0.3f, 0.3f
                jointObj.name             = jt.ToString();
                jointObj.transform.parent = body.transform;                          //body.transform
            }
        }

        return(body);
    }
Esempio n. 29
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = body.Joints[jt];
            Kinect.Joint?targetJoint = null;

            if (_BoneMap.ContainsKey(jt))
            {
                targetJoint = body.Joints[_BoneMap[jt]];
            }

            Transform jointObj = bodyObject.transform.Find(jt.ToString());
            jointObj.localPosition = GetVector3FromJoint(sourceJoint);

            LineRenderer lr = jointObj.GetComponent <LineRenderer>();
            if (targetJoint.HasValue)
            {
                lr.SetPosition(0, jointObj.localPosition);
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                lr.startColor = GetColorForState(sourceJoint.TrackingState);
                lr.endColor   = GetColorForState(targetJoint.Value.TrackingState);
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Esempio n. 30
0
 // Update is called once per frame
 void Update()
 {
     //Make sure that the BodySourceManager exists in the game before we use it
     if (BodySourceManager == null)
     {
         print("bodyManagerNotFound");
         return;
     }
     bodyManager = BodySourceManager.GetComponent <BodySourceManager>();
     if (bodyManager == null)
     {
         return;
     }
     //If the body data is null, stop
     data = bodyManager.GetData();
     if (data == null)
     {
         print("Body Data is Null");
         return;
     }
     //For each body that exists
     foreach (var body in data)
     {
         //If body == null, don't do any more code, just iterate the loop
         if (body == null)
         {
             //Stop here and iterate the loop again
             continue;
         }
     }
     //Iterate over each body in our array
     foreach (var body in data)
     {
         //If the body exists...
         if (body != null)
         {
             //If the body is currently being tracked by Kinect...
             if (body.IsTracked) //Important, used to see if this particular body instance is being tracked by the kinect at this time
             {
                 //Loop over the joints
                 for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
                 {
                     //If the joint is Head...
                     if (jt.ToString() == "Head")
                     {
                         //Reference the specific joint, not the Joint Type
                         Kinect.Joint sourceJoint = body.Joints[jt];
                         //3D point in space (x,y,z), real world coordinates (in meters)
                         CameraSpacePoint cameraPoint = sourceJoint.Position;
                         //Mapped point to 2D screen from 3D coordinates
                         ColorSpacePoint colorPoint = sensor.CoordinateMapper.MapCameraPointToColorSpace(cameraPoint);
                         Vector3         position   = new Vector3(colorPoint.X, -colorPoint.Y, 0);
                         jointObj.transform.position = position;
                         print(position.x + "," + position.y + "," + position.z);
                     }
                 }
             }
         }
     }
 }