Cleanup of enums and JS names

This commit is contained in:
Brad Davis 2015-10-21 15:57:37 -07:00
parent b9b03bd842
commit 4a1df286fd
9 changed files with 150 additions and 117 deletions

View file

@ -131,27 +131,8 @@ HifiControls.VrDialog {
onClicked: { onClicked: {
var mapping = Controller.newMapping(); var mapping = Controller.newMapping();
// Inverting a value // Inverting a value
mapping.from(hydra.RY).invert().to(standard.RY); mapping.from(standard.RY).invert().to(standard.RY);
mapping.from(hydra.RX).to(standard.RX);
mapping.from(hydra.LY).to(standard.LY);
mapping.from(hydra.LX).to(standard.LX);
// Assigning a value from a function
// mapping.from(function() { return Math.sin(Date.now() / 250); }).to(standard.RX);
// Constrainting a value to -1, 0, or 1, with a deadzone
// mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY);
mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw); mapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
// mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT);
// mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT);
// mapping.modifier(keyboard.Ctrl).scale(2.0)
// mapping.from(keyboard.A).to(actions.TranslateLeft)
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
// mapping.from(keyboard.A, keyboard.Shift, keyboard.Ctrl).scale(2.0).to(actions.TurnLeft)
// // First loopbacks
// // Then non-loopbacks by constraint level (number of inputs)
// mapping.from(xbox.RX).deadZone(0.2).to(xbox.RX)
// mapping.from(standard.RB, standard.LB, keyboard.Shift).to(actions.TurnLeft)
// mapping.from(keyboard.A, keyboard.Shift).to(actions.TurnLeft)
// mapping.from(keyboard.W).when(keyboard.Shift).to(actions.Forward)
testMapping = mapping; testMapping = mapping;
enabled = false enabled = false
text = "Built" text = "Built"
@ -175,13 +156,13 @@ HifiControls.VrDialog {
} }
Row { Row {
Xbox { device: root.standard; label: "Standard"; width: 360 } Standard { device: root.standard; label: "Standard"; width: 180 }
} }
Row { Row {
spacing: 8 spacing: 8
Xbox { device: root.xbox; label: "XBox"; width: 360 } Xbox { device: root.xbox; label: "XBox"; width: 180 }
Hydra { device: root.hydra; width: 360 } Hydra { device: root.hydra; width: 180 }
} }
Row { Row {

View file

@ -0,0 +1,35 @@
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
import "xbox"
Item {
id: root
property real aspect: 300.0 / 215.0
width: 300
height: width / aspect
property var device
property string label: ""
property real scale: width / 300.0
Xbox {
width: root.width; height: root.height
device: root.device
}
// Left primary
ToggleButton {
x: 0; y: parent.height - height;
controlId: root.device.LeftPrimaryThumb
width: 16 * root.scale; height: 16 * root.scale
}
// Left primary
ToggleButton {
x: parent.width - width; y: parent.height - height;
controlId: root.device.RB
width: 16 * root.scale; height: 16 * root.scale
}
}

View file

@ -100,20 +100,5 @@ Item {
width: 16 * root.scale; height: 12 * root.scale width: 16 * root.scale; height: 12 * root.scale
x: (177 * root.scale); y: (45 * root.scale) x: (177 * root.scale); y: (45 * root.scale)
} }
// Left primary
ToggleButton {
x: 0; y: parent.height - height;
controlId: root.device.LeftPrimaryThumb
width: 16 * root.scale; height: 16 * root.scale
}
// Left primary
ToggleButton {
x: parent.width - width; y: parent.height - height;
controlId: root.device.RightPrimaryThumb
width: 16 * root.scale; height: 16 * root.scale
}
} }
} }

View file

@ -33,18 +33,14 @@ ConnexionData::ConnexionData() : InputDevice("ConnexionClient") {}
void ConnexionData::handleAxisEvent() { void ConnexionData::handleAxisEvent() {
_axisStateMap[makeInput(ROTATION_AXIS_Y_POS).getChannel()] = (cc_rotation.y > 0.0f) ? cc_rotation.y / MAX_AXIS : 0.0f; auto rotation = cc_rotation / MAX_AXIS;
_axisStateMap[makeInput(ROTATION_AXIS_Y_NEG).getChannel()] = (cc_rotation.y < 0.0f) ? -cc_rotation.y / MAX_AXIS : 0.0f; _axisStateMap[ROTATE_X] = rotation.x;
_axisStateMap[makeInput(POSITION_AXIS_X_POS).getChannel()] = (cc_position.x > 0.0f) ? cc_position.x / MAX_AXIS : 0.0f; _axisStateMap[ROTATE_Y] = rotation.y;
_axisStateMap[makeInput(POSITION_AXIS_X_NEG).getChannel()] = (cc_position.x < 0.0f) ? -cc_position.x / MAX_AXIS : 0.0f; _axisStateMap[ROTATE_Z] = rotation.z;
_axisStateMap[makeInput(POSITION_AXIS_Y_POS).getChannel()] = (cc_position.y > 0.0f) ? cc_position.y / MAX_AXIS : 0.0f; auto position = cc_rotation / MAX_AXIS;
_axisStateMap[makeInput(POSITION_AXIS_Y_NEG).getChannel()] = (cc_position.y < 0.0f) ? -cc_position.y / MAX_AXIS : 0.0f; _axisStateMap[TRANSLATE_X] = position.x;
_axisStateMap[makeInput(POSITION_AXIS_Z_POS).getChannel()] = (cc_position.z > 0.0f) ? cc_position.z / MAX_AXIS : 0.0f; _axisStateMap[TRANSLATE_Y] = position.y;
_axisStateMap[makeInput(POSITION_AXIS_Z_NEG).getChannel()] = (cc_position.z < 0.0f) ? -cc_position.z / MAX_AXIS : 0.0f; _axisStateMap[TRANSLATE_Z] = position.z;
_axisStateMap[makeInput(ROTATION_AXIS_X_POS).getChannel()] = (cc_rotation.x > 0.0f) ? cc_rotation.x / MAX_AXIS : 0.0f;
_axisStateMap[makeInput(ROTATION_AXIS_X_NEG).getChannel()] = (cc_rotation.x < 0.0f) ? -cc_rotation.x / MAX_AXIS : 0.0f;
_axisStateMap[makeInput(ROTATION_AXIS_Z_POS).getChannel()] = (cc_rotation.z > 0.0f) ? cc_rotation.z / MAX_AXIS : 0.0f;
_axisStateMap[makeInput(ROTATION_AXIS_Z_NEG).getChannel()] = (cc_rotation.z < 0.0f) ? -cc_rotation.z / MAX_AXIS : 0.0f;
} }
void ConnexionData::setButton(int lastButtonState) { void ConnexionData::setButton(int lastButtonState) {
@ -57,24 +53,18 @@ void ConnexionData::buildDeviceProxy(controller::DeviceProxy::Pointer proxy) {
proxy->getButton = [this](const controller::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); }; proxy->getButton = [this](const controller::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this](const controller::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); }; proxy->getAxis = [this](const controller::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getAvailabeInputs = [this]() -> QVector<controller::Input::NamedPair> { proxy->getAvailabeInputs = [this]() -> QVector<controller::Input::NamedPair> {
QVector<controller::Input::NamedPair> availableInputs; using namespace controller;
static QVector<controller::Input::NamedPair> availableInputs {
availableInputs.append(controller::Input::NamedPair(makeInput(BUTTON_1), "Left button")); Input::NamedPair(makeInput(BUTTON_1), "LeftButton"),
availableInputs.append(controller::Input::NamedPair(makeInput(BUTTON_2), "Right button")); Input::NamedPair(makeInput(BUTTON_2), "RightButton"),
availableInputs.append(controller::Input::NamedPair(makeInput(BUTTON_3), "Both buttons")); Input::NamedPair(makeInput(BUTTON_3), "BothButtons"),
Input::NamedPair(makeInput(TRANSLATE_X), "TranslateX"),
availableInputs.append(controller::Input::NamedPair(makeInput(POSITION_AXIS_Y_NEG), "Move backward")); Input::NamedPair(makeInput(TRANSLATE_Y), "TranslateY"),
availableInputs.append(controller::Input::NamedPair(makeInput(POSITION_AXIS_Y_POS), "Move forward")); Input::NamedPair(makeInput(TRANSLATE_Z), "TranslateZ"),
availableInputs.append(controller::Input::NamedPair(makeInput(POSITION_AXIS_X_POS), "Move right")); Input::NamedPair(makeInput(ROTATE_X), "RotateX"),
availableInputs.append(controller::Input::NamedPair(makeInput(POSITION_AXIS_X_NEG), "Move Left")); Input::NamedPair(makeInput(ROTATE_Y), "RotateY"),
availableInputs.append(controller::Input::NamedPair(makeInput(POSITION_AXIS_Z_POS), "Move up")); Input::NamedPair(makeInput(ROTATE_Z), "RotateZ"),
availableInputs.append(controller::Input::NamedPair(makeInput(POSITION_AXIS_Z_NEG), "Move down")); };
availableInputs.append(controller::Input::NamedPair(makeInput(ROTATION_AXIS_Y_NEG), "Rotate backward"));
availableInputs.append(controller::Input::NamedPair(makeInput(ROTATION_AXIS_Y_POS), "Rotate forward"));
availableInputs.append(controller::Input::NamedPair(makeInput(ROTATION_AXIS_X_POS), "Rotate right"));
availableInputs.append(controller::Input::NamedPair(makeInput(ROTATION_AXIS_X_NEG), "Rotate left"));
availableInputs.append(controller::Input::NamedPair(makeInput(ROTATION_AXIS_Z_POS), "Rotate up"));
availableInputs.append(controller::Input::NamedPair(makeInput(ROTATION_AXIS_Z_NEG), "Rotate down"));
return availableInputs; return availableInputs;
}; };
} }

View file

@ -182,18 +182,12 @@ public:
static ConnexionData& getInstance(); static ConnexionData& getInstance();
ConnexionData(); ConnexionData();
enum PositionChannel { enum PositionChannel {
POSITION_AXIS_X_POS = 1, TRANSLATE_X,
POSITION_AXIS_X_NEG = 2, TRANSLATE_Y,
POSITION_AXIS_Y_POS = 3, TRANSLATE_Z,
POSITION_AXIS_Y_NEG = 4, ROTATE_X,
POSITION_AXIS_Z_POS = 5, ROTATE_Y,
POSITION_AXIS_Z_NEG = 6, ROTATE_Z,
ROTATION_AXIS_X_POS = 7,
ROTATION_AXIS_X_NEG = 8,
ROTATION_AXIS_Y_POS = 9,
ROTATION_AXIS_Y_NEG = 10,
ROTATION_AXIS_Z_POS = 11,
ROTATION_AXIS_Z_NEG = 12
}; };
enum ButtonChannel { enum ButtonChannel {

View file

@ -12,6 +12,23 @@
namespace controller { namespace controller {
Input::NamedPair makePair(ChannelType type, Action action, const QString& name) {
auto input = Input(UserInputMapper::ACTIONS_DEVICE, toInt(action), type);
return Input::NamedPair(input, name);
}
Input::NamedPair makeAxisPair(Action action, const QString& name) {
return makePair(ChannelType::AXIS, action, name);
}
Input::NamedPair makeButtonPair(Action action, const QString& name) {
return makePair(ChannelType::BUTTON, action, name);
}
Input::NamedPair makePosePair(Action action, const QString& name) {
return makePair(ChannelType::POSE, action, name);
}
// Device functions // Device functions
void ActionsDevice::buildDeviceProxy(DeviceProxy::Pointer proxy) { void ActionsDevice::buildDeviceProxy(DeviceProxy::Pointer proxy) {
proxy->_name = _name; proxy->_name = _name;
@ -19,33 +36,64 @@ namespace controller {
proxy->getAxis = [this](const Input& input, int timestamp) -> float { return 0; }; proxy->getAxis = [this](const Input& input, int timestamp) -> float { return 0; };
proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> { proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> {
QVector<Input::NamedPair> availableInputs{ QVector<Input::NamedPair> availableInputs{
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::LONGITUDINAL_BACKWARD), ChannelType::AXIS), "LONGITUDINAL_BACKWARD"), makeAxisPair(Action::TRANSLATE_X, "TranslateX"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::LONGITUDINAL_FORWARD), ChannelType::AXIS), "LONGITUDINAL_FORWARD"), makeAxisPair(Action::TRANSLATE_Y, "TranslateY"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::LATERAL_LEFT), ChannelType::AXIS), "LATERAL_LEFT"), makeAxisPair(Action::TRANSLATE_Z, "TranslateZ"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::LATERAL_RIGHT), ChannelType::AXIS), "LATERAL_RIGHT"), makeAxisPair(Action::ROLL, "Roll"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::VERTICAL_DOWN), ChannelType::AXIS), "VERTICAL_DOWN"), makeAxisPair(Action::PITCH, "Pitch"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::VERTICAL_UP), ChannelType::AXIS), "VERTICAL_UP"), makeAxisPair(Action::YAW, "Yaw"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::YAW_LEFT), ChannelType::AXIS), "YAW_LEFT"), makeAxisPair(Action::LONGITUDINAL_BACKWARD, "Backward"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::YAW_RIGHT), ChannelType::AXIS), "YAW_RIGHT"), makeAxisPair(Action::LONGITUDINAL_FORWARD, "Forward"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::PITCH_DOWN), ChannelType::AXIS), "PITCH_DOWN"), makeAxisPair(Action::LATERAL_LEFT, "StrafeLeft"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::PITCH_UP), ChannelType::AXIS), "PITCH_UP"), makeAxisPair(Action::LATERAL_RIGHT, "StrafeRight"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::BOOM_IN), ChannelType::AXIS), "BOOM_IN"), makeAxisPair(Action::VERTICAL_DOWN, "Down"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::BOOM_OUT), ChannelType::AXIS), "BOOM_OUT"), makeAxisPair(Action::VERTICAL_UP, "Up"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::LEFT_HAND), ChannelType::POSE), "LEFT_HAND"), makeAxisPair(Action::YAW_LEFT, "YawLeft"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::RIGHT_HAND), ChannelType::POSE), "RIGHT_HAND"), makeAxisPair(Action::YAW_RIGHT, "YawRight"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::LEFT_HAND_CLICK), ChannelType::BUTTON), "LEFT_HAND_CLICK"), makeAxisPair(Action::PITCH_DOWN, "PitchDown"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::RIGHT_HAND_CLICK), ChannelType::BUTTON), "RIGHT_HAND_CLICK"), makeAxisPair(Action::PITCH_UP, "PitchUp"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::SHIFT), ChannelType::BUTTON), "SHIFT"), makeAxisPair(Action::BOOM_IN, "BoomIn"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::ACTION1), ChannelType::BUTTON), "ACTION1"), makeAxisPair(Action::BOOM_OUT, "BoomOut"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::ACTION2), ChannelType::BUTTON), "ACTION2"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::CONTEXT_MENU), ChannelType::BUTTON), "CONTEXT_MENU"), makePosePair(Action::LEFT_HAND, "LeftHand"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::TOGGLE_MUTE), ChannelType::AXIS), "TOGGLE_MUTE"), makePosePair(Action::RIGHT_HAND, "RightHand"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::TRANSLATE_X), ChannelType::AXIS), "TranslateX"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::TRANSLATE_Y), ChannelType::AXIS), "TranslateY"), makeButtonPair(Action::LEFT_HAND_CLICK, "LeftHandClick"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::TRANSLATE_Z), ChannelType::AXIS), "TranslateZ"), makeButtonPair(Action::RIGHT_HAND_CLICK, "RightHandClick"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::ROLL), ChannelType::AXIS), "Roll"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::PITCH), ChannelType::AXIS), "Pitch"), makeButtonPair(Action::SHIFT, "Shift"),
Input::NamedPair(Input(UserInputMapper::ACTIONS_DEVICE, toInt(Action::YAW), ChannelType::AXIS), "Yaw") makeButtonPair(Action::ACTION1, "PrimaryAction"),
makeButtonPair(Action::ACTION2, "SecondaryAction"),
makeButtonPair(Action::CONTEXT_MENU, "ContextMenu"),
makeButtonPair(Action::TOGGLE_MUTE, "ToggleMute"),
// Deprecated aliases
// FIXME remove after we port all scripts
makeAxisPair(Action::LONGITUDINAL_BACKWARD, "LONGITUDINAL_BACKWARD"),
makeAxisPair(Action::LONGITUDINAL_FORWARD, "LONGITUDINAL_FORWARD"),
makeAxisPair(Action::LATERAL_LEFT, "LATERAL_LEFT"),
makeAxisPair(Action::LATERAL_RIGHT, "LATERAL_RIGHT"),
makeAxisPair(Action::VERTICAL_DOWN, "VERTICAL_DOWN"),
makeAxisPair(Action::VERTICAL_UP, "VERTICAL_UP"),
makeAxisPair(Action::YAW_LEFT, "YAW_LEFT"),
makeAxisPair(Action::YAW_RIGHT, "YAW_RIGHT"),
makeAxisPair(Action::PITCH_DOWN, "PITCH_DOWN"),
makeAxisPair(Action::PITCH_UP, "PITCH_UP"),
makeAxisPair(Action::BOOM_IN, "BOOM_IN"),
makeAxisPair(Action::BOOM_OUT, "BOOM_OUT"),
makePosePair(Action::LEFT_HAND, "LEFT_HAND"),
makePosePair(Action::RIGHT_HAND, "RIGHT_HAND"),
makeButtonPair(Action::LEFT_HAND_CLICK, "LEFT_HAND_CLICK"),
makeButtonPair(Action::RIGHT_HAND_CLICK, "RIGHT_HAND_CLICK"),
makeButtonPair(Action::SHIFT, "SHIFT"),
makeButtonPair(Action::ACTION1, "ACTION1"),
makeButtonPair(Action::ACTION2, "ACTION2"),
makeButtonPair(Action::CONTEXT_MENU, "CONTEXT_MENU"),
makeButtonPair(Action::TOGGLE_MUTE, "TOGGLE_MUTE"),
}; };
return availableInputs; return availableInputs;
}; };

View file

@ -95,10 +95,10 @@ void StandardController::buildDeviceProxy(DeviceProxy::Pointer proxy) {
availableInputs.append(makePair(DR, "Right")); availableInputs.append(makePair(DR, "Right"));
availableInputs.append(makePair(LeftPrimaryThumb, "LeftPrimaryThumb")); availableInputs.append(makePair(LEFT_PRIMARY_THUMB, "LeftPrimaryThumb"));
availableInputs.append(makePair(LeftSecondaryThumb, "LeftSecondaryThumb")); availableInputs.append(makePair(LEFT_SECONDARY_THUMB, "LeftSecondaryThumb"));
availableInputs.append(makePair(RightPrimaryThumb, "RightPrimaryThumb")); availableInputs.append(makePair(RIGHT_PRIMARY_THUMB, "RightPrimaryThumb"));
availableInputs.append(makePair(RightSecondaryThumb, "RightSecondaryThumb")); availableInputs.append(makePair(RIGHT_SECONDARY_THUMB, "RightSecondaryThumb"));
return availableInputs; return availableInputs;
}; };

View file

@ -37,10 +37,10 @@ namespace controller {
DR, DR,
// These don't map to SDL types // These don't map to SDL types
LeftPrimaryThumb, LEFT_PRIMARY_THUMB,
LeftSecondaryThumb, LEFT_SECONDARY_THUMB,
RightPrimaryThumb, RIGHT_PRIMARY_THUMB,
RightSecondaryThumb, RIGHT_SECONDARY_THUMB,
NUM_STANDARD_BUTTONS NUM_STANDARD_BUTTONS
}; };

View file

@ -414,10 +414,10 @@ void ViveControllerManager::buildDeviceProxy(controller::DeviceProxy::Pointer pr
makePair(LS, "LS"), makePair(LS, "LS"),
makePair(RS, "RS"), makePair(RS, "RS"),
makePair(LEFT_HAND, "LeftHand"),
makePair(RIGHT_HAND, "RightHand"),
}; };
//availableInputs.append(Input::NamedPair(makeInput(LEFT_HAND), "Left Hand"));
//availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 0), "Left Button A")); //availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 0), "Left Button A"));
//availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 0), "Left Grip Button")); //availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 0), "Left Grip Button"));
//availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 0), "Left Trackpad Button")); //availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 0), "Left Trackpad Button"));