diff --git a/examples/controllers/leap/laserPointer.js b/examples/controllers/leap/laserPointer.js index 156e9ba298..c7d72e6cff 100644 --- a/examples/controllers/leap/laserPointer.js +++ b/examples/controllers/leap/laserPointer.js @@ -22,8 +22,10 @@ var laserPointer = (function () { ]; function isHandPointing(hand) { - var MINIMUM_TRIGGER_PULL = 0.9; - return Controller.getTriggerValue(hand) > MINIMUM_TRIGGER_PULL; + var MINIMUM_TRIGGER_PULL = 0.9, + controller; + controller = hand === 0 ? Controller.Standard.LT : Controller.Standard.RT; + return Controller.getValue(controller) > MINIMUM_TRIGGER_PULL; } function isFingerPointing(hand) { diff --git a/examples/controllers/leap/leapHands.js b/examples/controllers/leap/leapHands.js index 6bdca051be..7835df7452 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); @@ -382,23 +381,14 @@ var leapHands = (function () { // Hand rotation in camera coordinates ... handRotation = { - x: handRotation.z, - y: handRotation.y, - z: handRotation.x, + 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); @@ -421,22 +411,14 @@ var leapHands = (function () { // Hand rotation in camera coordinates ... handRotation = { - x: handRotation.z, - y: handRotation.y, - z: handRotation.x, + 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 +444,7 @@ var leapHands = (function () { w: locRotation.w }; } - MyAvatar.setJointData(fingers[h][i][j].jointName, locRotation); + MyAvatar.setJointRotation(fingers[h][i][j].jointName, locRotation); } } } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5ac14ac0ec..c0315c44e3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2856,6 +2856,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 547f16ea8b..11053154b6 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -84,13 +84,12 @@ 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(); + } // Look for device DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); @@ -110,18 +109,24 @@ 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()); } +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 4c69551dd2..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); @@ -96,8 +98,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) {