mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-09 20:08:31 +02:00
editing equip code
This commit is contained in:
parent
fd47832857
commit
2c20593b6d
3 changed files with 65 additions and 16 deletions
|
@ -30,7 +30,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||||
var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ;
|
var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ;
|
||||||
|
|
||||||
var PROFILE = false;
|
var PROFILE = false;
|
||||||
var DEBUG = true;
|
var DEBUG = false;
|
||||||
|
|
||||||
if (typeof Test !== "undefined") {
|
if (typeof Test !== "undefined") {
|
||||||
PROFILE = true;
|
PROFILE = true;
|
||||||
|
|
|
@ -183,31 +183,62 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa
|
||||||
|
|
||||||
function EquipTimer(hand) {
|
function EquipTimer(hand) {
|
||||||
this.hand = hand;
|
this.hand = hand;
|
||||||
|
this.timelapsed = 0;
|
||||||
this.primaryTriggerPressed = false;
|
this.primaryTriggerPressed = false;
|
||||||
this.secondaryTriggerPressed = false;
|
this.secondaryTriggerPressed = false;
|
||||||
this.equipTime = EQUIP_TIME;
|
this.targetTime = EQUIP_TIME;
|
||||||
this.currentTimeLapse = 0;
|
|
||||||
this.equip = true;
|
|
||||||
this.finished = false;
|
this.finished = false;
|
||||||
this.circle3dProperties = CIRCLE_3D_PROPERTIES;
|
this.circle3dProperties = CIRCLE_3D_PROPERTIES;
|
||||||
this.circle3dOverlay = Overlays.addOverlay("circle3d", this.circle3dProperties);
|
this.circle3dOverlay = Overlays.addOverlay("circle3d", this.circle3dProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
EquipTimer.prototype.update = function(deltaTime, timestamp, controllerData) {
|
EquipTimer.prototype.update = function(deltaTime, targetEntityID, controllerData) {
|
||||||
/*var TRIGGER_ON_VALUE = 0.105;
|
var TRIGGER_ON_VALUE = 0.105;
|
||||||
var BUMPER_ON_VALUE = 0.5;
|
var BUMPER_ON_VALUE = 0.5;
|
||||||
var primaryTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE;
|
var primaryTriggerPressed = controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE;
|
||||||
var secondaryTriggerPressed = controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE;
|
var secondaryTriggerPressed = controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE;
|
||||||
|
|
||||||
if (primaryTriggerPressed || secondaryTriggerPressed) {
|
if (primaryTriggerPressed || secondaryTriggerPressed) {
|
||||||
if (primaryTriggerPressed === this.primaryTriggerPressed &&
|
if ((primaryTriggerPressed === this.primaryTriggerPressed) &&
|
||||||
*/
|
(secondaryTriggerPressed === this.secondaryTriggerPressed)) {
|
||||||
|
this.timelapsed += deltaTime * 1000; // convert to ms
|
||||||
|
// update overlay
|
||||||
|
|
||||||
|
var entityProperties = Entities.getEntityProperties(targetEntityID, ["position", "rotation"]);
|
||||||
|
if (entityProperties) {
|
||||||
|
var PI = 3.14159;
|
||||||
|
var TWO_PI = PI * 2;
|
||||||
|
var FORWARD_OFFSET = 0.1 * MyAvatar.sensorToWorldScale;
|
||||||
|
var direction = Vec3.subtract(entityProperties.position - HMD.position);
|
||||||
|
var overlayPosition = Vec3.sum(entityProperties.position, Vec3.multiply(FORWARD_OFFSET, direction));
|
||||||
|
}
|
||||||
|
if (this.timelapsed >= this.targetTime) {
|
||||||
|
print("finished");
|
||||||
|
this.finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.reset();
|
||||||
|
this.primaryTriggerPressed = primaryTriggerPressed;
|
||||||
|
this.secondaryTriggerPressed = secondaryTriggerPressed;
|
||||||
|
} else {
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
EquipTimer.prototype.finished = function() {
|
EquipTimer.prototype.done = function() {
|
||||||
return this.finished;
|
return this.finished;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EquipTimer.prototype.reset = function() {
|
||||||
|
this.finished = false;
|
||||||
|
this.timelapsed = 0;
|
||||||
|
this.primaryTriggerPressed = false;
|
||||||
|
this.secondaryTriggerPressed = false;
|
||||||
|
};
|
||||||
|
|
||||||
EquipTimer.prototype.cleanup = function() {
|
EquipTimer.prototype.cleanup = function() {
|
||||||
Overlays.deleteOverlay(this.circle3dOverlay);
|
Overlays.deleteOverlay(this.circle3dOverlay);
|
||||||
};
|
};
|
||||||
|
@ -324,6 +355,7 @@ EquipTimer.prototype.cleanup = function() {
|
||||||
this.shouldSendStart = false;
|
this.shouldSendStart = false;
|
||||||
this.equipedWithSecondary = false;
|
this.equipedWithSecondary = false;
|
||||||
this.handHasBeenRightsideUp = false;
|
this.handHasBeenRightsideUp = false;
|
||||||
|
this.equipAtRun = false;
|
||||||
|
|
||||||
this.parameters = makeDispatcherModuleParameters(
|
this.parameters = makeDispatcherModuleParameters(
|
||||||
300,
|
300,
|
||||||
|
@ -672,20 +704,23 @@ EquipTimer.prototype.cleanup = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
equipHotspotBuddy.update(deltaTime, timestamp, controllerData);
|
equipHotspotBuddy.update(deltaTime, timestamp, controllerData);
|
||||||
this.equiptTimer.update(deltaTime, timestamp, controllerData);
|
|
||||||
// if the potentialHotspot is cloneable, clone it and return it
|
// if the potentialHotspot is cloneable, clone it and return it
|
||||||
// if the potentialHotspot os not cloneable and locked return null
|
// if the potentialHotspot os not cloneable and locked return null
|
||||||
|
|
||||||
if (potentialEquipHotspot &&
|
if (potentialEquipHotspot &&
|
||||||
(((this.triggerSmoothedSqueezed() || this.secondarySmoothedSqueezed()) && !this.waitForTriggerRelease &&
|
(((this.triggerSmoothedSqueezed() || this.secondarySmoothedSqueezed()) && !this.waitForTriggerRelease) || this.messageGrabEntity)) {
|
||||||
this.equipTimer.finished()) || this.messageGrabEntity)) {
|
|
||||||
this.grabbedHotspot = potentialEquipHotspot;
|
this.grabbedHotspot = potentialEquipHotspot;
|
||||||
this.targetEntityID = this.grabbedHotspot.entityID;
|
this.targetEntityID = this.grabbedHotspot.entityID;
|
||||||
this.startEquipEntity(controllerData);
|
this.equipAtRun = true;
|
||||||
this.messageGrabEntity = false;
|
this.messageGrabEntity = false;
|
||||||
this.equipedWithSecondary = this.secondarySmoothedSqueezed();
|
if (this.messageGrabEntity) {
|
||||||
|
this.startEquipEntity(controllerData);
|
||||||
|
this.equipedWithSecondary = this.secondarySmoothedSqueezed();
|
||||||
|
this.equipAtRun = false;
|
||||||
|
}
|
||||||
return makeRunningValues(true, [potentialEquipHotspot.entityID], []);
|
return makeRunningValues(true, [potentialEquipHotspot.entityID], []);
|
||||||
} else {
|
} else {
|
||||||
|
this.equipAtRun = false;
|
||||||
return makeRunningValues(false, [], []);
|
return makeRunningValues(false, [], []);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -706,6 +741,19 @@ EquipTimer.prototype.cleanup = function() {
|
||||||
var timestamp = Date.now();
|
var timestamp = Date.now();
|
||||||
this.updateInputs(controllerData);
|
this.updateInputs(controllerData);
|
||||||
|
|
||||||
|
if (this.equipAtRun) {
|
||||||
|
if ((this.triggerSmoothedSqueezed() || this.secondarySmoothedSqueezed()) && !this.waitForTriggerRelease) {
|
||||||
|
this.equipTimer.update(deltaTime, this.targetEntityID, controllerData);
|
||||||
|
if (this.equipTimer.done()) {
|
||||||
|
this.equipAtRun = false;
|
||||||
|
this.startEquipEntity(controllerData);
|
||||||
|
this.equipedWithSecondary = this.secondarySmoothedSqueezed();
|
||||||
|
this.equipTimer.reset();
|
||||||
|
}
|
||||||
|
return makeRunningValues(true, [], []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.isTargetIDValid(controllerData)) {
|
if (!this.isTargetIDValid(controllerData)) {
|
||||||
this.endEquipEntity();
|
this.endEquipEntity();
|
||||||
return makeRunningValues(false, [], []);
|
return makeRunningValues(false, [], []);
|
||||||
|
|
|
@ -9,12 +9,13 @@
|
||||||
/* global Script, Controller, RIGHT_HAND, LEFT_HAND, MyAvatar, getGrabPointSphereOffset,
|
/* global Script, Controller, RIGHT_HAND, LEFT_HAND, MyAvatar, getGrabPointSphereOffset,
|
||||||
makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters,
|
makeRunningValues, Entities, enableDispatcherModule, disableDispatcherModule, makeDispatcherModuleParameters,
|
||||||
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
|
PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
|
||||||
DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData, makeLaserParams
|
DEFAULT_SEARCH_SPHERE_DISTANCE, getGrabbableData, makeLaserParams, entityIsCloneable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
||||||
Script.include("/~/system/libraries/controllers.js");
|
Script.include("/~/system/libraries/controllers.js");
|
||||||
|
Script.include("/~/system/libraries/cloneEntityUtils.js");
|
||||||
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
|
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
|
||||||
function HighlightNearbyEntities(hand) {
|
function HighlightNearbyEntities(hand) {
|
||||||
this.hand = hand;
|
this.hand = hand;
|
||||||
|
@ -28,7 +29,7 @@
|
||||||
|
|
||||||
|
|
||||||
this.isGrabable = function(controllerData, props) {
|
this.isGrabable = function(controllerData, props) {
|
||||||
if (dispatcherUtils.entityIsGrabbable(props) || dispatcherUtils.entityIsCloneable(props)) {
|
if (dispatcherUtils.entityIsGrabbable(props) || entityIsCloneable(props)) {
|
||||||
// if we've attempted to grab a child, roll up to the root of the tree
|
// if we've attempted to grab a child, roll up to the root of the tree
|
||||||
var groupRootProps = dispatcherUtils.findGroupParent(controllerData, props);
|
var groupRootProps = dispatcherUtils.findGroupParent(controllerData, props);
|
||||||
if (dispatcherUtils.entityIsGrabbable(groupRootProps)) {
|
if (dispatcherUtils.entityIsGrabbable(groupRootProps)) {
|
||||||
|
|
Loading…
Reference in a new issue