void Start()
 {
     nt = new NtUnity.Kinect();
 }
Example #2
0
        public void set(Kinect kinect, int n, bool mirrored = false, bool move = false, bool headMove = true)
        {
            Vector3 faceDir = kinect.getFaceDirectionByTrackingId(kinect.skeletonTrackingId[n]);

            if (isSavedPosition == false &&
                kinect.skeletonState[n][Kinect.JointType_SpineBase] != Kinect.TrackingState_NotTracked)
            {
                isSavedPosition = true;
                savedPosition   = kinect.skeleton[n][Kinect.JointType_SpineBase];
            }
            for (int i = 0; i < kinect.skeleton[n].Count; i++)
            {
                Vector3 jt = kinect.skeleton[n][i];
                if (mirrored)
                {
                    joint[i] = new Vector3(-jt.x, jt.y, -jt.z);
                }
                else
                {
                    joint[i] = new Vector3(jt.x, jt.y, savedPosition.z * 2 - jt.z);
                }
                jointState[i] = kinect.skeletonState[n][i];
            }
            if (mirrored)
            {
                swapJoint(Kinect.JointType_ShoulderLeft, Kinect.JointType_ShoulderRight);
                swapJoint(Kinect.JointType_ElbowLeft, Kinect.JointType_ElbowRight);
                swapJoint(Kinect.JointType_WristLeft, Kinect.JointType_WristRight);
                swapJoint(Kinect.JointType_HandLeft, Kinect.JointType_HandRight);
                swapJoint(Kinect.JointType_HipLeft, Kinect.JointType_HipRight);
                swapJoint(Kinect.JointType_KneeLeft, Kinect.JointType_KneeRight);
                swapJoint(Kinect.JointType_AnkleLeft, Kinect.JointType_AnkleRight);
                swapJoint(Kinect.JointType_FootLeft, Kinect.JointType_FootRight);
                swapJoint(Kinect.JointType_HandTipLeft, Kinect.JointType_HandTipRight);
                swapJoint(Kinect.JointType_ThumbLeft, Kinect.JointType_ThumbRight);
            }
            for (int i = 0; i < targetBone.Length; i++)
            {
                int s = jointSegment[2 * i], e = jointSegment[2 * i + 1];
                trackingSegment[targetBone[i]] = joint[e] - joint[s];
                trackingState[targetBone[i]]   = System.Math.Min(jointState[e], jointState[s]);
            }

            Vector3 waist = joint[Kinect.JointType_HipRight] - joint[Kinect.JointType_HipLeft];

            waist = new Vector3(waist.x, 0, waist.z);
            Quaternion rot    = Quaternion.FromToRotation(Vector3.right, waist);
            Quaternion rotInv = Quaternion.Inverse(rot);

            Vector3 shoulder = joint[Kinect.JointType_ShoulderRight] - joint[Kinect.JointType_ShoulderLeft];

            shoulder = new Vector3(shoulder.x, 0, shoulder.z);
            //Quaternion srot = Quaternion.FromToRotation(Vector3.right,shoulder);
            //Quaternion srotInv = Quaternion.Inverse(srot);

            humanoid.transform.rotation = Quaternion.identity;
            //humanoid.transform.rotation = savedHumanoidRotation;
            foreach (HumanBodyBones bone in targetBone)
            {
                if (rigBone[bone].isValid && trackingState[bone] != Kinect.TrackingState_NotTracked)
                {
                    rigBone[bone].transform.rotation = rotInv * Quaternion.FromToRotation(Vector3.up, trackingSegment[bone]);
                }
            }
            //rigBone[HumanBodyBones.Chest].offset(srot);
            if (headMove && faceDir.magnitude > 1e-6)
            {
                float pitch = faceDir.x, yaw = faceDir.y, roll = faceDir.z;
                if (mirrored)
                {
                    pitch = -pitch;
                    roll  = -roll;
                }
                else
                {
                    pitch = -pitch;
                    yaw   = -yaw;
                }
                rigBone[HumanBodyBones.Head].transform.rotation = Util.toQ(pitch, yaw, roll);
            }
            Quaternion bodyRot = rot;

            if (mirrored)
            {
                bodyRot = Quaternion.AngleAxis(180, Vector3.up) * bodyRot;
            }
            humanoid.transform.rotation = bodyRot;
            if (move == true)
            {
                Vector3 m = joint[Kinect.JointType_SpineBase];
                if (mirrored)
                {
                    m = new Vector3(-m.x, m.y, -m.z);
                }
                humanoid.transform.position = m;
            }
        }
Example #3
0
 void Start()
 {
     nt = new NtUnity.Kinect();
     cs = new NtUnity.UnityChanSkeleton(humanoid);
 }
Example #4
0
 void Start()
 {
     nt = new NtUnity.Kinect();
     hs = new NtUnity.HumanoidSkeleton(humanoid);
     humanoid.SetActive(false);
 }
Example #5
0
        public void set(Kinect kinect, int n, float correction, bool mirrored = false, bool move = false, bool headMove = true)
        {
            Vector3 faceDir = kinect.getFaceDirectionByTrackingId(kinect.skeletonTrackingId[n]);

            if (isSavedPosition == false &&
                kinect.skeletonState[n][Kinect.JointType_SpineBase] != Kinect.TrackingState_NotTracked)
            {
                isSavedPosition = true;
                savedPosition   = kinect.skeleton[n][Kinect.JointType_SpineBase];
            }
            for (int i = 0; i < kinect.skeleton[n].Count; i++)
            {
                Vector3 jt = kinect.skeleton[n][i];
                if (mirrored)
                {
                    joint[i] = new Vector3(jt.x, jt.y, -jt.z); // (-jt.x, jt.y, -jt.z)
                }
                else
                {
                    joint[i] = new Vector3(jt.x, jt.y, savedPosition.z * 2 - jt.z);
                }
                jointState[i] = kinect.skeletonState[n][i];
            }

            /*if (mirrored)
             * {
             *  swapJoint(Kinect.JointType_ShoulderLeft, Kinect.JointType_ShoulderRight);
             *  swapJoint(Kinect.JointType_ElbowLeft, Kinect.JointType_ElbowRight);
             *  swapJoint(Kinect.JointType_WristLeft, Kinect.JointType_WristRight);
             *  swapJoint(Kinect.JointType_HandLeft, Kinect.JointType_HandRight);
             *  swapJoint(Kinect.JointType_HipLeft, Kinect.JointType_HipRight);
             *  swapJoint(Kinect.JointType_KneeLeft, Kinect.JointType_KneeRight);
             *  swapJoint(Kinect.JointType_AnkleLeft, Kinect.JointType_AnkleRight);
             *  swapJoint(Kinect.JointType_FootLeft, Kinect.JointType_FootRight);
             *  swapJoint(Kinect.JointType_HandTipLeft, Kinect.JointType_HandTipRight);
             *  swapJoint(Kinect.JointType_ThumbLeft, Kinect.JointType_ThumbRight);
             * }*/
            //set humanoid
            for (int i = 0; i < targetBone.Length; i++)
            {
                int s = jointSegment[2 * i], e = jointSegment[2 * i + 1];
                trackingSegment[targetBone[i]] = joint[e] - joint[s]; // targetBone is unity model joint
                trackingState[targetBone[i]]   = System.Math.Min(jointState[e], jointState[s]);
            }
            //set 腰部 joint for setting every Joint's roatation
            Vector3 waist = joint[Kinect.JointType_HipRight] - joint[Kinect.JointType_HipLeft];

            waist = new Vector3(waist.x, 0, waist.z);/////////////////////這邊
            Quaternion rot    = Quaternion.FromToRotation(Vector3.right, waist);
            Quaternion rotInv = Quaternion.Inverse(rot);

            Vector3 shoulder = joint[Kinect.JointType_ShoulderRight] - joint[Kinect.JointType_ShoulderLeft];

            shoulder = new Vector3(shoulder.x, 0, shoulder.z);
            //Quaternion srot = Quaternion.FromToRotation(Vector3.right,shoulder);
            //Quaternion srotInv = Quaternion.Inverse(srot);

            humanoid.transform.rotation = Quaternion.identity;
            //humanoid.transform.rotation = savedHumanoidRotation;

            //setting joint's rotation by using fromto
            foreach (HumanBodyBones bone in targetBone)
            {
                if (rigBone[bone].isValid && trackingState[bone] != Kinect.TrackingState_NotTracked)
                {
                    rigBone[bone].transform.rotation = rotInv * Quaternion.FromToRotation(Vector3.up, trackingSegment[bone]);
                }
            }
            //rigBone[HumanBodyBones.Chest].offset(srot);

            //head rotation (maybe i can annotation it
            if (headMove && faceDir.magnitude > 1e-6)
            {
                float pitch = faceDir.x, yaw = faceDir.y, roll = faceDir.z;
                if (mirrored)
                {
                    pitch = -pitch;
                    roll  = -roll;
                }
                else
                {
                    pitch = -pitch;
                    yaw   = -yaw;
                }
                rigBone[HumanBodyBones.Head].transform.rotation = Util.toQ(pitch, yaw, roll);
            }
            //hip for rotation model
            Quaternion bodyRot = rot;

            if (mirrored)
            {
                // bodyRot = Quaternion.AngleAxis(180, Vector3.up) * bodyRot;
                float rota = PointRotation(joint[NtUnity.Kinect.JointType_ShoulderRight], joint[NtUnity.Kinect.JointType_ShoulderLeft]);
                //humanoid.transform.rotation = Quaternion.Euler(0, rota, 0);
                bodyRot = Quaternion.AngleAxis(-rota, Vector3.up) * bodyRot;
            }
            humanoid.transform.rotation = bodyRot;
            //spine for position model
            if (move == true)
            {
                Vector3 m = joint[Kinect.JointType_SpineBase];
                if (mirrored)
                {
                    m = new Vector3(-m.x, m.y, -m.z);
                }
                //edit model position----------------------
                m.x = m.x * Constants.prodis + correction;
                m.y = m.y * Constants.prodis;
                //edit model position----------------------
                humanoid.transform.position = m;
            }
        }