bring back very thin boxes instead of lines
This commit is contained in:
parent
4db69db0cd
commit
2793154bbb
@ -26,18 +26,26 @@ import kotlin.math.sin
|
|||||||
private fun calculateEdges(points: List<Vector2d>): Pair<ImmutableList<Poly.Edge>, ImmutableList<Vector2d>> {
|
private fun calculateEdges(points: List<Vector2d>): Pair<ImmutableList<Poly.Edge>, ImmutableList<Vector2d>> {
|
||||||
require(points.size >= 2) { "Provided poly is invalid (only ${points.size} points are defined)" }
|
require(points.size >= 2) { "Provided poly is invalid (only ${points.size} points are defined)" }
|
||||||
|
|
||||||
val edges = ImmutableList.Builder<Poly.Edge>()
|
|
||||||
|
|
||||||
if (points.size == 2) {
|
if (points.size == 2) {
|
||||||
// line, to make it one faced, we need to make only one edge
|
// line...
|
||||||
|
// while double edged line seems to work fine
|
||||||
|
// for more stable collision detection lets make it a very thin rectangle
|
||||||
|
|
||||||
|
val newPoints = ImmutableList.Builder<Vector2d>()
|
||||||
val (p0, p1) = points
|
val (p0, p1) = points
|
||||||
|
|
||||||
val diff = (p1 - p0).unitVector
|
val diff = (p1 - p0).unitVector
|
||||||
val normal = Vector2d(-diff.y, diff.x)
|
val normal = Vector2d(-diff.y, diff.x)
|
||||||
|
|
||||||
edges.add(Poly.Edge(p0, p1, normal))
|
newPoints.add(p0 + normal * 0.001)
|
||||||
|
newPoints.add(p1 + normal * 0.001)
|
||||||
|
newPoints.add(p1 - normal * 0.001)
|
||||||
|
newPoints.add(p0 - normal * 0.001)
|
||||||
|
|
||||||
|
return calculateEdges(newPoints.build())
|
||||||
} else {
|
} else {
|
||||||
|
val edges = ImmutableList.Builder<Poly.Edge>()
|
||||||
|
|
||||||
for (i in points.indices) {
|
for (i in points.indices) {
|
||||||
val p0 = points[i]
|
val p0 = points[i]
|
||||||
val p1 = points[(i + 1) % points.size]
|
val p1 = points[(i + 1) % points.size]
|
||||||
@ -47,9 +55,9 @@ private fun calculateEdges(points: List<Vector2d>): Pair<ImmutableList<Poly.Edge
|
|||||||
|
|
||||||
edges.add(Poly.Edge(p0, p1, normal))
|
edges.add(Poly.Edge(p0, p1, normal))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return edges.build() to ImmutableList.copyOf(points)
|
return edges.build() to ImmutableList.copyOf(points)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rotate(point: Vector2d, sin: Double, cos: Double): Vector2d {
|
private fun rotate(point: Vector2d, sin: Double, cos: Double): Vector2d {
|
||||||
|
Loading…
Reference in New Issue
Block a user