From 691fdff2a25276e6cc9405704acd14aad26fdbc4 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Fri, 20 May 2016 00:18:58 +0100 Subject: [PATCH] Grid motion is good now --- static/scripts/editor.js | 45 +++++++++++++++------------------ static/scripts/materials.js | 2 +- static/scripts/orbitcontrols.js | 1 + 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/static/scripts/editor.js b/static/scripts/editor.js index a477540..8fe5695 100644 --- a/static/scripts/editor.js +++ b/static/scripts/editor.js @@ -3,13 +3,12 @@ var pi2 = Math.PI / 2; editor.selection = undefined; -editor.planes = [ - new THREE.Plane(new THREE.Vector3(0, 0, 1), 0), - new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), - new THREE.Plane(new THREE.Vector3(1, 0, 0), 0) +editor.orientations = [ + new THREE.Euler(pi2, 0, 0), + new THREE.Euler(0, 0, 0), + new THREE.Euler(pi2, 0, pi2), ]; -editor.orientation = 0; -editor.plane = editor.planes[editor.orientation]; + editor.onFreeMove = function() { var found = editor.findNodeOnRay(mouse.ray); @@ -42,10 +41,7 @@ editor.addQubitAtPoint = function(point) { for (var node in abj.node) { var delta = new THREE.Vector3(); delta.subVectors(abj.node[node].position, point); - if (delta.length()<0.1){ - editor.focus(node); - return; - } + if (delta.length()<0.1){ return; } } abj.add_node(abj.order(), { position: point }); @@ -75,24 +71,25 @@ editor.prepare = function() { }; editor.onKey = function(evt) { - if (evt.keyCode == 32) { - editor.grid.rotation.x += Math.PI / 2; - editor.orientation = (editor.orientation + 1) % 3; - console.log(editor.orientation); - var m = editor.orientations[editor.orientation]; - editor.plane.applyMatrix4(m); - console.log(m); - editor.grid.matrix = m; - gui.render(); - gui.serverMessage("Rotated into the XY plane or whatever"); - } + if (evt.keyCode !== 32) {return;} + editor.setOrientation((editor.orientation + 1) % 3); +}; + +editor.setOrientation = function(orientation) { + editor.orientation = orientation; + var rotation = editor.orientations[orientation]; + var normal = new THREE.Vector3(0, 1, 0); + normal.applyEuler(rotation); + editor.grid.rotation.copy(rotation); + editor.plane = new THREE.Plane(); + editor.plane.setFromNormalAndCoplanarPoint(normal, editor.grid.position); + gui.render(); }; editor.makeGrid = function() { editor.grid = new THREE.GridHelper(10, 1); - editor.grid.rotation.x = Math.PI / 2; editor.grid.setColors(0xbbbbbb, 0xeeeeee); - editor.grid.matrixAutoUpdate = true; + editor.setOrientation(0); gui.scene.add(editor.grid); }; @@ -101,7 +98,7 @@ editor.update = function() {}; // Gets a reference to the node nearest to the mouse cursor editor.findNodeOnRay = function(ray) { for (var n in abj.node) { - if (ray.distanceSqToPoint(abj.node[n].position) < 0.3) { + if (ray.distanceSqToPoint(abj.node[n].position) < 0.012) { return n; } } diff --git a/static/scripts/materials.js b/static/scripts/materials.js index 2d77ee4..419ea84 100644 --- a/static/scripts/materials.js +++ b/static/scripts/materials.js @@ -27,7 +27,7 @@ materials.prepare = function() { color: "red" }); materials.qubit = new THREE.PointsMaterial({ - size: 0.7, + size: 0.5, map: ballSprite, alphaTest: 0.5, transparent: true, diff --git a/static/scripts/orbitcontrols.js b/static/scripts/orbitcontrols.js index 95616eb..afc704e 100644 --- a/static/scripts/orbitcontrols.js +++ b/static/scripts/orbitcontrols.js @@ -149,6 +149,7 @@ THREE.OrbitControls = function ( object, domElement ) { this.object.position.add( distance ); this.center.add( distance ); + this.target.add( distance ); };