Mathfx

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(C# - Mathfx.cs)
(Made Hermite()'s parameters the same as Lerp()'s, since they're conceptually similar.)
Line 17: Line 17:
 
public class Mathfx
 
public class Mathfx
 
{
 
{
     public float Hermite(float edge0, float edge1, float t)
+
     public float Hermite(float start, float end, float value)
 
     {
 
     {
         float tt = Mathf.Min(Mathf.Max((t - edge0) /(edge1 - edge0), 0.0f), 1.0f);
+
         float tt = Mathf.Min(Mathf.Max((value - start) / (end - start), 0.0f), 1.0f);
         return tt * tt * (3F - 2F * tt);
+
         return tt * tt * (3.0f - 2.0f * tt);
 
     }
 
     }
 
      
 
      

Revision as of 01:20, 18 December 2005

Description

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

Usage

  • Hermite - This function will interpolate while easing in and out at the edges.
  • Lerp - This function stands for Linearly Interpolate and is a work around for a bad Mathf.Lerp function as of 1.2b2.

C# - Mathfx.cs

<csharp>using UnityEngine; using System;

public class Mathfx {

   public 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 float Lerp(float start, float end, float value)
   {
       return ((1.0f - value) * start) + (value * end);
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox