0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

optimised Resolver.solveVelocity

This commit is contained in:
liabru 2023-07-23 13:50:26 +01:00
parent 97d502ea97
commit 182ba905d4

View file

@ -248,25 +248,23 @@ var Bounds = require('../geometry/Bounds');
var collision = pair.collision, var collision = pair.collision,
bodyA = collision.parentA, bodyA = collision.parentA,
bodyB = collision.parentB, bodyB = collision.parentB,
bodyAVelocity = bodyA.velocity,
bodyBVelocity = bodyB.velocity,
normalX = collision.normal.x, normalX = collision.normal.x,
normalY = collision.normal.y, normalY = collision.normal.y,
tangentX = collision.tangent.x, tangentX = collision.tangent.x,
tangentY = collision.tangent.y, tangentY = collision.tangent.y,
inverseMassTotal = pair.inverseMass,
friction = pair.friction * pair.frictionStatic * frictionNormalMultiplier,
contacts = pair.contacts, contacts = pair.contacts,
contactCount = pair.contactCount, contactCount = pair.contactCount,
contactShare = 1 / contactCount, contactShare = 1 / contactCount;
inverseMassTotal = bodyA.inverseMass + bodyB.inverseMass,
friction = pair.friction * pair.frictionStatic * frictionNormalMultiplier;
// update body velocities // get body velocities
bodyAVelocity.x = bodyA.position.x - bodyA.positionPrev.x; var bodyAVelocityX = bodyA.position.x - bodyA.positionPrev.x,
bodyAVelocity.y = bodyA.position.y - bodyA.positionPrev.y; bodyAVelocityY = bodyA.position.y - bodyA.positionPrev.y,
bodyBVelocity.x = bodyB.position.x - bodyB.positionPrev.x; bodyAAngularVelocity = bodyA.angle - bodyA.anglePrev,
bodyBVelocity.y = bodyB.position.y - bodyB.positionPrev.y; bodyBVelocityX = bodyB.position.x - bodyB.positionPrev.x,
bodyA.angularVelocity = bodyA.angle - bodyA.anglePrev; bodyBVelocityY = bodyB.position.y - bodyB.positionPrev.y,
bodyB.angularVelocity = bodyB.angle - bodyB.anglePrev; bodyBAngularVelocity = bodyB.angle - bodyB.anglePrev;
// resolve each contact // resolve each contact
for (j = 0; j < contactCount; j++) { for (j = 0; j < contactCount; j++) {
@ -278,10 +276,10 @@ var Bounds = require('../geometry/Bounds');
offsetBX = contactVertex.x - bodyB.position.x, offsetBX = contactVertex.x - bodyB.position.x,
offsetBY = contactVertex.y - bodyB.position.y; offsetBY = contactVertex.y - bodyB.position.y;
var velocityPointAX = bodyAVelocity.x - offsetAY * bodyA.angularVelocity, var velocityPointAX = bodyAVelocityX - offsetAY * bodyAAngularVelocity,
velocityPointAY = bodyAVelocity.y + offsetAX * bodyA.angularVelocity, velocityPointAY = bodyAVelocityY + offsetAX * bodyAAngularVelocity,
velocityPointBX = bodyBVelocity.x - offsetBY * bodyB.angularVelocity, velocityPointBX = bodyBVelocityX - offsetBY * bodyBAngularVelocity,
velocityPointBY = bodyBVelocity.y + offsetBX * bodyB.angularVelocity; velocityPointBY = bodyBVelocityY + offsetBX * bodyBAngularVelocity;
var relativeVelocityX = velocityPointAX - velocityPointBX, var relativeVelocityX = velocityPointAX - velocityPointBX,
relativeVelocityY = velocityPointAY - velocityPointBY; relativeVelocityY = velocityPointAY - velocityPointBY;