Esempio n. 1
0
    void CheckMainBody(Kinect.Body[] bodies)
    {
        // There is a chance that there will be no body avaliable
        if (bodies.Length <= m_MainCameraIndex)
        {
            return;
        }

        // Zero is always the main body
        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            Kinect.TrackingState trackingState = bodies[m_MainCameraIndex].Joints[jt].TrackingState;
            Kinect.Joint         sourceJoint   = bodies[m_MainCameraIndex].Joints[jt];
            GameObject           jtObj         = JointToGameObject(jt);
            if (jtObj)
            {
                if (jtObj.GetComponent <Renderer>())
                {
                    jtObj.GetComponent <Renderer>().enabled = !hideLocal;
                }
                if (jtObj.GetComponent <LineRenderer>())
                {
                    jtObj.GetComponent <LineRenderer>().enabled = !hideLocal;
                }
            }


            if (sourceJoint.TrackingState != Kinect.TrackingState.Tracked && bodies.Length > 1) // When there is only one body avalible (aka. only one camera tracking), do not try to use only tracked data
            {
                // Try replace it with tracked backups

                for (int n = 0; n < bodies.Length; n++)
                {
                    if (n == m_MainCameraIndex)
                    {
                        continue;
                    }
                    Kinect.Joint backupJoint = bodies[n].Joints[Kinect.JointMap._MirrorBoneMap[jt]];
                    if (backupJoint.TrackingState == Kinect.TrackingState.Tracked)
                    {
                        // We can try this
                        trackingState = backupJoint.TrackingState;
                        Vector3    jointPosition = getPosition(m_Cameras[n].JointToGameObject(Kinect.JointMap._MirrorBoneMap[jt]).transform.position);
                        Quaternion jointRotation = m_Cameras[n].JointToGameObject(Kinect.JointMap._MirrorBoneMap[jt]).transform.rotation;
                        FusedBody.UpdateJoint(jt, jointPosition, jointRotation, trackingState);
                        if (jtObj)
                        {
                            jtObj.transform.localPosition = getPosition(m_Cameras[n].JointToGameObject(Kinect.JointMap._MirrorBoneMap[jt]).transform.position);
                            jtObj.transform.localRotation = m_Cameras[n].JointToGameObject(Kinect.JointMap._MirrorBoneMap[jt]).transform.rotation;
                        }
                    }
                }
            }
            else
            {
                Vector3    jointPosition = getPosition(m_Cameras[m_MainCameraIndex].JointToGameObject(jt).transform.position);
                Quaternion jointRotation = m_Cameras[m_MainCameraIndex].JointToGameObject(jt).transform.rotation;
                FusedBody.UpdateJoint(jt, jointPosition, jointRotation, trackingState);
                if (jtObj)
                {
                    jtObj.transform.localPosition = getPosition(m_Cameras[m_MainCameraIndex].JointToGameObject(jt).transform.position);
                    jtObj.transform.localRotation = m_Cameras[m_MainCameraIndex].JointToGameObject(jt).transform.rotation;
                }
            }


            if (Kinect.JointMap._BoneMap.ContainsKey(jt) && jtObj)
            {
                LineRenderer lr = jtObj.GetComponent <LineRenderer>();
                if (lr)
                {
                    lr.SetPosition(0, jtObj.transform.position);
                    lr.SetPosition(1, JointToGameObject(Kinect.JointMap._BoneMap[jt]).transform.position);
                    // Update Rotation as well
                    if (Kinect.JointMap._RadialBoneMap.ContainsKey(jt))
                    {
                        jtObj.transform.rotation = Quaternion.LookRotation((JointToGameObject(Kinect.JointMap._RadialBoneMap[jt]).transform.position - jtObj.transform.position).normalized);
                    }
                }
            }
        }

        for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
        {
            if (jt == Kinect.JointType.SpineBase)
            {
                RelativeFusedBody.UpdateJoint(jt, FusedBody.Joints[jt].Position, FusedBody.JointOrientations[jt].Orientation, FusedBody.Joints[jt].TrackingState);
            }
            else if (Kinect.JointMap._RadialBoneMap.ContainsKey(jt))
            {
                RelativeFusedBody.UpdateJoint(jt, FusedBody.Joints[jt].Position - FusedBody.Joints[Kinect.JointMap._RadialBoneMap[jt]].Position, Quaternion.identity, FusedBody.Joints[jt].TrackingState);
            }
        }
    }
