Mathfx

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removed Unity bug blame, since it was actually my stupidity. ;))
(Thems should be static methods, eh?)
Line 17: Line 17:
 
public class Mathfx
 
public class Mathfx
 
{
 
{
     public float Hermite(float start, float end, float value)
+
     public static float Hermite(float start, float end, float value)
 
     {
 
     {
 
         float tt = Mathf.Min(Mathf.Max((value - start) / (end - start), 0.0f), 1.0f);
 
         float tt = Mathf.Min(Mathf.Max((value - start) / (end - start), 0.0f), 1.0f);
Line 23: Line 23:
 
     }
 
     }
 
      
 
      
     public float Lerp(float start, float end, float value)
+
     public static float Lerp(float start, float end, float value)
 
     {
 
     {
 
         return ((1.0f - value) * start) + (value * end);
 
         return ((1.0f - value) * start) + (value * end);

Revision as of 16:08, 11 February 2006

Description

The following snippet provides short functions for floating point numbers. See the usage section for individualized information.

Usage

  • Hermite - This method will interpolate while easing in and out at the limits.
  • Lerp - Short for 'linearly interpolate', this method is equivalent to Unity's Mathf.Lerp, included for comparison.

C# - Mathfx.cs

<csharp>using UnityEngine; using System;

public class Mathfx {

   public static float Hermite(float start, float end, float value)
   {
       float tt = Mathf.Min(Mathf.Max((value - start) / (end - start), 0.0f), 1.0f);
       return tt * tt * (3.0f - 2.0f * tt);
   }
   
   public static float Lerp(float start, float end, float value)
   {
       return ((1.0f - value) * start) + (value * end);
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox