summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-04-04 02:59:05 +0200
committerAki <please@ignore.pl>2021-04-04 02:59:05 +0200
commitdb07039a3d0522a62081d44ee38929bdb0a3cf32 (patch)
treea7d4164e05b058e1672487be70c0d1f997f3abde
parentbc45e6749ae8a3f9a8a7c74044d830f7dae90abc (diff)
downloadderelict-prototype-db07039a3d0522a62081d44ee38929bdb0a3cf32.zip
derelict-prototype-db07039a3d0522a62081d44ee38929bdb0a3cf32.tar.gz
derelict-prototype-db07039a3d0522a62081d44ee38929bdb0a3cf32.tar.bz2
Added simple clustering
-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))