@galacean/engine-math 0.0.0-experimental-2.0-game.19 → 0.0.0-experimental-2.0-migrate.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -837,20 +837,16 @@ BoundingSphere._tempVec30 = new Vector3();
837
837
  * @param matrix - The transform to apply to the bounding box
838
838
  * @param out - The transformed bounding box
839
839
  */ BoundingBox.transform = function transform(source, matrix, out) {
840
- // https://zeux.io/2010/10/17/aabb-from-obb-with-component-wise-abs/
841
- var center = BoundingBox._tempVec30;
842
- var extent = BoundingBox._tempVec31;
843
- source.getCenter(center);
844
- source.getExtent(extent);
845
- Vector3.transformCoordinate(center, matrix, center);
846
- var x = extent.x, y = extent.y, z = extent.z;
840
+ // Arvo's min/max method: for each matrix element, positive values multiply min for new min (max for new max),
841
+ // negative values multiply max for new min (min for new max), then add translation.
842
+ // Zero check avoids 0 * Infinity = NaN
843
+ var _source_min = source.min, minX = _source_min.x, minY = _source_min.y, minZ = _source_min.z;
844
+ var _source_max = source.max, maxX = _source_max.x, maxY = _source_max.y, maxZ = _source_max.z;
847
845
  var e = matrix.elements;
848
846
  // prettier-ignore
849
847
  var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e8 = e[8], e9 = e[9], e10 = e[10];
850
- extent.set((e0 === 0 ? 0 : Math.abs(x * e0)) + (e4 === 0 ? 0 : Math.abs(y * e4)) + (e8 === 0 ? 0 : Math.abs(z * e8)), (e1 === 0 ? 0 : Math.abs(x * e1)) + (e5 === 0 ? 0 : Math.abs(y * e5)) + (e9 === 0 ? 0 : Math.abs(z * e9)), (e2 === 0 ? 0 : Math.abs(x * e2)) + (e6 === 0 ? 0 : Math.abs(y * e6)) + (e10 === 0 ? 0 : Math.abs(z * e10)));
851
- // set min、max
852
- Vector3.subtract(center, extent, out.min);
853
- Vector3.add(center, extent, out.max);
848
+ out.min.set((e0 > 0 ? e0 * minX : e0 < 0 ? e0 * maxX : 0) + (e4 > 0 ? e4 * minY : e4 < 0 ? e4 * maxY : 0) + (e8 > 0 ? e8 * minZ : e8 < 0 ? e8 * maxZ : 0) + e[12], (e1 > 0 ? e1 * minX : e1 < 0 ? e1 * maxX : 0) + (e5 > 0 ? e5 * minY : e5 < 0 ? e5 * maxY : 0) + (e9 > 0 ? e9 * minZ : e9 < 0 ? e9 * maxZ : 0) + e[13], (e2 > 0 ? e2 * minX : e2 < 0 ? e2 * maxX : 0) + (e6 > 0 ? e6 * minY : e6 < 0 ? e6 * maxY : 0) + (e10 > 0 ? e10 * minZ : e10 < 0 ? e10 * maxZ : 0) + e[14]);
849
+ out.max.set((e0 > 0 ? e0 * maxX : e0 < 0 ? e0 * minX : 0) + (e4 > 0 ? e4 * maxY : e4 < 0 ? e4 * minY : 0) + (e8 > 0 ? e8 * maxZ : e8 < 0 ? e8 * minZ : 0) + e[12], (e1 > 0 ? e1 * maxX : e1 < 0 ? e1 * minX : 0) + (e5 > 0 ? e5 * maxY : e5 < 0 ? e5 * minY : 0) + (e9 > 0 ? e9 * maxZ : e9 < 0 ? e9 * minZ : 0) + e[13], (e2 > 0 ? e2 * maxX : e2 < 0 ? e2 * minX : 0) + (e6 > 0 ? e6 * maxY : e6 < 0 ? e6 * minY : 0) + (e10 > 0 ? e10 * maxZ : e10 < 0 ? e10 * minZ : 0) + e[14]);
854
850
  };
855
851
  /**
856
852
  * Calculate a bounding box that is as large as the total combined area of the two specified boxes.
@@ -865,8 +861,6 @@ BoundingSphere._tempVec30 = new Vector3();
865
861
  };
866
862
  return BoundingBox;
867
863
  }();
868
- BoundingBox._tempVec30 = new Vector3();
869
- BoundingBox._tempVec31 = new Vector3();
870
864
 
871
865
  /**
872
866
  * Contains static methods to help in determining intersections, containment, etc.
@@ -3663,6 +3657,23 @@ Matrix._tempMat30 = new Matrix3x3();
3663
3657
  Vector3.scale(this.direction, distance, out);
3664
3658
  return out.add(this.origin);
3665
3659
  };
3660
+ /**
3661
+ * Creates a clone of this ray.
3662
+ * @returns A clone of this ray
3663
+ */ _proto.clone = function clone() {
3664
+ var out = new Ray();
3665
+ out.copyFrom(this);
3666
+ return out;
3667
+ };
3668
+ /**
3669
+ * Copy this ray from the specified ray.
3670
+ * @param source - The specified ray
3671
+ * @returns This ray
3672
+ */ _proto.copyFrom = function copyFrom(source) {
3673
+ this.origin.copyFrom(source.origin);
3674
+ this.direction.copyFrom(source.direction);
3675
+ return this;
3676
+ };
3666
3677
  return Ray;
3667
3678
  }();
3668
3679