mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 01:13:32 +02:00
Fixing omnitool
This commit is contained in:
parent
e8be92cab8
commit
be148686a7
2 changed files with 29 additions and 33 deletions
|
@ -15,16 +15,18 @@ Script.include("omniTool/models/invisibleWand.js");
|
|||
|
||||
OmniToolModules = {};
|
||||
OmniToolModuleType = null;
|
||||
LOG_DEBUG = 1;
|
||||
|
||||
OmniTool = function(side) {
|
||||
OmniTool = function(left) {
|
||||
this.OMNI_KEY = "OmniTool";
|
||||
this.MAX_FRAMERATE = 60;
|
||||
this.UPDATE_INTERVAL = 1.0 / this.MAX_FRAMERATE
|
||||
this.SIDE = side;
|
||||
this.PALM = 2 * side;
|
||||
this.ACTION = findAction(side ? "ACTION2" : "ACTION1");
|
||||
this.ALT_ACTION = findAction(side ? "ACTION1" : "ACTION2");
|
||||
|
||||
this.left = left;
|
||||
var actions = Controller.Actions;
|
||||
var standard = Controller.Standard;
|
||||
this.palmControl = left ? actions.LeftHand : actions.RightHand;
|
||||
this.action = left ? standard.LeftPrimaryThumb : standard.RightPrimaryThumb;
|
||||
logDebug("Init OmniTool " + (left ? "left" : "right"));
|
||||
this.highlighter = new Highlighter();
|
||||
this.ignoreEntities = {};
|
||||
this.nearestOmniEntity = {
|
||||
|
@ -47,21 +49,21 @@ OmniTool = function(side) {
|
|||
this.showWand(false);
|
||||
|
||||
// Connect to desired events
|
||||
var _this = this;
|
||||
Controller.actionEvent.connect(function(action, state) {
|
||||
_this.onActionEvent(action, state);
|
||||
var that = this;
|
||||
Controller.inputEvent.connect(function(action, state) {
|
||||
that.onInputEvent(action, state);
|
||||
});
|
||||
|
||||
Script.update.connect(function(deltaTime) {
|
||||
_this.lastUpdateInterval += deltaTime;
|
||||
if (_this.lastUpdateInterval >= _this.UPDATE_INTERVAL) {
|
||||
_this.onUpdate(_this.lastUpdateInterval);
|
||||
_this.lastUpdateInterval = 0;
|
||||
that.lastUpdateInterval += deltaTime;
|
||||
if (that.lastUpdateInterval >= that.UPDATE_INTERVAL) {
|
||||
that.onUpdate(that.lastUpdateInterval);
|
||||
that.lastUpdateInterval = 0;
|
||||
}
|
||||
});
|
||||
|
||||
Script.scriptEnding.connect(function() {
|
||||
_this.onCleanup();
|
||||
that.onCleanup();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -86,15 +88,14 @@ OmniTool.prototype.onCleanup = function(action) {
|
|||
this.unloadModule();
|
||||
}
|
||||
|
||||
OmniTool.prototype.onActionEvent = function(action, state) {
|
||||
// FIXME figure out the issues when only one spatial controller is active
|
||||
// logDebug("Action: " + action + " " + state);
|
||||
|
||||
if (this.module && this.module.onActionEvent) {
|
||||
this.module.onActionEvent(action, state);
|
||||
OmniTool.prototype.onInputEvent = function(action, state) {
|
||||
// FIXME figure out the issues when only one spatial controller is active
|
||||
var actionNames = Controller.getActionNames();
|
||||
if (this.module && this.module.onInputEvent) {
|
||||
this.module.onInputEvent(action, state);
|
||||
}
|
||||
|
||||
if (action == this.ACTION) {
|
||||
if (action == this.action) {
|
||||
if (state) {
|
||||
this.onClick();
|
||||
} else {
|
||||
|
@ -127,7 +128,7 @@ OmniTool.prototype.setActive = function(active) {
|
|||
if (active === this.active) {
|
||||
return;
|
||||
}
|
||||
logDebug("OmniTool changing active state: " + active);
|
||||
logDebug("OmniTool " + this.left + " changing active state: " + active);
|
||||
this.active = active;
|
||||
this.model.setVisible(this.active);
|
||||
if (this.module && this.module.onActiveChanged) {
|
||||
|
@ -138,17 +139,17 @@ OmniTool.prototype.setActive = function(active) {
|
|||
|
||||
OmniTool.prototype.onUpdate = function(deltaTime) {
|
||||
// FIXME this returns data if either the left or right controller is not on the base
|
||||
this.position = Controller.getSpatialControlPosition(this.PALM);
|
||||
this.pose = Controller.getPoseValue(this.palmControl);
|
||||
this.position = this.left ? MyAvatar.leftHandTipPosition : MyAvatar.rightHandTipPosition;
|
||||
// When on the base, hydras report a position of 0
|
||||
this.setActive(Vec3.length(this.position) > 0.001);
|
||||
if (!this.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (this.model) {
|
||||
// Update the wand
|
||||
var rawRotation = Controller.getSpatialControlRawRotation(this.PALM);
|
||||
var rawRotation = this.pose.rotation;
|
||||
this.rotation = Quat.multiply(MyAvatar.orientation, rawRotation);
|
||||
this.model.setTransform({
|
||||
rotation: this.rotation,
|
||||
|
@ -306,6 +307,7 @@ OmniTool.prototype.scan = function() {
|
|||
}
|
||||
|
||||
OmniTool.prototype.unloadModule = function() {
|
||||
logDebug("Unloading omniTool module")
|
||||
if (this.module && this.module.onUnload) {
|
||||
this.module.onUnload();
|
||||
}
|
||||
|
@ -348,4 +350,4 @@ OmniTool.prototype.activateNewOmniModule = function() {
|
|||
}
|
||||
|
||||
// FIXME find a good way to sync the two omni tools
|
||||
OMNI_TOOLS = [ new OmniTool(0), new OmniTool(1) ];
|
||||
OMNI_TOOLS = [ new OmniTool(true), new OmniTool(false) ];
|
||||
|
|
|
@ -31,13 +31,7 @@ scaleLine = function (start, end, scale) {
|
|||
}
|
||||
|
||||
findAction = function(name) {
|
||||
var actions = Controller.getAllActions();
|
||||
for (var i = 0; i < actions.length; i++) {
|
||||
if (actions[i].actionName == name) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return Controller.findAction(name);
|
||||
}
|
||||
|
||||
addLine = function(origin, vector, color) {
|
||||
|
|
Loading…
Reference in a new issue