mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
hand controller pointer
This commit is contained in:
parent
53efe6bfb2
commit
e965b7fff1
4 changed files with 155 additions and 26 deletions
|
@ -420,16 +420,9 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
}
|
||||
};
|
||||
|
||||
this.isPointingAtUI = function(controllerData) {
|
||||
var hudRayPickInfo = controllerData.hudRayPicks[this.hand];
|
||||
var result = isPointingAtUI(hudRayPickInfo);
|
||||
print(result);
|
||||
return result;
|
||||
};
|
||||
|
||||
this.run = function (controllerData) {
|
||||
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE ||
|
||||
this.notPointingAtEntity(controllerData) || this.isPointingAtUI(controllerData)) {
|
||||
this.notPointingAtEntity(controllerData)) {
|
||||
this.endNearGrabAction();
|
||||
this.laserPointerOff();
|
||||
return makeRunningValues(false, [], []);
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
this.reticleMaxY;
|
||||
this.clicked = false;
|
||||
this.triggerClicked = 0;
|
||||
this.movedAway = false;
|
||||
this.parameters = ControllerDispatcherUtils.makeDispatcherModuleParameters(
|
||||
540,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
|
@ -113,8 +114,8 @@
|
|||
return (this.hand === RIGHT_HAND) ? Controller.Standard.LeftHand : Controller.Standard.RightHand;
|
||||
};
|
||||
|
||||
this.clicked = function() {
|
||||
return this.clicked;
|
||||
_this.isClicked = function() {
|
||||
return _this.triggerClicked;
|
||||
};
|
||||
|
||||
this.getOtherModule = function() {
|
||||
|
@ -131,8 +132,9 @@
|
|||
this.reticleMaxY = dims.y - MARGIN;
|
||||
};
|
||||
|
||||
this.hasNotSentClick = function() {
|
||||
_this.hasNotSentClick = function() {
|
||||
if (!_this.clicked) {
|
||||
print("sending clicked");
|
||||
_this.clicked = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -178,34 +180,44 @@
|
|||
Reticle.setPosition(point2d);
|
||||
};
|
||||
|
||||
this.pointingAtTablet = function(controllerData) {
|
||||
var rayPick = controllerData.rayPicks[this.hand];
|
||||
return (rayPick.objectID === HMD.tabletScreenID || rayPick.objectID === HMD.homeButtonID);
|
||||
};
|
||||
|
||||
this.moveMouseAwayFromTablet = function() {
|
||||
if (!this.movedAway) {
|
||||
var point = {x: 25, y: 25};
|
||||
// this.setReticlePosition(point);
|
||||
this.movedAway = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.processLaser = function(controllerData) {
|
||||
var controllerLocation = controllerData.controllerLocations[this.hand];
|
||||
if (controllerData.triggerValues[this.hand] < ControllerDispatcherUtils.TRIGGER_OFF_VALUE || !controllerLocation.valid) {
|
||||
if ((controllerData.triggerValues[this.hand] < ControllerDispatcherUtils.TRIGGER_ON_VALUE || !controllerLocation.valid) ||
|
||||
this.pointingAtTablet(controllerData)) {
|
||||
this.exitModule();
|
||||
return false;
|
||||
}
|
||||
|
||||
var hudRayPick = controllerData.hudRayPicks[this.hand];
|
||||
var controllerLocation = controllerData.controllerLocations[this.hand];
|
||||
var point2d = this.calculateNewReticlePosition(hudRayPick.intersection);
|
||||
this.setReticlePosition(point2d);
|
||||
print(Reticle.isPointOnSystemOverlay(point2d));
|
||||
if (!Reticle.isPointOnSystemOverlay(point2d)) {
|
||||
if (!Reticle.isPointingAtSystemOverlay(point2d)) {
|
||||
this.exitModule();
|
||||
print("----> exiting <------");
|
||||
return false;
|
||||
}
|
||||
|
||||
//this.setReticlePosition(point2d);
|
||||
|
||||
this.clicked = controllerData.triggerClicked[this.hand];
|
||||
|
||||
Reticle.visible = false;
|
||||
this.movedAway = false;
|
||||
this.triggerClicked = controllerData.triggerClicks[this.hand];
|
||||
this.processControllerTriggers(controllerData);
|
||||
this.updateLaserPointer(controllerData);
|
||||
return true;
|
||||
};
|
||||
|
||||
this.exitModule = function() {
|
||||
this.moveMouseAwayFromTablet();
|
||||
LaserPointers.disableLaserPointer(this.laserPointer);
|
||||
};
|
||||
|
||||
|
@ -240,12 +252,12 @@
|
|||
}
|
||||
|
||||
|
||||
var leftHudOverlayPointer = new HudOverlayPointer(LEFT_HAND);
|
||||
var leftHudOverlayPointer = new HudOverlayPointer(LEFT_HAND);
|
||||
var rightHudOverlayPointer = new HudOverlayPointer(RIGHT_HAND);
|
||||
|
||||
var clickMapping = Controller.newMapping('HudOverlayPointer-click');
|
||||
clickMapping.from(rightHudOverlayPointer.clicked()).when(rightHudOverlayPointer.hasNotSentClick()).to(Controller.Actions.ReticleClick);
|
||||
clickMapping.from(leftHudOverlayPointer.clicked()).when(leftHudOverlayPointer.hasNotSentClick()).to(Controller.Actions.ReticleClick);
|
||||
clickMapping.from(rightHudOverlayPointer.isClicked).to(Controller.Actions.ReticleClick);
|
||||
clickMapping.from(leftHudOverlayPointer.isClicked).to(Controller.Actions.ReticleClick);
|
||||
clickMapping.enable();
|
||||
|
||||
enableDispatcherModule("LeftHudOverlayPointer", leftHudOverlayPointer);
|
||||
|
|
123
scripts/system/controllers/controllerModules/mouseHMD.js
Normal file
123
scripts/system/controllers/controllerModules/mouseHMD.js
Normal file
|
@ -0,0 +1,123 @@
|
|||
//
|
||||
// mouseHMD.js
|
||||
//
|
||||
// scripts/system/controllers/controllerModules/
|
||||
//
|
||||
// Created by Dante Ruiz 2017-9-22
|
||||
// Copyright 2017 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
(function() {
|
||||
var ControllerDispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
|
||||
var WEIGHTING = 1 / 20; // simple moving average over last 20 samples
|
||||
var ONE_MINUS_WEIGHTING = 1 - WEIGHTING;
|
||||
var AVERAGE_MOUSE_VELOCITY_FOR_SEEK_TO = 20;
|
||||
function TimeLock(experation) {
|
||||
this.experation = experation;
|
||||
this.last = 0;
|
||||
this.update = function(time) {
|
||||
this.last = time || Date.now();
|
||||
};
|
||||
|
||||
this.expired = function(time) {
|
||||
return ((time || Date.now()) - this.last) > this.experation;
|
||||
};
|
||||
}
|
||||
|
||||
function MouseHMD() {
|
||||
var _this = this;
|
||||
this.mouseMoved = false;
|
||||
this.mouseActivity = new TimeLock(5000);
|
||||
this.handControllerActivity = new TimeLock(4000);
|
||||
this.parameters = ControllerDispatcherUtils.makeDispatcherModuleParameters(
|
||||
10,
|
||||
["mouse"],
|
||||
[],
|
||||
100);
|
||||
|
||||
this.onMouseMove = function() {
|
||||
_this.updateMouseActivity();
|
||||
};
|
||||
|
||||
this.onMouseClick = function() {
|
||||
_this.updateMouseActivity();
|
||||
};
|
||||
|
||||
this.updateMouseActivity = function(isClick) {
|
||||
if (_this.ignoreMouseActivity()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (HMD.active) {
|
||||
var now = Date.now();
|
||||
_this.mouseActivity.update(now);
|
||||
}
|
||||
};
|
||||
|
||||
this.ignoreMouseActivity = function() {
|
||||
if (!Reticle.allowMouseCapture) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var pos = Reticle.position;
|
||||
if (!pos || (pos.x == -1 && pos.y == -1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!_this.handControllerActivity.expired()) {
|
||||
print("has not expired");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
this.triggersPressed = function(controllerData, now) {
|
||||
var onValue = ControllerDispatcherUtils.TRIGGER_ON_VALUE;
|
||||
var rightHand = ControllerDispatcherUtils.RIGHT_HAND;
|
||||
var leftHand = ControllerDispatcherUtils.LEFT_HAND;
|
||||
var leftTriggerValue = controllerData.triggerValues[leftHand];
|
||||
var rightTriggerValue = controllerData.triggerValues[rightHand];
|
||||
|
||||
if (leftTriggerValue > onValue || rightTriggerValue > onValue) {
|
||||
this.handControllerActivity.update(now);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
this.isReady = function(controllerData, deltaTime) {
|
||||
var now = Date.now();
|
||||
this.triggersPressed(controllerData, now);
|
||||
if ((HMD.active && !this.mouseActivity.expired(now)) && _this.handControllerActivity.expired()) {
|
||||
Reticle.visible = true;
|
||||
return ControllerDispatcherUtils.makeRunningValues(true, [], []);
|
||||
}
|
||||
if (HMD.active) {
|
||||
Reticle.visble = false;
|
||||
}
|
||||
|
||||
return ControllerDispatcherUtils.makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.run = function(controllerData, deltaTime) {
|
||||
var now = Date.now();
|
||||
if (this.mouseActivity.expired(now) || this.triggersPressed(controllerData, now)) {
|
||||
Reticle.visible = false;
|
||||
return ControllerDispatcherUtils.makeRunningValues(false, [], []);
|
||||
}
|
||||
return ControllerDispatcherUtils.makeRunningValues(true, [], []);
|
||||
};
|
||||
}
|
||||
|
||||
var mouseHMD = new MouseHMD();
|
||||
enableDispatcherModule("MouseHMD", mouseHMD);
|
||||
|
||||
Controller.mouseMoveEvent.connect(mouseHMD.onMouseMove);
|
||||
Controller.mousePressEvent.connect(mouseHMD.onMouseClick);
|
||||
})();
|
|
@ -19,7 +19,7 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/nearParentGrabEntity.js",
|
||||
"controllerModules/nearParentGrabOverlay.js",
|
||||
"controllerModules/nearActionGrabEntity.js",
|
||||
//"controllerModules/farActionGrabEntity.js",
|
||||
"controllerModules/farActionGrabEntity.js",
|
||||
"controllerModules/tabletStylusInput.js",
|
||||
"controllerModules/equipEntity.js",
|
||||
"controllerModules/nearTrigger.js",
|
||||
|
@ -30,7 +30,8 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/farTrigger.js",
|
||||
"controllerModules/teleport.js",
|
||||
"controllerModules/scaleAvatar.js",
|
||||
"controllerModules/hudOverlayPointer.js"
|
||||
"controllerModules/hudOverlayPointer.js",
|
||||
"controllerModules/mouseHMD.js"
|
||||
];
|
||||
|
||||
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";
|
||||
|
|
Loading…
Reference in a new issue