private float GetShadeOpacity(
            ShiftsStorage.PointInfo source_of_shade,
            ShiftsStorage.PointInfo shaded_correction)
        {
            Debug.Assert(source_of_shade.distance <= shaded_correction.distance);

            float opacity = 1;

            float angle_in_percents = (float)(Helpers.GetAngleBetweenVectors(source_of_shade, shaded_correction) * 100 / Math.PI);

            Debug.Assert(angle_in_percents <= 100);

            // Opacity descendes gradualy on the sides of opaque sector.
            if (angle_in_percents < calibration_mode.size_of_opaque_sector_in_percents)
            {
                opacity = 1;
            }
            else if (angle_in_percents > calibration_mode.size_of_opaque_sector_in_percents + 10)
            {
                opacity = 0;
            }
            else
            {
                opacity = (calibration_mode.size_of_opaque_sector_in_percents + 10 - angle_in_percents) / (10);
            }

            float distance_from_shade_shell_to_shaded_correction = shaded_correction.distance - source_of_shade.distance;

            if (distance_from_shade_shell_to_shaded_correction < calibration_mode.shade_thickness_in_pixels)
            {
                opacity *= distance_from_shade_shell_to_shaded_correction / calibration_mode.shade_thickness_in_pixels;
            }

            return(opacity);
        }
Esempio n. 2
0
        public static float GetAngleBetweenVectors(
            ShiftsStorage.PointInfo a,
            ShiftsStorage.PointInfo b)
        {
            Debug.Assert(
                a.vector_from_correction_to_cursor.Length ==
                b.vector_from_correction_to_cursor.Length);

            float dot_product = 0;

            for (int i = 0; i < a.vector_from_correction_to_cursor.Length; i++)
            {
                dot_product += a.vector_from_correction_to_cursor[i] * b.vector_from_correction_to_cursor[i];
            }

            float cos = dot_product / a.distance / b.distance;

            if (cos > 1.0)
            {
                cos = 1.0f;
            }
            else if (cos < -1.0)
            {
                cos = -1.0f;
            }

            return((float)Math.Acos(cos));
        }