public KinectDataPoint getDataPoint(JointType type, KinectUser user)
        {
            KinectDataPoint result = null;
            jointMap.TryGetValue(type, out result);

            return result;
        }
    void IKinectUser_EventListener._onKinectUserUpdate(KinectUser kuser)
    {
        IDictionaryEnumerator ide = m_kinectUser_EventListener.GetEnumerator();

        while (ide.MoveNext())
        {
            IKinectUser_EventListener kl = (IKinectUser_EventListener)(((DictionaryEntry)(ide.Current)).Key);
            kl._onKinectUserUpdate(kuser);
        }
    }
 public override void _onKinectUserIn(KinectUser kuser)
 {
     for (int i = 0; i < m_kuser_ary.Length; ++i)
     {
         if (null == m_kuser_ary[i])
         {
             m_kuser_ary[i] = kuser;
             break;
         }
     }
 }
        public int getUserBodyAngle(KinectUser user)
        {
            KinectDataPoint sLeft = getDataPoint(JointType.ShoulderLeft, user);
            KinectDataPoint sRight = getDataPoint(JointType.ShoulderRight, user);

            if (null != sLeft && null != sRight)
            {
                return sRight.CalcDepthAngle(sLeft);
            }

            return 0;
        }
 public override void _onKinectUserUpdate(KinectUser kuser)
 {
     for (int i = 0; i < m_kuser_ary.Length; ++i)
     {
         if (null != m_kuser_ary[i] &&
             m_kuser_ary[i].m_id == kuser.m_id)
         {
             m_kuser_ary[i] = kuser;
             break;
         }
     }
 }
示例#6
0
    public void copyValues(KinectUser kuser)
    {
        m_id = kuser.m_id;

        for (int i = 0; i < m_bone.Length; ++i)
        {
            m_bone[i] = kuser.m_bone[i];
        }

        m_state           = kuser.m_state;
        m_handState_left  = kuser.m_handState_left;
        m_handState_right = kuser.m_handState_right;
    }
