-
-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add arbitrary non-convex polygon support (#2239)
This PR adds arbitrary non-convex polygon support using the `ex.PolygonCollider(...).triangulate()` method which produces a new `ex.CompositeCollider` composed of triangles. ![triangulation](https://user-images.githubusercontent.com/612071/153693435-932e6f86-c531-46c6-8b0c-0f89ec5b794c.gif) This PR also adds a `tessellate()` which will produce a triangle fan `ex.CompositeCollider`
- Loading branch information
Showing
8 changed files
with
295 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Triangulation</title> | ||
</head> | ||
<body> | ||
<script src="../../lib/excalibur.js"></script> | ||
<script src="./index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
var game = new ex.Engine({ | ||
width: 800, | ||
height: 600 | ||
}); | ||
game.toggleDebug(); | ||
game.debug.transform.showPosition = true; | ||
game.debug.transform.positionColor = ex.Color.Black; | ||
ex.Physics.useRealisticPhysics(); | ||
ex.Physics.gravity = ex.vec(0, 100); | ||
|
||
// star points | ||
var star: ex.Vector[] = []; | ||
var rotation = -Math.PI / 2; | ||
for (var i = 0; i < 5; i++) { | ||
// outer | ||
star.push(ex.vec(100 * Math.cos((2 * Math.PI * i)/5 + rotation), 100 * Math.sin((2 * Math.PI * i)/5 + rotation) )); | ||
// inner | ||
star.push(ex.vec(40 * Math.cos((2 * Math.PI * i)/5 + rotation + 2 * Math.PI / 10), 40 * Math.sin((2 * Math.PI * i)/5 + rotation + 2 * Math.PI / 10) )); | ||
} | ||
star.reverse(); | ||
var starCollider = new ex.PolygonCollider({points: star}); | ||
console.log("Collider Bounds", starCollider.localBounds); | ||
var starGraphic = new ex.Polygon({points: star, color: ex.Color.Yellow}); | ||
console.log("Graphic Bounds", starGraphic.localBounds); | ||
|
||
var actor = new ex.Actor({x: 200, y: 200, collisionType: ex.CollisionType.Active}); | ||
// This is an odd quirk but because we center graphics by default, and the star is asymmetric | ||
actor.graphics.use(starGraphic, { offset: ex.vec(0, -10)}); | ||
actor.collider.set(starCollider.triangulate()); | ||
actor.angularVelocity = 3; | ||
game.add(actor); | ||
|
||
|
||
var actor2 = new ex.Actor({x: 400, y: 200, collisionType: ex.CollisionType.Active}); | ||
actor2.collider.set(ex.Shape.Box(100, 100).tessellate()); | ||
actor2.graphics.use(new ex.Rectangle({ width: 100, height: 100, color: ex.Color.Black})); | ||
game.add(actor2); | ||
|
||
|
||
var ground = new ex.Actor({anchor: ex.Vector.Zero, x: 0, y: 500, width: 800, height: 10, color: ex.Color.Black, collisionType: ex.CollisionType.Fixed}); | ||
game.add(ground); | ||
|
||
|
||
game.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters