summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-04-02 00:22:36 +0200
committerAki <please@ignore.pl>2021-04-02 00:22:36 +0200
commit0e7a49a66f93463ad66842f8558d66e669e27309 (patch)
treecfd62f678f653d74e757ac0adf5820908eef0a53
parent8726e73c06fab4613bb9e30dfea4b51fcb41c13d (diff)
downloadderelict-prototype-0e7a49a66f93463ad66842f8558d66e669e27309.zip
derelict-prototype-0e7a49a66f93463ad66842f8558d66e669e27309.tar.gz
derelict-prototype-0e7a49a66f93463ad66842f8558d66e669e27309.tar.bz2
Wrecks are now automatically translated
-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)