Beispiel #1
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);
    }
Beispiel #2
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;
    }
Beispiel #3
0
    private void RefreshBodyObject(Kinect.Body body, GameObject bodyObject)
    {
        TrackingPoints tracker = _TrackerMap[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);

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

            if (tracker.TrackerMap.ContainsKey(jt))
            {
                lr.SetWidth(1.0f, 1.0f);

                Kinect.Joint wristJoint;
                Kinect.Joint elbowJoint;
                Kinect.Joint sholderJoint;

                if (jt == Kinect.JointType.WristRight)
                {
                    wristJoint   = body.Joints[Kinect.JointType.WristRight];
                    elbowJoint   = body.Joints[Kinect.JointType.ElbowRight];
                    sholderJoint = body.Joints[Kinect.JointType.ShoulderRight];
                }
                else
                {
                    wristJoint   = body.Joints[Kinect.JointType.WristLeft];
                    elbowJoint   = body.Joints[Kinect.JointType.ElbowLeft];
                    sholderJoint = body.Joints[Kinect.JointType.ShoulderLeft];
                }

                Vector3 elbowPosition   = new Vector3(elbowJoint.Position.X, elbowJoint.Position.Y, elbowJoint.Position.Z);
                Vector3 sholderPosition = new Vector3(sholderJoint.Position.X, sholderJoint.Position.Y, sholderJoint.Position.Z);
                Vector3 wristPosition   = new Vector3(wristJoint.Position.X, wristJoint.Position.Y, wristJoint.Position.Z);

                Vector3 previousVector = sholderPosition - elbowPosition;
                Vector3 nextVector     = wristPosition - elbowPosition;

                float angle    = Vector3.Angle(previousVector, nextVector);
                bool  isActive = angle > POINT_ANGLE;

                GameObject handCollider = tracker.TrackerMap[jt];
                if (handCollider.activeSelf != isActive)
                {
                    handCollider.SetActive(isActive);
                }

                handCollider.transform.position = jointObj.localPosition;

                Vector3 previousJoinPosition = GetVector3FromJoint(targetJoint.Value);
                handCollider.transform.LookAt(previousJoinPosition);

                handCollider.transform.position -= handCollider.transform.forward * (handCollider.transform.localScale.z / 2);
            }
        }
    }