OSDN Git Service

three.jsをThirdPartyに追加
[webglgame/webgl_framework.git] / webglFramework / Thirdparty / three.js-master / src / extras / curves / SplineCurve.js
1 import { Curve } from '../core/Curve';
2 import { CatmullRom } from '../core/Interpolations';
3 import { Vector2 } from '../../math/Vector2';
4
5
6 function SplineCurve( points /* array of Vector2 */ ) {
7
8         Curve.call( this );
9
10         this.points = ( points === undefined ) ? [] : points;
11
12 }
13
14 SplineCurve.prototype = Object.create( Curve.prototype );
15 SplineCurve.prototype.constructor = SplineCurve;
16
17 SplineCurve.prototype.isSplineCurve = true;
18
19 SplineCurve.prototype.getPoint = function ( t ) {
20
21         var points = this.points;
22         var point = ( points.length - 1 ) * t;
23
24         var intPoint = Math.floor( point );
25         var weight = point - intPoint;
26
27         var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
28         var point1 = points[ intPoint ];
29         var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
30         var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
31
32         return new Vector2(
33                 CatmullRom( weight, point0.x, point1.x, point2.x, point3.x ),
34                 CatmullRom( weight, point0.y, point1.y, point2.y, point3.y )
35         );
36
37 };
38
39 export { SplineCurve };