Beispiel #1
0
    //Not useed - for general avatar creation.
    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 = new GameObject();

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }
        // Add avatar gameobject from source
        GameObject avatar = Instantiate(Resources.Load(avatarAssetName, typeof(GameObject))) as GameObject;

        avatar.transform.parent = body.transform;
        avatar.name             = "Avatar";
        //avatar.transform.parent = body.transform.Find("SpineBase");
        return(body);
    }
Beispiel #2
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.Sphere);

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            //lr.material = BoneMaterial;
            lr.material = new Material(Shader.Find("Particles/Additive"));
            lr.SetWidth(bone_scale, bone_scale);

            jointObj.transform.localScale = new Vector3(joint_scale, joint_scale, joint_scale);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }
        return(body);
    }
Beispiel #3
0
    /// <summary>
    /// Creates the body object.
    /// </summary>
    /// <returns>The body object.</returns>
    /// <param name="id">Identifier.</param>
    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);

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

        return(body);
    }
    }     // Update

    // creates the object in the view regarding the body id
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);          // Crate a new body GameObject with id name

        // loop over all joints to draw body (ThumbRight is the highest value)
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube); // Create cube for every joint

            LineRenderer lr = jointObj.AddComponent <LineRenderer> ();            // linerender to connect joints
            lr.SetVertexCount(2);                                                 // Segments of line
            lr.material = BoneMaterial;                                           // Line material
            lr.SetWidth(linewidth, linewidth);                                    // Line width

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);        // Joint cube scale
            jointObj.name             = jt.ToString();                            // Joint cube name
            jointObj.transform.parent = body.transform;                           // Parent ob the Cube is the Body + id GameObject
        }
        return(body);
    }
Beispiel #5
0
    public void CheckWinCondition(Wall wall)
    {
        int failedJoints = 0;

        if (BodyManager.instance.MyPlayerBody != null)
        {
            currentPlayer = BodyManager.instance.MyPlayerBody.transform;

            for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
            {
                ///Find the child object that matches
                ///the current joints name
                Transform currentJointObj = currentPlayer.Find(jt.ToString());

                if (currentJointObj.GetComponent <JointManager>().isHitting)
                {
                    failedJoints += 1;
                }
            }

            if (failedJoints == 0)
            {
                PerfectPassWall(wall);
            }
            else
            {
                BreakWall(wall);
            }
        }
        else
        {
            BreakWall(wall);
            failedJoints = 24;
        }


        StartCoroutine(UpdatePanicBar(failedJoints));
        UpdateScore(24 - failedJoints);

        SpawnNextWall();
    }
Beispiel #6
0
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("realtime01");

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

            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            //lr.material = BoneMaterial;
            lr.material = new Material(Shader.Find("Particles/Additive"));
            lr.SetWidth(bone_scale, bone_scale);

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

            /*---------------------- Arrow GameObject ------------------------------*/
            GameObject mainPoint = new GameObject();
            mainPoint.transform.parent = jointObj.transform;
            mainPoint.name             = "mainPoint";

            GameObject point1 = new GameObject();
            point1.transform.parent = jointObj.transform;
            point1.name             = "1";

            GameObject cylinder = new GameObject();
            cylinder.name                    = "cylinder";
            cylinder.transform.parent        = point1.transform;
            cylinder.transform.localPosition = new Vector3(0f, 1f, 0f);
            cylinder.transform.localScale    = new Vector3(radius, 1f, radius);
            MeshFilter line_mesh = cylinder.AddComponent <MeshFilter> ();
            line_mesh.mesh = cylinderMesh;
            MeshRenderer line_Renderer = cylinder.AddComponent <MeshRenderer> ();
            line_Renderer.material = lineMat;

            cylinder.GetComponent <MeshRenderer> ().enabled = false;
        }
        return(body);
    }
Beispiel #7
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);
            if (body.TrackingId == nearest_body && jt == Kinect.JointType.Head)
            {
                headposition.X   = jointObj.position.x - BodyPosition.position.x;
                headposition.Y   = jointObj.position.y - BodyPosition.position.y;
                headposition.Z   = jointObj.position.z - BodyPosition.position.z;
                camerapoints [0] = headposition;
            }
            if (body.TrackingId == nearest_body && jt == Kinect.JointType.SpineShoulder)
            {
                neckposition.X   = jointObj.position.x - BodyPosition.position.x;
                neckposition.Y   = jointObj.position.y - BodyPosition.position.y;
                neckposition.Z   = jointObj.position.z - BodyPosition.position.z;
                camerapoints [1] = neckposition;
            }
            LineRenderer lr = jointObj.GetComponent <LineRenderer>();
            if (targetJoint.HasValue)
            {
                lr.SetPosition(0, jointObj.localPosition + BodyPosition.position);
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value) + BodyPosition.position);
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
    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.Sphere);

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

        body.transform.position      = parentGameObject.transform.position;
        body.transform.localRotation = parentGameObject.transform.localRotation;
        body.transform.localScale    = parentGameObject.transform.localScale;
        body.transform.parent        = parentGameObject.transform;

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

        //body.SetActive(false);

        // Create joints
        //foreach (Kinect.JointType joint in _joints)
        //{
        //    GameObject newJoint = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //    newJoint.transform.localScale = new Vector3(0.6f, 0.6f, 0.6f);
        //    newJoint.name = joint.ToString();

        //    newJoint.transform.parent = body.transform;
        //}
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj;
            if (jt == Kinect.JointType.FootLeft || jt == Kinect.JointType.FootRight)
            {
                jointObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                jointObj.transform.localScale = new Vector3(1f, 1f, 1f);
            }
            else
            {
                jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                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);
    }
    //is supposed to calculate the distance


    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 = new GameObject();
            //GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);

            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }
        // Add avatar gameobject from source
        GameObject avatar = Instantiate(Resources.Load(avatarAssetName, typeof(GameObject))) as GameObject;

        avatar.transform.parent = body.transform;
        avatar.name             = "Avatar";
        //Try to add tags for different bodyparts
        GameObject l1 = GameObject.Find("l1");

        l1.tag = "Back";
        GameObject l02 = GameObject.Find("l02");

        l02.tag = "Back";
        GameObject l2 = GameObject.Find("l2");

        l2.tag = "Back";
        GameObject l3 = GameObject.Find("l3");

        l3.tag = "Back";
        GameObject l4 = GameObject.Find("l4");

        l4.tag = "Back";
        GameObject l5 = GameObject.Find("l5");

        l5.tag = "Back";
        //avatar.transform.parent = body.transform.Find("SpineBase");
        return(body);
    }
Beispiel #11
0
    IEnumerator RefreshBodyObject(Kinect.Body body, GameObject bodyObject, float waitTime)
    {
        yield return(new WaitForSeconds(waitTime));

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint            sourceJoint      = body.Joints[jt];
            Kinect.JointOrientation jointOrientation = body.JointOrientations[jt];
            Kinect.Joint?           targetJoint      = null;

            //sourceJoint.TrackingState

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

            if (bodyObject)
            {
                Transform jointObj = bodyObject.transform.FindChild(jt.ToString());
                jointObj.localPosition = GetVector3FromJoint(sourceJoint);
                jointObj.rotation      = GetQuaternionFromJointOrientation(jointOrientation);

                AliceSync.s.UpdateBodyPart(body.TrackingId, jointObj.name, jointObj.localPosition, jointObj.localRotation, GetInferedState(sourceJoint.TrackingState));
                jointObj.gameObject.GetComponent <Renderer>().material.color = GetColorForState(sourceJoint.TrackingState);

                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));
                }
                else
                {
                    lr.enabled = false;
                }
            }
        }
    }
Beispiel #12
0
    private GameObject CreateBodyObject(Kinect.Body bodyOBJ, ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        img.enabled      = false; img2.enabled = false;
        startPositonBody = true;
        firstYLeft       = true; firstYRight = true;
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++) // for each bone (JointType)
        {
            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.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.Joint sourceJoint = bodyOBJ.Joints[jt];
            Transform    jointObj2   = body.transform.Find(jt.ToString()); // get obj joint form jt
            jointObj2.localPosition = GetVector3FromJoint(sourceJoint);
            if (startPositonBody)
            {
                if (jt.Equals(Kinect.JointType.FootLeft))
                {
                    start_AnkleLeft_z = jointObj2.localPosition.z;
                }
                if (jt.Equals(Kinect.JointType.FootRight))
                {
                    start_AnkleRight_z = jointObj2.localPosition.z;
                }
            }
        }

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

        body.transform.parent   = this.transform;
        body.transform.position = new Vector3(1, 0, 0);

        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;

            if (jt.Equals(Kinect.JointType.HandRight))
            {
                jointObj.transform.localScale = new Vector3(0.3f, 3f, 3f);
                jointObj.AddComponent <Rigidbody>();
                jointObj.GetComponent <Rigidbody> ().isKinematic   = true;
                jointObj.GetComponent <Renderer> ().material.color = Color.red;
                jointObj.tag = "Racket";
            }
            else
            {
                jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
                jointObj.GetComponent <BoxCollider>().isTrigger = true;
                //jointObj.GetComponent<Renderer> ().enabled = false;
            }
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        body.transform.rotation   = Quaternion.Euler(0, 180, 0);
        body.transform.localScale = new Vector3(-1, 1, 1) * 3;

        return(body);
    }
