/// used for updating every frame
    /// @note While we are still steady (i.e. we haven't gotten a "not steady" event) we update
    /// the time and frame every frame!
    public override void UpdateFrame()
    {
        if (m_context == null || m_context.UserSkeletonValid == false)
        {
            return; // no data;
        }
        NISkeletonTracker tracker = m_pointTracker as NISkeletonTracker;

        if (tracker.Valid == false)
        {
            return; // no one to track.
        }
        NISelectedPlayer player = tracker.GetTrackedPlayer();

        if (player == null || player.Valid == false)
        {
            return;
        }
        NIUserAndSkeleton.NIPoseDetectionStateStatus curStatus = new NIUserAndSkeleton.NIPoseDetectionStateStatus();
        if (m_context.UserGenrator.GetPoseStatus(player.OpenNIUserID, m_poseName, ref curStatus) == false)
        {
            return; // we do not have good pose information
        }
        if (curStatus.m_eState != PoseDetectionState.InPose)
        {
            return;
        }
        if (curStatus.m_timePoseHeld >= m_timeToHoldPose)
        {
            InternalFireDetectEvent();
        }
    }
    // protected methods
    protected override bool InternalInit(NIPointTracker hand)
    {
        NISkeletonTracker curHand = hand as NISkeletonTracker;

        if (curHand == null)
        {
            return(false);
        }
        if (m_context == null || m_context.UserSkeletonValid == false)
        {
            return(false);
        }
        NISelectedPlayer player = curHand.GetTrackedPlayer();

        if (player == null)
        {
            return(false); // no player
        }
        player.m_userChangeEventHandler += PlayerUserChangeHandler;
        if (player.Valid)
        {
            validRequestedPoseDetection = m_context.UserGenrator.RequestPoseDetection(m_poseName, player.OpenNIUserID);
            return(validRequestedPoseDetection);
        }
        validRequestedPoseDetection = false;
        return(true);
    }
