Quellcode durchsuchen

Bug fixed in Ray.intersectPlane to compute the corret distance
Added Vector4.toVector3() method.
Added Matrix.getTranslation() and get/setRow() methods.

nockawa vor 9 Jahren
Ursprung
Commit
5e59078d4b
2 geänderte Dateien mit 32 neuen und 2 gelöschten Zeilen
  1. 3 2
      src/Culling/babylon.ray.ts
  2. 29 0
      src/Math/babylon.math.ts

+ 3 - 2
src/Culling/babylon.ray.ts

@@ -267,12 +267,13 @@
             tc = (Math.abs(tN) < Ray.smallnum ? 0.0 : tN / tD);
 
             // get the difference of the two closest points
-            var dP = w.add(u.multiplyByFloats(sc, sc, sc)).subtract(v.multiplyByFloats(tc, tc, tc));  // = S1(sc) - S2(tc)
+            let qtc = v.multiplyByFloats(tc, tc, tc);
+            var dP = w.add(u.multiplyByFloats(sc, sc, sc)).subtract(qtc);  // = S1(sc) - S2(tc)
 
             var isIntersected = (tc > 0) && (tc <= this.length) && (dP.lengthSquared() < (threshold * threshold));   // return intersection result
 
             if (isIntersected) {
-                return tc;
+                return qtc.length();
             }
             return -1;
         }

+ 29 - 0
src/Math/babylon.math.ts

@@ -1455,6 +1455,10 @@
             return this;
         }
 
+        public toVector3(): Vector3 {
+            return new Vector3(this.x, this.y, this.z);
+        }
+
         public clone(): Vector4 {
             return new Vector4(this.x, this.y, this.z, this.w);
         }
@@ -2043,6 +2047,10 @@
 
             return this;
         }
+        
+        public getTranslation(): Vector3 {
+            return new Vector3(this.m[12], this.m[13], this.m[14]);
+        }
 
         public multiply(other: Matrix): Matrix {
             var result = new Matrix();
@@ -2227,6 +2235,27 @@
             result.m[15] = initialM44;
         }
 
+        public getRow(index: number): Vector4 {
+            if (index < 0 || index > 3) {
+                return null;
+            }
+
+            var i = index * 4;
+            return new Vector4(this.m[i + 0], this.m[i + 1], this.m[i + 2], this.m[i + 3]);
+        }
+
+        public setRow(index: number, row: Vector4): boolean {
+            if (index < 0 || index > 3) {
+                return false;
+            }
+
+            var i = index * 4;
+            this.m[i + 0] = row.x;
+            this.m[i + 1] = row.y;
+            this.m[i + 2] = row.z;
+            this.m[i + 3] = row.w;
+        }
+
         public static FromValues(initialM11: number, initialM12: number, initialM13: number, initialM14: number,
             initialM21: number, initialM22: number, initialM23: number, initialM24: number,
             initialM31: number, initialM32: number, initialM33: number, initialM34: number,