Browse Source

Better selection

master
Pete Shadbolt 8 years ago
parent
commit
b8dec55fab
1 changed files with 15 additions and 6 deletions
  1. +15
    -6
      static/scripts/editor.js

+ 15
- 6
static/scripts/editor.js View File

@@ -29,7 +29,7 @@ editor.focus = function(node) {
gui.controls.target.copy(abj.node[node].position); gui.controls.target.copy(abj.node[node].position);
gui.hideNodeMessage(); gui.hideNodeMessage();
editor.selection = node; editor.selection = node;
gui.serverMessage("Selected node " + node + "");
gui.serverMessage("Selected node " + node + ".");
}; };


editor.addQubitAtPoint = function(point) { editor.addQubitAtPoint = function(point) {
@@ -37,13 +37,22 @@ editor.addQubitAtPoint = function(point) {
return; return;
} }
point.round(); point.round();
abj.add_node(abj.order(), {
position: point
});

// Check for clashes
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;
}
}

abj.add_node(abj.order(), { position: point });
editor.grid.position.copy(point); editor.grid.position.copy(point);
gui.controls.target.copy(point); gui.controls.target.copy(point);
graph.update(); graph.update();
gui.serverMessage("Created node at " + JSON.stringify(point));
gui.serverMessage("Created node.");
}; };


editor.onClick = function() { editor.onClick = function() {
@@ -92,7 +101,7 @@ editor.update = function() {};
// Gets a reference to the node nearest to the mouse cursor // Gets a reference to the node nearest to the mouse cursor
editor.findNodeOnRay = function(ray) { editor.findNodeOnRay = function(ray) {
for (var n in abj.node) { for (var n in abj.node) {
if (ray.distanceSqToPoint(abj.node[n].position) < 0.03) {
if (ray.distanceSqToPoint(abj.node[n].position) < 0.3) {
return n; return n;
} }
} }


Loading…
Cancel
Save