Example #1
0
        public override bool Process(Trigger trigger)
        {
            trigger.ErrorDetected = false;
            if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Object))
            {
                trigger.ErrorDetected = true;
                return(false);
            }

            bool success = false;

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

            EventTrigger specificTrigger = (EventTrigger)trigger;

            specificTrigger.Source = this.name;

            var tracker = SenseToolkitManager.Instance.SenseManager.QueryTracker();

            if (SenseToolkitManager.Instance.Initialized && tracker != null)
            {
                if (_trackerID < 0 && Tracker2DPath != "")
                {
                    if (tracker.Set2DTrackFromFile(Tracker2DPath, out _trackerID) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        trigger.ErrorDetected = true;
                        Debug.LogError("Cannot set 2D image. Make sure it is a valid image (png)");
                        return(false);
                    }
                }

                PXCMTracker.TrackingValues trackingValues;

                int currentNumberOfObjects = tracker.QueryNumberTrackingValues();

                if (Tracker2DPath == "")
                {
                    if (currentNumberOfObjects < _numberOfDetectedObjects)
                    {
                        if (currentNumberOfObjects >= NumberOfObjects - 1)
                        {
                            if (currentNumberOfObjects == NumberOfObjects - 1 || RiseForEveryLostObject)
                            {
                                success = true;
                            }
                        }
                    }

                    _numberOfDetectedObjects = currentNumberOfObjects;
                }
                else
                {
                    // for now assuming there is maximum 1 object

                    if (tracker.QueryTrackingValues(_trackerID, out trackingValues) >= pxcmStatus.PXCM_STATUS_NO_ERROR && trackingValues.state == PXCMTracker.ETrackingState.ETS_TRACKING)
                    {
                        // here we would check how many we found...

                        currentNumberOfObjects = 1;
                        success = false;
                    }
                    else
                    {
                        if (_numberOfDetectedObjects >= NumberOfObjects)
                        {
                            currentNumberOfObjects = 0;
                            success = true;
                        }
                    }
                }

                _numberOfDetectedObjects = currentNumberOfObjects;
            }
            return(success);
        }