Skip to content

Commit

Permalink
Change permeable name to sensors, add isSensor to Pair
Browse files Browse the repository at this point in the history
  • Loading branch information
Misiur committed Dec 28, 2015
1 parent 6e7add1 commit 28084b0
Show file tree
Hide file tree
Showing 11 changed files with 6,689 additions and 22 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<li><a href="http://brm.io/matter-js-demo-master#beachBalls">Beach Balls</a></li>
<li><a href="http://brm.io/matter-js-demo-master#stress">Stress 1</a></li>
<li><a href="http://brm.io/matter-js-demo-master#stress2">Stress 2</a></li>
<li><a href="http://brm.io/matter-js-demo#sensors">Sensors</a></li>
</ul>
<br>
</td>
Expand Down Expand Up @@ -95,6 +96,7 @@ See how others are using matter.js physics
- Constraints
- Gravity
- Sleeping and static bodies
- Sensors
- Rounded corners (chamfering)
- Views (translate, zoom)
- Collision queries (raycasting, region tests)
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1>Matter.js Demo (Edge Build)</h1>
<option value="beachBalls">Beach Balls</option>
<option value="stress">Stress 1</option>
<option value="stress2">Stress 2</option>
<option value="permeableObjects">Permeable Objects</option>
<option value="sensors">Sensors</option>
</select>
<input id="demo-reset" value="Reset" type="submit">
<div class="demo-view-source nav-links">
Expand Down
9 changes: 9 additions & 0 deletions demo/js/lib/matter-dev.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/permeableObjects.js → examples/sensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Common = Matter.Common,
Events = Matter.Events;

Example.permeableObjects = function(demo) {
Example.sensors = function(demo) {
var engine = demo.engine,
world = engine.world,
sceneEvents = demo.sceneEvents;
Expand All @@ -14,7 +14,7 @@
greenColor = '#C7F464';

var collider = Bodies.rectangle(400, 300, 500, 50, {
isPermeable: true,
isSensor: true,
isStatic: true,
render: {
strokeStyle: redColor,
Expand Down
6 changes: 3 additions & 3 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var Axes = require('../geometry/Axes');
angularSpeed: 0,
velocity: { x: 0, y: 0 },
angularVelocity: 0,
isPermeable: false,
isSensor: false,
isStatic: false,
isSleeping: false,
motion: 0,
Expand Down Expand Up @@ -789,9 +789,9 @@ var Axes = require('../geometry/Axes');
*/

/**
* A flag that indicates whether a body is considered permeable. A permeable body triggers collision events, but doesn't react with colliding body physically.
* A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically.
*
* @property isPermeable
* @property isSensor
* @type boolean
* @default false
*/
Expand Down
1 change: 1 addition & 0 deletions src/collision/Pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var Contact = require('./Contact');
activeContacts: [],
separation: 0,
isActive: true,
isSensor: bodyA.isSensor || bodyB.isSensor,
timeCreated: timestamp,
timeUpdated: timestamp,
inverseMass: parentA.inverseMass + parentB.inverseMass,
Expand Down
20 changes: 4 additions & 16 deletions src/collision/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ var Bounds = require('../geometry/Bounds');
for (i = 0; i < pairs.length; i++) {
pair = pairs[i];

if (!pair.isActive)
if (!pair.isActive || pair.isSensor)
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 @@ -92,17 +89,14 @@ var Bounds = require('../geometry/Bounds');
for (i = 0; i < pairs.length; i++) {
pair = pairs[i];

if (!pair.isActive || pair.separation < 0)
if (!pair.isActive || pair.isSensor || pair.separation < 0)
continue;

collision = pair.collision;
bodyA = collision.parentA;
bodyB = collision.parentB;
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 @@ -186,7 +180,7 @@ var Bounds = require('../geometry/Bounds');
for (i = 0; i < pairs.length; i++) {
pair = pairs[i];

if (!pair.isActive)
if (!pair.isActive || pair.isSensor)
continue;

contacts = pair.activeContacts;
Expand All @@ -195,9 +189,6 @@ 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++) {
Expand Down Expand Up @@ -248,7 +239,7 @@ var Bounds = require('../geometry/Bounds');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i];

if (!pair.isActive)
if (!pair.isActive || pair.isSensor)
continue;

var collision = pair.collision,
Expand All @@ -259,9 +250,6 @@ 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
Loading

0 comments on commit 28084b0

Please sign in to comment.