Exemplo n.º 1
0
        public static float GetAngleBetweenVectors(
            ShiftStorageCache.PointInfo a,
            ShiftStorageCache.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));
        }
Exemplo n.º 2
0
        private float GetShadeOpacity(
            ShiftStorageCache.PointInfo source_of_shade,
            ShiftStorageCache.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 in the sector between opaque and transparent sectors.
            if (angle_in_percents < calibration_mode.size_of_opaque_sector_in_percents)
            {
                opacity = 1;
            }
            else if (angle_in_percents > 100 - calibration_mode.size_of_transparent_sector_in_percents)
            {
                opacity = 0;
            }
            else
            {
                opacity = (angle_in_percents + calibration_mode.size_of_transparent_sector_in_percents - 100) /
                          (calibration_mode.size_of_opaque_sector_in_percents + calibration_mode.size_of_transparent_sector_in_percents - 100);
            }

            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 * source_of_shade.weight);
        }