Пример #1
0
		/// <summary>
		/// The infamous Map function of vvvv for 4d-vectors and range bounds given as vectors
		/// </summary>
		/// <param name="Input">Input value to convert</param>
		/// <param name="InMin">Minimum of input value range</param>
		/// <param name="InMax">Maximum of input value range</param>
		/// <param name="OutMin">Minimum of destination value range</param>
		/// <param name="OutMax">Maximum of destination value range</param>
		/// <param name="mode">Defines the behavior of the function if the input value exceeds the destination range 
		/// <see cref="VVVV.Utils.VMath.TMapMode">TMapMode</see></param>
		/// <returns>Input vector mapped from input range into destination range</returns>
		public static Vector4D Map(Vector4D Input, Vector4D InMin, Vector4D InMax, Vector4D OutMin, Vector4D OutMax, TMapMode mode)
		{
			return new Vector4D(Map(Input.x, InMin.x, InMax.x, OutMin.x, OutMax.x, mode),
			                    Map(Input.y, InMin.y, InMax.y, OutMin.y, OutMax.y, mode),
			                    Map(Input.z, InMin.z, InMax.z, OutMin.z, OutMax.z, mode),
			                    Map(Input.w, InMin.w, InMax.w, OutMin.w, OutMax.w, mode));
		}
Пример #2
0
		/// <summary>
		/// The infamous Map function of vvvv for 2d-vectors and range bounds given as vectors
		/// </summary>
		/// <param name="Input">Input value to convert</param>
		/// <param name="InMin">Minimum of input value range</param>
		/// <param name="InMax">Maximum of input value range</param>
		/// <param name="OutMin">Minimum of destination value range</param>
		/// <param name="OutMax">Maximum of destination value range</param>
		/// <param name="mode">Defines the behavior of the function if the input value exceeds the destination range 
		/// <see cref="VVVV.Utils.VMath.TMapMode">TMapMode</see></param>
		/// <returns>Input vector mapped from input range into destination range</returns>
		public static Vector2D Map(Vector2D Input, Vector2D InMin, Vector2D InMax, Vector2D OutMin, Vector2D OutMax, TMapMode mode)
		{
			return new Vector2D(Map(Input.x, InMin.x, InMax.x, OutMin.x, OutMax.x, mode),
			                    Map(Input.y, InMin.y, InMax.y, OutMin.y, OutMax.y, mode));
		}
Пример #3
0
 /// <summary>
 /// The infamous Map function of vvvv for values
 /// </summary>
 /// <param name="Input">Input value to convert</param>
 /// <param name="InMin">Minimum of input value range</param>
 /// <param name="InMax">Maximum of input value range</param>
 /// <param name="OutMin">Minimum of destination value range</param>
 /// <param name="OutMax">Maximum of destination value range</param>
 /// <param name="mode">Defines the behavior of the function if the input value exceeds the destination range 
 /// <see cref="VVVV.Utils.VMath.TMapMode">TMapMode</see></param>
 /// <returns>Input value mapped from input range into destination range</returns>
 public static double Map(double Input, double InMin, double InMax, double OutMin, double OutMax, TMapMode mode)
 {
     double ratio = Ratio(Input, InMin, InMax, mode);
     return Lerp(OutMin, OutMax, ratio);
 }
Пример #4
0
		/// <summary>
		/// The infamous Map function of vvvv for 4d-vectors and value range bounds
		/// </summary>
		/// <param name="Input">Input value to convert</param>
		/// <param name="InMin">Minimum of input value range</param>
		/// <param name="InMax">Maximum of input value range</param>
		/// <param name="OutMin">Minimum of destination value range</param>
		/// <param name="OutMax">Maximum of destination value range</param>
		/// <param name="mode">Defines the behavior of the function if the input value exceeds the destination range 
		/// <see cref="VVVV.Utils.VMath.TMapMode">TMapMode</see></param>
		/// <returns>Input vector mapped from input range into destination range</returns>
		public static Vector4D Map(Vector4D Input, double InMin, double InMax, double OutMin, double OutMax, TMapMode mode)
		{
			return new Vector4D(Map(Input.x, InMin, InMax, OutMin, OutMax, mode),
			                    Map(Input.y, InMin, InMax, OutMin, OutMax, mode),
			                    Map(Input.z, InMin, InMax, OutMin, OutMax, mode),
			                    Map(Input.w, InMin, InMax, OutMin, OutMax, mode));
		}
Пример #5
0
        /// <summary>
         /// This Method can be seen as an inverse of Lerp (in Mode Float). Additionally it provides the infamous Mapping Modes, author: velcrome
         /// </summary>
         /// <param name="Input">Input value to convert</param>
         /// <param name="start">Minimum of input value range</param>
         /// <param name="end">Maximum of input value range</param>
         /// <param name="mode">Defines the behavior of the function if the input value exceeds the destination range 
         /// <see cref="VVVV.Utils.VMath.TMapMode">TMapMode</see></param>
         /// <returns>Input value mapped from input range into destination range</returns>
         public static double Ratio(double Input, double start, double end, TMapMode mode)
         {
             if (end.CompareTo(start) == 0) return 0;
 
             double range = end - start;
             double ratio = (Input - start) / range;
 
             if (mode == TMapMode.Float) { }
             else if (mode == TMapMode.Clamp)
             {
                 if (ratio < 0) ratio = 0;
                 if (ratio > 1) ratio = 1;
             }
             else
             {
                 if (mode == TMapMode.Wrap)
                 {
                     // includes fix for inconsistent behaviour of old delphi Map 
                     // node when handling integers
                     int rangeCount = (int)Math.Floor(ratio);
                     ratio -= rangeCount;
                 }
                 else if (mode == TMapMode.Mirror)
                 {
                     // merke: if you mirror an input twice it is displaced twice the range. same as wrapping twice really
                     int rangeCount = (int)Math.Floor(ratio);
                     rangeCount -= rangeCount & 1; // if uneven, make it even. bitmask of one is same as mod2
                     ratio -= rangeCount;
 
                     if (ratio > 1) ratio = 2 - ratio; // if on the max side of things now (due to rounding down rangeCount), mirror once against max
                 }
             }
             return ratio;
         }