Skip to content

Commit

Permalink
Added RigidBody.expandAABB()
Browse files Browse the repository at this point in the history
  • Loading branch information
markeasting committed Nov 26, 2023
1 parent 04e67f3 commit df1c273
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/physics/Collider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export class Collider {
expanded_aabb = new Box3();
aabbHelper = new Box3Helper(this.expanded_aabb);

public expandAABB(scalar: number): void {
this.expanded_aabb
.copy(this.aabb)
.expandByScalar(scalar);
}

public updateGlobalPose(pose: Pose): void {
// console.log('updateRotation not implemented')
}
Expand Down
6 changes: 4 additions & 2 deletions src/physics/RigidBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ export class RigidBody {

this.prevPose.copy(this.pose); // Just in case pose was changed directly after setting static

this.collider.expanded_aabb.copy(this.collider.aabb);

this.updateGeometry();
this.updateCollider();

Expand Down Expand Up @@ -383,6 +381,10 @@ export class RigidBody {
}

public updateCollider() {
if (!this.isDynamic) {
this.collider.expandAABB(1.0);
}

this.collider.updateGlobalPose(this.pose);
}

Expand Down
4 changes: 1 addition & 3 deletions src/physics/solver/XPBDSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ export class XPBDSolver extends BaseSolver {
continue;

/* (3.5) k * dt * vbody */
body.collider.expanded_aabb
.copy(body.collider.aabb)
.expandByScalar(2.0 * dt * body.vel.length());
body.collider.expandAABB(2.0 * dt * body.vel.length());

body.force.set(0, 0, 0);
body.torque.set(0, 0, 0);
Expand Down

0 comments on commit df1c273

Please sign in to comment.