0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-13 16:18:50 -05:00

Add permeable objects

This commit is contained in:
Marcin Misiurski 2015-10-21 00:15:20 +02:00
parent 5ff218234a
commit 1573359354
2 changed files with 15 additions and 2 deletions

View file

@ -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,

View file

@ -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;