mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 09:44:21 +02:00
fixed teleport, added avatar scaling, allow laser to be used on tablet when stylus is shown
This commit is contained in:
parent
826cb9e909
commit
a46e41607c
7 changed files with 145 additions and 6 deletions
|
@ -439,6 +439,7 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
|
||||
// gather up the readiness of the near-grab modules
|
||||
var nearGrabNames = [
|
||||
this.hand === RIGHT_HAND ? "RightScaleAvatar" : "LeftScaleAvatar",
|
||||
this.hand === RIGHT_HAND ? "RightFarTriggerEntity" : "LeftFarTriggerEntity",
|
||||
this.hand === RIGHT_HAND ? "RightNearActionGrabEntity" : "LeftNearActionGrabEntity",
|
||||
this.hand === RIGHT_HAND ? "RightNearParentingGrabEntity" : "LeftNearParentingGrabEntity",
|
||||
|
|
|
@ -209,6 +209,15 @@ Script.include("/~/system/libraries/utils.js");
|
|||
return this.exitModule();
|
||||
}
|
||||
}
|
||||
|
||||
var teleport = getEnabledModuleByName(this.hand === RIGHT_HAND ? "RightTeleporter" : "LeftTeleporter");
|
||||
if (teleport) {
|
||||
var teleportReady = teleport.isReady(controllerData);
|
||||
if (teleportReady.active) {
|
||||
return this.exitModule();
|
||||
}
|
||||
}
|
||||
|
||||
this.processControllerTriggers(controllerData);
|
||||
this.updateLaserPointer(controllerData);
|
||||
this.sendPickData(controllerData);
|
||||
|
@ -251,4 +260,6 @@ Script.include("/~/system/libraries/utils.js");
|
|||
disableDispatcherModule("LeftHandInEditMode");
|
||||
disableDispatcherModule("RightHandInEditMode");
|
||||
};
|
||||
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
}());
|
||||
|
|
84
scripts/system/controllers/controllerModules/scaleAvatar.js
Normal file
84
scripts/system/controllers/controllerModules/scaleAvatar.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
// handControllerGrab.js
|
||||
//
|
||||
// Created by Dante Ruiz on 9/11/17
|
||||
//
|
||||
// Grabs physically moveable entities with hydra-like controllers; it works for either near or far objects.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
/* global getEntityCustomData, flatten, Xform, Script, Quat, Vec3, MyAvatar, Entities, Overlays, Settings,
|
||||
Reticle, Controller, Camera, Messages, Mat4, getControllerWorldLocation, getGrabPointSphereOffset,
|
||||
setGrabCommunications, Menu, HMD, isInEditMode, AvatarList */
|
||||
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||
|
||||
//Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
(function () {
|
||||
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
|
||||
function ScaleAvatar(hand) {
|
||||
this.hand = hand;
|
||||
this.scalingStartAvatarScale = 0;
|
||||
this.scalingStartDistance = 0;
|
||||
|
||||
this.parameters = dispatcherUtils.makeDispatcherModuleParameters(
|
||||
120,
|
||||
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
||||
[],
|
||||
100
|
||||
);
|
||||
|
||||
this.otherHand = function() {
|
||||
return this.hand === dispatcherUtils.RIGHT_HAND ? dispatcherUtils.LEFT_HAND : dispatcherUtils.RIGHT_HAND;
|
||||
};
|
||||
|
||||
this.getOtherModule = function() {
|
||||
var otherModule = this.hand === dispatcherUtils.RIGHT_HAND ? leftScaleAvatar : rightScaleAvatar;
|
||||
return otherModule;
|
||||
};
|
||||
|
||||
this.triggersPressed = function(controllerData) {
|
||||
if (controllerData.triggerValues[this.hand] === 1 && controllerData.secondaryValues[this.hand] === 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.isReady = function(controllerData) {
|
||||
var otherModule = this.getOtherModule();
|
||||
if (this.triggersPressed(controllerData) && otherModule.triggersPressed(controllerData)) {
|
||||
this.scalingStartAvatarScale = MyAvatar.scale;
|
||||
this.scalingStartDistance = Vec3.length(Vec3.subtract(controllerData.controllerLocations[this.hand].position,
|
||||
controllerData.controllerLocations[this.otherHand()].position));
|
||||
return dispatcherUtils.makeRunningValues(true, [], []);
|
||||
}
|
||||
return dispatcherUtils.makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.run = function(controllerData) {
|
||||
var otherModule = this.getOtherModule();
|
||||
if (this.triggersPressed(controllerData) && otherModule.triggersPressed(controllerData)) {
|
||||
if (this.hand === dispatcherUtils.RIGHT_HAND) {
|
||||
var scalingCurrentDistance = Vec3.length(Vec3.subtract(controllerData.controllerLocations[this.hand].position,
|
||||
controllerData.controllerLocations[this.otherHand()].position));
|
||||
|
||||
var newAvatarScale = (scalingCurrentDistance / this.scalingStartDistance) * this.scalingStartAvatarScale;
|
||||
MyAvatar.scale = newAvatarScale;
|
||||
}
|
||||
return dispatcherUtils.makeRunningValues(true, [], []);
|
||||
}
|
||||
return dispatcherUtils.makeRunningValues(false, [], []);
|
||||
};
|
||||
}
|
||||
|
||||
var leftScaleAvatar = new ScaleAvatar(dispatcherUtils.LEFT_HAND);
|
||||
var rightScaleAvatar = new ScaleAvatar(dispatcherUtils.RIGHT_HAND);
|
||||
|
||||
dispatcherUtils.enableDispatcherModule("LeftScaleAvatar", leftScaleAvatar);
|
||||
dispatcherUtils.enableDispatcherModule("RightScaleAvatar", rightScaleAvatar);
|
||||
|
||||
this.cleanup = function() {
|
||||
dispatcherUtils.disableDispatcherModule("LeftScaleAvatar");
|
||||
dispatcherUtils.disableDispatcherModule("RightScaleAvatar");
|
||||
};
|
||||
})();
|
|
@ -20,7 +20,7 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
var HAPTIC_STYLUS_STRENGTH = 1.0;
|
||||
var HAPTIC_STYLUS_DURATION = 20.0;
|
||||
|
||||
var WEB_DISPLAY_STYLUS_DISTANCE = 0.1;
|
||||
var WEB_DISPLAY_STYLUS_DISTANCE = 0.5;
|
||||
var WEB_STYLUS_LENGTH = 0.2;
|
||||
var WEB_TOUCH_Y_OFFSET = 0.05; // how far forward (or back with a negative number) to slide stylus in hand
|
||||
|
||||
|
@ -474,7 +474,7 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
this.processStylus = function(controllerData) {
|
||||
this.updateStylusTip();
|
||||
|
||||
if (!this.stylusTip.valid) {
|
||||
if (!this.stylusTip.valid || this.overlayLaserActive(controllerData)) {
|
||||
this.pointFinger(false);
|
||||
this.hideStylus();
|
||||
return false;
|
||||
|
@ -646,6 +646,14 @@ Script.include("/~/system/libraries/controllers.js");
|
|||
}
|
||||
};
|
||||
|
||||
this.overlayLaserActive = function(controllerData) {
|
||||
var overlayLaserModule = getEnabledModuleByName(this.hand === RIGHT_HAND ? "RightOverlayLaserInput" : "LeftOverlayLaserInput");
|
||||
if (overlayLaserModule) {
|
||||
return overlayLaserModule.isReady(controllerData).active;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.isReady = function (controllerData) {
|
||||
if (this.processStylus(controllerData)) {
|
||||
return makeRunningValues(true, [], []);
|
||||
|
|
|
@ -170,6 +170,11 @@ function Teleporter(hand) {
|
|||
this.currentTarget = TARGET.INVALID;
|
||||
this.currentResult = null;
|
||||
|
||||
this.getOtherModule = function() {
|
||||
var otherModule = this.hand === RIGHT_HAND ? leftTeleporter : rightTeleporter;
|
||||
return otherModule;
|
||||
};
|
||||
|
||||
this.teleportRayHandVisible = LaserPointers.createLaserPointer({
|
||||
joint: (_this.hand === RIGHT_HAND) ? "RightHand" : "LeftHand",
|
||||
filter: RayPick.PICK_ENTITIES,
|
||||
|
@ -231,15 +236,32 @@ function Teleporter(hand) {
|
|||
[],
|
||||
100);
|
||||
|
||||
this.enterTeleport = function() {
|
||||
if (coolInTimeout !== null) {
|
||||
Script.clearTimeout(coolInTimeout);
|
||||
}
|
||||
|
||||
this.state = TELEPORTER_STATES.COOL_IN;
|
||||
coolInTimeout = Script.setTimeout(function() {
|
||||
if (_this.state === TELEPORTER_STATES.COOL_IN) {
|
||||
_this.state = TELEPORTER_STATES.TARGETTING;
|
||||
}
|
||||
}, COOL_IN_DURATION);
|
||||
};
|
||||
|
||||
|
||||
this.isReady = function(controllerData, deltaTime) {
|
||||
if (_this.buttonValue !== 0) {
|
||||
var otherModule = this.getOtherModule();
|
||||
if (_this.buttonValue !== 0 && !otherModule.active) {
|
||||
this.active = true;
|
||||
this.enterTeleport();
|
||||
return makeRunningValues(true, [], []);
|
||||
}
|
||||
return makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.run = function(controllerData, deltaTime) {
|
||||
_this.state = TELEPORTER_STATES.TARGETTING;
|
||||
//_this.state = TELEPORTER_STATES.TARGETTING;
|
||||
|
||||
// Get current hand pose information to see if the pose is valid
|
||||
var pose = Controller.getPoseValue(handInfo[(_this.hand === RIGHT_HAND) ? 'right' : 'left'].controllerInput);
|
||||
|
@ -306,7 +328,7 @@ function Teleporter(hand) {
|
|||
return makeRunningValues(true, [], []);
|
||||
}
|
||||
|
||||
if (target === TARGET.NONE || target === TARGET.INVALID) {
|
||||
if (target === TARGET.NONE || target === TARGET.INVALID || this.state === TELEPORTER_STATES.COOL_IN) {
|
||||
// Do nothing
|
||||
} else if (target === TARGET.SEAT) {
|
||||
Entities.callEntityMethod(result.objectID, 'sit');
|
||||
|
@ -319,6 +341,7 @@ function Teleporter(hand) {
|
|||
}
|
||||
|
||||
this.disableLasers();
|
||||
this.active = false;
|
||||
return makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
|
|
|
@ -28,7 +28,8 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/inEditMode.js",
|
||||
"controllerModules/disableOtherModule.js",
|
||||
"controllerModules/farTrigger.js",
|
||||
"controllerModules/teleport.js"
|
||||
"controllerModules/teleport.js",
|
||||
"controllerModules/scaleAvatar.js"
|
||||
];
|
||||
|
||||
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";
|
||||
|
|
|
@ -301,3 +301,14 @@ findGroupParent = function (controllerData, targetProps) {
|
|||
|
||||
return targetProps;
|
||||
};
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = {
|
||||
makeDispatcherModuleParameters: makeDispatcherModuleParameters,
|
||||
enableDispatcherModule: enableDispatcherModule,
|
||||
disableDispatcherModule: disableDispatcherModule,
|
||||
makeRunningValues: makeRunningValues,
|
||||
LEFT_HAND: LEFT_HAND,
|
||||
RIGHT_HAND: RIGHT_HAND
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue