improve position fixing
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import QuickHull from 'quickhull' // DEPRECATED: hulls were a failed concept for position fixing
|
||||
import SAT from 'sat'
|
||||
import { Shape, ShapeUtils, Vector2 } from 'three'
|
||||
|
||||
@@ -8,6 +9,7 @@ export default class Terrain {
|
||||
relativeVertices = []
|
||||
|
||||
#colliders = []
|
||||
#hull = null
|
||||
#vertices = []
|
||||
#unadjustedWaypoints = []
|
||||
|
||||
@@ -24,6 +26,7 @@ export default class Terrain {
|
||||
}
|
||||
|
||||
get colliders() { return this.#colliders }
|
||||
get hull() { return this.#hull } // DEPRECATED: hulls were a failed concept for position fixing
|
||||
get unadjustedWaypoints() { return this.#unadjustedWaypoints }
|
||||
get vertices() { return this.#vertices }
|
||||
|
||||
@@ -73,6 +76,16 @@ export default class Terrain {
|
||||
}
|
||||
|
||||
this.#colliders = ShapeUtils.triangulateShape(points.shape, points.holes).map(indicesToPolygon)
|
||||
this.#calculateHull()
|
||||
}
|
||||
|
||||
// DEPRECATED: hulls were a failed concept for position fixing
|
||||
#calculateHull() {
|
||||
const vertices = QuickHull(this.#vertices.map((v) => ({ x: v.x, y: v.y }))).map((v) => new Vector2(v.x, v.y))
|
||||
const first = vertices.at(0)
|
||||
const satPoints = [new SAT.Vector(...first.toArray()), ...vertices.slice(1).map((v) => new SAT.Vector(...v.clone(first).sub(first).toArray()))]
|
||||
|
||||
this.#hull = new SAT.Polygon(satPoints[0], [new SAT.Vector(), ...satPoints.slice(1)])
|
||||
}
|
||||
|
||||
#calculatePosition() {
|
||||
|
||||
Reference in New Issue
Block a user