mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-13 16:18:50 -05:00
Revert "Merge branch 'pr/526'"
This reverts commit52f3734b3e
, reversing changes made toc04536f2c0
.
This commit is contained in:
parent
d1f1c1907a
commit
3216d7e986
4 changed files with 74 additions and 35 deletions
38
src/collision/Contact.js
Normal file
38
src/collision/Contact.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* The `Matter.Contact` module contains methods for creating and manipulating collision contacts.
|
||||||
|
*
|
||||||
|
* @class Contact
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Contact = {};
|
||||||
|
|
||||||
|
module.exports = Contact;
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new contact.
|
||||||
|
* @method create
|
||||||
|
* @param {vertex} vertex
|
||||||
|
* @return {contact} A new contact
|
||||||
|
*/
|
||||||
|
Contact.create = function(vertex) {
|
||||||
|
return {
|
||||||
|
id: Contact.id(vertex),
|
||||||
|
vertex: vertex,
|
||||||
|
normalImpulse: 0,
|
||||||
|
tangentImpulse: 0
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a contact id.
|
||||||
|
* @method id
|
||||||
|
* @param {vertex} vertex
|
||||||
|
* @return {string} Unique contactID
|
||||||
|
*/
|
||||||
|
Contact.id = function(vertex) {
|
||||||
|
return vertex.body.id + '_' + vertex.index;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
|
@ -8,6 +8,8 @@ var Pair = {};
|
||||||
|
|
||||||
module.exports = Pair;
|
module.exports = Pair;
|
||||||
|
|
||||||
|
var Contact = require('./Contact');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,12 +21,15 @@ module.exports = Pair;
|
||||||
*/
|
*/
|
||||||
Pair.create = function(collision, timestamp) {
|
Pair.create = function(collision, timestamp) {
|
||||||
var bodyA = collision.bodyA,
|
var bodyA = collision.bodyA,
|
||||||
bodyB = collision.bodyB;
|
bodyB = collision.bodyB,
|
||||||
|
parentA = collision.parentA,
|
||||||
|
parentB = collision.parentB;
|
||||||
|
|
||||||
var pair = {
|
var pair = {
|
||||||
id: Pair.id(bodyA, bodyB),
|
id: Pair.id(bodyA, bodyB),
|
||||||
bodyA: bodyA,
|
bodyA: bodyA,
|
||||||
bodyB: bodyB,
|
bodyB: bodyB,
|
||||||
|
contacts: {},
|
||||||
activeContacts: [],
|
activeContacts: [],
|
||||||
separation: 0,
|
separation: 0,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
|
@ -32,12 +37,11 @@ module.exports = Pair;
|
||||||
isSensor: bodyA.isSensor || bodyB.isSensor,
|
isSensor: bodyA.isSensor || bodyB.isSensor,
|
||||||
timeCreated: timestamp,
|
timeCreated: timestamp,
|
||||||
timeUpdated: timestamp,
|
timeUpdated: timestamp,
|
||||||
collision: null,
|
inverseMass: parentA.inverseMass + parentB.inverseMass,
|
||||||
inverseMass: 0,
|
friction: Math.min(parentA.friction, parentB.friction),
|
||||||
friction: 0,
|
frictionStatic: Math.max(parentA.frictionStatic, parentB.frictionStatic),
|
||||||
frictionStatic: 0,
|
restitution: Math.max(parentA.restitution, parentB.restitution),
|
||||||
restitution: 0,
|
slop: Math.max(parentA.slop, parentB.slop)
|
||||||
slop: 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Pair.update(pair, collision, timestamp);
|
Pair.update(pair, collision, timestamp);
|
||||||
|
@ -53,28 +57,31 @@ module.exports = Pair;
|
||||||
* @param {number} timestamp
|
* @param {number} timestamp
|
||||||
*/
|
*/
|
||||||
Pair.update = function(pair, collision, timestamp) {
|
Pair.update = function(pair, collision, timestamp) {
|
||||||
|
var contacts = pair.contacts,
|
||||||
|
supports = collision.supports,
|
||||||
|
activeContacts = pair.activeContacts,
|
||||||
|
parentA = collision.parentA,
|
||||||
|
parentB = collision.parentB;
|
||||||
|
|
||||||
pair.collision = collision;
|
pair.collision = collision;
|
||||||
|
pair.inverseMass = parentA.inverseMass + parentB.inverseMass;
|
||||||
|
pair.friction = Math.min(parentA.friction, parentB.friction);
|
||||||
|
pair.frictionStatic = Math.max(parentA.frictionStatic, parentB.frictionStatic);
|
||||||
|
pair.restitution = Math.max(parentA.restitution, parentB.restitution);
|
||||||
|
pair.slop = Math.max(parentA.slop, parentB.slop);
|
||||||
|
activeContacts.length = 0;
|
||||||
|
|
||||||
if (collision.collided) {
|
if (collision.collided) {
|
||||||
var supports = collision.supports,
|
|
||||||
activeContacts = pair.activeContacts,
|
|
||||||
parentA = collision.parentA,
|
|
||||||
parentB = collision.parentB;
|
|
||||||
|
|
||||||
pair.inverseMass = parentA.inverseMass + parentB.inverseMass;
|
|
||||||
pair.friction = Math.min(parentA.friction, parentB.friction);
|
|
||||||
pair.frictionStatic = Math.max(parentA.frictionStatic, parentB.frictionStatic);
|
|
||||||
pair.restitution = Math.max(parentA.restitution, parentB.restitution);
|
|
||||||
pair.slop = Math.max(parentA.slop, parentB.slop);
|
|
||||||
|
|
||||||
for (var i = 0; i < supports.length; i++) {
|
for (var i = 0; i < supports.length; i++) {
|
||||||
activeContacts[i] = supports[i].contact;
|
var support = supports[i],
|
||||||
}
|
contactId = Contact.id(support),
|
||||||
|
contact = contacts[contactId];
|
||||||
|
|
||||||
// optimise array size
|
if (contact) {
|
||||||
var supportCount = supports.length;
|
activeContacts.push(contact);
|
||||||
if (supportCount < activeContacts.length) {
|
} else {
|
||||||
activeContacts.length = supportCount;
|
activeContacts.push(contacts[contactId] = Contact.create(support));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pair.separation = collision.depth;
|
pair.separation = collision.depth;
|
||||||
|
@ -117,4 +124,4 @@ module.exports = Pair;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -44,16 +44,9 @@ var Common = require('../core/Common');
|
||||||
y: point.y,
|
y: point.y,
|
||||||
index: i,
|
index: i,
|
||||||
body: body,
|
body: body,
|
||||||
isInternal: false,
|
isInternal: false
|
||||||
contact: null
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vertex.contact = {
|
|
||||||
vertex: vertex,
|
|
||||||
normalImpulse: 0,
|
|
||||||
tangentImpulse: 0
|
|
||||||
};
|
|
||||||
|
|
||||||
vertices.push(vertex);
|
vertices.push(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,4 +444,4 @@ var Common = require('../core/Common');
|
||||||
return upper.concat(lower);
|
return upper.concat(lower);
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -4,6 +4,7 @@ Matter.Body = require('../body/Body');
|
||||||
Matter.Composite = require('../body/Composite');
|
Matter.Composite = require('../body/Composite');
|
||||||
Matter.World = require('../body/World');
|
Matter.World = require('../body/World');
|
||||||
|
|
||||||
|
Matter.Contact = require('../collision/Contact');
|
||||||
Matter.Detector = require('../collision/Detector');
|
Matter.Detector = require('../collision/Detector');
|
||||||
Matter.Grid = require('../collision/Grid');
|
Matter.Grid = require('../collision/Grid');
|
||||||
Matter.Pairs = require('../collision/Pairs');
|
Matter.Pairs = require('../collision/Pairs');
|
||||||
|
|
Loading…
Reference in a new issue