提交 49b73289 编写于 作者: M Marco Fugaro

Add MathUtils.damp()

上级 c215d896
......@@ -71,6 +71,17 @@
Returns a value that alternates between 0 and [param:Float length].</p>
<h3>[method:Float damp]( [param:Float x], [param:Float y], [param:Float lambda], [param:Float dt] )</h3>
<p>
[page:Float x] - Current point. <br />
[page:Float y] - Target point. <br />
[page:Float lambda] - A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual. <br />
[page:Float dt] - Delta time in seconds.<br><br />
Smoothly interpolate a number from [page:Float x] toward [page:Float y] in a spring-like manner using the [page:Float dt] to maintain frame rate independent movement.
For details, see [link:http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ Frame Rate Independent Damping Using Lerp].
</p>
<h3>[method:Integer ceilPowerOfTwo]( [param:Number n] )</h3>
<p>Returns the smallest power of 2 that is greater than or equal to [page:Number n].</p>
......
......@@ -68,6 +68,17 @@
Returns a value that alternates between 0 and [param:Float length].</p>
<h3>[method:Float damp]( [param:Float x], [param:Float y], [param:Float lambda], [param:Float dt] )</h3>
<p>
[page:Float x] - Current point. <br />
[page:Float y] - Target point. <br />
[page:Float lambda] - A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual. <br />
[page:Float dt] - Delta time in seconds.<br><br />
Smoothly interpolate a number from [page:Float x] toward [page:Float y] in a spring-like manner using the [page:Float dt] to maintain frame rate independent movement.
For details, see [link:http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ Frame Rate Independent Damping Using Lerp].
</p>
<h3>[method:Integer ceilPowerOfTwo]( [param:Number n] )</h3>
<p>返回大于等于 [page:Number n] 的2的最小次幂。</p>
......
......@@ -94,6 +94,18 @@ export namespace MathUtils {
*/
export function pingpong( x: number, length?: number ): number;
/**
* Smoothly interpolate a number from x toward y in a spring-like
* manner using the dt to maintain frame rate independent movement.
*
* @param x Current point.
* @param y Target point.
* @param lambda A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual.
* @param dt Delta time in seconds.
* @return {number}
*/
export function damp( x: number, y: number, lambda: number, dt: number ): number;
/**
* @deprecated Use {@link Math#floorPowerOfTwo .floorPowerOfTwo()}
*/
......
......@@ -70,6 +70,14 @@ const MathUtils = {
},
// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
damp: function ( x, y, lambda, dt ) {
return MathUtils.lerp( x, y, 1 - Math.exp( - lambda * dt ) );
},
// http://en.wikipedia.org/wiki/Smoothstep
smoothstep: function ( x, min, max ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册