|
@@ -56,6 +56,15 @@ export interface ISpriteManager extends IDisposable {
|
|
|
*/
|
|
|
intersects(ray: Ray, camera: Camera, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean): Nullable<PickingInfo>;
|
|
|
|
|
|
+ /**
|
|
|
+ * Intersects the sprites with a ray
|
|
|
+ * @param ray defines the ray to intersect with
|
|
|
+ * @param camera defines the current active camera
|
|
|
+ * @param predicate defines a predicate used to select candidate sprites
|
|
|
+ * @returns null if no hit or a PickingInfo array
|
|
|
+ */
|
|
|
+ multiIntersects(ray: Ray, camera: Camera, predicate?: (sprite: Sprite) => boolean): Nullable<PickingInfo[]>;
|
|
|
+
|
|
|
/**
|
|
|
* Renders the list of sprites on screen.
|
|
|
*/
|
|
@@ -341,8 +350,8 @@ export class SpriteManager implements ISpriteManager {
|
|
|
var max = Vector3.Zero();
|
|
|
var distance = Number.MAX_VALUE;
|
|
|
var currentSprite: Nullable<Sprite> = null;
|
|
|
- var pickedPoint = Vector3.Zero();
|
|
|
- var cameraSpacePosition = Vector3.Zero();
|
|
|
+ var pickedPoint = TmpVectors.Vector3[0].copyFromFloats(0, 0, 0);
|
|
|
+ var cameraSpacePosition = TmpVectors.Vector3[1].copyFromFloats(0, 0, 0);
|
|
|
var cameraView = camera.getViewMatrix();
|
|
|
|
|
|
for (var index = 0; index < count; index++) {
|
|
@@ -387,7 +396,7 @@ export class SpriteManager implements ISpriteManager {
|
|
|
result.distance = distance;
|
|
|
|
|
|
// Get picked point
|
|
|
- let direction = TmpVectors.Vector3[0];
|
|
|
+ let direction = TmpVectors.Vector3[2];
|
|
|
direction.copyFrom(ray.direction);
|
|
|
direction.normalize();
|
|
|
direction.scaleInPlace(distance);
|
|
@@ -402,6 +411,68 @@ export class SpriteManager implements ISpriteManager {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Intersects the sprites with a ray
|
|
|
+ * @param ray defines the ray to intersect with
|
|
|
+ * @param camera defines the current active camera
|
|
|
+ * @param predicate defines a predicate used to select candidate sprites
|
|
|
+ * @returns null if no hit or a PickingInfo array
|
|
|
+ */
|
|
|
+ public multiIntersects(ray: Ray, camera: Camera, predicate?: (sprite: Sprite) => boolean): Nullable<PickingInfo[]> {
|
|
|
+ var count = Math.min(this._capacity, this.sprites.length);
|
|
|
+ var min = Vector3.Zero();
|
|
|
+ var max = Vector3.Zero();
|
|
|
+ var distance: number;
|
|
|
+ var results: Nullable<PickingInfo[]> = [];
|
|
|
+ var pickedPoint = TmpVectors.Vector3[0].copyFromFloats(0, 0, 0);
|
|
|
+ var cameraSpacePosition = TmpVectors.Vector3[1].copyFromFloats(0, 0, 0);
|
|
|
+ var cameraView = camera.getViewMatrix();
|
|
|
+
|
|
|
+ for (var index = 0; index < count; index++) {
|
|
|
+ var sprite = this.sprites[index];
|
|
|
+ if (!sprite) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (predicate) {
|
|
|
+ if (!predicate(sprite)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else if (!sprite.isPickable) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector3.TransformCoordinatesToRef(sprite.position, cameraView, cameraSpacePosition);
|
|
|
+
|
|
|
+ min.copyFromFloats(cameraSpacePosition.x - sprite.width / 2, cameraSpacePosition.y - sprite.height / 2, cameraSpacePosition.z);
|
|
|
+ max.copyFromFloats(cameraSpacePosition.x + sprite.width / 2, cameraSpacePosition.y + sprite.height / 2, cameraSpacePosition.z);
|
|
|
+
|
|
|
+ if (ray.intersectsBoxMinMax(min, max)) {
|
|
|
+ distance = Vector3.Distance(cameraSpacePosition, ray.origin);
|
|
|
+
|
|
|
+ var result = new PickingInfo();
|
|
|
+ results.push(result);
|
|
|
+
|
|
|
+ cameraView.invertToRef(TmpVectors.Matrix[0]);
|
|
|
+ result.hit = true;
|
|
|
+ result.pickedSprite = sprite;
|
|
|
+ result.distance = distance;
|
|
|
+
|
|
|
+ // Get picked point
|
|
|
+ let direction = TmpVectors.Vector3[2];
|
|
|
+ direction.copyFrom(ray.direction);
|
|
|
+ direction.normalize();
|
|
|
+ direction.scaleInPlace(distance);
|
|
|
+
|
|
|
+ ray.origin.addToRef(direction, pickedPoint);
|
|
|
+ result.pickedPoint = Vector3.TransformCoordinates(pickedPoint, TmpVectors.Matrix[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return results;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Render all child sprites
|
|
|
*/
|
|
|
public render(): void {
|