phaser/src/math/interpolation/QuadraticBezierInterpolation.js

54 lines
1,017 B
JavaScript
Raw Normal View History

2018-03-02 20:42:12 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2020-01-15 12:07:09 +00:00
* @copyright 2020 Photon Storm Ltd.
2019-05-10 15:15:04 +00:00
* @license {@link https://opensource.org/licenses/MIT|MIT License}
2018-03-02 20:42:12 +00:00
*/
2019-02-12 12:14:26 +00:00
/**
* @ignore
*/
2018-03-02 20:42:12 +00:00
function P0 (t, p)
{
var k = 1 - t;
2018-03-02 23:16:11 +00:00
return k * k * p;
2018-03-02 20:42:12 +00:00
}
2019-02-12 12:14:26 +00:00
/**
* @ignore
*/
2018-03-02 20:42:12 +00:00
function P1 (t, p)
{
2018-03-05 01:40:11 +00:00
return 2 * (1 - t) * t * p;
2018-03-02 20:42:12 +00:00
}
2019-02-12 12:14:26 +00:00
/**
* @ignore
*/
2018-03-02 20:42:12 +00:00
function P2 (t, p)
{
return t * t * p;
}
// https://github.com/mrdoob/three.js/blob/master/src/extras/core/Interpolations.js
/**
* A quadratic bezier interpolation method.
2018-03-02 20:42:12 +00:00
*
* @function Phaser.Math.Interpolation.QuadraticBezier
* @since 3.2.0
2018-03-02 20:42:12 +00:00
*
* @param {number} t - The percentage of interpolation, between 0 and 1.
* @param {number} p0 - The start point.
* @param {number} p1 - The control point.
* @param {number} p2 - The end point.
2018-03-02 20:42:12 +00:00
*
* @return {number} The interpolated value.
2018-03-02 20:42:12 +00:00
*/
var QuadraticBezierInterpolation = function (t, p0, p1, p2)
{
return P0(t, p0) + P1(t, p1) + P2(t, p2);
};
module.exports = QuadraticBezierInterpolation;