From db07039a3d0522a62081d44ee38929bdb0a3cf32 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 4 Apr 2021 02:59:05 +0200 Subject: Added simple clustering --- derelict.js | 24 ++++++++++++++++++++---- 1 file 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)) -- cgit v1.1