Beispiel #14
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);              //always update positions

            //draw the body if enabled
            if (showBody)
            {
                jointObj.gameObject.GetComponent <MeshRenderer>().enabled = true;
                LineRenderer lr = jointObj.GetComponent <LineRenderer>();
                lr.enabled = true;
                if (targetJoint.HasValue)
                {
                    lr.SetPosition(0, jointObj.localPosition);
                    lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                    lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
                }
                else
                {
                    lr.enabled = false;
                }
            }
            else
            {
                LineRenderer lr = jointObj.GetComponent <LineRenderer>();
                lr.enabled = false;
                jointObj.gameObject.GetComponent <MeshRenderer>().enabled = false;
            }
        }
    }
Beispiel #15
0
    //CREA EL CUERPO mediante los cubos (nombre y ecala) pero no les da ubicación
    private GameObject CreateBodyObject(ulong id)
    {
        //crea un cuerpo y le da un id
        GameObject body = new GameObject("Body:" + id);

        //recorre los joint del cuerpo en el kinect
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            //por cada joint crea un cubo
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);


            //al cubo joint lo escala, le da un nombre y lo asigna al cuerpo
            jointObj.transform.localScale = new Vector3(0.000005f, 0.000005f, 0.000005f);
            //jointObj.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);

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

        return(body);
    }
Beispiel #16
0
    /// <summary>
    /// Draws the lines between the
    /// joints the create a visible player
    /// </summary>
    /// <param name="body"></param>
    /// <param name="bodyObject"></param>
    private void DrawBodyLines(Kinect.Body body, GameObject bodyObject)
    {
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Transform currentJoint = bodyObject.transform.Find(jt.ToString());
            Transform nextJoint    = null;

            if (_BoneMap.ContainsKey(jt))
            {
                nextJoint = bodyObject.transform.Find(_BoneMap[jt].ToString());
            }

            LineRenderer lr = currentJoint.GetComponent <LineRenderer>();

            if (nextJoint != null)
            {
                lr.SetPosition(0, currentJoint.position);
                colliding = currentJoint.GetComponent <JointManager>().isHitting;

                lr.SetPosition(1, nextJoint.position);

                if (colliding)
                {
                    lr.startColor = failColor;
                    lr.endColor   = failColor;
                }
                else if (!colliding)
                {
                    lr.startColor = winColor;
                    lr.endColor   = winColor;
                }
            }

            else
            {
                lr.enabled = false;
            }
        }
    }
Beispiel #17
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);
            //Debug.Log("body outside " + body.TrackingId);
            if (jt == Kinect.JointType.FootLeft && jointObj.localPosition.x >= detectionThreshold)
            {
                //Debug.Log("body inside " + body.TrackingId);
                if (!setupDone && doSetup)
                {
                    SetupPedal(jointObj.localPosition);
                }
                manageCyclingTimes(jointObj.localPosition);
                //-4.2 (Down) -2.1 (Up) -> set the threshold at 3
            }

            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));
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Beispiel #18
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        message = "";
        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);

            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));
            }
            else
            {
                lr.enabled = false;
            }
            float xval = (int)((jointObj.position.x) * 10000) / 10000f;
            float yval = (int)((jointObj.position.y) * 10000) / 10000f;
            float zval = (int)((jointObj.position.z) * 10000) / 10000f;
            message += xval.ToString() + " " + yval.ToString() + " " + zval.ToString() + " ";

            if (jt == Kinect.JointType.Head)
            {
                camera.transform.position = jointObj.transform.position + new Vector3(0, 0, 0);
            }
        }
    }
Beispiel #19
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)
            {
                if (jt == Kinect.JointType.Neck)
                {
                    Vector3 vD = bodyObject.transform.Find(Kinect.JointType.Head.ToString()).position - jointObj.transform.position;
                    jointObj.transform.LookAt(GetVector3FromJoint(targetJoint.Value));
                }
                else
                {
                    jointObj.transform.LookAt(GetVector3FromJoint(targetJoint.Value));
                }

                lr.SetPosition(0, jointObj.localPosition);
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Beispiel #20
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        count++;
        Kinect.Joint s = body.Joints[Kinect.JointType.WristLeft];
        Kinect.Joint t = body.Joints[Kinect.JointType.WristRight];

        Kinect.Joint bodyJoint = body.Joints[Kinect.JointType.SpineBase];
        bodyObject.transform.position = GetVector3FromJoint(bodyJoint);


        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.position = GetVector3FromJoint(sourceJoint);



            LineRenderer lr = jointObj.GetComponent <LineRenderer>();
            if (targetJoint.HasValue)
            {
                lr.SetPosition(0, jointObj.position);
                lr.SetPosition(1, GetVector3FromJoint(targetJoint.Value));
                lr.startColor = GetColorForState(sourceJoint.TrackingState);
                lr.endColor   = GetColorForState(targetJoint.Value.TrackingState);
            }
            else
            {
                lr.enabled = false;
            }
        }
    }
