Selaa lähdekoodia

added curve3 length() method

jbousquie 10 vuotta sitten
vanhempi
commit
646c440bc5
1 muutettua tiedostoa jossa 16 lisäystä ja 1 poistoa
  1. 16 1
      Babylon/Math/babylon.math.ts

+ 16 - 1
Babylon/Math/babylon.math.ts

@@ -3420,6 +3420,7 @@
 
     export class Curve3 {
         private _points: Vector3[];
+        private _length:number = 0;
 
         // QuadraticBezier(origin_V3, control_V3, destination_V3 )
         public static CreateQuadraticBezier(v0: Vector3, v1: Vector3, v2: Vector3, nbPoints: number): Curve3 {
@@ -3451,12 +3452,17 @@
 
         constructor(points: Vector3[]) {
             this._points = points;
+            this._length = this._computeLength(points);
         }
 
         public getPoints() {
             return this._points;
         }
 
+        public length() {
+            return this._length;
+        }
+
         public continue(curve: Curve3): Curve3 {
             var lastPoint = this._points[this._points.length - 1];
             var continuedPoints = this._points.slice();
@@ -3464,7 +3470,16 @@
             for (var i = 1; i < curvePoints.length; i++) {
                 continuedPoints.push(curvePoints[i].subtract(curvePoints[0]).add(lastPoint));
             }
-            return new Curve3(continuedPoints);
+            var continuedCurve = new Curve3(continuedPoints);
+            return continuedCurve;
+        }
+
+        private _computeLength(path: Vector3[]): number {
+            var l = 0;
+            for (var i = 1; i < path.length; i++) {
+                l += (path[i].subtract(path[i - 1])).length();
+            }
+            return l;
         }
     }