content/hifi-content/dave/walk-tools/walkTools/libraries/three.js/extras/curves/CubicBezierCurve.js
2022-02-13 22:49:05 +01:00

40 lines
1 KiB
JavaScript

/**************************************************************
* Cubic Bezier curve
**************************************************************/
THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
this.v0 = v0;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
};
THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
var tx, ty;
tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
return new THREE.Vector2( tx, ty );
};
THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
var tx, ty;
tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
var tangent = new THREE.Vector2( tx, ty );
tangent.normalize();
return tangent;
};