Beispiel #21
0
    private GameObject CreateBodyObject()
    {
        GameObject body = new GameObject("TrackedBody");

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            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.03f, 0.03f, 0.03f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        body.SetActive(false);

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

        //change position
        body.transform.position = BodyPosition.position;
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            //add customize layer
            jointObj.layer = LayerMask.NameToLayer("KinectBody");
            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);

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

        return(body);
    }
Beispiel #23
0
    private GameObject addBone(String name, float radius, GameObject prefab, Transform body, Kinect.JointType joint1, Kinect.JointType joint2 = null)
    {
        GameObject bone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);

        bone.name = name; bone.transform.parent = body;
        BoneScript script = bone.getComponent("BoneScript") as BoneScript;

        script.radius = radius;
        script.joint1 = body.FindChild(joint1.ToString()).gameObject;
        if (joint2 != null)
        {
            script.joint2 = body.FindChild(joint2.ToString()).gameObject;
        }
        else if (_BoneMap.ContainsKey(joint1))
        {
            script.joint2 = body.FindChild(_BoneMap [joint1].ToString()).gameObject;
        }
        else
        {
            Debug.LogError("BAD JOINT: " + joint1);
        }
        return(bone);
    }
Beispiel #24
0
    //透過骨骼ID建立新的骨骼物件。
    private GameObject CreateBodyObject(ulong id)
    {
        Debug.Log("Create new Player!");
        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的Component,給予其兩個座標,賦予其材質球,在設定線段的粗細。
            LineRenderer lr = jointObj.AddComponent <LineRenderer>();
            lr.SetVertexCount(2);
            lr.material = BoneMaterial;
            lr.SetWidth(0.05f, 0.05f);
            //設定該方塊的尺寸,並且給他對應的物件名稱,並且parent到主物件上面。
            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

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

        body.layer = LayerMask.NameToLayer("Skeleton");

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

            DestroyImmediate(jointObj.GetComponent("BoxCollider"));

            if (jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight ||
                jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight ||
                jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight)
            {
                Rigidbody2D rigid = jointObj.AddComponent <Rigidbody2D>();
                rigid.isKinematic = true;
                CircleCollider2D col = jointObj.AddComponent <CircleCollider2D>();
                col.enabled   = true;
                col.isTrigger = true;
                col.radius    = 4.0f;
            }

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

            jointObj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
            jointObj.layer            = body.layer;
        }
        return(body);
    }
Beispiel #26
0
/*    private void Align_Body()
 *  {
 *
 *  }*/

    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.position);
                lr.SetPosition(1, GetVector3FromScene(targetJoint.Value, bodyObject));
                lr.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            }
            else
            {
                lr.enabled = false;
            }

            /* VIVE-KINECT CALIBRATION
             * if (jt == Kinect.JointType.Head)
             * {
             *  jointObj.tag = "Head";
             *  Vector3 headOffset = GetVector3FromJoint(sourceJoint); //Offset of head node from body
             *  bodyObject.transform.position = new Vector3(mainCamera.transform.position.x - headOffset.x, mainCamera.transform.position.y - headOffset.y, mainCamera.transform.position.z - headOffset.z); //Sets body pos
             * }
             * END */
        }
    }
    private GameObject CreateBodyObject(ulong id)
    {
        GameObject body = new GameObject("Body:" + id);

        body.transform.localScale = new Vector3(1, 1, 1);
        body.transform.position   = gameObject.transform.position;
        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);

            jointObj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
            if (jt == Kinect.JointType.HandLeft)
            {
                jointObj.AddComponent <HandScript>();
                jointObj.GetComponent <HandScript>().BodySourceManager = this.BodySourceManager;
                jointObj.GetComponent <HandScript>().joint             = Kinect.JointType.HandLeft;
                jointObj.GetComponent <HandScript>().SpawnManager      = SpawnManger;
            }
            if (jt == Kinect.JointType.HandRight)
            {
                jointObj.AddComponent <HandScript>();
                jointObj.GetComponent <HandScript>().BodySourceManager = this.BodySourceManager;
                jointObj.GetComponent <HandScript>().joint             = Kinect.JointType.HandRight;
                jointObj.GetComponent <HandScript>().SpawnManager      = SpawnManger;
            }
        }

        return(body);
    }
Beispiel #28
0
    private GameObject CreateBodyObject(ulong body_id)
    {
        GameObject body = new GameObject("Body:" + body_id);

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            GameObject jointObj = null;
            if (jt == Kinect.JointType.Head)
            {
                jointObj = Instantiate(CreatePrimitive(PrimitiveType.Sphere));
            }
            else
            {
                GameObject.Instantiate(new GameObject());
            }
            jointObj.name             = jt.ToString();
            jointObj.transform.parent = body.transform;
        }

        Transform bodyTransform = body.transform;

        bones    = new GameObject[9];
        bones[0] = addBone("Body", 1.5f, bone_prefab, bodyTransform,
                           Kinect.JointType.SpineBase,
                           Kinect.JointType.SpineShoulder);
        bones[1] = addBone("LeftArmTop", 0.8f, bone_prefab, bodyTransform, Kinect.JointType.ElbowLeft);
        bones[2] = addBone("LeftArmBottom", 0.5f, bone_prefab, bodyTransform, Kinect.JointType.WristLeft);
        bones[3] = addBone("RightArmTop", 0.8f, bone_prefab, bodyTransform, Kinect.JointType.ElbowRight);
        bones[4] = addBone("RightArmBottom", 0.5f, bone_prefab, bodyTransform, Kinect.JointType.WristRight);
        bones[5] = addBone("LeftLegTop", 0.8f, bone_prefab, bodyTransform, Kinect.JointType.KneeLeft);
        bones[6] = addBone("LeftLegBottom", 0.5f, bone_prefab, bodyTransform, Kinect.JointType.AnkleLeft);
        bones[7] = addBone("RightLegTop", 0.8f, bone_prefab, bodyTransform, Kinect.JointType.KneeRight);
        bones[8] = addBone("RightLegBottom", 0.5f, bone_prefab, bodyTransform, Kinect.JointType.AnkleRight);

        return(body);
    }
    /*    public void SendHeadTransform(Vector3 position, Quaternion rotation)
     *  {
     *      // If we are connected to a session, broadcast our head info
     *      if (this.serverConnection != null && this.serverConnection.IsConnected())
     *      {
     *          // Create an outgoing network message to contain all the info we want to send
     *          NetworkOutMessage msg = CreateMessage((byte)TestMessageID.HeadTransform);
     *
     *          AppendTransform(msg, position, rotation);
     *
     *          // Send the message as a broadcast, which will cause the server to forward it to all other users in the session.
     *          this.serverConnection.Broadcast(
     *              msg,
     *              MessagePriority.Immediate,
     *              MessageReliability.UnreliableSequenced,
     *              MessageChannel.Avatar);
     *      }
     *  }
     */

    public void SendBodyData(ulong trackingID, GameObject bodyData)
    {
        // If we are connected to a session, broadcast our info
        //Debug.Log("SendBodyData");

        if (this.serverConnection != null && this.serverConnection.IsConnected())
        {
            NetworkOutMessage msg = CreateMessage((byte)TestMessageID.BodyData);

            msg.Write((long)trackingID);

            for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
            {
                Transform bodyItem = bodyData.transform.FindChild(jt.ToString());
                AppendTransform(msg, bodyItem);
            }
            // Send the message as a broadcast
            this.serverConnection.Broadcast(
                msg,
                MessagePriority.Immediate,
                MessageReliability.UnreliableSequenced,
                MessageChannel.Avatar);
        }
    }
Beispiel #30
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.SetColors(GetColorForState(sourceJoint.TrackingState), GetColorForState(targetJoint.Value.TrackingState));
            }
            else
            {
                lr.enabled = false;
            }
        }

        //float shoulderElbowAngleL = GetAngle(body, Kinect.JointType.ShoulderLeft, Kinect.JointType.ElbowLeft);
        //Debug.Log(shoulderElbowAngleL);
        //float hipKneeAngleL = GetAngle(body, Kinect.JointType.HipLeft, Kinect.JointType.KneeLeft);
        //Debug.Log(hipKneeAngleL);
        float hipKneeAngleR = GetAngle(body, Kinect.JointType.HipRight, Kinect.JointType.KneeRight);

        Debug.Log(hipKneeAngleR);
    }