fix 'any endpoints' for axis style inputs

This commit is contained in:
Brad Hefta-Gaub 2016-10-08 18:18:54 -07:00
parent 87d66ffdf8
commit 8da9fccb5d
3 changed files with 18 additions and 4 deletions

View file

@ -95,6 +95,11 @@ namespace controller {
return getValue(Input(device, source, ChannelType::BUTTON).getID());
}
float ScriptingInterface::getAxisValue(int source) const {
auto userInputMapper = DependencyManager::get<UserInputMapper>();
return userInputMapper->getValue(Input((uint32_t)source));
}
float ScriptingInterface::getAxisValue(StandardAxisChannel source, uint16_t device) const {
return getValue(Input(device, source, ChannelType::AXIS).getID());
}

View file

@ -81,6 +81,7 @@ namespace controller {
Q_INVOKABLE float getValue(const int& source) const;
Q_INVOKABLE float getButtonValue(StandardButtonChannel source, uint16_t device = 0) const;
Q_INVOKABLE float getAxisValue(StandardAxisChannel source, uint16_t device = 0) const;
Q_INVOKABLE float getAxisValue(int source) const;
Q_INVOKABLE Pose getPoseValue(const int& source) const;
Q_INVOKABLE Pose getPoseValue(StandardPoseChannel source, uint16_t device = 0) const;

View file

@ -27,19 +27,27 @@ AnyEndpoint::AnyEndpoint(Endpoint::List children) : Endpoint(Input::INVALID_INPU
}
}
// The value of an any-point is considered to be the maxiumum absolute value,
// this handles any's of multiple axis values as well as single values as well
float AnyEndpoint::peek() const {
float result = 0;
float result = 0.0f;
for (auto& child : _children) {
result = std::max(result, child->peek());
auto childValue = child->peek();
if (std::abs(childValue) > std::abs(result)) {
result = childValue;
}
}
return result;
}
// Fetching the value must trigger any necessary side effects of value() on ALL the children.
float AnyEndpoint::value() {
float result = 0;
float result = 0.0f;
for (auto& child : _children) {
result = std::max(result, child->value());
auto childValue = child->value();
if (std::abs(childValue) > std::abs(result)) {
result = childValue;
}
}
return result;
}