From 15733593540c09ef7dcb796710fba8675093cd7a Mon Sep 17 00:00:00 2001 From: Marcin Misiurski Date: Wed, 21 Oct 2015 00:15:20 +0200 Subject: [PATCH] Add permeable objects --- src/body/Body.js | 1 + src/collision/Resolver.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/body/Body.js b/src/body/Body.js index f7e3ae54..3459cc54 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -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, diff --git a/src/collision/Resolver.js b/src/collision/Resolver.js index e86dbd10..2c9b7b5c 100644 --- a/src/collision/Resolver.js +++ b/src/collision/Resolver.js @@ -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), @@ -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; @@ -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]; @@ -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;