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

Change permeable name to sensors, add isSensor to Pair

This commit is contained in:
Marcin Misiurski 2015-12-28 21:30:56 +01:00
parent 6e7add16bf
commit 28084b005a
11 changed files with 6689 additions and 22 deletions

View file

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

View file

@ -74,7 +74,7 @@
<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">

9
demo/js/lib/matter-dev.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -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;
@ -14,7 +14,7 @@
greenColor = '#C7F464';
var collider = Bodies.rectangle(400, 300, 500, 50, {
isPermeable: true,
isSensor: true,
isStatic: true,
render: {
strokeStyle: redColor,

View file

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

View file

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

View file

@ -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),
@ -92,7 +89,7 @@ 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;
@ -100,9 +97,6 @@ var Bounds = require('../geometry/Bounds');
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;
@ -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;
@ -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++) {
@ -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,
@ -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;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff