source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/curves/SplineCurve.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 1.1 KB
Line 
1/**************************************************************
2 * Spline curve
3 **************************************************************/
4
5THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
6
7 this.points = (points == undefined) ? [] : points;
8
9};
10
11THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
12
13THREE.SplineCurve.prototype.getPoint = function ( t ) {
14
15 var v = new THREE.Vector2();
16 var c = [];
17 var points = this.points, point, intPoint, weight;
18 point = ( points.length - 1 ) * t;
19
20 intPoint = Math.floor( point );
21 weight = point - intPoint;
22
23 c[ 0 ] = intPoint == 0 ? intPoint : intPoint - 1;
24 c[ 1 ] = intPoint;
25 c[ 2 ] = intPoint > points.length - 2 ? points.length -1 : intPoint + 1;
26 c[ 3 ] = intPoint > points.length - 3 ? points.length -1 : intPoint + 2;
27
28 v.x = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].x, points[ c[ 1 ] ].x, points[ c[ 2 ] ].x, points[ c[ 3 ] ].x, weight );
29 v.y = THREE.Curve.Utils.interpolate( points[ c[ 0 ] ].y, points[ c[ 1 ] ].y, points[ c[ 2 ] ].y, points[ c[ 3 ] ].y, weight );
30
31 return v;
32
33};
Note: See TracBrowser for help on using the repository browser.