Example #3
0
    /// Gesture initialization
    ///
    /// This method is responsible for initializing the gesture to work with a specific hand tracker
    /// @param hand the hand tracker to work with
    /// @return true on success, false on failure (e.g. if the hand tracker does not work with the gesture).
    protected override bool InternalInit(NIPointTracker hand)
    {
        NISkeletonTracker curHand = hand as NISkeletonTracker;

        if (curHand == null)
        {
            return(false);
        }
        return(true);
    }
    /// used for updating every frame
    /// @note While we are still steady (i.e. we haven't gotten a "not steady" event) we update
    /// the time and frame every frame!
    public override void UpdateFrame()
    {
        float             confidence;
        NISkeletonTracker hand     = m_pointTracker as NISkeletonTracker;
        Vector3           newPoint = hand.GetPosWithConfidence(out confidence);

        if (confidence <= 0.5)
        {
            m_currentSteady = false;
            return; // we simply ignore the point...
        }
        m_points.AddPoint(ref newPoint);
        int     numPoints;
        Vector3 stdSqr = m_points.GetStdDeviationSqr(m_steadyTestTime, out numPoints);

        if (numPoints < 1)
        {
            return; // we don't have the points to decide what to do, so we'll just wait...
        }
        if (stdSqr.magnitude < m_steadyStdSqrThreshold && m_currentSteady == false)
        {
            // we found a NEW steady result
            m_currentSteady    = true;
            m_firstSteady      = Time.time;
            m_firedSteadyEvent = false;
            m_firstSteadyPoint = newPoint;
        }
        if (m_currentSteady && stdSqr.magnitude > m_unsteadyStdSqrThreshold)
        {
            m_currentSteady = false;
            return;
        }
        if (m_currentSteady)
        {
            Vector3 pointChange = newPoint - m_firstSteadyPoint;
            if (pointChange.magnitude > m_maxMoveFromFirstSteady)
            {
                m_currentSteady = false;
                return;
            }
            float diffTime = Time.time - m_firstSteady;
            if (diffTime >= m_timeToClick || m_timeToClick <= 0)
            {
                InternalFireDetectEvent();
            }
            if (diffTime > m_timeToReset)
            {
                m_currentSteady = false;
            }
        }
    }
    // protected methods

    /// this method tries to fill a new point on each of the relevant joints.
    /// It returns true if it succeed and false otherwise
    /// @note it will fail if even one of the points has a low confidence!
    /// @return true on success, false on failure.
    protected bool FillPoints()
    {
        // first we find a reference to the skeleton capability
        NISkeletonTracker hand = m_pointTracker as NISkeletonTracker;

        if (hand == null)
        {
            return(false); // no hand to track
        }
        NISelectedPlayer player = hand.GetTrackedPlayer();

        if (player == null || player.Valid == false || player.Tracking == false)
        {
            return(false); // no player to work with...
        }
        // We need to figure out if we have a good confidence on all joints

        SkeletonJointPosition rightHand;
        SkeletonJointPosition leftHand;
        SkeletonJointPosition rightElbow;
        SkeletonJointPosition leftElbow;

        if (player.GetSkeletonJointPosition(SkeletonJoint.RightHand, out rightHand) == false || rightHand.Confidence <= 0.5f)
        {
            return(false);
        }
        if (player.GetSkeletonJointPosition(SkeletonJoint.LeftHand, out leftHand) == false || leftHand.Confidence <= 0.5f)
        {
            return(false);
        }
        if (player.GetSkeletonJointPosition(SkeletonJoint.RightElbow, out rightElbow) == false || rightElbow.Confidence <= 0.5f)
        {
            return(false);
        }
        if (player.GetSkeletonJointPosition(SkeletonJoint.LeftElbow, out leftElbow) == false || leftElbow.Confidence <= 0.5f)
        {
            return(false);
        }
        Vector3 pos = NIConvertCoordinates.ConvertPos(rightHand.Position);

        m_pointsRightHand.AddPoint(ref pos);
        pos = NIConvertCoordinates.ConvertPos(leftHand.Position);
        m_pointsLeftHand.AddPoint(ref pos);
        pos = NIConvertCoordinates.ConvertPos(rightElbow.Position);
        m_pointsRightElbow.AddPoint(ref pos);
        pos = NIConvertCoordinates.ConvertPos(leftElbow.Position);
        m_pointsLeftElbow.AddPoint(ref pos);
        return(true);
    }
    /// @brief Called when the inspector is initialized
    public void OnEnable()
    {
        NISkeletonTracker tracker = target as NISkeletonTracker;

        if (tracker == null)
        {
            m_lastDescription = "Error";
        }
        else
        {
            m_lastDescription = tracker.GetTrackerType();
        }
        m_style           = new GUIStyle();
        m_style.wordWrap  = true;
        m_style.fontStyle = FontStyle.Normal;
        m_content         = new GUIContent();
    }
 /// Release the gesture
 public override void ReleaseGesture()
 {
     if (m_context != null && m_context.UserSkeletonValid)
     {
         NISkeletonTracker tracker = m_pointTracker as NISkeletonTracker;
         if (tracker.Valid)
         {
             NISelectedPlayer player = tracker.GetTrackedPlayer();
             if (player != null && player.Valid && validRequestedPoseDetection)
             {
                 m_context.UserGenrator.ReleasePoseDetection(m_poseName, player.OpenNIUserID);
             }
         }
     }
     m_context      = null;
     m_poseName     = "";
     m_pointTracker = null;
 }
    /// This is true if the gesture is in the middle of doing (i.e. it has detected but not gone out of the gesture).
    /// for our purposes this means the steady event has occurred and the unsteady has not occurred yet
    /// @return a value between 0 and 1. 0 means no pose, 1 means the pose has been detected and held
    /// for a while. a value in the middle means the pose has been detected and has been held this
    /// portion of the time required to fire the trigger (@ref m_timeToHoldPose).
    public override float GestureInProgress()
    {
        if (m_context == null || m_context.UserSkeletonValid == false)
        {
            return(0.0f); // no data;
        }
        NISkeletonTracker tracker = m_pointTracker as NISkeletonTracker;

        if (tracker.Valid == false)
        {
            return(0.0f); // no one to track.
        }
        NISelectedPlayer player = tracker.GetTrackedPlayer();

        if (player == null || player.Valid == false)
        {
            return(0.0f);
        }
        NIUserAndSkeleton.NIPoseDetectionStateStatus curStatus = new NIUserAndSkeleton.NIPoseDetectionStateStatus();
        if (m_context.UserGenrator.GetPoseStatus(player.OpenNIUserID, m_poseName, ref curStatus) == false)
        {
            return(0.0f); // we do not have good pose information
        }
        if (curStatus.m_eState != PoseDetectionState.InPose)
        {
            return(0.0f);
        }
        if (curStatus.m_timePoseHeld < 0)
        {
            return(0.0f);
        }
        if (curStatus.m_timePoseHeld >= m_timeToHoldPose)
        {
            return(1.0f);
        }
        return(curStatus.m_timePoseHeld / m_timeToHoldPose);
    }
