Skip to content

Commit

Permalink
Add permeable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Misiur committed Dec 28, 2015
1 parent 5ff2182 commit 1573359
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var Axes = require('../geometry/Axes');
angularSpeed: 0,
velocity: { x: 0, y: 0 },
angularVelocity: 0,
isPermeable: false,
isStatic: false,
isSleeping: false,
motion: 0,
Expand Down
16 changes: 14 additions & 2 deletions src/collision/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ var Bounds = require('../geometry/Bounds');

if (!pair.isActive)
continue;

collision = pair.collision;
bodyA = collision.parentA;
bodyB = collision.parentB;
normal = collision.normal;

if (bodyA.isPermeable || bodyB.isPermeable)
continue;

// get current separation between body edges involved in collision
bodyBtoA = Vector.sub(Vector.add(bodyB.positionImpulse, bodyB.position, tempA),
Expand All @@ -98,6 +101,9 @@ var Bounds = require('../geometry/Bounds');
normal = collision.normal;
positionImpulse = (pair.separation - pair.slop) * timeScale;

if (bodyA.isPermeable || bodyB.isPermeable)
continue;

if (bodyA.isStatic || bodyB.isStatic)
positionImpulse *= 2;

Expand Down Expand Up @@ -189,7 +195,10 @@ var Bounds = require('../geometry/Bounds');
bodyB = collision.parentB;
normal = collision.normal;
tangent = collision.tangent;


if (bodyA.isPermeable || bodyB.isPermeable)
continue;

// resolve each contact
for (j = 0; j < contacts.length; j++) {
contact = contacts[j];
Expand Down Expand Up @@ -250,6 +259,9 @@ var Bounds = require('../geometry/Bounds');
contacts = pair.activeContacts,
contactShare = 1 / contacts.length;

if (bodyA.isPermeable || bodyB.isPermeable)
continue;

// update body velocities
bodyA.velocity.x = bodyA.position.x - bodyA.positionPrev.x;
bodyA.velocity.y = bodyA.position.y - bodyA.positionPrev.y;
Expand Down

0 comments on commit 1573359

Please sign in to comment.