Skip to content

Commit

Permalink
perf: Polygon check winding on negative scale
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed May 18, 2024
1 parent c453783 commit a54f7f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/engine/Collision/Colliders/PolygonCollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,11 @@ export class PolygonCollider extends Collider {
for (let i = 0; i < len; i++) {
this._transformedPoints[i] = this._globalMatrix.multiply(points[i].clone());
}
// TODO possible optimization here only check if the transform has a potentially problematic value?
// it is possible for the transform to change the winding, scale (-1, 1) for example
this._checkAndUpdateWinding(this._transformedPoints);
const scale = this._globalMatrix.getScale();
if (scale.x < 0 || scale.y < 0) {
this._checkAndUpdateWinding(this._transformedPoints);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/engine/Math/affine-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export class AffineMatrix {

this._scale[0] = x;
this._scale[1] = y;
this._scaleSignX = sign(x);
this._scaleSignY = sign(y);
return this;
}

Expand Down Expand Up @@ -406,6 +408,8 @@ export class AffineMatrix {
public clone(dest?: AffineMatrix): AffineMatrix {
const mat = dest || new AffineMatrix();
mat.data.set(this.data);
mat._scaleSignX = this._scaleSignX;
mat._scaleSignY = this._scaleSignY;
return mat;
}

Expand Down

0 comments on commit a54f7f0

Please sign in to comment.