mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 17:10:45 +02:00
Change far grab to chorded input 'superpower'
This commit is contained in:
parent
bdafb99402
commit
f52b096bb9
1 changed files with 90 additions and 25 deletions
|
@ -32,7 +32,8 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
if (parentPropsLength !== 0) {
|
||||
var targetEntity = {
|
||||
id: this.parentProps[parentPropsLength - 1].id,
|
||||
props: this.parentProps[parentPropsLength - 1]};
|
||||
props: this.parentProps[parentPropsLength - 1]
|
||||
};
|
||||
this.targetEntityID = targetEntity.id;
|
||||
this.targetEntityProps = targetEntity.props;
|
||||
return targetEntity;
|
||||
|
@ -41,11 +42,13 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.targetEntityProps = this.entityProps;
|
||||
return {
|
||||
id: this.entityID,
|
||||
props: this.entityProps};
|
||||
props: this.entityProps
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function FarGrabEntity(hand) {
|
||||
var _this = this;
|
||||
this.hand = hand;
|
||||
this.grabbing = false;
|
||||
this.targetEntityID = null;
|
||||
|
@ -318,15 +321,70 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
return null;
|
||||
};
|
||||
|
||||
var mappingName = "FarGrab-Mapping-" + Math.random();
|
||||
var grabMapping;
|
||||
|
||||
this.setup = function () {
|
||||
grabMapping = Controller.newMapping(mappingName);
|
||||
grabMapping.from(Controller.Standard.LT).peek().to(_this.getLeftTrigger);
|
||||
grabMapping.from(Controller.Standard.RT).peek().to(_this.getRightTrigger);
|
||||
Controller.enableMapping(mappingName);
|
||||
};
|
||||
|
||||
this.cleanup = function () {
|
||||
grabMapping.disable();
|
||||
};
|
||||
|
||||
this.leftTrigger = 0.0;
|
||||
this.rightTrigger = 0.0;
|
||||
|
||||
this.getDominantHand = function () {
|
||||
return (MyAvatar.getDominantHand() === "left") ? LEFT_HAND : RIGHT_HAND;
|
||||
};
|
||||
|
||||
this.getOffHand = function () {
|
||||
return (MyAvatar.getDominantHand() === "left") ? RIGHT_HAND : LEFT_HAND;
|
||||
};
|
||||
|
||||
this.getLeftTrigger = function (value) {
|
||||
_this.leftTrigger = value;
|
||||
};
|
||||
|
||||
this.getRightTrigger = function (value) {
|
||||
_this.rightTrigger = value;
|
||||
};
|
||||
|
||||
this.getDominantTrigger = function () {
|
||||
return (MyAvatar.getDominantHand() === "left") ? (_this.leftTrigger) : (_this.rightTrigger);
|
||||
};
|
||||
|
||||
this.getOffHandTrigger = function () {
|
||||
return (MyAvatar.getDominantHand() === "left") ? (_this.rightTrigger) : (_this.leftTrigger);
|
||||
};
|
||||
|
||||
this.shouldShowLaser = function () {
|
||||
return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false;
|
||||
};
|
||||
|
||||
this.shouldGrab = function () {
|
||||
return (_this.getDominantTrigger() > TRIGGER_ON_VALUE && _this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false;
|
||||
};
|
||||
|
||||
this.shouldCancel = function () {
|
||||
// Kill condition : Off hand is <= 15% trigger pull.
|
||||
return (_this.getOffHandTrigger() <= TRIGGER_OFF_VALUE) ? true : false;
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
if (HMD.active) {
|
||||
if (HMD.active && this.hand === this.getOffHand()) {
|
||||
if (this.notPointingAtEntity(controllerData)) {
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
|
||||
this.distanceHolding = false;
|
||||
|
||||
if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
|
||||
//if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
|
||||
if (this.shouldShowLaser()) {
|
||||
return makeRunningValues(true, [], []);
|
||||
} else {
|
||||
this.destroyContextOverlay();
|
||||
|
@ -336,7 +394,9 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
};
|
||||
|
||||
this.run = function (controllerData) {
|
||||
if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) {
|
||||
//if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) {
|
||||
if (this.shouldCancel() || this.targetIsNull()) {
|
||||
print("Canceling...");
|
||||
this.endFarGrabEntity(controllerData);
|
||||
return makeRunningValues(false, [], []);
|
||||
}
|
||||
|
@ -383,7 +443,8 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
|
||||
var rayPickInfo = controllerData.rayPicks[this.hand];
|
||||
if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) {
|
||||
if (controllerData.triggerClicks[this.hand]) {
|
||||
if (this.shouldGrab()) {
|
||||
print("Grabbing...");
|
||||
var entityID = rayPickInfo.objectID;
|
||||
var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES);
|
||||
if (targetProps.href !== "") {
|
||||
|
@ -485,11 +546,15 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
|
||||
var leftFarGrabEntity = new FarGrabEntity(LEFT_HAND);
|
||||
var rightFarGrabEntity = new FarGrabEntity(RIGHT_HAND);
|
||||
leftFarGrabEntity.setup();
|
||||
rightFarGrabEntity.setup();
|
||||
|
||||
enableDispatcherModule("LeftFarGrabEntity", leftFarGrabEntity);
|
||||
enableDispatcherModule("RightFarGrabEntity", rightFarGrabEntity);
|
||||
|
||||
function cleanup() {
|
||||
leftFarGrabEntity.cleanup();
|
||||
rightFarGrabEntity.cleanup();
|
||||
disableDispatcherModule("LeftFarGrabEntity");
|
||||
disableDispatcherModule("RightFarGrabEntity");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue