示例#1
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject, Text text)
    {
        count++;
        Kinect.Joint   s  = body.Joints[Kinect.JointType.WristLeft];
        Kinect.Joint   t  = body.Joints[Kinect.JointType.WristRight];
        BodyProperties BP = bodyObject.GetComponent <BodyProperties>();

        //text.color = UnityEngine.Color.white;
        //text.text = BP.startGame.ToString();
        //text.text += "\n" + BP.InitializeObj.ToString();
        //text.text += "\n" + BP.countinst.ToString();
        //text.fontSize = 25;
        //text.text += "\n" + BP.leftarmLength;
        //text.text += "\n" + BP.rightarmLength;
        //text.text = Math.Round(BP.CalculateDistance(s, t), 2).ToString();
        //text.text += "\n"+Math.Round(BP.CalculateDistanceByFormula(s, t), 2).ToString();

        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);
            if (jointObj.name.Contains("Head") && count % 7 == 0)
            {
                JointsProperties jp = jointObj.GetComponent <JointsProperties>();
                //Debug.Log(jointObj.name + ": (" + jp.position.x + "," + jp.position.y + "," + jp.position.z + ")");
            }
            GameObject       JointObject = jointObj.gameObject;
            JointsProperties joint       = JointObject.GetComponent <JointsProperties>();
            joint.position = jointObj.position;
            joint.UpdateDistanceFromGround();



            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;
            }
        }
    }
示例#2
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];
        BodyProperties BP = bodyObject.GetComponent <BodyProperties>();

        Kinect.Joint bodyJoint = body.Joints[Kinect.JointType.SpineBase];
        bodyObject.transform.position = GetVector3FromJoint(bodyJoint);
        Kinect.Vector4 BodyOrientation = body.JointOrientations[Kinect.JointType.SpineBase].Orientation;
        bodyObject.transform.rotation = GetQuaterion(BodyOrientation);


        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("Skeleton" + jt.ToString());
            jointObj.position = GetVector3FromJoint(sourceJoint);
            if (jointObj.name.Contains("Head") && count % 7 == 0)
            {
                JointsProperties jp = jointObj.GetComponent <JointsProperties>();
                //Debug.Log(jointObj.name + ": (" + jp.position.x + "," + jp.position.y + "," + jp.position.z + ")");
            }
            GameObject       JointObject = jointObj.gameObject;
            JointsProperties joint       = JointObject.GetComponent <JointsProperties>();
            joint.position = jointObj.position;
            joint.UpdateDistanceFromGround();
            joint.TrackingState = sourceJoint.TrackingState;
            JointObject.GetComponent <Renderer>().material.color = GetColorForState(sourceJoint.TrackingState);



            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;
            }
        }
    }