Exemplo n.º 1
0
        private void OnNewCoordinates(TobiiCoordinates coordinates)
        {
            lock (Helpers.locker)
            {
                if (mouse_state == MouseState.Controlling || mouse_state == MouseState.Calibrating)
                {
                    if (DateTime.Now > freeze_until)
                    {
                        this.current_coordinates = coordinates.ToCoordinates(Options.Instance.calibration_mode.additional_dimensions_configuration);
                        gaze_point = coordinates.gaze_point;

                        if (mouse_state == MouseState.Calibrating && Helpers.GetDistance(gaze_point, calibration_start_gaze_point) > Options.Instance.reset_calibration_zone_size)
                        {
                            mouse_state = MouseState.Controlling;
                        }

                        if (mouse_state == MouseState.Controlling &&
                            (DateTime.Now - last_shift_update_time).TotalMilliseconds > Options.Instance.calibration_mode.update_period_ms)
                        {
                            last_shift_update_time = DateTime.Now;
                            calibration_shift      = CalibrationManager.Instance.GetShift(current_coordinates);
                        }
                    }

                    UpdateCursorPosition();
                }
            }
        }
Exemplo n.º 2
0
        private void OnNewCoordinates(TobiiCoordinates coordinates)
        {
            lock (Helpers.locker)
            {
                if (mouse_state == MouseState.Idle &&
                    (DateTime.Now - idle_start_time).TotalSeconds > 60)
                {
                    CoordinateSmoother.Reset();
                    return;
                }

                if (DateTime.Now > freeze_until)
                {
                    if (mouse_state == MouseState.Calibrating &&
                        Helpers.GetDistance(coordinates.gaze_point, calibration_start_gaze_point) > Options.Instance.reset_calibration_zone_size)
                    {
                        mouse_state = MouseState.Controlling;
                    }

                    if (mouse_state == MouseState.Calibrating)
                    {
                        // The only thing to update while calibrating is gaze point.
                        float[] coordinates_copy = new float[smoothened_error_correction.сoordinates.Length];
                        smoothened_error_correction.сoordinates.CopyTo(coordinates_copy, 0);
                        var smoothened_error_correction_clone = new EyeTrackerErrorCorrection(coordinates_copy, smoothened_error_correction.shift);
                        smoothened_error_correction_clone.сoordinates[0] = coordinates.gaze_point.X;
                        smoothened_error_correction_clone.сoordinates[1] = coordinates.gaze_point.Y;
                        smoothened_error_correction = CoordinateSmoother.Smoothen(smoothened_error_correction_clone);
                    }
                    else
                    {
                        // The eye tracker provides shaky data that has to be smoothened before transforming to the mouse cursor position.
                        // |CalibrationManager| amplifies this shaking.
                        // To cancel the amplification we smoothen data BEFORE it goes to |CalibrationManager|.
                        //
                        // Another problem is |CalibrationManager| also may be a source of shaking (even on smoothened input).
                        // So in addition to smoothening its input we have to smoothen its output.
                        // Smoothening data twice leads to bigger latency but otherwise, the cursor shakes.
                        // Big latency is compensated by |instant_jump_distance|.
                        var shift             = smoothened_error_correction == null ? new Point(0, 0) : CalibrationManager.Instance.GetShift(smoothened_error_correction.сoordinates);
                        var shaky_coordinates = coordinates.ToCoordinates(Options.Instance.calibration_mode.additional_dimensions_configuration);
                        smoothened_error_correction = CoordinateSmoother.Smoothen(new EyeTrackerErrorCorrection(shaky_coordinates, shift));
                    }
                }
                else
                {
                    // Adds inertia on exit from freeze state.
                    CoordinateSmoother.Smoothen(smoothened_error_correction);
                }

                if (mouse_state == MouseState.Controlling || mouse_state == MouseState.Calibrating)
                {
                    UpdateCursorPosition();
                }
            }
        }