示例#7
0
 void OnKinectUserLeave(KinectUser kuser)
 {
     Debug.Log("KinectListner_Impl_outputLog::OnKinectUserLeave -> " + kuser.m_id);
 }
 public int getUserBodyAngle(KinectUser user)
 {
     return 0;
 }
 private JointType isGestureActive(KinectUser user)
 {
     lock (lockObj)
     {
         return userDetector.isGestureActive(user, dataPointMap[user]);
     }
 }
        private InteractionGesture checkOneHandedGestures(JointType joint, int bodyAngle, KinectUser user)
        {
            bool gestureFound = false;

            lock (lockObj)
            {
                /*----- circle gestures -----*/
                gestureFound = circleDetector.CheckCircleClockGesture(dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.CircleClock;

                gestureFound = circleDetector.CheckCircleCounterClockGesture(dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.CircleCounterClock;

                /*----- wave gesture -----*/
                gestureFound = waveDetector.CheckWaveGesture(dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.Wave;

                /*----- push / pull gestures -----*/
                gestureFound = pushPullDetector.CheckPushGesture(bodyAngle, dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.PushOneHanded;

                // TODO: activate pull gesture
                //gestureFound = pushPullDetector.CheckPullGesture(bodyAngle, dataPointMap[user].GetQueue(joint));
                //if (gestureFound) return InteractionGesture.PullOneHanded;

                /*----- swipe gestures -----*/
                gestureFound = swipeDetector.CheckToLeftSwipeGesture(bodyAngle, dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.SwipeToLeft;

                gestureFound = swipeDetector.CheckToRightSwipeGesture(bodyAngle, dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.SwipeToRight;

                gestureFound = swipeDetector.CheckUpSwipeGesture(bodyAngle, dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.SwipeUp;

                gestureFound = swipeDetector.CheckDownSwipeGesture(bodyAngle, dataPointMap[user].GetQueue(joint));
                if (gestureFound) return InteractionGesture.SwipeDown;
            }

            return InteractionGesture.None;
        }
        private void addDataPoint(JointType joint, KinectUser user)
        {
            KinectDataPoint point = getSekeltonService().getDataPoint(joint, user);

            if (null != point)
            {
                dataPointMap[user].AddPoint(point, joint);
            }
        }
示例#12
0
 public KinectUser(KinectUser kuser)
 {
     copyValues(kuser);
 }
    void RotateJoint(KinectUser kuser, int bone)
    {
        //if blendWeight is 0 there is no need to compute the rotations
        if (blendWeight <= 0)
        {
            return;
        }
        Vector3 upDir    = new Vector3();
        Vector3 rightDir = new Vector3();

        if (bone == (int)Kinect.NuiSkeletonPositionIndex.Spine)
        {
            upDir    = ((Hip_Left.transform.position + Hip_Right.transform.position) / 2F) - Hip_Override.transform.position;
            rightDir = Hip_Right.transform.position - Hip_Left.transform.position;
        }

        //if the model is not animated, reset rotations to fix twisted joints
        if (!animated)
        {
            _bones[bone].transform.localRotation = _baseRotation[bone];
        }

        //if the required bone data from the kinect isn't available, return
        //if( kuser.m_bone[bone] == Kinect.NuiSkeletonPositionTrackingState.NotTracked)
        //{
        //	return;
        //}

        //get the target direction of the bone in world space
        //for the majority of bone it's bone - 1 to bone, but Hip_Override and the outside
        //shoulders are determined differently.

        Vector3 dir = _boneDir[bone];
        Vector3 target;

        //if bone % 4 == 0 then it is either an outside shoulder or the hip override
        if (bone % 4 == 0)
        {
            //hip override is at Hip_Left
            if (bone == (int)Kinect.NuiSkeletonPositionIndex.HipLeft)
            {
                //target = vector from hip_center to average of hips left and right
                target = ((kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.HipLeft]
                           + kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.HipRight]) / 2F)
                         - kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.HipCenter];
            }
            //otherwise it is one of the shoulders
            else
            {
                //target = vector from shoulder_center to bone
                target = kuser.m_bone[bone] - kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.ShoulderCenter];
            }
        }
        else
        {
            //target = vector from previous bone to bone
            target = kuser.m_bone[bone] - kuser.m_bone[bone - 1];
        }
        //transform it into bone-local space (independant of the transform of the controller)
        target = transform.TransformDirection(target);
        //m_kuser.m_bone = target;
        target = _bones[bone].transform.InverseTransformDirection(target);
        //create a rotation that rotates dir into target
        Quaternion quat = Quaternion.FromToRotation(dir, target);

        //if bone is the spine, add in the rotation along the spine
        if (bone == (int)Kinect.NuiSkeletonPositionIndex.Spine)
        {
            //rotate the chest so that it faces forward (determined by the shoulders)
            dir    = _chestRight;
            target = kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.ShoulderRight]
                     - kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.ShoulderLeft];

            target  = transform.TransformDirection(target);
            target  = _bones[bone].transform.InverseTransformDirection(target);
            target -= Vector3.Project(target, _boneDir[bone]);

            quat *= Quaternion.FromToRotation(dir, target);
        }
        //if bone is the hip override, add in the rotation along the hips
        else if (bone == (int)Kinect.NuiSkeletonPositionIndex.HipLeft)
        {
            //rotate the hips so they face forward (determined by the hips)
            dir    = _hipRight;
            target = kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.HipRight]
                     - kuser.m_bone[(int)Kinect.NuiSkeletonPositionIndex.HipLeft];

            target  = transform.TransformDirection(target);
            target  = _bones[bone].transform.InverseTransformDirection(target);
            target -= Vector3.Project(target, _boneDir[bone]);

            quat *= Quaternion.FromToRotation(dir, target);
        }

        //reduce the effect of the rotation using the blend parameter
        quat = Quaternion.Lerp(Quaternion.identity, quat, blendWeight);
        //apply the rotation to the local rotation of the bone
        _bones[bone].transform.localRotation = _bones[bone].transform.localRotation * quat;

        if (bone == (int)Kinect.NuiSkeletonPositionIndex.Spine)
        {
            restoreBone(_bones[(int)Kinect.NuiSkeletonPositionIndex.HipLeft], _boneDir[(int)Kinect.NuiSkeletonPositionIndex.HipLeft], upDir);
            restoreBone(_bones[(int)Kinect.NuiSkeletonPositionIndex.HipLeft], _hipRight, rightDir);
        }

        return;
    }
