2018-02-12 16:01:20 +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-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-10-06 02:05:01 +00:00
|
|
|
/**
|
2020-02-04 14:51:43 +00:00
|
|
|
* Calculates a Catmull-Rom value from the given points, based on an alpha of 0.5.
|
2017-10-06 02:05:01 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.CatmullRom
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-02-04 14:51:43 +00:00
|
|
|
* @param {number} t - The amount to interpolate by.
|
|
|
|
* @param {number} p0 - The first control point.
|
|
|
|
* @param {number} p1 - The second control point.
|
|
|
|
* @param {number} p2 - The third control point.
|
|
|
|
* @param {number} p3 - The fourth control point.
|
2017-10-06 02:05:01 +00:00
|
|
|
*
|
2018-05-24 11:59:27 +00:00
|
|
|
* @return {number} The Catmull-Rom value.
|
2017-10-06 02:05:01 +00:00
|
|
|
*/
|
2017-09-21 01:30:35 +00:00
|
|
|
var CatmullRom = function (t, p0, p1, p2, p3)
|
2016-12-07 17:16:59 +00:00
|
|
|
{
|
2017-09-21 01:30:35 +00:00
|
|
|
var v0 = (p2 - p0) * 0.5;
|
|
|
|
var v1 = (p3 - p1) * 0.5;
|
|
|
|
var t2 = t * t;
|
|
|
|
var t3 = t * t2;
|
2016-12-07 17:16:59 +00:00
|
|
|
|
|
|
|
return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CatmullRom;
|