Mathfx
From Unify Community Wiki
(Difference between revisions)
(→C# - Mathfx.cs: *Now* hermite works, I think.) |
m (How did this get into Category:Effects?) |
||
Line 1: | Line 1: | ||
[[Category: Concepts]] | [[Category: Concepts]] | ||
[[Category: Math]] | [[Category: Math]] | ||
− | |||
[[Category: C Sharp]] | [[Category: C Sharp]] | ||
== Description == | == Description == |
Revision as of 08:45, 26 May 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.
- Sinerp - Short for 'sinusoidal interpolation', this method will interpolate while easing around the end, when value is near one.
- 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) { return Mathf.Lerp(start, end, value * value * (3.0f - 2.0f * value)); } public static float Sinerp(float start, float end, float value) { return Mathf.Lerp(start, end, Mathf.Sin(value * Mathf.PI * 0.5f)); }
public static float Lerp(float start, float end, float value) { return ((1.0f - value) * start) + (value * end); }
} </csharp>