summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--derelict.js48
1 files changed, 22 insertions, 26 deletions
diff --git a/derelict.js b/derelict.js
index 7e2da08..c35f285 100644
--- a/derelict.js
+++ b/derelict.js
@@ -13,10 +13,10 @@ class SkirmishGrid {
renderer
renderer2d
- constructor(obj) {
- this.container = obj.container
- this.renderer = obj.renderer
- this.renderer2d = obj.renderer2d
+ constructor({container, renderer, renderer2d}) {
+ this.container = container
+ this.renderer = renderer
+ this.renderer2d = renderer2d
const aspect = this.container.clientWidth / this.container.clientHeight
this.camera = new THREE.PerspectiveCamera(80, aspect, 0.1, 1000)
@@ -45,18 +45,21 @@ class SkirmishGrid {
}
}
-function Wreck(vec3, km) {
- const point = new THREE.Object3D()
- point.position.copy(vec3)
+class Wreck {
+ domElement = document.createElement('div')
+ point = new THREE.Object3D()
+ killmail
- const div = document.createElement('div')
- div.className = 'wreck'
- const w = document.importNode(wreck, true)
- div.appendChild(w)
- const label = new CSS2DObject(div)
- point.add(label)
+ constructor({killmail, position}) {
+ const icon = document.importNode(obj.icon, true)
+ const object2d = new CSS2DObject(this.domElement)
- return point;
+ this.killmail = killmail
+ this.domElement.className = 'wreck'
+ this.domElement.appendChild(icon)
+ this.point.position.copy(position)
+ this.point.add(object2d)
+ }
}
function loadWreckIcon() {
@@ -94,20 +97,13 @@ function processKillmails(grid, killmails) {
center.divideScalar(positions.length)
clusters[0].sort((a, b) => a.killmail_time.localeCompare(b.killmail_time))
let elements = []
- clusters[0].forEach(km => {
- const vec3 = km.victim.position
+ clusters[0].forEach(killmail => {
+ const vec3 = killmail.victim.position
vec3.sub(center)
vec3.divideScalar(SCALE)
- const point = new THREE.Object3D()
- point.position.copy(vec3)
- const div = document.createElement('div')
- div.className = 'wreck'
- const w = document.importNode(wreck, true)
- div.appendChild(w)
- const label = new CSS2DObject(div)
- point.add(label)
- grid.add(point)
- elements.push(div)
+ const wreck = new Wreck({position: vec3, killmail})
+ grid.add(wreck.point)
+ elements.push(wreck.domElement)
})
const timeline = document.getElementById("timeline")
timeline.max = elements.length + 1