From e25d4c17e8943092f9046dab7fe1d7361dc9747c Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 25 Nov 2015 09:29:40 +1300 Subject: [PATCH 1/6] Fix InputController (Leap Motion) not able to be created --- .../src/scripting/ControllerScriptingInterface.cpp | 12 ++++++------ .../src/scripting/ControllerScriptingInterface.h | 4 ++-- libraries/script-engine/src/ScriptEngine.cpp | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 547f16ea8b..719bfe7f1f 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -84,11 +84,11 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { return qApp->getUiSize(); } -controller::InputController::Pointer ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { - // This is where we retreive the Device Tracker category and then the sub tracker within it +controller::InputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { + // This is where we retrieve the Device Tracker category and then the sub tracker within it auto icIt = _inputControllers.find(0); if (icIt != _inputControllers.end()) { - return (*icIt).second; + return (*icIt).second.get(); } @@ -110,15 +110,15 @@ controller::InputController::Pointer ControllerScriptingInterface::createInputCo controller::InputController::Pointer inputController = std::make_shared(deviceID, trackerID, this); controller::InputController::Key key = inputController->getKey(); _inputControllers.insert(InputControllerMap::value_type(key, inputController)); - return inputController; + return inputController.get(); } } } - return controller::InputController::Pointer(); + return nullptr; } -void ControllerScriptingInterface::releaseInputController(controller::InputController::Pointer input) { +void ControllerScriptingInterface::releaseInputController(controller::InputController* input) { _inputControllers.erase(input->getKey()); } diff --git a/interface/src/scripting/ControllerScriptingInterface.h b/interface/src/scripting/ControllerScriptingInterface.h index 4c69551dd2..22d8f8be1f 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -96,8 +96,8 @@ public slots: virtual glm::vec2 getViewportDimensions() const; /// Factory to create an InputController - virtual controller::InputController::Pointer createInputController(const QString& deviceName, const QString& tracker); - virtual void releaseInputController(controller::InputController::Pointer input); + virtual controller::InputController* createInputController(const QString& deviceName, const QString& tracker); + virtual void releaseInputController(controller::InputController* input); signals: void keyPressEvent(const KeyEvent& event); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 995a92bf83..49009a3ad2 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -81,6 +81,9 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) { out = qobject_cast(object.toQObject()); } +Q_DECLARE_METATYPE(controller::InputController*) +static int inputControllerPointerId = qRegisterMetaType(); + QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) { return engine->newQObject(in); } @@ -89,8 +92,6 @@ void inputControllerFromScriptValue(const QScriptValue &object, controller::Inpu out = qobject_cast(object.toQObject()); } - - static bool hasCorrectSyntax(const QScriptProgram& program) { const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode()); if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) { From 5ecbaa5b93b92ac821db8b3db7af2022990dfef1 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 25 Nov 2015 09:43:55 +1300 Subject: [PATCH 2/6] Fix InputController (Leap Motion) not being updated --- interface/src/Application.cpp | 2 ++ interface/src/scripting/ControllerScriptingInterface.cpp | 9 +++++++-- interface/src/scripting/ControllerScriptingInterface.h | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4dc218ecdc..189234894d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2825,6 +2825,8 @@ void Application::update(float deltaTime) { } } + _controllerScriptingInterface->updateInputControllers(); + // Transfer the user inputs to the driveKeys // FIXME can we drop drive keys and just have the avatar read the action states directly? myAvatar->clearDriveKeys(); diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 719bfe7f1f..11053154b6 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -89,8 +89,7 @@ controller::InputController* ControllerScriptingInterface::createInputController auto icIt = _inputControllers.find(0); if (icIt != _inputControllers.end()) { return (*icIt).second.get(); - } - + } // Look for device DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); @@ -122,6 +121,12 @@ void ControllerScriptingInterface::releaseInputController(controller::InputContr _inputControllers.erase(input->getKey()); } +void ControllerScriptingInterface::updateInputControllers() { + for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) { + (*it).second->update(); + } +} + InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : _deviceTrackerId(deviceTrackerId), _subTrackerId(subTrackerId), diff --git a/interface/src/scripting/ControllerScriptingInterface.h b/interface/src/scripting/ControllerScriptingInterface.h index 22d8f8be1f..8bd698cfb2 100644 --- a/interface/src/scripting/ControllerScriptingInterface.h +++ b/interface/src/scripting/ControllerScriptingInterface.h @@ -85,6 +85,8 @@ public: bool isKeyCaptured(const KeyEvent& event) const; bool isJoystickCaptured(int joystickIndex) const; + void updateInputControllers(); + public slots: virtual void captureKeyEvents(const KeyEvent& event); From 6736eefbc11e7932d476d0acecd2624dae06fe13 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 25 Nov 2015 14:14:22 +1300 Subject: [PATCH 3/6] Fix arm and finger joint control in leapHands.js for desktop mode --- examples/controllers/leap/leapHands.js | 33 ++++++++++---------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 6bdca051be..04b65349a9 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -193,13 +193,12 @@ var leapHands = (function () { } // Set avatar arms vertical, forearms horizontal, as "zero" position for calibration - MyAvatar.setJointData("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, -90.0)); - MyAvatar.setJointData("LeftForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0)); - MyAvatar.setJointData("LeftHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); - MyAvatar.setJointData("RightArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 90.0)); - MyAvatar.setJointData("RightForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0)); - MyAvatar.setJointData("RightHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); - + MyAvatar.setJointRotation("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0)); + MyAvatar.setJointRotation("LeftForeArm", Quat.fromPitchYawRollDegrees(0.0, 90.0, 90.0)); + MyAvatar.setJointRotation("LeftHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); + MyAvatar.setJointRotation("RightArm", Quat.fromPitchYawRollDegrees(90.0,0.0, 0.0)); + MyAvatar.setJointRotation("RightForeArm", Quat.fromPitchYawRollDegrees(0.0, -90.0, -90.0)); + MyAvatar.setJointRotation("RightHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); // Wait for arms to assume their positions before calculating Script.setTimeout(finishCalibration, CALIBRATION_TIME); @@ -421,22 +420,14 @@ var leapHands = (function () { // Hand rotation in camera coordinates ... handRotation = { - x: handRotation.z, - y: handRotation.y, - z: handRotation.x, - w: handRotation.w + x: -handRotation.x, + y: -handRotation.z, + z: -handRotation.y, + w: handRotation.w, }; // Hand rotation in avatar coordinates ... - if (h === 0) { - handRotation.x = -handRotation.x; - handRotation = Quat.multiply(Quat.angleAxis(-90.0, { x: 0, y: 1, z: 0 }), - handRotation); - } else { - handRotation.z = -handRotation.z; - handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 0, y: 1, z: 0 }), - handRotation); - } + handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 1, y: 0, z: 0 }), handRotation); } // Set hand position and orientation ... @@ -462,7 +453,7 @@ var leapHands = (function () { w: locRotation.w }; } - MyAvatar.setJointData(fingers[h][i][j].jointName, locRotation); + MyAvatar.setJointRotation(fingers[h][i][j].jointName, locRotation); } } } From 566b27156c710a08ef294f3f3ce6508ec70f675a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 25 Nov 2015 15:45:33 +1300 Subject: [PATCH 4/6] Fix hand and finger joint control in leapHands.js for HMD mode --- examples/controllers/leap/leapHands.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 04b65349a9..42df89084d 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -381,23 +381,14 @@ var leapHands = (function () { // Hand rotation in camera coordinates ... handRotation = { - x: handRotation.z, - y: handRotation.y, - z: handRotation.x, - w: handRotation.w + x: -handRotation.x, + y: -handRotation.z, + z: -handRotation.y, + w: handRotation.w, }; // Hand rotation in avatar coordinates ... - if (h === 0) { - handRotation.x = -handRotation.x; - handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 1, y: 0, z: 0 }), handRotation); - handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 0, y: 0, z: 1 }), handRotation); - } else { - handRotation.z = -handRotation.z; - handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 1, y: 0, z: 0 }), handRotation); - handRotation = Quat.multiply(Quat.angleAxis(-90.0, { x: 0, y: 0, z: 1 }), handRotation); - } - + handRotation = Quat.multiply(Quat.angleAxis(180.0, { x: 0, y: 1, z: 0 }), handRotation); cameraOrientation.x = -cameraOrientation.x; cameraOrientation.z = -cameraOrientation.z; handRotation = Quat.multiply(cameraOrientation, handRotation); From 46cbc349d15d7f103e4568abb42fa183f2e9f7d8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 25 Nov 2015 16:39:09 +1300 Subject: [PATCH 5/6] Fix laserPointer.js for Hydras Leap Motion working already. --- examples/controllers/leap/laserPointer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/controllers/leap/laserPointer.js b/examples/controllers/leap/laserPointer.js index 156e9ba298..c8c3cf372a 100644 --- a/examples/controllers/leap/laserPointer.js +++ b/examples/controllers/leap/laserPointer.js @@ -23,7 +23,8 @@ var laserPointer = (function () { function isHandPointing(hand) { var MINIMUM_TRIGGER_PULL = 0.9; - return Controller.getTriggerValue(hand) > MINIMUM_TRIGGER_PULL; + var controller = hand === 0 ? Controller.Standard.LT : Controller.Standard.RT; + return Controller.getValue(controller) > MINIMUM_TRIGGER_PULL; } function isFingerPointing(hand) { From 6e076985f2ececbb2013cb14d7f72e346ce91394 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 25 Nov 2015 16:46:53 +1300 Subject: [PATCH 6/6] JSLint --- examples/controllers/leap/laserPointer.js | 5 +++-- examples/controllers/leap/leapHands.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/controllers/leap/laserPointer.js b/examples/controllers/leap/laserPointer.js index c8c3cf372a..c7d72e6cff 100644 --- a/examples/controllers/leap/laserPointer.js +++ b/examples/controllers/leap/laserPointer.js @@ -22,8 +22,9 @@ var laserPointer = (function () { ]; function isHandPointing(hand) { - var MINIMUM_TRIGGER_PULL = 0.9; - var controller = hand === 0 ? Controller.Standard.LT : Controller.Standard.RT; + var MINIMUM_TRIGGER_PULL = 0.9, + controller; + controller = hand === 0 ? Controller.Standard.LT : Controller.Standard.RT; return Controller.getValue(controller) > MINIMUM_TRIGGER_PULL; } diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 42df89084d..7835df7452 100644 --- a/examples/controllers/leap/leapHands.js +++ b/examples/controllers/leap/leapHands.js @@ -196,7 +196,7 @@ var leapHands = (function () { MyAvatar.setJointRotation("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0)); MyAvatar.setJointRotation("LeftForeArm", Quat.fromPitchYawRollDegrees(0.0, 90.0, 90.0)); MyAvatar.setJointRotation("LeftHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); - MyAvatar.setJointRotation("RightArm", Quat.fromPitchYawRollDegrees(90.0,0.0, 0.0)); + MyAvatar.setJointRotation("RightArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0)); MyAvatar.setJointRotation("RightForeArm", Quat.fromPitchYawRollDegrees(0.0, -90.0, -90.0)); MyAvatar.setJointRotation("RightHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0)); @@ -384,7 +384,7 @@ var leapHands = (function () { x: -handRotation.x, y: -handRotation.z, z: -handRotation.y, - w: handRotation.w, + w: handRotation.w }; // Hand rotation in avatar coordinates ... @@ -414,7 +414,7 @@ var leapHands = (function () { x: -handRotation.x, y: -handRotation.z, z: -handRotation.y, - w: handRotation.w, + w: handRotation.w }; // Hand rotation in avatar coordinates ...