summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--derelict.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/derelict.js b/derelict.js
index 88a4b94..77767bf 100644
--- a/derelict.js
+++ b/derelict.js
@@ -35,13 +35,29 @@ function loadWreckIcon() {
}
function processKillmails(killmails) {
+ let clusters = []
+ killmails.forEach(km => {
+ const pos = km.victim.position
+ km.victim.position = new THREE.Vector3(pos.x, pos.y, pos.z)
+ const vec3 = km.victim.position
+ let added = false
+ for (const cluster of clusters) {
+ if (cluster[0].victim.position.distanceTo(vec3) < 100 * SCALE) {
+ cluster.push(km)
+ added = true
+ break
+ }
+ }
+ if (!added) {
+ clusters.push([km])
+ }
+ })
let center = new THREE.Vector3()
- const positions = killmails.map(km => km.victim.position)
+ let positions = clusters[0].map(km => km.victim.position)
positions.forEach(pos => center.add(new THREE.Vector3(pos.x, pos.y, pos.z)))
center.divideScalar(positions.length)
- killmails.forEach(km => {
- const pos = km.victim.position
- const vec3 = new THREE.Vector3(pos.x, pos.y, pos.z)
+ clusters[0].forEach(km => {
+ const vec3 = km.victim.position
vec3.sub(center)
vec3.divideScalar(SCALE)
scene.add(Wreck(vec3))