Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions demos/ballpit/BallShooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,21 @@ export class BallShooter extends xb.Script {
const position = sphere.position.copy(body.translation());
// If the ball falls behind the depth then adjust the spawnTime to begin
// expiring the ball.

// Use depth matrices if depth is enabled, otherwise fall back to camera matrices
const viewMatrix = xb.depth?.enabled
? xb.depth.depthViewMatrices[0]
: xb.core.camera.matrixWorldInverse;
const projectionMatrix = xb.depth?.enabled
? xb.depth.depthProjectionMatrices[0]
: xb.core.camera.projectionMatrix;

const viewSpacePosition = this.viewSpacePosition
.copy(position)
.applyMatrix4(xb.depth.depthViewMatrices[0]);
.applyMatrix4(viewMatrix);
const clipSpacePosition = this.clipSpacePosition
.copy(viewSpacePosition)
.applyMatrix4(xb.depth.depthProjectionMatrices[0]);
.applyMatrix4(projectionMatrix);
const ballIsInView =
-1.0 <= clipSpacePosition.x &&
clipSpacePosition.x <= 1.0 &&
Expand Down