예제 #1
0
        public override bool Process(Trigger trigger)
        {
            trigger.ErrorDetected = false;
            if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Hand))
            {
                trigger.ErrorDetected = true;
                Debug.LogError("Hand Analysis Module Not Set");
                return(false);
            }

            if (!(trigger is EventTrigger))
            {
                trigger.ErrorDetected = true;
                return(false);
            }

            //AcquireFrame
            if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null)
            {
                if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 0)
                {
                    int totalNumOfFiredGestures = SenseToolkitManager.Instance.HandDataOutput.QueryFiredGesturesNumber();
                    PXCMHandData.GestureData gestureData;

                    for (int i = 0; i < totalNumOfFiredGestures; i++)
                    {
                        if (SenseToolkitManager.Instance.HandDataOutput.QueryFiredGestureData(i, out gestureData) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            PXCMHandData.IHand handData = null;
                            if ((ContinuousTracking && SenseToolkitManager.Instance.HandDataOutput.QueryHandDataById(_uniqueID, out handData) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                                ||
                                SenseToolkitManager.Instance.HandDataOutput.QueryHandData(WhichHand, HandIndex, out handData) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                _uniqueID = handData.QueryUniqueId();
                                if (handData.QueryUniqueId() == gestureData.handId)
                                {
                                    MCTTypes.RSUnityToolkitGestures firedGesture = MCTTypes.GetGesture(gestureData.name);

                                    if (((!Gesture.Equals(MCTTypes.RSUnityToolkitGestures.None)) && Gesture.Equals(firedGesture)))
                                    {
                                        if (!_lastFrameDetected)
                                        {
                                            _lastFrameDetected = true;
                                            return(true);
                                        }
                                        else
                                        {
                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    _lastFrameDetected = false;
                }
            }
            return(false);
        }
예제 #2
0
        public override bool Process(Trigger trigger)
        {
            trigger.ErrorDetected = false;
            if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Hand))
            {
                trigger.ErrorDetected = true;
                Debug.LogError("Hand Analysis Module Not Set");
                return(false);
            }

            if (!(trigger is EventTrigger))
            {
                trigger.ErrorDetected = true;
                return(false);
            }


            EventTrigger specificTrigger = (EventTrigger)trigger;

            specificTrigger.Source = this.name;


            bool success = false;

            if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null)
            {
                PXCMHandData.IHand data = null;

                if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 0
                    &&
                    (
                        (ContinuousTracking && SenseToolkitManager.Instance.HandDataOutput.QueryHandDataById(_uniqueID, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        ||
                        SenseToolkitManager.Instance.HandDataOutput.QueryHandData(WhichHand, HandIndex, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    )
                {
                    _uniqueID          = data.QueryUniqueId();
                    _lastFrameDetected = true;
                }
                else
                {
                    if (_lastFrameDetected)
                    {
                        success = true;
                    }

                    _lastFrameDetected = false;
                }
            }
            else
            {
                return(false);
            }

            return(success);
        }
예제 #3
0
        public override bool Process(Trigger trigger)
        {
            trigger.ErrorDetected = false;
            if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Hand))
            {
                trigger.ErrorDetected = true;
                Debug.LogError("Hand Analysis Module Not Set");
                return(false);
            }

            if (!(trigger is TrackTrigger))
            {
                trigger.ErrorDetected = true;
                return(false);
            }

            bool success = false;

            // make sure we have valid values

            if (RealWorldBoxDimensions.x <= 0)
            {
                RealWorldBoxDimensions.x = 1;
            }

            if (RealWorldBoxDimensions.y <= 0)
            {
                RealWorldBoxDimensions.y = 1;
            }

            if (RealWorldBoxDimensions.z <= 0)
            {
                RealWorldBoxDimensions.z = 1;
            }


            if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null)
            {
                PXCMHandData.IHand data = null;

                if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 0 &&
                    ((ContinuousTracking && SenseToolkitManager.Instance.HandDataOutput.QueryHandDataById(_uniqueID, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                     ||
                     SenseToolkitManager.Instance.HandDataOutput.QueryHandData(WhichHand, HandIndex, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    )
                {
                    // Process Tracking

                    _uniqueID = data.QueryUniqueId();
                    PXCMHandData.JointData jointData;

                    data.QueryTrackedJoint(TrackedJoint, out jointData);

                    TrackTrigger specificTrigger = (TrackTrigger)trigger;

                    PXCMPoint3DF32 point    = jointData.positionWorld;
                    Vector3        position = new Vector3(point.x, point.y, point.z);

                    position.x *= -100;
                    position.y *= 100;
                    position.z *= 100;

                    if (position.x + position.y + position.z == 0)
                    {
                        return(false);
                    }

                    TrackingUtilityClass.ClampToRealWorldInputBox(ref position, RealWorldBoxCenter, RealWorldBoxDimensions);
                    TrackingUtilityClass.Normalize(ref position, RealWorldBoxCenter, RealWorldBoxDimensions);

                    if (!float.IsNaN(position.x) && !float.IsNaN(position.y) && !float.IsNaN(position.z))
                    {
                        specificTrigger.Position = position;
                    }
                    else
                    {
                        return(false);
                    }

                    Quaternion q = new Quaternion(jointData.globalOrientation.x, jointData.globalOrientation.y,
                                                  jointData.globalOrientation.z, jointData.globalOrientation.w);

                    q = q * _zInvert * _yInvert;

                    specificTrigger.RotationQuaternion = q;

                    success = true;
                }
            }
            else
            {
                return(false);
            }

            return(success);
        }
        public override bool Process(Trigger trigger)
        {
            trigger.ErrorDetected = false;

            if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Hand))
            {
                Debug.LogError("Hand Analysis Module Not Set");
                trigger.ErrorDetected = true;
                return(false);
            }

            if (!(trigger is TranslationTrigger))
            {
                trigger.ErrorDetected = true;
                return(false);
            }

            bool success = false;

            // make sure we have valid values

            if (RealWorldBoxDimensions.x <= 0)
            {
                RealWorldBoxDimensions.x = 1;
            }

            if (RealWorldBoxDimensions.y <= 0)
            {
                RealWorldBoxDimensions.y = 1;
            }

            if (RealWorldBoxDimensions.z <= 0)
            {
                RealWorldBoxDimensions.z = 1;
            }


            if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null)
            {
                PXCMHandData.IHand data = null;

                if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 0
                    &&
                    (
                        (ContinuousTracking && SenseToolkitManager.Instance.HandDataOutput.QueryHandDataById(_uniqueID, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        ||
                        SenseToolkitManager.Instance.HandDataOutput.QueryHandData(WhichHand, HandIndex, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    )
                {
                    _uniqueID = data.QueryUniqueId();

                    // Process Translation
                    if (trigger is TranslationTrigger)
                    {
                        TranslationTrigger specificTrigger = (TranslationTrigger)trigger;

                        PXCMHandData.JointData jointData;
                        data.QueryTrackedJoint(TrackedJoint, out jointData);

                        Vector3 vecPos = new Vector3(-(jointData.positionWorld.x), (jointData.positionWorld.y), jointData.positionWorld.z);

                        vecPos.x *= 100;
                        vecPos.y *= 100;
                        vecPos.z *= 100;

                        TrackingUtilityClass.ClampToRealWorldInputBox(ref vecPos, RealWorldBoxCenter, RealWorldBoxDimensions);
                        TrackingUtilityClass.Normalize(ref vecPos, RealWorldBoxCenter, RealWorldBoxDimensions);

                        if (specificTrigger.Restart)
                        {
                            specificTrigger.Restart = false;
                            _referencePosition      = vecPos;
                            return(false);
                        }

                        specificTrigger.Translation = vecPos - _referencePosition;

                        Vector3 passCriteria = new Vector3();
                        passCriteria.x = Mathf.Abs(vecPos.x) - Mathf.Abs(Thresholds.x);
                        passCriteria.y = Mathf.Abs(vecPos.y) - Mathf.Abs(Thresholds.y);
                        passCriteria.z = Mathf.Abs(vecPos.z) - Mathf.Abs(Thresholds.z);

                        if (passCriteria.x > 0 || passCriteria.y > 0 || passCriteria.z > 0)
                        {
                            _referencePosition = vecPos;

                            success = true;
                        }
                    }
                }
            }
            else
            {
                return(false);
            }

            return(success);
        }
예제 #5
0
        public override bool Process(Trigger trigger)
        {
            trigger.ErrorDetected = false;
            if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Hand))
            {
                trigger.ErrorDetected = true;
                Debug.LogError("Hand Analysis Module Not Set");
                return(false);
            }

            if (!(trigger is EventTrigger))
            {
                trigger.ErrorDetected = true;
                return(false);
            }

            bool success = false;

            //AcquireFrame
            if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null)
            {
                PXCMHandData.IHand data = null;

                if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 0
                    &&
                    (
                        (ContinuousTracking && SenseToolkitManager.Instance.HandDataOutput.QueryHandDataById(_uniqueID, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        ||
                        SenseToolkitManager.Instance.HandDataOutput.QueryHandData(WhichHand, HandIndex, out data) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    )
                {
                    _uniqueID = data.QueryUniqueId();

                    PXCMHandData.JointData jointD;
                    data.QueryTrackedJoint(PXCMHandData.JointType.JOINT_PINKY_JT2, out jointD);

                    if (jointD.confidence < 100)
                    {
                        return(false);
                    }

                    if (data.QueryOpenness() <= OpennessFactor)
                    {
                        _lastFrameDetected = true;
                    }
                    else
                    {
                        if (_lastFrameDetected)
                        {
                            success = true;
                        }

                        _lastFrameDetected = false;
                    }
                }
                else
                {
                    if (_lastFrameDetected)
                    {
                        success = true;
                    }

                    _lastFrameDetected = false;
                }
            }
            return(success);
        }