mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
fixed collision rendering
This commit is contained in:
parent
84d9f591aa
commit
bc9a051e73
1 changed files with 41 additions and 1 deletions
|
@ -779,6 +779,7 @@ var Render = {};
|
||||||
options = engine.render.options,
|
options = engine.render.options,
|
||||||
pair,
|
pair,
|
||||||
collision,
|
collision,
|
||||||
|
corrected,
|
||||||
i,
|
i,
|
||||||
j;
|
j;
|
||||||
|
|
||||||
|
@ -787,6 +788,10 @@ var Render = {};
|
||||||
// render collision positions
|
// render collision positions
|
||||||
for (i = 0; i < pairs.length; i++) {
|
for (i = 0; i < pairs.length; i++) {
|
||||||
pair = pairs[i];
|
pair = pairs[i];
|
||||||
|
|
||||||
|
if (!pair.isActive)
|
||||||
|
continue;
|
||||||
|
|
||||||
collision = pair.collision;
|
collision = pair.collision;
|
||||||
for (j = 0; j < pair.activeContacts.length; j++) {
|
for (j = 0; j < pair.activeContacts.length; j++) {
|
||||||
var contact = pair.activeContacts[j],
|
var contact = pair.activeContacts[j],
|
||||||
|
@ -804,9 +809,39 @@ var Render = {};
|
||||||
|
|
||||||
c.beginPath();
|
c.beginPath();
|
||||||
|
|
||||||
|
// render corrected positions
|
||||||
|
for (i = 0; i < pairs.length; i++) {
|
||||||
|
pair = pairs[i];
|
||||||
|
|
||||||
|
if (!pair.isActive)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
collision = pair.collision;
|
||||||
|
corrected = collision.supportCorrected;
|
||||||
|
|
||||||
|
if (collision.bodyB === collision.supports[0].body) {
|
||||||
|
c.rect(collision.supportCorrected.x - 1.5, collision.supportCorrected.y - 1.5, 3.5, 3.5);
|
||||||
|
} else {
|
||||||
|
c.rect(collision.supportCorrected.x - 1.5 + (2 * collision.penetration.x), collision.supportCorrected.y - 1.5 + (2 * collision.penetration.y), 3.5, 3.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.wireframes) {
|
||||||
|
c.strokeStyle = 'rgba(255,165,0,0.7)';
|
||||||
|
} else {
|
||||||
|
c.strokeStyle = 'orange';
|
||||||
|
}
|
||||||
|
c.stroke();
|
||||||
|
|
||||||
|
c.beginPath();
|
||||||
|
|
||||||
// render collision normals
|
// render collision normals
|
||||||
for (i = 0; i < pairs.length; i++) {
|
for (i = 0; i < pairs.length; i++) {
|
||||||
pair = pairs[i];
|
pair = pairs[i];
|
||||||
|
|
||||||
|
if (!pair.isActive)
|
||||||
|
continue;
|
||||||
|
|
||||||
collision = pair.collision;
|
collision = pair.collision;
|
||||||
|
|
||||||
if (pair.activeContacts.length > 0) {
|
if (pair.activeContacts.length > 0) {
|
||||||
|
@ -818,7 +853,12 @@ var Render = {};
|
||||||
normalPosY = (pair.activeContacts[0].vertex.y + pair.activeContacts[1].vertex.y) / 2;
|
normalPosY = (pair.activeContacts[0].vertex.y + pair.activeContacts[1].vertex.y) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (collision.bodyB === collision.supports[0].body) {
|
||||||
c.moveTo(normalPosX - collision.normal.x * 8, normalPosY - collision.normal.y * 8);
|
c.moveTo(normalPosX - collision.normal.x * 8, normalPosY - collision.normal.y * 8);
|
||||||
|
} else {
|
||||||
|
c.moveTo(normalPosX + collision.normal.x * 8, normalPosY + collision.normal.y * 8);
|
||||||
|
}
|
||||||
|
|
||||||
c.lineTo(normalPosX, normalPosY);
|
c.lineTo(normalPosX, normalPosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue