Showing the changes to libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp (1 of 52 files). Show all
Unified · Split
| @@ -12,15 +12,19 @@ · 11 unmodified lines | ||
| 12 | 12 | #include "ViveControllerManager.h" |
| 13 | 13 | |
| 14 | 14 | #include <PerfStat.h> |
| 15 | − | |
| 16 | −#include "GeometryCache.h" | |
| 15 | +#include <PathUtils.h> | |
| 16 | +#include <GeometryCache.h> | |
| 17 | 17 | #include <gpu/Batch.h> |
| 18 | 18 | #include <gpu/Context.h> |
| 19 | 19 | #include <DeferredLightingEffect.h> |
| 20 | 20 | #include <display-plugins/openvr/OpenVrHelpers.h> |
| 21 | −#include "NumericalConstants.h" | |
| 21 | +#include <NumericalConstants.h> | |
| 22 | 22 | #include <plugins/PluginContainer.h> |
| 23 | −#include "UserActivityLogger.h" | |
| 23 | +#include <UserActivityLogger.h> | |
| 24 | + | |
| 25 | +#include <controllers/UserInputMapper.h> | |
| 26 | + | |
| 27 | +#include <controllers/StandardControls.h> | |
| 24 | 28 | |
| 25 | 29 | #ifdef Q_OS_WIN |
| 26 | 30 | extern vr::IVRSystem* _hmd; |
| @@ -29,18 +33,6 @@ extern vr::TrackedDevicePose_t _trackedDevicePose[vr::k_unMaxTrackedDeviceCount] · 2 unmodified lines | ||
| 29 | 33 | extern mat4 _trackedDevicePoseMat4[vr::k_unMaxTrackedDeviceCount]; |
| 30 | 34 | #endif |
| 31 | 35 | |
| 32 | −const unsigned int LEFT_MASK = 0U; | |
| 33 | −const unsigned int RIGHT_MASK = 1U; | |
| 34 | − | |
| 35 | −const uint64_t VR_BUTTON_A = 1U << 1; | |
| 36 | −const uint64_t VR_GRIP_BUTTON = 1U << 2; | |
| 37 | −const uint64_t VR_TRACKPAD_BUTTON = 1ULL << 32; | |
| 38 | −const uint64_t VR_TRIGGER_BUTTON = 1ULL << 33; | |
| 39 | − | |
| 40 | −const unsigned int BUTTON_A = 1U << 1; | |
| 41 | −const unsigned int GRIP_BUTTON = 1U << 2; | |
| 42 | −const unsigned int TRACKPAD_BUTTON = 1U << 3; | |
| 43 | −const unsigned int TRIGGER_BUTTON = 1U << 4; | |
| 44 | 36 | |
| 45 | 37 | const float CONTROLLER_LENGTH_OFFSET = 0.0762f; // three inches |
| 46 | 38 | const QString CONTROLLER_MODEL_STRING = "vr_controller_05_wireless_b"; |
| @@ -173,8 +165,8 @@ void ViveControllerManager::updateRendering(RenderArgs* args, render::ScenePoint · 126 unmodified lines | ||
| 173 | 165 | //pendingChanges.updateItem(_leftHandRenderID, ); |
| 174 | 166 | |
| 175 | 167 | |
| 176 | − UserInputMapper::PoseValue leftHand = _poseStateMap[makeInput(JointChannel::LEFT_HAND).getChannel()]; | |
| 177 | − UserInputMapper::PoseValue rightHand = _poseStateMap[makeInput(JointChannel::RIGHT_HAND).getChannel()]; | |
| 168 | + controller::Pose leftHand = _poseStateMap[controller::StandardPoseChannel::LEFT_HAND]; | |
| 169 | + controller::Pose rightHand = _poseStateMap[controller::StandardPoseChannel::RIGHT_HAND]; | |
| 178 | 170 | |
| 179 | 171 | gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { |
| 180 | 172 | auto geometryCache = DependencyManager::get<GeometryCache>(); |
| @@ -186,21 +178,20 @@ void ViveControllerManager::updateRendering(RenderArgs* args, render::ScenePoint · 5 unmodified lines | ||
| 186 | 178 | //batch._glBindTexture(GL_TEXTURE_2D, _uexture); |
| 187 | 179 | |
| 188 | 180 | if (leftHand.isValid()) { |
| 189 | − renderHand(leftHand, batch, LEFT_HAND); | |
| 181 | + renderHand(leftHand, batch, 1); | |
| 190 | 182 | } |
| 191 | 183 | if (rightHand.isValid()) { |
| 192 | − renderHand(rightHand, batch, RIGHT_HAND); | |
| 184 | + renderHand(rightHand, batch, -1); | |
| 193 | 185 | } |
| 194 | 186 | }); |
| 195 | 187 | } |
| 196 | 188 | } |
| 197 | 189 | |
| 198 | −void ViveControllerManager::renderHand(UserInputMapper::PoseValue pose, gpu::Batch& batch, int index) { | |
| 199 | − auto userInputMapper = DependencyManager::get<UserInputMapper>(); | |
| 190 | +void ViveControllerManager::renderHand(const controller::Pose& pose, gpu::Batch& batch, int sign) { | |
| 191 | + auto userInputMapper = DependencyManager::get<controller::UserInputMapper>(); | |
| 200 | 192 | Transform transform(userInputMapper->getSensorToWorldMat()); |
| 201 | 193 | transform.postTranslate(pose.getTranslation() + pose.getRotation() * glm::vec3(0, 0, CONTROLLER_LENGTH_OFFSET)); |
| 202 | 194 | |
| 203 | − int sign = index == LEFT_HAND ? 1 : -1; | |
| 204 | 195 | glm::quat rotation = pose.getRotation() * glm::angleAxis(PI, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::angleAxis(sign * PI_OVER_TWO, glm::vec3(0.0f, 0.0f, 1.0f)); |
| 205 | 196 | transform.postRotate(rotation); |
| 206 | 197 | |
| @@ -251,6 +242,7 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) { · 44 unmodified lines | ||
| 251 | 242 | } |
| 252 | 243 | |
| 253 | 244 | numTrackedControllers++; |
| 245 | + bool left = numTrackedControllers == 1; | |
| 254 | 246 | |
| 255 | 247 | const mat4& mat = _trackedDevicePoseMat4[device]; |
| 256 | 248 | |
| @@ -264,14 +256,18 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) { · 7 unmodified lines | ||
| 264 | 256 | //qDebug() << (numTrackedControllers == 1 ? "Left: " : "Right: "); |
| 265 | 257 | //qDebug() << "Trackpad: " << controllerState.rAxis[0].x << " " << controllerState.rAxis[0].y; |
| 266 | 258 | //qDebug() << "Trigger: " << controllerState.rAxis[1].x << " " << controllerState.rAxis[1].y; |
| 267 | − handleButtonEvent(controllerState.ulButtonPressed, numTrackedControllers - 1); | |
| 268 | − for (int i = 0; i < vr::k_unControllerStateAxisCount; i++) { | |
| 269 | − handleAxisEvent(Axis(i), controllerState.rAxis[i].x, controllerState.rAxis[i].y, numTrackedControllers - 1); | |
| 259 | + for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) { | |
| 260 | + auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i); | |
| 261 | + bool pressed = 0 != (controllerState.ulButtonPressed & mask); | |
| 262 | + handleButtonEvent(i, pressed, left); | |
| 263 | + } | |
| 264 | + for (uint32_t i = 0; i < vr::k_unControllerStateAxisCount; i++) { | |
| 265 | + handleAxisEvent(i, controllerState.rAxis[i].x, controllerState.rAxis[i].y, left); | |
| 270 | 266 | } |
| 271 | 267 | } |
| 272 | 268 | } |
| 273 | 269 | |
| 274 | − auto userInputMapper = DependencyManager::get<UserInputMapper>(); | |
| 270 | + auto userInputMapper = DependencyManager::get<controller::UserInputMapper>(); | |
| 275 | 271 | |
| 276 | 272 | if (numTrackedControllers == 0) { |
| 277 | 273 | if (_deviceID != 0) { |
| @@ -282,8 +278,7 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) { · 4 unmodified lines | ||
| 282 | 278 | } |
| 283 | 279 | |
| 284 | 280 | if (_trackedControllers == 0 && numTrackedControllers > 0) { |
| 285 | − registerToUserInputMapper(*userInputMapper); | |
| 286 | − assignDefaultInputMapping(*userInputMapper); | |
| 281 | + userInputMapper->registerDevice(this); | |
| 287 | 282 | UserActivityLogger::getInstance().connectedDevice("spatial_controller", "steamVR"); |
| 288 | 283 | } |
| 289 | 284 | |
| @@ -296,33 +291,41 @@ void ViveControllerManager::focusOutEvent() { · 6 unmodified lines | ||
| 296 | 291 | _buttonPressedMap.clear(); |
| 297 | 292 | }; |
| 298 | 293 | |
| 299 | −void ViveControllerManager::handleAxisEvent(Axis axis, float x, float y, int index) { | |
| 300 | − if (axis == TRACKPAD_AXIS) { | |
| 301 | − _axisStateMap[makeInput(AXIS_Y_POS, index).getChannel()] = (y > 0.0f) ? y : 0.0f; | |
| 302 | − _axisStateMap[makeInput(AXIS_Y_NEG, index).getChannel()] = (y < 0.0f) ? -y : 0.0f; | |
| 303 | − _axisStateMap[makeInput(AXIS_X_POS, index).getChannel()] = (x > 0.0f) ? x : 0.0f; | |
| 304 | − _axisStateMap[makeInput(AXIS_X_NEG, index).getChannel()] = (x < 0.0f) ? -x : 0.0f; | |
| 305 | − } else if (axis == TRIGGER_AXIS) { | |
| 306 | − _axisStateMap[makeInput(BACK_TRIGGER, index).getChannel()] = x; | |
| 294 | +// These functions do translation from the Steam IDs to the standard controller IDs | |
| 295 | +void ViveControllerManager::handleAxisEvent(uint32_t axis, float x, float y, bool left) { | |
| 296 | +#ifdef Q_OS_WIN | |
| 297 | + using namespace controller; | |
| 298 | + if (axis == vr::k_EButton_SteamVR_Touchpad) { | |
| 299 | + _axisStateMap[left ? LX : RX] = x; | |
| 300 | + _axisStateMap[left ? LY : RY] = y; | |
| 301 | + } else if (axis == vr::k_EButton_SteamVR_Trigger) { | |
| 302 | + _axisStateMap[left ? LT : RT] = x; | |
| 307 | 303 | } |
| 304 | +#endif | |
| 308 | 305 | } |
| 309 | 306 | |
| 310 | −void ViveControllerManager::handleButtonEvent(uint64_t buttons, int index) { | |
| 311 | − if (buttons & VR_BUTTON_A) { | |
| 312 | − _buttonPressedMap.insert(makeInput(BUTTON_A, index).getChannel()); | |
| 313 | − } | |
| 314 | − if (buttons & VR_GRIP_BUTTON) { | |
| 315 | − _buttonPressedMap.insert(makeInput(GRIP_BUTTON, index).getChannel()); | |
| 316 | − } | |
| 317 | − if (buttons & VR_TRACKPAD_BUTTON) { | |
| 318 | − _buttonPressedMap.insert(makeInput(TRACKPAD_BUTTON, index).getChannel()); | |
| 307 | +// These functions do translation from the Steam IDs to the standard controller IDs | |
| 308 | +void ViveControllerManager::handleButtonEvent(uint32_t button, bool pressed, bool left) { | |
| 309 | +#ifdef Q_OS_WIN | |
| 310 | + if (!pressed) { | |
| 311 | + return; | |
| 319 | 312 | } |
| 320 | − if (buttons & VR_TRIGGER_BUTTON) { | |
| 321 | − _buttonPressedMap.insert(makeInput(TRIGGER_BUTTON, index).getChannel()); | |
| 313 | + | |
| 314 | + if (button == vr::k_EButton_ApplicationMenu) { | |
| 315 | + // FIXME? | |
| 316 | + _buttonPressedMap.insert(left ? controller::A : controller::A); | |
| 317 | + } else if (button == vr::k_EButton_Grip) { | |
| 318 | + // Tony says these are harder to reach, so make them the meta buttons | |
| 319 | + _buttonPressedMap.insert(left ? controller::BACK : controller::START); | |
| 320 | + } else if (button == vr::k_EButton_SteamVR_Trigger) { | |
| 321 | + _buttonPressedMap.insert(left ? controller::LB : controller::RB); | |
| 322 | + } else if (button == vr::k_EButton_SteamVR_Touchpad) { | |
| 323 | + _buttonPressedMap.insert(left ? controller::LS : controller::RS); | |
| 322 | 324 | } |
| 325 | +#endif | |
| 323 | 326 | } |
| 324 | 327 | |
| 325 | −void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) { | |
| 328 | +void ViveControllerManager::handlePoseEvent(const mat4& mat, bool left) { | |
| 326 | 329 | glm::vec3 position = extractTranslation(mat); |
| 327 | 330 | glm::quat rotation = glm::quat_cast(mat); |
| 328 | 331 | |
| @@ -378,7 +381,7 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) { · 49 unmodified lines | ||
| 378 | 381 | |
| 379 | 382 | const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f)); |
| 380 | 383 | const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); |
| 381 | − float sign = (index == LEFT_HAND) ? -1.0f : 1.0f; | |
| 384 | + float sign = left ? -1.0f : 1.0f; | |
| 382 | 385 | const glm::quat signedQuaterZ = glm::angleAxis(sign * PI / 2.0f, glm::vec3(0.0f, 0.0f, 1.0f)); |
| 383 | 386 | const glm::quat eighthX = glm::angleAxis(PI / 4.0f, glm::vec3(1.0f, 0.0f, 0.0f)); |
| 384 | 387 | const glm::quat offset = glm::inverse(signedQuaterZ * eighthX); |
| @@ -386,92 +389,93 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) { · 1 unmodified line | ||
| 386 | 389 | |
| 387 | 390 | position += rotation * glm::vec3(0, 0, -CONTROLLER_LENGTH_OFFSET); |
| 388 | 391 | |
| 389 | − _poseStateMap[makeInput(JointChannel(index)).getChannel()] = UserInputMapper::PoseValue(position, rotation); | |
| 392 | + _poseStateMap[left ? controller::LEFT_HAND : controller::RIGHT_HAND] = controller::Pose(position, rotation); | |
| 390 | 393 | } |
| 391 | 394 | |
| 392 | −void ViveControllerManager::registerToUserInputMapper(UserInputMapper& mapper) { | |
| 393 | − // Grab the current free device ID | |
| 394 | − _deviceID = mapper.getFreeDeviceID(); | |
| 395 | − | |
| 396 | − auto proxy = UserInputMapper::DeviceProxy::Pointer(new UserInputMapper::DeviceProxy(_name)); | |
| 397 | − proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); }; | |
| 398 | − proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); }; | |
| 399 | − proxy->getPose = [this](const UserInputMapper::Input& input, int timestamp) -> UserInputMapper::PoseValue { return this->getPose(input.getChannel()); }; | |
| 400 | − proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> { | |
| 401 | − QVector<UserInputMapper::InputPair> availableInputs; | |
| 402 | − availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_HAND), "Left Hand")); | |
| 403 | − | |
| 404 | − availableInputs.append(UserInputMapper::InputPair(makeInput(BUTTON_A, 0), "Left Button A")); | |
| 405 | − availableInputs.append(UserInputMapper::InputPair(makeInput(GRIP_BUTTON, 0), "Left Grip Button")); | |
| 406 | − availableInputs.append(UserInputMapper::InputPair(makeInput(TRACKPAD_BUTTON, 0), "Left Trackpad Button")); | |
| 407 | − availableInputs.append(UserInputMapper::InputPair(makeInput(TRIGGER_BUTTON, 0), "Left Trigger Button")); | |
| 408 | − | |
| 409 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_Y_POS, 0), "Left Trackpad Up")); | |
| 410 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_Y_NEG, 0), "Left Trackpad Down")); | |
| 411 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_X_POS, 0), "Left Trackpad Right")); | |
| 412 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_X_NEG, 0), "Left Trackpad Left")); | |
| 413 | − availableInputs.append(UserInputMapper::InputPair(makeInput(BACK_TRIGGER, 0), "Left Back Trigger")); | |
| 395 | +void ViveControllerManager::buildDeviceProxy(controller::DeviceProxy::Pointer proxy) { | |
| 396 | + using namespace controller; | |
| 397 | + proxy->_name = _name; | |
| 398 | + proxy->getButton = [this](const Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); }; | |
| 399 | + proxy->getAxis = [this](const Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); }; | |
| 400 | + proxy->getPose = [this](const Input& input, int timestamp) -> Pose { return this->getPose(input.getChannel()); }; | |
| 401 | + proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> { | |
| 402 | + QVector<Input::NamedPair> availableInputs{ | |
| 403 | + // Trackpad analogs | |
| 404 | + makePair(LX, "LX"), | |
| 405 | + makePair(LY, "LY"), | |
| 406 | + makePair(RX, "RX"), | |
| 407 | + makePair(RY, "RY"), | |
| 408 | + // trigger analogs | |
| 409 | + makePair(LT, "LT"), | |
| 410 | + makePair(RT, "RT"), | |
| 411 | + | |
| 412 | + makePair(LB, "LB"), | |
| 413 | + makePair(RB, "RB"), | |
| 414 | + | |
| 415 | + makePair(LS, "LS"), | |
| 416 | + makePair(RS, "RS"), | |
| 417 | + }; | |
| 418 | + | |
| 419 | + //availableInputs.append(Input::NamedPair(makeInput(LEFT_HAND), "Left Hand")); | |
| 420 | + | |
| 421 | + //availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 0), "Left Button A")); | |
| 422 | + //availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 0), "Left Grip Button")); | |
| 423 | + //availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 0), "Left Trackpad Button")); | |
| 424 | + //availableInputs.append(Input::NamedPair(makeInput(TRIGGER_BUTTON, 0), "Left Trigger Button")); | |
| 425 | + | |
| 426 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_POS, 0), "Left Trackpad Up")); | |
| 427 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_NEG, 0), "Left Trackpad Down")); | |
| 428 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_X_POS, 0), "Left Trackpad Right")); | |
| 429 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_X_NEG, 0), "Left Trackpad Left")); | |
| 430 | + //availableInputs.append(Input::NamedPair(makeInput(BACK_TRIGGER, 0), "Left Back Trigger")); | |
| 431 | + | |
| 432 | + | |
| 433 | + //availableInputs.append(Input::NamedPair(makeInput(RIGHT_HAND), "Right Hand")); | |
| 434 | + | |
| 435 | + //availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 1), "Right Button A")); | |
| 436 | + //availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 1), "Right Grip Button")); | |
| 437 | + //availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 1), "Right Trackpad Button")); | |
| 438 | + //availableInputs.append(Input::NamedPair(makeInput(TRIGGER_BUTTON, 1), "Right Trigger Button")); | |
| 439 | + | |
| 440 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_POS, 1), "Right Trackpad Up")); | |
| 441 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_NEG, 1), "Right Trackpad Down")); | |
| 442 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_X_POS, 1), "Right Trackpad Right")); | |
| 443 | + //availableInputs.append(Input::NamedPair(makeInput(AXIS_X_NEG, 1), "Right Trackpad Left")); | |
| 444 | + //availableInputs.append(Input::NamedPair(makeInput(BACK_TRIGGER, 1), "Right Back Trigger")); | |
| 414 | 445 | |
| 415 | − | |
| 416 | − availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_HAND), "Right Hand")); | |
| 417 | − | |
| 418 | − availableInputs.append(UserInputMapper::InputPair(makeInput(BUTTON_A, 1), "Right Button A")); | |
| 419 | − availableInputs.append(UserInputMapper::InputPair(makeInput(GRIP_BUTTON, 1), "Right Grip Button")); | |
| 420 | − availableInputs.append(UserInputMapper::InputPair(makeInput(TRACKPAD_BUTTON, 1), "Right Trackpad Button")); | |
| 421 | − availableInputs.append(UserInputMapper::InputPair(makeInput(TRIGGER_BUTTON, 1), "Right Trigger Button")); | |
| 422 | − | |
| 423 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_Y_POS, 1), "Right Trackpad Up")); | |
| 424 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_Y_NEG, 1), "Right Trackpad Down")); | |
| 425 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_X_POS, 1), "Right Trackpad Right")); | |
| 426 | − availableInputs.append(UserInputMapper::InputPair(makeInput(AXIS_X_NEG, 1), "Right Trackpad Left")); | |
| 427 | − availableInputs.append(UserInputMapper::InputPair(makeInput(BACK_TRIGGER, 1), "Right Back Trigger")); | |
| 428 | − | |
| 429 | 446 | return availableInputs; |
| 430 | 447 | }; |
| 431 | − proxy->resetDeviceBindings = [this, &mapper] () -> bool { | |
| 432 | − mapper.removeAllInputChannelsForDevice(_deviceID); | |
| 433 | − this->assignDefaultInputMapping(mapper); | |
| 434 | − return true; | |
| 435 | − }; | |
| 436 | − mapper.registerDevice(_deviceID, proxy); | |
| 437 | −} | |
| 438 | − | |
| 439 | −void ViveControllerManager::assignDefaultInputMapping(UserInputMapper& mapper) { | |
| 440 | − const float JOYSTICK_MOVE_SPEED = 1.0f; | |
| 441 | − | |
| 442 | − // Left Trackpad: Movement, strafing | |
| 443 | − mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(AXIS_Y_POS, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 444 | − mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(AXIS_Y_NEG, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 445 | − mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(AXIS_X_POS, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 446 | − mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(AXIS_X_NEG, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 447 | − | |
| 448 | − // Right Trackpad: Vertical movement, zooming | |
| 449 | − mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(AXIS_Y_POS, 1), makeInput(TRACKPAD_BUTTON, 1), JOYSTICK_MOVE_SPEED); | |
| 450 | − mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(AXIS_Y_NEG, 1), makeInput(TRACKPAD_BUTTON, 1), JOYSTICK_MOVE_SPEED); | |
| 451 | − | |
| 452 | − // Buttons | |
| 453 | − mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_A, 0)); | |
| 454 | − mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_A, 1)); | |
| 455 | − | |
| 456 | − mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(GRIP_BUTTON, 0)); | |
| 457 | − mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(GRIP_BUTTON, 1)); | |
| 458 | − | |
| 459 | − mapper.addInputChannel(UserInputMapper::LEFT_HAND_CLICK, makeInput(BACK_TRIGGER, 0)); | |
| 460 | − mapper.addInputChannel(UserInputMapper::RIGHT_HAND_CLICK, makeInput(BACK_TRIGGER, 1)); | |
| 461 | − | |
| 462 | − // Hands | |
| 463 | − mapper.addInputChannel(UserInputMapper::LEFT_HAND, makeInput(LEFT_HAND)); | |
| 464 | − mapper.addInputChannel(UserInputMapper::RIGHT_HAND, makeInput(RIGHT_HAND)); | |
| 465 | −} | |
| 466 | − | |
| 467 | −UserInputMapper::Input ViveControllerManager::makeInput(unsigned int button, int index) { | |
| 468 | − return UserInputMapper::Input(_deviceID, button | (index == 0 ? LEFT_MASK : RIGHT_MASK), UserInputMapper::ChannelType::BUTTON); | |
| 469 | 448 | } |
| 470 | 449 | |
| 471 | −UserInputMapper::Input ViveControllerManager::makeInput(ViveControllerManager::JoystickAxisChannel axis, int index) { | |
| 472 | − return UserInputMapper::Input(_deviceID, axis | (index == 0 ? LEFT_MASK : RIGHT_MASK), UserInputMapper::ChannelType::AXIS); | |
| 450 | +QString ViveControllerManager::getDefaultMappingConfig() { | |
| 451 | + static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/vive.json"; | |
| 452 | + return MAPPING_JSON; | |
| 473 | 453 | } |
| 474 | 454 | |
| 475 | −UserInputMapper::Input ViveControllerManager::makeInput(JointChannel joint) { | |
| 476 | − return UserInputMapper::Input(_deviceID, joint, UserInputMapper::ChannelType::POSE); | |
| 477 | −} | |
| 455 | +//void ViveControllerManager::assignDefaultInputMapping(UserInputMapper& mapper) { | |
| 456 | +// const float JOYSTICK_MOVE_SPEED = 1.0f; | |
| 457 | +// | |
| 458 | +// // Left Trackpad: Movement, strafing | |
| 459 | +// mapper.addInputChannel(UserInputMapper::LONGITUDINAL_FORWARD, makeInput(AXIS_Y_POS, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 460 | +// mapper.addInputChannel(UserInputMapper::LONGITUDINAL_BACKWARD, makeInput(AXIS_Y_NEG, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 461 | +// mapper.addInputChannel(UserInputMapper::LATERAL_RIGHT, makeInput(AXIS_X_POS, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 462 | +// mapper.addInputChannel(UserInputMapper::LATERAL_LEFT, makeInput(AXIS_X_NEG, 0), makeInput(TRACKPAD_BUTTON, 0), JOYSTICK_MOVE_SPEED); | |
| 463 | +// | |
| 464 | +// // Right Trackpad: Vertical movement, zooming | |
| 465 | +// mapper.addInputChannel(UserInputMapper::VERTICAL_UP, makeInput(AXIS_Y_POS, 1), makeInput(TRACKPAD_BUTTON, 1), JOYSTICK_MOVE_SPEED); | |
| 466 | +// mapper.addInputChannel(UserInputMapper::VERTICAL_DOWN, makeInput(AXIS_Y_NEG, 1), makeInput(TRACKPAD_BUTTON, 1), JOYSTICK_MOVE_SPEED); | |
| 467 | +// | |
| 468 | +// // Buttons | |
| 469 | +// mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_A, 0)); | |
| 470 | +// mapper.addInputChannel(UserInputMapper::SHIFT, makeInput(BUTTON_A, 1)); | |
| 471 | +// | |
| 472 | +// mapper.addInputChannel(UserInputMapper::ACTION1, makeInput(GRIP_BUTTON, 0)); | |
| 473 | +// mapper.addInputChannel(UserInputMapper::ACTION2, makeInput(GRIP_BUTTON, 1)); | |
| 474 | +// | |
| 475 | +// mapper.addInputChannel(UserInputMapper::LEFT_HAND_CLICK, makeInput(BACK_TRIGGER, 0)); | |
| 476 | +// mapper.addInputChannel(UserInputMapper::RIGHT_HAND_CLICK, makeInput(BACK_TRIGGER, 1)); | |
| 477 | +// | |
| 478 | +// // Hands | |
| 479 | +// mapper.addInputChannel(UserInputMapper::LEFT_HAND, makeInput(LEFT_HAND)); | |
| 480 | +// mapper.addInputChannel(UserInputMapper::RIGHT_HAND, makeInput(RIGHT_HAND)); | |
| 481 | +//} | |