Esempio n. 2
0
        // Update is called once per frame
        void Update()
        {
            if (pointMan)
            {
                for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
                {
                    if (jt == Kinect.JointType.SpineBase) // Set spine base directly since it does not have relative scale
                    {
                        if (JointToGameObject(jt).jointGameObject)
                        {
                            if (JointToGameObject(jt).jointGameObject.transform.root != JointToGameObject(jt).jointGameObject.transform)
                            {
                                FusedAbsoluteModelBody.UpdateJoint(jt,
                                                                   JointToGameObject(jt).jointGameObject.transform.root.rotation *pointMan.FusedBody.Joints[jt].Position + JointToGameObject(jt).jointGameObject.transform.root.position,
                                                                   Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);

                                FusedRelativeModelBody.UpdateJoint(jt,
                                                                   JointToGameObject(jt).jointGameObject.transform.root.rotation *pointMan.FusedBody.Joints[jt].Position,
                                                                   Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);
                            }
                            else
                            {
                                FusedAbsoluteModelBody.UpdateJoint(jt, pointMan.FusedBody.Joints[jt].Position, Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);
                                FusedRelativeModelBody.UpdateJoint(jt, pointMan.FusedBody.Joints[jt].Position, Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);
                            }
                            if (JointToGameObject(jt).applyTransform)
                            {
                                JointToGameObject(jt).jointGameObject.transform.position = FusedAbsoluteModelBody.Joints[jt].Position;
                            }
                        }
                    }
                    else if (JointToGameObject(jt).jointGameObject&& JointToGameObject(Kinect.JointMap._RadialBoneMap[jt]).jointGameObject&& boneSize.ContainsKey(jt))
                    {
                        if (pointMan.RelativeFusedBody.Joints[jt].Position.magnitude != 0)
                        {
                            //Debug.Log(pointMan.RelativeFusedBody.Joints[jt].Position.magnitude + " -> " + boneSize[jt]);
                            FusedAbsoluteModelBody.UpdateJoint(jt,
                                                               JointToGameObject(Kinect.JointMap._RadialBoneMap[jt]).jointGameObject.transform.root.rotation *
                                                               (pointMan.RelativeFusedBody.Joints[jt].Position / pointMan.RelativeFusedBody.Joints[jt].Position.magnitude * boneSize[jt]) +
                                                               FusedAbsoluteModelBody.Joints[Kinect.JointMap._RadialBoneMap[jt]].Position,
                                                               Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);

                            FusedRelativeModelBody.UpdateJoint(jt,
                                                               JointToGameObject(Kinect.JointMap._RadialBoneMap[jt]).jointGameObject.transform.root.rotation *
                                                               (pointMan.RelativeFusedBody.Joints[jt].Position / pointMan.RelativeFusedBody.Joints[jt].Position.magnitude * boneSize[jt]),
                                                               Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);
                        }
                        else
                        {
                            FusedAbsoluteModelBody.UpdateJoint(jt,
                                                               JointToGameObject(Kinect.JointMap._RadialBoneMap[jt]).jointGameObject.transform.root.rotation *
                                                               Vector3.ClampMagnitude(pointMan.RelativeFusedBody.Joints[jt].Position, boneSize[jt]) +
                                                               FusedAbsoluteModelBody.Joints[Kinect.JointMap._RadialBoneMap[jt]].Position,
                                                               Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);

                            FusedRelativeModelBody.UpdateJoint(jt,
                                                               JointToGameObject(Kinect.JointMap._RadialBoneMap[jt]).jointGameObject.transform.root.rotation *
                                                               Vector3.ClampMagnitude(pointMan.RelativeFusedBody.Joints[jt].Position, boneSize[jt]),
                                                               Quaternion.identity, pointMan.FusedBody.Joints[jt].TrackingState);
                        }
                        if (JointToGameObject(jt).applyTransform)
                        {
                            JointToGameObject(jt).jointGameObject.transform.position = FusedAbsoluteModelBody.Joints[jt].Position;
                        }
                    }
                }
            }
        }