コード例 #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));
        }
コード例 #2
0
ファイル: InputRange.cs プロジェクト: ForsakenGS/LostKids
		/// <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 ); 
		}
コード例 #3
0
        internal float GetValue(InputDevice device)
        {
            if (device == null)
            {
                return(0f);
            }
            float value = device.GetControl(Control).Value;

            return(InputRange.Remap(value, SourceRange, InputRangeType.ZeroToOne));
        }
コード例 #4
0
ファイル: InputRange.cs プロジェクト: SilentPanda/blindfield
        /// <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));
        }
コード例 #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);
 }
コード例 #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);
        }