working on using UserInputMapper::Pose, merging

This commit is contained in:
Sam Gondelman 2015-06-30 17:34:34 -07:00
parent 1ea8e85fe8
commit a154c809c0
5 changed files with 39 additions and 11 deletions

View file

@ -2536,6 +2536,7 @@ void Application::update(float deltaTime) {
_myAvatar->setDriveKeys(ROT_DOWN, userInputMapper->getActionState(UserInputMapper::PITCH_DOWN));
_myAvatar->setDriveKeys(ROT_LEFT, userInputMapper->getActionState(UserInputMapper::YAW_LEFT));
_myAvatar->setDriveKeys(ROT_RIGHT, userInputMapper->getActionState(UserInputMapper::YAW_RIGHT));
// TODO: set hand positions somehow
}
_myAvatar->setDriveKeys(BOOM_IN, userInputMapper->getActionState(UserInputMapper::BOOM_IN));
_myAvatar->setDriveKeys(BOOM_OUT, userInputMapper->getActionState(UserInputMapper::BOOM_OUT));

View file

@ -226,6 +226,7 @@ void ViveControllerManager::registerToUserInputMapper(UserInputMapper& mapper) {
auto proxy = UserInputMapper::DeviceProxy::Pointer(new UserInputMapper::DeviceProxy("SteamVR Controller"));
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getPose = [this] (const UserInputMapper::Input& input, int timestamp) -> UserInputMapper::PoseValue { return this->getPose(input.getChannel()); }
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
QVector<UserInputMapper::InputPair> availableInputs;
// availableInputs.append(UserInputMapper::InputPair(makeInput(BUTTON_0, 0), "Left Start"));
@ -322,6 +323,15 @@ float ViveControllerManager::getAxis(int channel) const {
}
}
UserInputMapper::PoseValue ViveControllerManager::getPose(int channel) const {
auto pose = _poseStateMap.find(channel);
if (pose != _poseStateMap.end()) {
return (*pose).second;
} else {
return UserInputMapper::PoseValue();
}
}
UserInputMapper::Input ViveControllerManager::makeInput(unsigned int button, int index) {
return UserInputMapper::Input(0);
// return UserInputMapper::Input(_deviceID, button | (index == 0 ? LEFT_MASK : RIGHT_MASK), UserInputMapper::ChannelType::BUTTON);

View file

@ -39,9 +39,11 @@ public:
typedef std::unordered_set<int> ButtonPressedMap;
typedef std::map<int, float> AxisStateMap;
typedef std::map<int, UserInputMapper::PoseValue> PoseStateMap;
float getButton(int channel) const;
float getAxis(int channel) const;
UserInputMapper::PoseValue getPose(int channel) const;
UserInputMapper::Input makeInput(unsigned int button, int index);
UserInputMapper::Input makeInput(JoystickAxisChannel axis, int index);
@ -69,6 +71,7 @@ protected:
ButtonPressedMap _buttonPressedMap;
AxisStateMap _axisStateMap;
PoseStateMap _poseStateMap;
};

View file

@ -152,6 +152,10 @@ void UserInputMapper::update(float deltaTime) {
for (auto& channel : _actionStates) {
channel = 0.0f;
}
for (auto& channel : _poseStates) {
channel = PoseValue();
}
int currentTimestamp = 0;
@ -187,8 +191,8 @@ void UserInputMapper::update(float deltaTime) {
_actionStates[channelInput.first] += inputMapping._scale * deviceProxy->getAxis(inputID, currentTimestamp);
break;
}
case ChannelType::JOINT: {
// _channelStates[channelInput.first].jointVal = deviceProxy->getJoint(inputID, currentTimestamp);
case ChannelType::POSE: {
_poseStates[channelInput.first] = deviceProxy->getPose(inputID, currentTimestamp);
break;
}
default: {
@ -207,6 +211,7 @@ void UserInputMapper::update(float deltaTime) {
if (_actionStates[i] > 0) {
emit actionEvent(i, _actionStates[i]);
}
// TODO: emit signal for pose changes
}
}
@ -241,6 +246,8 @@ void UserInputMapper::assignDefaulActionScales() {
_actionScales[PITCH_UP] = 1.0f; // 1 degree per unit
_actionScales[BOOM_IN] = 1.0f; // 1m per unit
_actionScales[BOOM_OUT] = 1.0f; // 1m per unit
_actionScales[LEFT_HAND] = 1.0f; // default
_actionScales[RIGHT_HAND] = 1.0f; // default
_actionStates[SHIFT] = 1.0f; // on
_actionStates[ACTION1] = 1.0f; // default
_actionStates[ACTION2] = 1.0f; // default
@ -261,6 +268,8 @@ void UserInputMapper::createActionNames() {
_actionNames[PITCH_UP] = "PITCH_UP";
_actionNames[BOOM_IN] = "BOOM_IN";
_actionNames[BOOM_OUT] = "BOOM_OUT";
_actionNames[LEFT_HAND] = "LEFT_HAND";
_actionNames[RIGHT_HAND] = "RIGHT_HAND";
_actionNames[SHIFT] = "SHIFT";
_actionNames[ACTION1] = "ACTION1";
_actionNames[ACTION2] = "ACTION2";

View file

@ -33,7 +33,7 @@ public:
UNKNOWN = 0,
BUTTON = 1,
AXIS,
JOINT,
POSE,
};
// Input is the unique identifier to find a n input channel of a particular device
@ -64,7 +64,7 @@ public:
bool isButton() const { return getType() == ChannelType::BUTTON; }
bool isAxis() const { return getType() == ChannelType::AXIS; }
bool isJoint() const { return getType() == ChannelType::JOINT; }
bool isPose() const { return getType() == ChannelType::POSE; }
// WORKAROUND: the explicit initializer here avoids a bug in GCC-4.8.2 (but not found in 4.9.2)
// where the default initializer (a C++-11ism) for the union data above is not applied.
@ -80,19 +80,19 @@ public:
// Modifiers are just button inputID
typedef std::vector< Input > Modifiers;
class JointValue {
class PoseValue {
public:
glm::vec3 translation{ 0.0f };
glm::quat rotation;
JointValue() {};
JointValue(const JointValue&) = default;
JointValue& operator = (const JointValue&) = default;
PoseValue() {};
PoseValue(const PoseValue&) = default;
PoseValue& operator = (const PoseValue&) = default;
};
typedef std::function<bool (const Input& input, int timestamp)> ButtonGetter;
typedef std::function<float (const Input& input, int timestamp)> AxisGetter;
typedef std::function<JointValue (const Input& input, int timestamp)> JointGetter;
typedef std::function<PoseValue (const Input& input, int timestamp)> PoseGetter;
typedef QPair<Input, QString> InputPair;
typedef std::function<QVector<InputPair> ()> AvailableInputGetter;
typedef std::function<bool ()> ResetBindings;
@ -105,8 +105,8 @@ public:
QString _name;
ButtonGetter getButton = [] (const Input& input, int timestamp) -> bool { return false; };
AxisGetter getAxis = [] (const Input& input, int timestamp) -> bool { return 0.0f; };
JointGetter getJoint = [] (const Input& input, int timestamp) -> JointValue { return JointValue(); };
AxisGetter getAxis = [] (const Input& input, int timestamp) -> float { return 0.0f; };
PoseGetter getPose = [] (const Input& input, int timestamp) -> PoseValue { return PoseValue(); };
AvailableInputGetter getAvailabeInputs = [] () -> AvailableInput { return QVector<InputPair>(); };
ResetBindings resetDeviceBindings = [] () -> bool { return true; };
@ -143,6 +143,9 @@ public:
BOOM_IN,
BOOM_OUT,
LEFT_HAND,
RIGHT_HAND,
SHIFT,
ACTION1,
@ -157,6 +160,7 @@ public:
QVector<Action> getAllActions();
QString getActionName(Action action) { return UserInputMapper::_actionNames[(int) action]; }
float getActionState(Action action) const { return _actionStates[action]; }
float getPoseState(Action action) const { return _poseStates[action]; }
void assignDefaulActionScales();
// Add input channel to the mapper and check that all the used channels are registered.
@ -228,6 +232,7 @@ protected:
std::vector<float> _actionStates = std::vector<float>(NUM_ACTIONS, 0.0f);
std::vector<float> _actionScales = std::vector<float>(NUM_ACTIONS, 1.0f);
std::vector<PoseValue> _poseStates = std::vector<PoseValue>(NUM_ACTIONS);
};
Q_DECLARE_METATYPE(UserInputMapper::InputPair)