示例#14
0
 void OnKinectUserUpdate(KinectUser kuser)
 {
 }
    // Update is called once per frame
    void Update()
    {
        m_kuser.Clear();

        Hashtable h = KinectListenerManager.m_skeletonWrapper.getKinectUserTable();

        if (h.Count == 1)
        {
            IDictionaryEnumerator ide = h.GetEnumerator();
            while (ide.MoveNext())
            {
                KinectUser kuser = (KinectUser)(((DictionaryEntry)(ide.Current)).Value);

                if (kuser.m_bone[0].x <= 0.0f)
                {
                    m_kuser.Add(kuser);
                    break;
                }
                else
                {
                    m_kuser.Add(null);  //leftUser不存在
                    m_kuser.Add(kuser); //rightUser存在
                    break;
                }
            }
        }
        else if (h.Count > 1)
        {//more than 1
            float      dis_min_left   = float.MaxValue;
            KinectUser kuser_min_left = null;

            float      dis_min_right   = float.MaxValue;
            KinectUser kuser_min_right = null;

            IDictionaryEnumerator ide = h.GetEnumerator();
            while (ide.MoveNext())
            {
                KinectUser kuser = (KinectUser)(((DictionaryEntry)(ide.Current)).Value);

                if (kuser.m_bone[0].x <= 0.0f)
                {//left
                    float dis = Vector3.Distance(m_leftPoint, kuser.m_bone[0]);
                    if (dis < dis_min_left)
                    {
                        dis_min_left   = dis;
                        kuser_min_left = kuser;
                    }
                }
                else
                {//right
                    float dis = Vector3.Distance(m_rightPoint, kuser.m_bone[0]);
                    if (dis < dis_min_right)
                    {
                        dis_min_right   = dis;
                        kuser_min_right = kuser;
                    }
                }
            }

            if (null != kuser_min_right)
            {
                m_kuser.Add(kuser_min_left);
                m_kuser.Add(kuser_min_right);
            }
            else if (null != kuser_min_left)
            {
                m_kuser.Add(kuser_min_left);
            }
        }

        m_kuser_ary = m_kuser.ToArray();
    }
        public JointType isGestureActive(KinectUser user, PointQueue queue)
        {
            KinectDataPoint handLeft = getSekeltonService().getDataPoint(JointType.HandLeft, user);
            KinectDataPoint handRight = getSekeltonService().getDataPoint(JointType.HandRight, user);
            KinectDataPoint head = getSekeltonService().getDataPoint(JointType.Head, user);

            if (null != handLeft && null != handRight && null != head)
            {
                JointType? result = null;

                if (handLeft.Y > head.Y && handRight.Y > head.Y)
                {
                    result = null;
                }
                else if (handLeft.Y > head.Y && handLeft.ScreenY < handRight.ScreenY)
                {
                    result = JointType.HandRight;
                }
                else if (handRight.Y > head.Y && handRight.ScreenY < handLeft.ScreenY)
                {
                    result = JointType.HandLeft;
                }

                if (null != result)
                {
                    if (null == LastActiveUser || user != LastActiveUser)
                    {
                        LastActiveUser = user;
                        queue.GetQueue(result.Value);
                    }
                    return result.Value;
                }
            }

            // if the last user is not active anymore -> set lastActiveUser to null
            if (null != LastActiveUser && user == LastActiveUser.Value)
            {
                LastActiveUser = null;
            }

            return default(JointType);
        }
 public virtual void _onKinectUserUpdate(KinectUser kuser)
 {
     SendMessage("OnKinectUserUpdate", kuser, SendMessageOptions.DontRequireReceiver);
 }