예제 #1
0
파일: InputRange.cs 프로젝트: Hengle/otiose
        /// <summary>
        /// Remap the specified value, from one range to another.
        /// </summary>
        /// <param name="value">The value to remap.</param>
        /// <param name="sourceRange">The source range to map from.</param>
        /// <param name="targetRange">The target range to map to.</param>
        public static float Remap(float value, InputRange sourceRange, InputRange targetRange)
        {
            if (sourceRange.Excludes(value))
            {
                return(0.0f);
            }
            var sourceValue = Mathf.inverseLerp(sourceRange.Value0, sourceRange.Value1, value);

            return(Mathf.lerp(targetRange.Value0, targetRange.Value1, sourceValue));
        }
예제 #2
0
        public float MapValue(float value)
        {
            if (Raw)
            {
                value = value * Scale;
                value = SourceRange.Excludes(value) ? 0.0f : value;
            }
            else
            {
                // Scale value and clamp to a legal range.
                value = Mathf.clamp(value * Scale, -1.0f, 1.0f);

                // Remap from source range to target range.
                value = InputRange.Remap(value, SourceRange, TargetRange);
            }

            if (Invert)
            {
                value = -value;
            }

            return(value);
        }