mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-29 06:50:04 +02:00
Merge pull request #6487 from ctrlaltdavid/20740
Get the Leap Motion working again
This commit is contained in:
commit
52d6fdac1a
6 changed files with 41 additions and 47 deletions
|
@ -22,8 +22,10 @@ var laserPointer = (function () {
|
||||||
];
|
];
|
||||||
|
|
||||||
function isHandPointing(hand) {
|
function isHandPointing(hand) {
|
||||||
var MINIMUM_TRIGGER_PULL = 0.9;
|
var MINIMUM_TRIGGER_PULL = 0.9,
|
||||||
return Controller.getTriggerValue(hand) > MINIMUM_TRIGGER_PULL;
|
controller;
|
||||||
|
controller = hand === 0 ? Controller.Standard.LT : Controller.Standard.RT;
|
||||||
|
return Controller.getValue(controller) > MINIMUM_TRIGGER_PULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFingerPointing(hand) {
|
function isFingerPointing(hand) {
|
||||||
|
|
|
@ -193,13 +193,12 @@ var leapHands = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set avatar arms vertical, forearms horizontal, as "zero" position for calibration
|
// Set avatar arms vertical, forearms horizontal, as "zero" position for calibration
|
||||||
MyAvatar.setJointData("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, -90.0));
|
MyAvatar.setJointRotation("LeftArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0));
|
||||||
MyAvatar.setJointData("LeftForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0));
|
MyAvatar.setJointRotation("LeftForeArm", Quat.fromPitchYawRollDegrees(0.0, 90.0, 90.0));
|
||||||
MyAvatar.setJointData("LeftHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0));
|
MyAvatar.setJointRotation("LeftHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0));
|
||||||
MyAvatar.setJointData("RightArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 90.0));
|
MyAvatar.setJointRotation("RightArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 0.0));
|
||||||
MyAvatar.setJointData("RightForeArm", Quat.fromPitchYawRollDegrees(90.0, 0.0, 180.0));
|
MyAvatar.setJointRotation("RightForeArm", Quat.fromPitchYawRollDegrees(0.0, -90.0, -90.0));
|
||||||
MyAvatar.setJointData("RightHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0));
|
MyAvatar.setJointRotation("RightHand", Quat.fromPitchYawRollRadians(0.0, 0.0, 0.0));
|
||||||
|
|
||||||
|
|
||||||
// Wait for arms to assume their positions before calculating
|
// Wait for arms to assume their positions before calculating
|
||||||
Script.setTimeout(finishCalibration, CALIBRATION_TIME);
|
Script.setTimeout(finishCalibration, CALIBRATION_TIME);
|
||||||
|
@ -382,23 +381,14 @@ var leapHands = (function () {
|
||||||
|
|
||||||
// Hand rotation in camera coordinates ...
|
// Hand rotation in camera coordinates ...
|
||||||
handRotation = {
|
handRotation = {
|
||||||
x: handRotation.z,
|
x: -handRotation.x,
|
||||||
y: handRotation.y,
|
y: -handRotation.z,
|
||||||
z: handRotation.x,
|
z: -handRotation.y,
|
||||||
w: handRotation.w
|
w: handRotation.w
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hand rotation in avatar coordinates ...
|
// Hand rotation in avatar coordinates ...
|
||||||
if (h === 0) {
|
handRotation = Quat.multiply(Quat.angleAxis(180.0, { x: 0, y: 1, z: 0 }), handRotation);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraOrientation.x = -cameraOrientation.x;
|
cameraOrientation.x = -cameraOrientation.x;
|
||||||
cameraOrientation.z = -cameraOrientation.z;
|
cameraOrientation.z = -cameraOrientation.z;
|
||||||
handRotation = Quat.multiply(cameraOrientation, handRotation);
|
handRotation = Quat.multiply(cameraOrientation, handRotation);
|
||||||
|
@ -421,22 +411,14 @@ var leapHands = (function () {
|
||||||
|
|
||||||
// Hand rotation in camera coordinates ...
|
// Hand rotation in camera coordinates ...
|
||||||
handRotation = {
|
handRotation = {
|
||||||
x: handRotation.z,
|
x: -handRotation.x,
|
||||||
y: handRotation.y,
|
y: -handRotation.z,
|
||||||
z: handRotation.x,
|
z: -handRotation.y,
|
||||||
w: handRotation.w
|
w: handRotation.w
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hand rotation in avatar coordinates ...
|
// Hand rotation in avatar coordinates ...
|
||||||
if (h === 0) {
|
handRotation = Quat.multiply(Quat.angleAxis(90.0, { x: 1, y: 0, z: 0 }), handRotation);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set hand position and orientation ...
|
// Set hand position and orientation ...
|
||||||
|
@ -462,7 +444,7 @@ var leapHands = (function () {
|
||||||
w: locRotation.w
|
w: locRotation.w
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MyAvatar.setJointData(fingers[h][i][j].jointName, locRotation);
|
MyAvatar.setJointRotation(fingers[h][i][j].jointName, locRotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2856,6 +2856,8 @@ void Application::update(float deltaTime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_controllerScriptingInterface->updateInputControllers();
|
||||||
|
|
||||||
// Transfer the user inputs to the driveKeys
|
// Transfer the user inputs to the driveKeys
|
||||||
// FIXME can we drop drive keys and just have the avatar read the action states directly?
|
// FIXME can we drop drive keys and just have the avatar read the action states directly?
|
||||||
myAvatar->clearDriveKeys();
|
myAvatar->clearDriveKeys();
|
||||||
|
|
|
@ -84,14 +84,13 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const {
|
||||||
return qApp->getUiSize();
|
return qApp->getUiSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::InputController::Pointer ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
|
controller::InputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
|
||||||
// This is where we retreive the Device Tracker category and then the sub tracker within it
|
// This is where we retrieve the Device Tracker category and then the sub tracker within it
|
||||||
auto icIt = _inputControllers.find(0);
|
auto icIt = _inputControllers.find(0);
|
||||||
if (icIt != _inputControllers.end()) {
|
if (icIt != _inputControllers.end()) {
|
||||||
return (*icIt).second;
|
return (*icIt).second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Look for device
|
// Look for device
|
||||||
DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString());
|
DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString());
|
||||||
if (deviceID < 0) {
|
if (deviceID < 0) {
|
||||||
|
@ -110,18 +109,24 @@ controller::InputController::Pointer ControllerScriptingInterface::createInputCo
|
||||||
controller::InputController::Pointer inputController = std::make_shared<InputController>(deviceID, trackerID, this);
|
controller::InputController::Pointer inputController = std::make_shared<InputController>(deviceID, trackerID, this);
|
||||||
controller::InputController::Key key = inputController->getKey();
|
controller::InputController::Key key = inputController->getKey();
|
||||||
_inputControllers.insert(InputControllerMap::value_type(key, inputController));
|
_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());
|
_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) :
|
InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :
|
||||||
_deviceTrackerId(deviceTrackerId),
|
_deviceTrackerId(deviceTrackerId),
|
||||||
_subTrackerId(subTrackerId),
|
_subTrackerId(subTrackerId),
|
||||||
|
|
|
@ -85,6 +85,8 @@ public:
|
||||||
bool isKeyCaptured(const KeyEvent& event) const;
|
bool isKeyCaptured(const KeyEvent& event) const;
|
||||||
bool isJoystickCaptured(int joystickIndex) const;
|
bool isJoystickCaptured(int joystickIndex) const;
|
||||||
|
|
||||||
|
void updateInputControllers();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
virtual void captureKeyEvents(const KeyEvent& event);
|
virtual void captureKeyEvents(const KeyEvent& event);
|
||||||
|
@ -96,8 +98,8 @@ public slots:
|
||||||
virtual glm::vec2 getViewportDimensions() const;
|
virtual glm::vec2 getViewportDimensions() const;
|
||||||
|
|
||||||
/// Factory to create an InputController
|
/// Factory to create an InputController
|
||||||
virtual controller::InputController::Pointer createInputController(const QString& deviceName, const QString& tracker);
|
virtual controller::InputController* createInputController(const QString& deviceName, const QString& tracker);
|
||||||
virtual void releaseInputController(controller::InputController::Pointer input);
|
virtual void releaseInputController(controller::InputController* input);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void keyPressEvent(const KeyEvent& event);
|
void keyPressEvent(const KeyEvent& event);
|
||||||
|
|
|
@ -81,6 +81,9 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) {
|
||||||
out = qobject_cast<AvatarData*>(object.toQObject());
|
out = qobject_cast<AvatarData*>(object.toQObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(controller::InputController*)
|
||||||
|
static int inputControllerPointerId = qRegisterMetaType<controller::InputController*>();
|
||||||
|
|
||||||
QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) {
|
QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) {
|
||||||
return engine->newQObject(in);
|
return engine->newQObject(in);
|
||||||
}
|
}
|
||||||
|
@ -89,8 +92,6 @@ void inputControllerFromScriptValue(const QScriptValue &object, controller::Inpu
|
||||||
out = qobject_cast<controller::InputController*>(object.toQObject());
|
out = qobject_cast<controller::InputController*>(object.toQObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool hasCorrectSyntax(const QScriptProgram& program) {
|
static bool hasCorrectSyntax(const QScriptProgram& program) {
|
||||||
const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
|
const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
|
||||||
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
||||||
|
|
Loading…
Reference in a new issue