Example #9
0
    /// mono-behavior start - initializes the input
    public void Start()
    {
        if(m_input==null)
        {
            m_input = FindObjectOfType(typeof(NIInput)) as NIInput;
            if (m_input == null)
                throw new System.Exception("Please add an NIInput object to the scene");
        }

        if(m_tracker == null) {
            m_tracker = FindObjectOfType(typeof(NISkeletonTracker)) as NISkeletonTracker;
        }

        swipeRightDetector = new InputGestureDetector(m_input, "NIGUI_SWIPE_RIGHT");
        swipeLeftDetector = new InputGestureDetector(m_input, "NIGUI_SWIPE_LEFT");
        crossHandDetector = new InputGestureDetector(m_input, "NIGUI_CROSS_HAND");
        pushDetector = new InputGestureDetector(m_input, "NIGUI_PUSH");
        waveDetector = new InputGestureDetector(m_input, "NIGUI_WAVE");
        steadyDetector = new InputGestureDetector(m_input, "NIGUI_CLICK");
        leftHandupDetector = new InputGestureDetector(m_input, "NIGUI_LEFT_HANDUP");
        menuAreaNormalized =
            new Rect (menuArea.x * Screen.width - (menuArea.width * 0.5f),
                menuArea.y * Screen.height - (menuArea.height * 0.5f),
                menuArea.width, menuArea.height);
    }
Example #10
0
    // protected methods

    /// this method tries to fill a new point on each of the relevant joints.
    /// It returns true if it succeed and false otherwise
    /// @note it will fail if even one of the points has a low confidence!
    /// @return true on success, false on failure.
    protected bool FillPoints()
    {
        // first we find a reference to the skeleton capability
        NISkeletonTracker hand = m_pointTracker as NISkeletonTracker;

        if (hand == null)
        {
            return(false); // no hand to track
        }
        int userID;
        SkeletonCapability capability = hand.GetSkeletonCapability(out userID);

        if (capability == null)
        {
            return(false); // no skeleton capability
        }
        // now that we have a legal capability lets make sure all relevant joints are supported
        if (capability.IsJointActive(SkeletonJoint.RightHand) == false)
        {
            return(false); // joint not supported!
        }
        if (capability.IsJointActive(SkeletonJoint.LeftHand) == false)
        {
            return(false); // joint not supported!
        }
        if (capability.IsJointActive(SkeletonJoint.RightElbow) == false)
        {
            return(false); // joint not supported!
        }
        if (capability.IsJointActive(SkeletonJoint.LeftElbow) == false)
        {
            return(false); // joint not supported!
        }
        // since now we know all relevant joints are supported we need to figure out if we have
        // a good confidence for
        SkeletonJointPosition rightHand = capability.GetSkeletonJointPosition(userID, SkeletonJoint.RightHand);

        if (rightHand.Confidence <= 0.5f)
        {
            return(false); // we have low confidence so lets ignore this set
        }
        SkeletonJointPosition leftHand = capability.GetSkeletonJointPosition(userID, SkeletonJoint.LeftHand);

        if (leftHand.Confidence <= 0.5f)
        {
            return(false); // we have low confidence so lets ignore this set
        }
        SkeletonJointPosition rightElbow = capability.GetSkeletonJointPosition(userID, SkeletonJoint.RightElbow);

        if (rightElbow.Confidence <= 0.5f)
        {
            return(false); // we have low confidence so lets ignore this set
        }
        SkeletonJointPosition leftElbow = capability.GetSkeletonJointPosition(userID, SkeletonJoint.LeftElbow);

        if (leftElbow.Confidence <= 0.5f)
        {
            return(false); // we have low confidence so lets ignore this set
        }
        Vector3 pos = NIConvertCoordinates.ConvertPos(rightHand.Position);

        m_pointsRightHand.AddPoint(ref pos);
        pos = NIConvertCoordinates.ConvertPos(leftHand.Position);
        m_pointsLeftHand.AddPoint(ref pos);
        pos = NIConvertCoordinates.ConvertPos(rightElbow.Position);
        m_pointsRightElbow.AddPoint(ref pos);
        pos = NIConvertCoordinates.ConvertPos(leftElbow.Position);
        m_pointsLeftElbow.AddPoint(ref pos);
        return(true);
    }
    /// editor OnInspectorGUI to control the NIEventLogger properties
    override public void OnInspectorGUI()
    {
        EditorGUI.indentLevel = 0;
        EditorGUIUtility.LookLikeInspector();
        NISkeletonTracker tracker = target as NISkeletonTracker;

        GUILayout.Label("Tracker description:  ");
        GUILayout.BeginHorizontal();
        GUILayout.Space(20);
        GUILayout.Label(m_lastDescription, m_style);
        GUILayout.EndHorizontal();

        if (m_lastDescription.CompareTo(tracker.GetTrackerType()) != 0)
        {
            EditorGUILayout.Space();
            Color tmpColor = m_style.normal.textColor;
            m_style.normal.textColor = Color.red;
            m_content.text           = "Tracker description changed! Please relink all references";
            m_content.tooltip        = "When objects reference the tracker (such as NIInput), they use the description to choose between the various options. When the description changes, the linking is lost. You need to relink all references unless you return the description to the previous definition by changing the player and joint";
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label(m_content, m_style);
            GUILayout.EndHorizontal();
            m_style.normal.textColor = tmpColor;
        }
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Who to track", "");
        EditorGUI.indentLevel += 2;
        tracker.m_playerNum    = EditorGUILayout.IntField("Player Num", tracker.m_playerNum);
        if (tracker.m_playerNum < 0)
        {
            tracker.m_playerNum = 0;
        }
        tracker.m_jointToUse                = (SkeletonJoint)EditorGUILayout.EnumPopup("Joint to track", (System.Enum)tracker.m_jointToUse);
        EditorGUI.indentLevel              -= 2;
        tracker.m_context                   = EditorGUILayout.ObjectField("context", tracker.m_context, typeof(OpenNISettingsManager), true) as OpenNISettingsManager;
        tracker.m_playerManager             = EditorGUILayout.ObjectField("Player manager", tracker.m_playerManager, typeof(NIPlayerManager), true) as NIPlayerManager;
        tracker.m_startingPoseReferenceType = (NISkeletonTracker.StartingPosReferenceType)EditorGUILayout.EnumPopup("StartPos type", (System.Enum)tracker.m_startingPoseReferenceType);
        EditorGUI.indentLevel              += 2;
        switch (tracker.m_startingPoseReferenceType)
        {
        case NISkeletonTracker.StartingPosReferenceType.SetPointReference:
            tracker.m_StartPosModifier = EditorGUILayout.Vector3Field("StartPos", tracker.m_StartPosModifier);
            break;

        case NISkeletonTracker.StartingPosReferenceType.TrackedJointReference:
            EditorGUILayout.LabelField("StartPos=ref of", "" + tracker.m_jointToUse);
            break;

        case NISkeletonTracker.StartingPosReferenceType.StaticModifierToOtherJoint:
            tracker.m_referenceJoint   = (SkeletonJoint)EditorGUILayout.EnumPopup("cur position of", (System.Enum)tracker.m_referenceJoint);
            tracker.m_StartPosModifier = EditorGUILayout.Vector3Field("Modified by", tracker.m_StartPosModifier);
            break;

        case NISkeletonTracker.StartingPosReferenceType.ScaledModifierToOtherJoint:
            tracker.m_referenceJoint   = (SkeletonJoint)EditorGUILayout.EnumPopup("cur position of", (System.Enum)tracker.m_referenceJoint);
            tracker.m_StartPosModifier = EditorGUILayout.Vector3Field("Modified by", tracker.m_StartPosModifier);
            EditorGUILayout.LabelField("scaled by distance", "between");
            EditorGUI.indentLevel         += 2;
            tracker.m_referenceJointScale1 = (SkeletonJoint)EditorGUILayout.EnumPopup("joint1", (System.Enum)tracker.m_referenceJointScale1);
            tracker.m_referenceJointScale2 = (SkeletonJoint)EditorGUILayout.EnumPopup("joint2", (System.Enum)tracker.m_referenceJointScale2);
            EditorGUI.indentLevel         -= 2;
            break;
        }
        EditorGUI.indentLevel -= 2;
        EditorGUILayout.Space();
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }