private void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
            {
                return;
            }

            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
            {
                SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
            {
                SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = false;
            }

            foreach (GazeIndex index in GazePriority)
            {
                Ray  GazeRay;
                int  dart_board_layer_id = LayerMask.NameToLayer("NoReflection");
                bool eye_focus;
                if (eye_callback_registered)
                {
                    eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out FocusInfo, 0, MaxDistance, (1 << dart_board_layer_id), eyeData);
                }
                else
                {
                    eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out FocusInfo, 0, MaxDistance, (1 << dart_board_layer_id));
                }

                if (eye_focus)
                {
                    DartBoard dartBoard = FocusInfo.transform.GetComponent <DartBoard>();
                    if (dartBoard != null)
                    {
                        dartBoard.Focus(FocusInfo.point);
                    }
                    break;
                }
            }
        }
Exemplo n.º 2
0
    private void FixedUpdate()
    {
        if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
            SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
        {
            return;
        }



        if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eyeCallbackRegistered == false)
        {
            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(
                Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            eyeCallbackRegistered = true;
        }
        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eyeCallbackRegistered == true)
        {
            SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(
                Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            eyeCallbackRegistered = false;
        }

        foreach (GazeIndex index in gazePriority)
        {
            Ray  GazeRay;
            bool eye_focus;

            //eye call back should be enabled so we can get extra EyeData and save them in a logger
            if (eyeCallbackRegistered)
            {
                eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out focusInfo, 0,
                                                  maxDistance, ignoreLayerBitMask, EyeData);

                //Can be used if we don't want to specify layer to be ignored
                //eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out FocusInfo, 0, MaxDistance, eyeData);
            }
            else
            {
                eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out focusInfo, 0,
                                                  maxDistance, ignoreLayerBitMask);
            }
            //Debug.Log("Time_delta_unity: " + Time.deltaTime*1000 + "Time_unity: " + Time.time*1000 +
            //          " Frame_unity: " + Time.frameCount + " Time_ET: " + EyeData.timestamp +
            //          " Frame_ET: " + EyeData.frame_sequence);

            //ET Logging
            //if(focusInfo.collider != null) Debug.Log("Looking at: " + focusInfo.collider.gameObject.name);
            if (loggerInitialized)
            {
                logDataSb.Clear();
                //for 3D ET projection (collider hit) coordinate
                if (logEtPosition)
                {
                    logDataSb.Append(focusInfo.point.x + LoggerFormatDictionary["separatorFormat"] +
                                     focusInfo.point.y + LoggerFormatDictionary["separatorFormat"] +
                                     focusInfo.point.z);
                }
                //for collider hit name
                if (logFixatedObject)
                {
                    if (!string.IsNullOrEmpty(logData))
                    {
                        logDataSb.Append(LoggerFormatDictionary["separatorFormat"]);
                    }

                    if (focusInfo.collider == null)
                    {
                        if (eyeCallbackRegistered && EyeData.no_user)
                        {
                            fixationReport = "no user";
                        }
                        else
                        {
                            fixationReport = "no data";
                        }
                    }
                    else
                    {
                        fixationReport = focusInfo.collider.gameObject.name;
                    }
                    logDataSb.Append(fixationReport);
                }
                //extra data per left/right eye
                if (logBothEyes)
                {
                    //TODO...
                }
                //extra data per HTC eyetracker service variables
                if (logAccuracy)
                {
                    //TODO...
                }

                //finally, send to logger...
                Logger.GetComponent <PathScript>().logCustomData(logName, logDataSb.ToString(), this.gameObject);
            }

            //canvas logging
            if (logFixationToCanvas)
            {
                FixationCanvas.text = fixationReport;
            }

            if (eye_focus)
            {
                //renders user-point
                // the line has coordinates of gaze ray previosly calulated by Focus function
                if (renderGazeRay && gazeRayRenderer != null)
                {
                    Vector3 GazeDirectionCombined_FromFocus =
                        Camera.main.transform.TransformDirection(GazeRay.direction);
                    gazeRayRenderer.SetPosition(0, Camera.main.transform.position);
                    gazeRayRenderer.SetPosition(1, Camera.main.transform.position +
                                                GazeDirectionCombined_FromFocus * maxDistance);
                }

                if (drawGazeSphere)
                {
                    gazeSphere.transform.position = focusInfo.point;
                }
                break;
            }
        }
    }
Exemplo n.º 3
0
        private void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING)
            {
                return;
            }

            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && _eyeCallbackRegistered == false)
            {
                SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                _eyeCallbackRegistered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && _eyeCallbackRegistered == true)
            {
                SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                _eyeCallbackRegistered = false;
            }

            bool eyeFocus = false;

            foreach (GazeIndex index in _gazePriority)
            {
                Ray gazeRay;

                if (_eyeCallbackRegistered)
                {
                    eyeFocus = SRanipal_Eye_v2.Focus(index, out gazeRay, out _focusInfo, 0, _maxDistance, trackedObjectLayers, _eyeData);
                }
                else
                {
                    eyeFocus = SRanipal_Eye_v2.Focus(index, out gazeRay, out _focusInfo, 0, _maxDistance, trackedObjectLayers);
                }

                if (eyeFocus)
                {
                    _previousObjectInFocus = _objectInFocus;
                    _objectInFocus         = _focusInfo.collider;

                    var previousTrackedObject = _trackedObject;
                    _trackedObject = _focusInfo.transform.GetComponent <TrackedObject>();
                    if (_trackedObject != null)
                    {
                        _trackedObjectInfo = new TrackedObjectInfo(_trackedObject.ObjectId, _focusInfo.distance);
                    }

                    if (_objectInFocus == _previousObjectInFocus)
                    {
                        //do nothing
                    }
                    else
                    {
                        if (previousTrackedObject != null)
                        {
                            ExitGaze(previousTrackedObject);
                        }

                        if (_trackedObject != null)
                        {
                            EnterGaze(_trackedObject);
                        }
                    }
                    break;
                }
            }
            if (!eyeFocus)
            {
                _previousObjectInFocus = null;
                _objectInFocus         = null;
                if (_trackedObject != null)
                {
                    ExitGaze(_trackedObject);
                }
                _trackedObject = null;
            }
        }