0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-03-14 00:38:41 -04:00

Reverse vertices order from counterclockwise to clockwise if one scale is negative.

Regarding: https://github.com/liabru/matter-js/issues/443
I was having an issue with bodies that were flipped over X wobbling on edges. But not in their original scale. I saw the above issue and thought that might be the issue. So I created this solution which solved the issue of the body wobbling on the edge and some minor other issues I was noticing.
This commit is contained in:
Robert Kowalski 2019-01-24 05:24:45 -05:00 committed by GitHub
parent 2ec247b7af
commit 52cfe9523f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -254,11 +254,27 @@ var Common = require('../core/Common');
var vertex,
delta;
for (var i = 0; i < vertices.length; i++) {
vertex = vertices[i];
delta = Vector.sub(vertex, point);
vertices[i].x = point.x + delta.x * scaleX;
vertices[i].y = point.y + delta.y * scaleY;
// Reverse the order from counterclockwise to clockwise when scaleX or scaleY is negative, but not both.
if (scaleX < 0 && scaleY > 0 || scaleX > 0 && scaleY < 0) {
var pastVertices = [];
for (var i = 0; i < vertices.length; i++)
pastVertices[i] = { x: vertices[i].x, y: vertices[i].y };
for (var i = 0, j = pastVertices.length - 1; i < pastVertices.length; i++) {
j = pastVertices.length - i - 1;
vertex = pastVertices[j];
delta = Vector.sub(vertex, point);
vertices[i].x = point.x + delta.x * scaleX;
vertices[i].y = point.y + delta.y * scaleY;
}
} else {
for (var i = 0; i < vertices.length; i++) {
vertex = vertices[i];
delta = Vector.sub(vertex, point);
vertices[i].x = point.x + delta.x * scaleX;
vertices[i].y = point.y + delta.y * scaleY;
}
}
return vertices;
@ -451,4 +467,4 @@ var Common = require('../core/Common');
return upper.concat(lower);
};
})();
})();