mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Working on ui
This commit is contained in:
parent
9d07bf1585
commit
dc7d20ff86
5 changed files with 136 additions and 8 deletions
|
@ -7,8 +7,6 @@ BallController = function(side, magBalls) {
|
|||
this.highlighter = new Highlighter();
|
||||
this.highlighter.setSize(BALL_SIZE);
|
||||
this.ghostEdges = {};
|
||||
this.lastUpdate = 0;
|
||||
this.updateInterval = 0.05;
|
||||
}
|
||||
|
||||
BallController.prototype = Object.create( HandController.prototype );
|
||||
|
@ -72,3 +70,34 @@ BallController.prototype.onCleanup = function() {
|
|||
HandController.prototype.onCleanup.call(this);
|
||||
this.clearGhostEdges();
|
||||
}
|
||||
|
||||
BallController.prototype.onAltClick = function() {
|
||||
return;
|
||||
var target = this.magBalls.findNearestNode(this.tipPosition, BALL_SELECTION_RADIUS);
|
||||
if (!target) {
|
||||
logDebug(target);
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME move to delete shape
|
||||
var toDelete = {};
|
||||
var deleteQueue = [ target ];
|
||||
while (deleteQueue.length) {
|
||||
var curNode = deleteQueue.shift();
|
||||
if (toDelete[curNode]) {
|
||||
continue;
|
||||
}
|
||||
toDelete[curNode] = true;
|
||||
for (var nodeId in this.magBalls.getConnectedNodes(curNode)) {
|
||||
deleteQueue.push(nodeId);
|
||||
}
|
||||
}
|
||||
for (var nodeId in toDelete) {
|
||||
this.magBalls.destroyNode(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BallController.prototype.onAltRelease = function() {
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ HandController = function(side) {
|
|||
this.palm = 2 * side;
|
||||
this.tip = 2 * side + 1;
|
||||
this.action = findAction(side ? "ACTION2" : "ACTION1");
|
||||
this.altAction = findAction(side ? "ACTION1" : "ACTION2");
|
||||
this.active = false;
|
||||
this.tipScale = 1.4;
|
||||
this.pointer = Overlays.addOverlay("sphere", {
|
||||
|
@ -41,6 +42,10 @@ HandController = function(side) {
|
|||
}
|
||||
|
||||
HandController.prototype.onActionEvent = function(action, state) {
|
||||
var spatialControlCount = Controller.getNumberOfSpatialControls();
|
||||
// If only 2 spacial controls, then we only have one controller active, so use either button
|
||||
// otherwise, only use the specified action
|
||||
|
||||
if (action == this.action) {
|
||||
if (state) {
|
||||
this.onClick();
|
||||
|
@ -48,6 +53,14 @@ HandController.prototype.onActionEvent = function(action, state) {
|
|||
this.onRelease();
|
||||
}
|
||||
}
|
||||
|
||||
if (action == this.altAction) {
|
||||
if (state) {
|
||||
this.onAltClick();
|
||||
} else {
|
||||
this.onAltRelease();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HandController.prototype.setActive = function(active) {
|
||||
|
@ -65,11 +78,18 @@ HandController.prototype.setActive = function(active) {
|
|||
}
|
||||
|
||||
HandController.prototype.updateControllerState = function() {
|
||||
// FIXME this returns data if either the left or right controller is not on the base
|
||||
this.palmPos = Controller.getSpatialControlPosition(this.palm);
|
||||
var tipPos = Controller.getSpatialControlPosition(this.tip);
|
||||
this.tipPosition = scaleLine(this.palmPos, tipPos, this.tipScale);
|
||||
// When on the base hydras report a position of 0
|
||||
// When on the base, hydras report a position of 0
|
||||
this.setActive(Vec3.length(this.palmPos) > 0.001);
|
||||
|
||||
//logDebug(Controller.getTriggerValue(0) + " " + Controller.getTriggerValue(1));
|
||||
|
||||
//if (this.active) {
|
||||
// logDebug("#ctrls " + Controller.getNumberOfSpatialControls() + " Side: " + this.side + " Palm: " + this.palm + " " + vec3toStr(this.palmPos))
|
||||
//}
|
||||
}
|
||||
|
||||
HandController.prototype.onCleanup = function() {
|
||||
|
@ -95,3 +115,13 @@ HandController.prototype.onClick = function() {
|
|||
HandController.prototype.onRelease = function() {
|
||||
logDebug("Base hand controller does nothing on release");
|
||||
}
|
||||
|
||||
HandController.prototype.onAltClick = function() {
|
||||
logDebug("Base hand controller does nothing on alt click");
|
||||
}
|
||||
|
||||
HandController.prototype.onAltRelease = function() {
|
||||
logDebug("Base hand controller does nothing on alt click");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@ Script.include("edgeSpring.js");
|
|||
MagBalls = function() {
|
||||
Graph.call(this);
|
||||
|
||||
this.MAX_ADJUST_ITERATIONS = 100;
|
||||
this.lastUpdateAge = 0;
|
||||
this.stable = false;
|
||||
this.adjustIterations = 0;
|
||||
this.selectedNodes = {};
|
||||
this.edgeObjects = {};
|
||||
|
||||
|
@ -39,6 +41,7 @@ MagBalls.prototype.onUpdate = function(deltaTime) {
|
|||
if (this.lastUpdateAge > UPDATE_INTERVAL) {
|
||||
this.lastUpdateAge = 0;
|
||||
if (!this.stable) {
|
||||
this.adjustIterations += 1;
|
||||
// logDebug("Update");
|
||||
var adjusted = false;
|
||||
var nodeAdjustResults = {};
|
||||
|
@ -68,9 +71,10 @@ MagBalls.prototype.onUpdate = function(deltaTime) {
|
|||
}
|
||||
}, ((UPDATE_INTERVAL * 1000) / 2));
|
||||
|
||||
if (!adjusted) {
|
||||
if (!adjusted || this.adjustIterations > this.MAX_ADJUST_ITERATIONS) {
|
||||
this.adjustIterations = 0;
|
||||
this.stable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +133,7 @@ MagBalls.prototype.grabBall = function(position, maxDist) {
|
|||
selected = this.createNode({ position: position });
|
||||
}
|
||||
if (selected) {
|
||||
this.stable = true;
|
||||
this.breakEdges(selected);
|
||||
this.selectedNodes[selected] = true;
|
||||
}
|
||||
|
@ -159,12 +164,11 @@ MagBalls.prototype.releaseBall = function(releasedBall) {
|
|||
|
||||
var targets = this.findPotentialEdges(releasedBall);
|
||||
if (!targets || !Object.keys(targets).length) {
|
||||
this.destroyNode(releasedBall);
|
||||
// this.destroyNode(releasedBall);
|
||||
}
|
||||
for (var otherBallId in targets) {
|
||||
this.createEdge(otherBallId, releasedBall);
|
||||
}
|
||||
// this.clean();
|
||||
this.validate();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,5 @@ MenuController = function(side) {
|
|||
HandController.call(this, side);
|
||||
}
|
||||
|
||||
|
||||
// FIXME resolve some of the issues with dual controllers before allowing both controllers active
|
||||
var handControllers = [new BallController(LEFT_CONTROLLER, magBalls)]; //, new HandController(RIGHT) ];
|
||||
|
|
66
examples/toys/magBalls/menuController.js
Normal file
66
examples/toys/magBalls/menuController.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
Script.include("handController.js");
|
||||
|
||||
MenuController = function(side, magBalls) {
|
||||
HandController.call(this, side);
|
||||
}
|
||||
|
||||
MenuController.prototype = Object.create( HandController.prototype );
|
||||
|
||||
MenuController.prototype.onUpdate = function(deltaTime) {
|
||||
HandController.prototype.onUpdate.call(this, deltaTime);
|
||||
if (!this.selected) {
|
||||
// Find the highlight target and set it.
|
||||
var target = this.magBalls.findNearestNode(this.tipPosition, BALL_SELECTION_RADIUS);
|
||||
this.highlighter.highlight(target);
|
||||
return;
|
||||
}
|
||||
this.highlighter.highlight(null);
|
||||
Entities.editEntity(this.selected, { position: this.tipPosition });
|
||||
var targetBalls = this.magBalls.findPotentialEdges(this.selected);
|
||||
for (var ballId in targetBalls) {
|
||||
if (!this.ghostEdges[ballId]) {
|
||||
// create the ovleray
|
||||
this.ghostEdges[ballId] = Overlays.addOverlay("line3d", {
|
||||
start: this.magBalls.getNodePosition(ballId),
|
||||
end: this.tipPosition,
|
||||
color: COLORS.RED,
|
||||
alpha: 1,
|
||||
lineWidth: 5,
|
||||
visible: true,
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(this.ghostEdges[ballId], {
|
||||
end: this.tipPosition,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (var ballId in this.ghostEdges) {
|
||||
if (!targetBalls[ballId]) {
|
||||
Overlays.deleteOverlay(this.ghostEdges[ballId]);
|
||||
delete this.ghostEdges[ballId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MenuController.prototype.onClick = function() {
|
||||
this.selected = this.magBalls.grabBall(this.tipPosition, BALL_SELECTION_RADIUS);
|
||||
this.highlighter.highlight(null);
|
||||
}
|
||||
|
||||
MenuController.prototype.onRelease = function() {
|
||||
this.clearGhostEdges();
|
||||
this.magBalls.releaseBall(this.selected);
|
||||
this.selected = null;
|
||||
}
|
||||
|
||||
MenuController.prototype.clearGhostEdges = function() {
|
||||
for(var ballId in this.ghostEdges) {
|
||||
Overlays.deleteOverlay(this.ghostEdges[ballId]);
|
||||
delete this.ghostEdges[ballId];
|
||||
}
|
||||
}
|
||||
|
||||
MenuController.prototype.onCleanup = function() {
|
||||
HandController.prototype.onCleanup.call(this);
|
||||
this.clearGhostEdges();
|
||||
}
|
Loading…
Reference in a new issue