diff --git a/examples/controllers/controllerMappings.js b/examples/controllers/controllerMappings.js deleted file mode 100644 index 3848f62096..0000000000 --- a/examples/controllers/controllerMappings.js +++ /dev/null @@ -1,101 +0,0 @@ - -// -// controllerScriptingExamples.js -// examples -// -// Created by Sam Gondelman on 6/2/15 -// Copyright 2015 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 -// - -// Assumes you only have the default keyboard connected - -/*myFirstMapping = function() { -return { - "name": "example", - "channels": [ - { "from": "Keyboard.W", "to": "Actions.LONGITUDINAL_FORWARD" }, - { "from": "Keyboard.S", "to": "Actions.LONGITUDINAL_BACKWARD" }, - - { "from": "Keyboard.Left", "to": "Actions.LATERAL_LEFT" }, - { "from": "Keyboard.Right", "to": "Actions.LATERAL_RIGHT" }, - - { "from": "Keyboard.A", "to": "Actions.YAW_LEFT" }, - { "from": "Keyboard.D", "to": "Actions.YAW_RIGHT" }, - - { "from": "Keyboard.C", "to": "Actions.VERTICAL_DOWN" }, - { "from": "Keyboard.E", "to": "Actions.VERTICAL_UP" }, - { - "from": "Standard.LX", - "filters": [ { - "type": "scale", - "params": [2.0], - } - ], - "to": "Actions.LATERAL_LEFT", - }, { - "from": "Keyboard.B", - "to": "Actions.Yaw" - } - ] -} -} -*/ -mySecondMapping = function() { -return { - "name": "example2", - "channels": [ - { "from": "Standard.LY", "to": "Actions.TranslateZ" }, - { "from": "Standard.LX", "to": "Actions.Yaw" }, - ] -} -} - -//Script.include('mapping-test0.json'); -/*var myFirstMappingJSON = myFirstMapping(); -print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON)); - -var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON)); - - -Controller.enableMapping("example3"); - -var mySecondMappingJSON = mySecondMapping(); -print('mySecondMappingJSON' + JSON.stringify(mySecondMappingJSON)); - -var mapping2 = Controller.parseMapping(JSON.stringify(mySecondMappingJSON)); -mapping2.enable(); - -Controller.enableMapping("example2"); -*/ -var mapping3 = Controller.loadMapping(Script.resolvePath("example3.json")); -Controller.enableMapping("example3"); - -/* -Object.keys(Controller.Standard).forEach(function (input) { - print("Controller.Standard." + input + ":" + Controller.Standard[input]); -}); - -Object.keys(Controller.Hardware).forEach(function (deviceName) { - Object.keys(Controller.Hardware[deviceName]).forEach(function (input) { - print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); - }); -}); - -Object.keys(Controller.Actions).forEach(function (actionName) { - print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]); -}); -*/ - - -Controller.hardwareChanged.connect(function () { - print("hardwareChanged ---------------------------------------------------"); - Object.keys(Controller.Hardware).forEach(function (deviceName) { - Object.keys(Controller.Hardware[deviceName]).forEach(function (input) { - print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); - }); - }); - print("-------------------------------------------------------------------"); -}); \ No newline at end of file diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index a8919105d1..2d82896e26 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -74,6 +74,13 @@ var ACTION_TTL = 15; // seconds var ACTION_TTL_REFRESH = 5; var PICKS_PER_SECOND_PER_HAND = 5; var MSECS_PER_SEC = 1000.0; +var GRABBABLE_PROPERTIES = ["position", + "rotation", + "gravity", + "ignoreForCollisions", + "collisionsWillMove", + "locked", + "name"]; var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js @@ -234,7 +241,7 @@ function MyController(hand) { this.debugLine = function(closePoint, farPoint, color){ Entities.addEntity({ type: "Line", - name: "Debug Line", + name: "Grab Debug Entity", dimensions: LINE_ENTITY_DIMENSIONS, visible: true, position: closePoint, @@ -249,7 +256,7 @@ function MyController(hand) { if (this.pointer === null) { this.pointer = Entities.addEntity({ type: "Line", - name: "pointer", + name: "grab pointer", dimensions: LINE_ENTITY_DIMENSIONS, visible: true, position: closePoint, @@ -308,6 +315,8 @@ function MyController(hand) { } this.search = function() { + this.grabbedEntity = null; + //if this hand is the one that's disabled, we don't want to search for anything at all if (this.hand === disabledHand) { return; @@ -358,7 +367,6 @@ function MyController(hand) { if (intersection.intersects) { // the ray is intersecting something we can move. var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); - this.grabbedEntity = intersection.entityID; //this code will disabled the beam for the opposite hand of the one that grabbed it if the entity says so var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA); @@ -372,8 +380,11 @@ function MyController(hand) { disabledHand = 'none'; } + if (intersection.properties.name == "Grab Debug Entity") { + continue; + } + if (typeof grabbableData.grabbable !== 'undefined' && !grabbableData.grabbable) { - this.grabbedEntity = null; continue; } if (intersectionDistance > pickRay.length) { @@ -383,56 +394,93 @@ function MyController(hand) { if (intersectionDistance <= NEAR_PICK_MAX_DISTANCE) { // the hand is very close to the intersected object. go into close-grabbing mode. if (grabbableData.wantsTrigger) { + this.grabbedEntity = intersection.entityID; this.setState(STATE_NEAR_GRABBING_NON_COLLIDING); + return; } else if (!intersection.properties.locked) { + this.grabbedEntity = intersection.entityID; this.setState(STATE_NEAR_GRABBING); + return; } - } else { + } else if (! entityIsGrabbedByOther(intersection.entityID)) { // don't allow two people to distance grab the same object - if (entityIsGrabbedByOther(intersection.entityID)) { - this.grabbedEntity = null; - } else { + if (intersection.properties.collisionsWillMove + && !intersection.properties.locked) { // the hand is far from the intersected object. go into distance-holding mode - if (intersection.properties.collisionsWillMove - && !intersection.properties.locked) { - this.setState(STATE_DISTANCE_HOLDING); - } else { - this.setState(STATE_FAR_GRABBING_NON_COLLIDING); - } + this.grabbedEntity = intersection.entityID; + this.setState(STATE_DISTANCE_HOLDING); + return; + } else if (grabbableData.wantsTrigger) { + this.grabbedEntity = intersection.entityID; + this.setState(STATE_FAR_GRABBING_NON_COLLIDING); + return; } } } } + // forward ray test failed, try sphere test. + if (WANT_DEBUG) { + Entities.addEntity({ + type: "Sphere", + name: "Grab Debug Entity", + dimensions: {x: GRAB_RADIUS, y: GRAB_RADIUS, z: GRAB_RADIUS}, + visible: true, + position: handPosition, + color: { red: 0, green: 255, blue: 0}, + lifetime: 0.1 + }); + } + + var nearbyEntities = Entities.findEntities(handPosition, GRAB_RADIUS); + var minDistance = PICK_MAX_DISTANCE; + var i, props, distance, grabbableData; + for (i = 0; i < nearbyEntities.length; i++) { + var grabbableDataForCandidate = + getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], DEFAULT_GRABBABLE_DATA); + if (typeof grabbableDataForCandidate.grabbable !== 'undefined' && !grabbableDataForCandidate.grabbable) { + continue; + } + var propsForCandidate = + Entities.getEntityProperties(nearbyEntities[i], GRABBABLE_PROPERTIES); + + if (propsForCandidate.type == 'Unknown') { + continue; + } + + if (propsForCandidate.type == 'Light') { + continue; + } + + if (propsForCandidate.locked && !grabbableDataForCandidate.wantsTrigger) { + continue; + } + + if (propsForCandidate.name == "Grab Debug Entity") { + continue; + } + + if (propsForCandidate.name == "grab pointer") { + continue; + } + + distance = Vec3.distance(propsForCandidate.position, handPosition); + if (distance < minDistance) { + this.grabbedEntity = nearbyEntities[i]; + minDistance = distance; + props = propsForCandidate; + grabbableData = grabbableDataForCandidate; + } + } if (this.grabbedEntity === null) { - // forward ray test failed, try sphere test. - var nearbyEntities = Entities.findEntities(handPosition, GRAB_RADIUS); - var minDistance = PICK_MAX_DISTANCE; - var i, props, distance, grabbableData; - for (i = 0; i < nearbyEntities.length; i++) { - var grabbableDataForCandidate = - getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], DEFAULT_GRABBABLE_DATA); - if (!grabbableDataForCandidate.grabbable) { - continue; - } - var propsForCandidate = - Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]); - distance = Vec3.distance(propsForCandidate.position, handPosition); - if (distance < minDistance && propsForCandidate.name !== "pointer") { - this.grabbedEntity = nearbyEntities[i]; - minDistance = distance; - props = propsForCandidate; - grabbableData = grabbableDataForCandidate; - } - } - if (this.grabbedEntity === null) { - return; - } - if (grabbableData.wantsTrigger) { - this.setState(STATE_NEAR_GRABBING_NON_COLLIDING); - } else if (!props.locked) { - this.setState(STATE_NEAR_GRABBING); - } + return; + } + if (grabbableData.wantsTrigger) { + this.setState(STATE_NEAR_GRABBING_NON_COLLIDING); + return; + } else if (!props.locked) { + this.setState(STATE_NEAR_GRABBING); + return; } }; @@ -440,9 +488,7 @@ function MyController(hand) { var handControllerPosition = (this.hand === RIGHT_HAND) ? MyAvatar.rightHandPosition : MyAvatar.leftHandPosition; var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(controllerHandInput).rotation); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation", - "gravity", "ignoreForCollisions", - "collisionsWillMove"]); + var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); var now = Date.now(); // add the action and initialize some variables @@ -492,7 +538,7 @@ function MyController(hand) { var handControllerPosition = (this.hand === RIGHT_HAND) ? MyAvatar.rightHandPosition : MyAvatar.leftHandPosition; var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(controllerHandInput).rotation); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); + var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); this.lineOn(handPosition, Vec3.subtract(grabbedProperties.position, handPosition), INTERSECT_COLOR); @@ -585,9 +631,7 @@ function MyController(hand) { this.lineOff(); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, - ["position", "rotation", "gravity", - "ignoreForCollisions", "collisionsWillMove"]); + var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); this.activateEntity(this.grabbedEntity, grabbedProperties); if (grabbedProperties.collisionsWillMove && NEAR_GRABBING_KINEMATIC) { Entities.editEntity(this.grabbedEntity, { diff --git a/interface/resources/controllers/mapping-config.json b/interface/resources/controllers/mapping-config.json deleted file mode 100644 index 2ccd216c2f..0000000000 --- a/interface/resources/controllers/mapping-config.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "Full Mapping config including the standard hydra and gamepad and one more thing", - "mappings": [ - { "src": "./mapping-hydra.json" }, - { "src": "./mapping-xbox.json" }, - { - "name": "example mapping for standard to js function", - "channels": [ { - "from": "Standard.B", - "to": { - "type":"js", - "function": "function(value){ print(\"Standard.B = \" + value );}" - } - }, { - "from": "Standard.B", - "to": { - "type":"js", - "src": "http://www.theNextBigThing.com/hifiInputSignalHandler.js" - } - } - ] - } - ] -} diff --git a/interface/resources/controllers/mapping-test0.json b/interface/resources/controllers/mapping-test0.json deleted file mode 100644 index 5232c97f19..0000000000 --- a/interface/resources/controllers/mapping-test0.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "example mapping from Standard to actions", - "channels": [ { - "from": "Standard.LY", - "filters": [ { - "type": "clamp", - "min": 0, - "max": 1 - } - ], - "to": "Actions.Forward" - }, { - "from": "Standard.LY", - "filters": [ { - "type": "clamp", - "min": -1, - "max": 0 - }, { - "type": "invert" - } - ], - "to": "Actions.Backward" - }, { - "from": "Standard.LX", - "filters": [ { - "type": "scale", - "scale": 2.0 - } - ], - "to": "Actions.Yaw" - }, { - "from": "Standard.A", - "to": "Actions.Action0" - } - ] -} \ No newline at end of file diff --git a/interface/resources/controllers/standard-old.json b/interface/resources/controllers/standard-old.json deleted file mode 100644 index b662e5394d..0000000000 --- a/interface/resources/controllers/standard-old.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "Standard to Action", - "channels": [ - { "from": "Standard.LY", "to": "Actions.TranslateZ" }, - { "from": "Standard.LX", "to": "Actions.TranslateX" }, - { "from": "Standard.RX", "to": "Actions.Yaw" }, - { "from": "Standard.RY", "to": "Actions.Pitch" }, - { - "from": "Standard.DU", - "to": "Actions.LONGITUDINAL_FORWARD", - "filters": [ { "type": "scale", "scale": 0.5 } ] - }, - { - "from": "Standard.DD", - "to": "Actions.LONGITUDINAL_BACKWARD", - "filters": [ { "type": "scale", "scale": 0.5 } ] - }, - { - "from": "Standard.DR", - "to": "Actions.LATERAL_RIGHT", - "filters": [ { "type": "scale", "scale": 0.5 } ] - }, - { - "from": "Standard.DL", - "to": "Actions.LATERAL_LEFT", - "filters": [ { "type": "scale", "scale": 0.5 } ] - }, - { "from": "Standard.Y", "to": "Actions.VERTICAL_UP" }, - { "from": "Standard.X", "to": "Actions.VERTICAL_DOWN" }, - { - "from": "Standard.RT", - "to": "Actions.BOOM_IN", - "filters": [ { "type": "scale", "scale": 0.1 } ] - }, - { - "from": "Standard.LT", - "to": "Actions.BOOM_OUT", - "filters": [ { "type": "scale", "scale": 0.1 } ] - }, - { "from": "Standard.LeftHand", "to": "Actions.LEFT_HAND" }, - { "from": "Standard.RightHand", "to": "Actions.RIGHT_HAND" } - ] -} diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index d312913a23..5de188c0b6 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -2,21 +2,19 @@ "name": "Standard to Action", "channels": [ { "from": "Standard.LY", "to": "Actions.TranslateZ" }, + { "from": "Standard.LX", "to": "Actions.TranslateX" }, - { "from": "Standard.LX", + { "from": "Standard.RX", "when": [ "Application.InHMD", "Application.ComfortMode" ], "to": "Actions.StepYaw", "filters": [ { "type": "pulse", "interval": 0.5 }, - { "type": "scale", "scale": 15 } + { "type": "scale", "scale": 22.5 } ] }, - - { "from": "Standard.LX", "to": "Actions.Yaw" }, - - { "from": "Standard.RX", "to": "Actions.TranslateX" }, - { "from": "Standard.RY", "filters": "invert", "to": "Actions.TranslateY" }, + { "from": "Standard.RX", "to": "Actions.Yaw" }, + { "from": "Standard.RY", "when": "!Application.InHMD", "to": "Actions.Pitch" }, { "from": [ "Standard.DU", "Standard.DL", "Standard.DR", "Standard.DD" ], "to": "Standard.LeftPrimaryThumb" }, diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index a4fcd3689e..2fcf0decce 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -132,8 +132,6 @@ void AvatarActionHold::doKinematicUpdate(float deltaTimeStep) { if (_previousSet) { glm::vec3 positionalVelocity = (_positionalTarget - _previousPositionalTarget) / deltaTimeStep; rigidBody->setLinearVelocity(glmToBullet(positionalVelocity)); - // back up along velocity a bit in order to smooth out a "vibrating" appearance - _positionalTarget -= positionalVelocity * deltaTimeStep / 2.0f; } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 400f8e4372..20ce62e322 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -53,7 +53,6 @@ using namespace std; -static quint64 COMFORT_MODE_PULSE_TIMING = USECS_PER_SECOND / 2; // turn once per half second const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f); const float YAW_SPEED = 150.0f; // degrees/sec const float PITCH_SPEED = 100.0f; // degrees/sec @@ -259,23 +258,9 @@ void MyAvatar::simulate(float deltaTime) { stepAction = true; } } - quint64 now = usecTimestampNow(); - quint64 pulseDeltaTime = now - _lastStepPulse; - if (!stepAction) { - _lastStepPulse = 0; - } - - if (stepAction && pulseDeltaTime > COMFORT_MODE_PULSE_TIMING) { - _pulseUpdate = true; - } updateOrientation(deltaTime); updatePosition(deltaTime); - - if (_pulseUpdate) { - _lastStepPulse = now; - _pulseUpdate = false; - } } { @@ -1299,11 +1284,11 @@ void MyAvatar::prepareForPhysicsSimulation() { _characterController.setAvatarPositionAndOrientation(getPosition(), getOrientation()); if (qApp->isHMDMode()) { updateHMDFollowVelocity(); - _characterController.setHMDVelocity(_hmdFollowVelocity); - } else { - _characterController.setHMDVelocity(Vectors::ZERO); + } else if (_isFollowingHMD) { _isFollowingHMD = false; + _hmdFollowVelocity = Vectors::ZERO; } + _characterController.setHMDVelocity(_hmdFollowVelocity); } void MyAvatar::harvestResultsFromPhysicsSimulation() { @@ -1339,6 +1324,7 @@ void MyAvatar::adjustSensorTransform(glm::vec3 hmdShift) { // the "adjustment" is more or less complete so stop following _isFollowingHMD = false; _hmdFollowSpeed = 0.0f; + _hmdFollowVelocity = Vectors::ZERO; // and slam the body's transform anyway to eliminate any slight errors glm::vec3 finalBodyPosition = extractTranslation(worldBodyMatrix); nextAttitude(finalBodyPosition, finalBodyRotation); @@ -1623,7 +1609,7 @@ void MyAvatar::updateOrientation(float deltaTime) { // get an instantaneous 15 degree turn. If you keep holding the key down you'll get another // snap turn every half second. quint64 now = usecTimestampNow(); - if (_driveKeys[STEP_YAW] != 0.0f && now - _lastStepPulse > COMFORT_MODE_PULSE_TIMING) { + if (_driveKeys[STEP_YAW] != 0.0f) { totalBodyYaw += _driveKeys[STEP_YAW]; } @@ -1692,9 +1678,9 @@ glm::vec3 MyAvatar::applyKeyboardMotor(float deltaTime, const glm::vec3& localVe glm::vec3 newLocalVelocity = localVelocity; float stepControllerInput = fabsf(_driveKeys[STEP_TRANSLATE_Z]) + fabsf(_driveKeys[STEP_TRANSLATE_Z]) + fabsf(_driveKeys[STEP_TRANSLATE_Z]); quint64 now = usecTimestampNow(); + // FIXME how do I implement step translation as well? - if (stepControllerInput && now - _lastStepPulse > COMFORT_MODE_PULSE_TIMING) { - } + float keyboardInput = fabsf(_driveKeys[TRANSLATE_Z]) + fabsf(_driveKeys[TRANSLATE_X]) + fabsf(_driveKeys[TRANSLATE_Y]); if (keyboardInput) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index f5d8c35904..13742747db 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -421,8 +421,6 @@ private: AtRestDetector _hmdAtRestDetector; bool _lastIsMoving { false }; - quint64 _lastStepPulse { 0 }; - bool _pulseUpdate { false }; }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode); diff --git a/libraries/shared/src/AtRestDetector.cpp b/libraries/shared/src/AtRestDetector.cpp index d790e2b066..4c08b30dcd 100644 --- a/libraries/shared/src/AtRestDetector.cpp +++ b/libraries/shared/src/AtRestDetector.cpp @@ -32,7 +32,7 @@ void AtRestDetector::reset(const glm::vec3& startPosition, const glm::quat& star bool AtRestDetector::update(const glm::vec3& position, const glm::quat& rotation) { uint64_t now = usecTimestampNow(); - float dt = (float)(_lastUpdateTime - now) / (float)USECS_PER_SECOND; + float dt = (float)(now - _lastUpdateTime) / (float)USECS_PER_SECOND; _lastUpdateTime = now; const float TAU = 1.0f; float delta = glm::min(dt / TAU, 1.0f);