示例#1
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        Debug.Log(body.Joints [Kinect.JointType.Head].Position.Y - body.Joints [Kinect.JointType.FootLeft].Position.Y);
        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 = Vector3.MoveTowards(jointObj.localPosition, GetVector3FromJoint(sourceJoint), 100 * Time.deltaTime);
            if (jt.Equals(Kinect.JointType.HandRight))
            {
                Windows.Kinect.Vector4 orientation = body.JointOrientations [jt].Orientation;
                jointObj.localRotation = Quaternion.RotateTowards(jointObj.localRotation, new Quaternion(orientation.X, orientation.Y, orientation.Z, orientation.W), 800 * Time.deltaTime);
                //jointObj.Rotate(0, 90, 0);
            }

            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;
            }
        }
    }
示例#2
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);
    }
示例#3
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);
    }
示例#4
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]]; // select bone to move
            }

            Transform jointObj = bodyObject.transform.Find(jt.ToString()); // get obj joint form jt
            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));

                // Left
                if (jt.Equals(Kinect.JointType.FootLeft))
                {
                    /* if(firstYLeft)
                     * {
                     *   start_AnkleLeft_y = GetVector3FromJoint(targetJoint.Value).y;
                     *   max_AnkleLeft_y = start_AnkleLeft_y;
                     *   firstYLeft = false;
                     * }*/
                    currentZAnkleLeft = GetVector3FromJoint(targetJoint.Value).z;
                    currentYAnkleLeft = GetVector3FromJoint(targetJoint.Value).y;
                    float valueDifZLeft = start_AnkleRight_z - currentZAnkleLeft;
                    float valueDifYLeft = currentYAnkleRight - currentYAnkleLeft;
                    distanceLeft    = Mathf.Sqrt(valueDifZLeft * valueDifZLeft + valueDifYLeft * valueDifYLeft);
                    debugText.text  = "current Y Left" + currentYAnkleLeft.ToString();
                    debugText2.text = "current Y Right" + currentYAnkleRight.ToString(); //
                    debugText3.text = "Dif Y " + valueDifYLeft.ToString();               //

                    debugText4.text = "Dif Z " + valueDifZLeft.ToString();
                    debugText5.text = "Current Z " + jointObj.localPosition.z.ToString();
                    debugText6.text = "Start Z " + (start_AnkleLeft_z).ToString();

                    if (valueDifZLeft < 0.5)
                    {
                        startPointLeft = true;
                    }


                    spear.transform.position = new Vector3(GetVector3FromJoint(targetJoint.Value).x, currentYAnkleLeft, currentZAnkleLeft);


                    /* if (max_AnkleLeft_y < GetVector3FromJoint(targetJoint.Value).y && startPointLeft)
                     * {
                     *   max_AnkleLeft_y = GetVector3FromJoint(targetJoint.Value).y;
                     * }*/
                    //if (max_AnkleLeft_y - start_AnkleLeft_y > talToMove)
                    if (startPointLeft)
                    {
                        if (valueDifZLeft > 2.6 && valueDifYLeft > -1)
                        {
                            img.enabled    = true;
                            startPointLeft = false;
                            tuchLeft       = true;
                        }
                        else if (tuchLeft)
                        {
                            img.enabled = false;
                            tuchLeft    = false;
                            // max_AnkleLeft_y = start_AnkleLeft_y;
                        }
                    }
                }
                // Right
                if (jt.Equals(Kinect.JointType.FootRight))
                {
                    if (firstYRight)
                    {
                        start_AnkleRight_y = GetVector3FromJoint(targetJoint.Value).y;
                        max_AnkleRight_y   = start_AnkleRight_y;
                        firstYRight        = false;
                    }

                    currentZAnkleRight = GetVector3FromJoint(targetJoint.Value).z;
                    currentYAnkleRight = GetVector3FromJoint(targetJoint.Value).y;
                    float valuDifzRight = start_AnkleRight_z - currentZAnkleRight;

                    target.transform.position = new Vector3(GetVector3FromJoint(targetJoint.Value).x, currentYAnkleRight, start_AnkleRight_z - 2.6f);
                    if (valuDifzRight < 1.5)
                    {
                        startPointRight = true;
                    }

                    if (max_AnkleRight_y < GetVector3FromJoint(targetJoint.Value).y&& startPointRight)
                    {
                        max_AnkleRight_y = GetVector3FromJoint(targetJoint.Value).y;
                    }
                    if (max_AnkleRight_y - start_AnkleRight_y > talToMove)
                    {
                        /* if (valuDifzRight > 2.5)
                         * {
                         *   img2.enabled = true;
                         *   startPointRight = false;
                         *   tuchRight = true;
                         * }
                         * else if (tuchRight)
                         * {
                         *   img2.enabled = false;
                         *   tuchRight = false;
                         *   max_AnkleRight_y = start_AnkleRight_y;
                         * }*/
                    }
                }
            }
            else
            {
                lr.enabled = false;
            }
        }
        startPositonBody = false;
    }