summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--derelict.js30
1 files changed, 19 insertions, 11 deletions
diff --git a/derelict.js b/derelict.js
index 6605fe3..4839fe6 100644
--- a/derelict.js
+++ b/derelict.js
@@ -27,12 +27,14 @@ const killmails = [
{id: 91831050, hash: "29b01fa248efffe2ebe7dc220e584ed779a91b28"},
]
+const SCALE = 10000
+
init()
animate()
-function Wreck(x, y, z) {
+function Wreck(vec3) {
const point = new THREE.Object3D()
- point.position.fromArray([x, y, z])
+ point.position.copy(vec3)
const div = document.createElement('div')
div.className = 'wreck'
@@ -55,6 +57,20 @@ function loadWreckIcon() {
})
}
+function processKillmails(killmails) {
+ let center = new THREE.Vector3()
+ const positions = killmails.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)
+ vec3.sub(center)
+ vec3.divideScalar(SCALE)
+ scene.add(Wreck(vec3))
+ })
+}
+
function init() {
camera = new THREE.PerspectiveCamera(80, window.innerWidth / window.innerHeight, 0.1, 100)
camera.position.set(8, 8, 8)
@@ -67,15 +83,7 @@ function init() {
const retrieve = km => fetch(url(km)).then(response => response.json())
return Promise.all(killmails.map(retrieve))
})
- .then(killmails => {
- killmails.forEach(km => {
- const pos = km.victim.position
- pos.x += 921513306266.4209 // TODO: Calculate average instead of magic translation.
- pos.y -= 490635208815.2254
- pos.z -= 916212889453.0426
- scene.add(Wreck(pos.x / 10000, pos.y / 10000, pos.z / 10000))
- })
- })
+ .then(processKillmails)
const grid = new THREE.GridHelper(30, 30)
scene.add(grid)