Exemplo n.º 1
0
        internal static float Remap(float value, InputRangeType sourceRangeType, InputRangeType targetRangeType)
        {
            InputRange sourceRange = TypeToRange[(int)sourceRangeType];
            InputRange targetRange = TypeToRange[(int)targetRangeType];

            return(Remap(value, sourceRange, targetRange));
        }
Exemplo n.º 2
0
		/// <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 ); 
		}
        internal float GetValue(InputDevice device)
        {
            if (device == null)
            {
                return(0f);
            }
            float value = device.GetControl(Control).Value;

            return(InputRange.Remap(value, SourceRange, InputRangeType.ZeroToOne));
        }
Exemplo n.º 4
0
        /// <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));
        }
Exemplo n.º 5
0
 public float MapValue(float value)
 {
     if (Raw)
     {
         value *= Scale;
         value  = ((!SourceRange.Excludes(value)) ? value : 0f);
     }
     else
     {
         value = Mathf.Clamp(value * Scale, -1f, 1f);
         value = InputRange.Remap(value, SourceRange, TargetRange);
     }
     if (Invert)
     {
         value = 0f - value;
     }
     return(value);
 }
Exemplo n.º 6
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);
        }