mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 16:41:02 +02:00
Use Controller axis value timestamp for mouse movement Controller events
This commit is contained in:
parent
84c6bb4797
commit
d12b504a88
46 changed files with 152 additions and 134 deletions
|
@ -223,7 +223,7 @@ Pointer::Buttons PathPointer::getPressedButtons(const PickResultPointer& pickRes
|
||||||
std::string button = trigger.getButton();
|
std::string button = trigger.getButton();
|
||||||
TriggerState& state = _states[button];
|
TriggerState& state = _states[button];
|
||||||
// TODO: right now, LaserPointers don't support axes, only on/off buttons
|
// TODO: right now, LaserPointers don't support axes, only on/off buttons
|
||||||
if (trigger.getEndpoint()->peek() >= 1.0f) {
|
if (trigger.getEndpoint()->peek().value >= 1.0f) {
|
||||||
toReturn.insert(button);
|
toReturn.insert(button);
|
||||||
|
|
||||||
if (_previousButtons.find(button) == _previousButtons.end()) {
|
if (_previousButtons.find(button) == _previousButtons.end()) {
|
||||||
|
|
|
@ -15,4 +15,7 @@ namespace controller {
|
||||||
AxisValue::AxisValue(const float value, const quint64 timestamp) :
|
AxisValue::AxisValue(const float value, const quint64 timestamp) :
|
||||||
value(value), timestamp(timestamp) { }
|
value(value), timestamp(timestamp) { }
|
||||||
|
|
||||||
|
bool AxisValue::operator==(const AxisValue& right) const {
|
||||||
|
return value == right.value && timestamp == right.timestamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@ namespace controller {
|
||||||
|
|
||||||
AxisValue() {}
|
AxisValue() {}
|
||||||
AxisValue(const float value, const quint64 timestamp);
|
AxisValue(const float value, const quint64 timestamp);
|
||||||
|
|
||||||
|
bool operator ==(const AxisValue& right) const;
|
||||||
|
bool operator !=(const AxisValue& right) const { return !(*this == right); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,26 +68,25 @@ namespace controller {
|
||||||
return Input::NamedPair(makeInput(pose), name);
|
return Input::NamedPair(makeInput(pose), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
float InputDevice::getValue(ChannelType channelType, uint16_t channel) const {
|
AxisValue InputDevice::getValue(ChannelType channelType, uint16_t channel) const {
|
||||||
switch (channelType) {
|
switch (channelType) {
|
||||||
case ChannelType::AXIS:
|
case ChannelType::AXIS:
|
||||||
return getAxis(channel).value;
|
return getAxis(channel);
|
||||||
|
|
||||||
case ChannelType::BUTTON:
|
case ChannelType::BUTTON:
|
||||||
return getButton(channel);
|
return { getButton(channel), 0 };
|
||||||
|
|
||||||
case ChannelType::POSE:
|
case ChannelType::POSE:
|
||||||
return getPose(channel).valid ? 1.0f : 0.0f;
|
return { getPose(channel).valid ? 1.0f : 0.0f, 0 };
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0f;
|
return { 0.0f, 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AxisValue InputDevice::getValue(const Input& input) const {
|
||||||
float InputDevice::getValue(const Input& input) const {
|
|
||||||
return getValue(input.getType(), input.channel);
|
return getValue(input.getType(), input.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,8 @@ public:
|
||||||
AxisValue getAxis(int channel) const;
|
AxisValue getAxis(int channel) const;
|
||||||
Pose getPose(int channel) const;
|
Pose getPose(int channel) const;
|
||||||
|
|
||||||
float getValue(const Input& input) const;
|
AxisValue getValue(const Input& input) const;
|
||||||
float getValue(ChannelType channelType, uint16_t channel) const;
|
AxisValue getValue(ChannelType channelType, uint16_t channel) const;
|
||||||
Pose getPoseValue(uint16_t channel) const;
|
Pose getPoseValue(uint16_t channel) const;
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
|
@ -89,17 +89,17 @@ namespace controller {
|
||||||
|
|
||||||
float ScriptingInterface::getValue(const int& source) const {
|
float ScriptingInterface::getValue(const int& source) const {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
return userInputMapper->getValue(Input((uint32_t)source));
|
return userInputMapper->getValue(Input((uint32_t)source)).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScriptingInterface::getAxisValue(int source) const {
|
float ScriptingInterface::getAxisValue(int source) const {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
return userInputMapper->getValue(Input((uint32_t)source));
|
return userInputMapper->getValue(Input((uint32_t)source)).value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose ScriptingInterface::getPoseValue(const int& source) const {
|
Pose ScriptingInterface::getPoseValue(const int& source) const {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
return userInputMapper->getPose(Input((uint32_t)source));
|
return userInputMapper->getPose(Input((uint32_t)source));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Action> ScriptingInterface::getAllActions() {
|
QVector<Action> ScriptingInterface::getAllActions() {
|
||||||
|
|
|
@ -290,17 +290,17 @@ void UserInputMapper::update(float deltaTime) {
|
||||||
if ((int)_lastStandardStates.size() != standardInputs.size()) {
|
if ((int)_lastStandardStates.size() != standardInputs.size()) {
|
||||||
_lastStandardStates.resize(standardInputs.size());
|
_lastStandardStates.resize(standardInputs.size());
|
||||||
for (auto& lastValue : _lastStandardStates) {
|
for (auto& lastValue : _lastStandardStates) {
|
||||||
lastValue = 0;
|
lastValue = AxisValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < standardInputs.size(); ++i) {
|
for (int i = 0; i < standardInputs.size(); ++i) {
|
||||||
const auto& input = standardInputs[i].first;
|
const auto& input = standardInputs[i].first;
|
||||||
float value = getValue(input);
|
AxisValue value = getValue(input);
|
||||||
float& oldValue = _lastStandardStates[i];
|
AxisValue& oldValue = _lastStandardStates[i];
|
||||||
if (value != oldValue) {
|
if (value != oldValue) {
|
||||||
oldValue = value;
|
oldValue = value;
|
||||||
emit inputEvent(input.id, value);
|
emit inputEvent(input.id, value.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inputRecorder->frameTick();
|
inputRecorder->frameTick();
|
||||||
|
@ -604,10 +604,10 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
||||||
destination->apply(value, source);
|
destination->apply(value, source);
|
||||||
} else {
|
} else {
|
||||||
// Fetch the value, may have been overriden by previous loopback routes
|
// Fetch the value, may have been overriden by previous loopback routes
|
||||||
float value = getValue(source, route->peek);
|
auto value = getValue(source, route->peek);
|
||||||
|
|
||||||
if (debugRoutes && route->debug) {
|
if (debugRoutes && route->debug) {
|
||||||
qCDebug(controllers) << "Value was " << value;
|
qCDebug(controllers) << "Value was " << value.value << value.timestamp;
|
||||||
}
|
}
|
||||||
// Apply each of the filters.
|
// Apply each of the filters.
|
||||||
for (const auto& filter : route->filters) {
|
for (const auto& filter : route->filters) {
|
||||||
|
@ -615,7 +615,7 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debugRoutes && route->debug) {
|
if (debugRoutes && route->debug) {
|
||||||
qCDebug(controllers) << "Filtered value was " << value;
|
qCDebug(controllers) << "Filtered value was " << value.value << value.timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
destination->apply(value, source);
|
destination->apply(value, source);
|
||||||
|
@ -741,15 +741,15 @@ void UserInputMapper::enableMapping(const QString& mappingName, bool enable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float UserInputMapper::getValue(const Endpoint::Pointer& endpoint, bool peek) {
|
AxisValue UserInputMapper::getValue(const Endpoint::Pointer& endpoint, bool peek) {
|
||||||
return peek ? endpoint->peek() : endpoint->value();
|
return peek ? endpoint->peek() : endpoint->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
float UserInputMapper::getValue(const Input& input) const {
|
AxisValue UserInputMapper::getValue(const Input& input) const {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
auto endpoint = endpointFor(input);
|
auto endpoint = endpointFor(input);
|
||||||
if (!endpoint) {
|
if (!endpoint) {
|
||||||
return 0;
|
return AxisValue();
|
||||||
}
|
}
|
||||||
return endpoint->value();
|
return endpoint->value();
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace controller {
|
||||||
void unloadMappings(const QStringList& jsonFiles);
|
void unloadMappings(const QStringList& jsonFiles);
|
||||||
void unloadMapping(const QString& jsonFile);
|
void unloadMapping(const QString& jsonFile);
|
||||||
|
|
||||||
float getValue(const Input& input) const;
|
AxisValue getValue(const Input& input) const;
|
||||||
Pose getPose(const Input& input) const;
|
Pose getPose(const Input& input) const;
|
||||||
|
|
||||||
// perform an action when the UserInputMapper mutex is acquired.
|
// perform an action when the UserInputMapper mutex is acquired.
|
||||||
|
@ -147,9 +147,9 @@ namespace controller {
|
||||||
std::vector<float> _actionScales = std::vector<float>(toInt(Action::NUM_ACTIONS), 1.0f);
|
std::vector<float> _actionScales = std::vector<float>(toInt(Action::NUM_ACTIONS), 1.0f);
|
||||||
std::vector<float> _lastActionStates = std::vector<float>(toInt(Action::NUM_ACTIONS), 0.0f);
|
std::vector<float> _lastActionStates = std::vector<float>(toInt(Action::NUM_ACTIONS), 0.0f);
|
||||||
std::vector<Pose> _poseStates = std::vector<Pose>(toInt(Action::NUM_ACTIONS));
|
std::vector<Pose> _poseStates = std::vector<Pose>(toInt(Action::NUM_ACTIONS));
|
||||||
std::vector<float> _lastStandardStates = std::vector<float>();
|
std::vector<AxisValue> _lastStandardStates = std::vector<AxisValue>();
|
||||||
|
|
||||||
static float getValue(const EndpointPointer& endpoint, bool peek = false);
|
static AxisValue getValue(const EndpointPointer& endpoint, bool peek = false);
|
||||||
static Pose getPose(const EndpointPointer& endpoint, bool peek = false);
|
static Pose getPose(const EndpointPointer& endpoint, bool peek = false);
|
||||||
|
|
||||||
friend class RouteBuilderProxy;
|
friend class RouteBuilderProxy;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
#include "../AxisValue.h"
|
||||||
#include "../Input.h"
|
#include "../Input.h"
|
||||||
#include "../Pose.h"
|
#include "../Pose.h"
|
||||||
|
|
||||||
|
@ -36,12 +37,13 @@ namespace controller {
|
||||||
using WriteLambda = std::function<void(float)>;
|
using WriteLambda = std::function<void(float)>;
|
||||||
|
|
||||||
Endpoint(const Input& input) : _input(input) {}
|
Endpoint(const Input& input) : _input(input) {}
|
||||||
virtual float value() { return peek(); }
|
virtual AxisValue value() { return peek(); }
|
||||||
virtual float peek() const = 0;
|
virtual AxisValue peek() const = 0;
|
||||||
virtual void apply(float value, const Pointer& source) = 0;
|
virtual void apply(AxisValue value, const Pointer& source) = 0;
|
||||||
virtual Pose peekPose() const { return Pose(); };
|
virtual Pose peekPose() const { return Pose(); };
|
||||||
virtual Pose pose() { return peekPose(); }
|
virtual Pose pose() { return peekPose(); }
|
||||||
virtual void apply(const Pose& value, const Pointer& source) {}
|
virtual void apply(const Pose& value, const Pointer& source) {}
|
||||||
|
virtual bool isAxis() const { return _input.isAxis(); }
|
||||||
virtual bool isPose() const { return _input.isPose(); }
|
virtual bool isPose() const { return _input.isPose(); }
|
||||||
virtual bool writeable() const { return true; }
|
virtual bool writeable() const { return true; }
|
||||||
virtual bool readable() const { return true; }
|
virtual bool readable() const { return true; }
|
||||||
|
@ -59,8 +61,8 @@ namespace controller {
|
||||||
LambdaEndpoint(ReadLambda readLambda, WriteLambda writeLambda = [](float) {})
|
LambdaEndpoint(ReadLambda readLambda, WriteLambda writeLambda = [](float) {})
|
||||||
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) { }
|
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) { }
|
||||||
|
|
||||||
virtual float peek() const override { return _readLambda(); }
|
virtual AxisValue peek() const override { return AxisValue(_readLambda(), 0); }
|
||||||
virtual void apply(float value, const Pointer& source) override { _writeLambda(value); }
|
virtual void apply(AxisValue value, const Pointer& source) override { _writeLambda(value.value); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ReadLambda _readLambda;
|
ReadLambda _readLambda;
|
||||||
|
@ -76,8 +78,8 @@ namespace controller {
|
||||||
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) {
|
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float peek() const override { return _readLambda(); }
|
virtual AxisValue peek() const override { return AxisValue(_readLambda(), 0); }
|
||||||
virtual void apply(float value, const Pointer& source) override { _writeLambda(value); }
|
virtual void apply(AxisValue value, const Pointer& source) override { _writeLambda(value.value); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ReadLambda& _readLambda;
|
const ReadLambda& _readLambda;
|
||||||
|
@ -91,15 +93,15 @@ namespace controller {
|
||||||
: Endpoint(id) {
|
: Endpoint(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float peek() const override { return _currentValue; }
|
virtual AxisValue peek() const override { return _currentValue; }
|
||||||
virtual void apply(float value, const Pointer& source) override { _currentValue = value; }
|
virtual void apply(AxisValue value, const Pointer& source) override { _currentValue = value; }
|
||||||
|
|
||||||
virtual Pose peekPose() const override { return _currentPose; }
|
virtual Pose peekPose() const override { return _currentPose; }
|
||||||
virtual void apply(const Pose& value, const Pointer& source) override {
|
virtual void apply(const Pose& value, const Pointer& source) override {
|
||||||
_currentPose = value;
|
_currentPose = value;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
float _currentValue { 0.0f };
|
AxisValue _currentValue { 0.0f, 0 };
|
||||||
Pose _currentPose {};
|
Pose _currentPose {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include <QtCore/QEasingCurve>
|
#include <QtCore/QEasingCurve>
|
||||||
|
|
||||||
|
#include "../AxisValue.h"
|
||||||
#include "../Pose.h"
|
#include "../Pose.h"
|
||||||
|
|
||||||
class QJsonValue;
|
class QJsonValue;
|
||||||
|
@ -37,7 +38,7 @@ namespace controller {
|
||||||
|
|
||||||
virtual ~Filter() = default;
|
virtual ~Filter() = default;
|
||||||
|
|
||||||
virtual float apply(float value) const = 0;
|
virtual AxisValue apply(AxisValue value) const = 0;
|
||||||
virtual Pose apply(Pose value) const = 0;
|
virtual Pose apply(Pose value) const = 0;
|
||||||
|
|
||||||
// Factory features
|
// Factory features
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace controller {
|
||||||
class EndpointConditional : public Conditional {
|
class EndpointConditional : public Conditional {
|
||||||
public:
|
public:
|
||||||
EndpointConditional(Endpoint::Pointer endpoint) : _endpoint(endpoint) {}
|
EndpointConditional(Endpoint::Pointer endpoint) : _endpoint(endpoint) {}
|
||||||
virtual bool satisfied() override { return _endpoint && _endpoint->peek() != 0.0f; }
|
virtual bool satisfied() override { return _endpoint && _endpoint->peek().value != 0.0f; }
|
||||||
private:
|
private:
|
||||||
Endpoint::Pointer _endpoint;
|
Endpoint::Pointer _endpoint;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,22 +15,22 @@
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
void ActionEndpoint::apply(float newValue, const Pointer& source) {
|
void ActionEndpoint::apply(AxisValue newValue, const Pointer& source) {
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||||
QString actionName;
|
QString actionName;
|
||||||
if (inputRecorder->isPlayingback() || inputRecorder->isRecording()) {
|
if (inputRecorder->isPlayingback() || inputRecorder->isRecording()) {
|
||||||
actionName = userInputMapper->getActionName(Action(_input.getChannel()));
|
actionName = userInputMapper->getActionName(Action(_input.getChannel()));
|
||||||
if (inputRecorder->isPlayingback()) {
|
if (inputRecorder->isPlayingback()) {
|
||||||
newValue = inputRecorder->getActionState(actionName);
|
newValue = AxisValue(inputRecorder->getActionState(actionName), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentValue += newValue;
|
_currentValue.value += newValue.value;
|
||||||
if (_input != Input::INVALID_INPUT) {
|
if (_input != Input::INVALID_INPUT) {
|
||||||
userInputMapper->deltaActionState(Action(_input.getChannel()), newValue);
|
userInputMapper->deltaActionState(Action(_input.getChannel()), newValue.value);
|
||||||
}
|
}
|
||||||
inputRecorder->setActionState(actionName, newValue);
|
inputRecorder->setActionState(actionName, newValue.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
||||||
|
@ -51,7 +51,7 @@ void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionEndpoint::reset() {
|
void ActionEndpoint::reset() {
|
||||||
_currentValue = 0.0f;
|
_currentValue = AxisValue();
|
||||||
_currentPose = Pose();
|
_currentPose = Pose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ class ActionEndpoint : public Endpoint {
|
||||||
public:
|
public:
|
||||||
ActionEndpoint(const Input& id = Input::INVALID_INPUT) : Endpoint(id) { }
|
ActionEndpoint(const Input& id = Input::INVALID_INPUT) : Endpoint(id) { }
|
||||||
|
|
||||||
virtual float peek() const override { return _currentValue; }
|
virtual AxisValue peek() const override { return _currentValue; }
|
||||||
virtual void apply(float newValue, const Pointer& source) override;
|
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||||
|
|
||||||
virtual Pose peekPose() const override { return _currentPose; }
|
virtual Pose peekPose() const override { return _currentPose; }
|
||||||
virtual void apply(const Pose& value, const Pointer& source) override;
|
virtual void apply(const Pose& value, const Pointer& source) override;
|
||||||
|
@ -32,7 +32,7 @@ public:
|
||||||
virtual void reset() override;
|
virtual void reset() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float _currentValue{ 0.0f };
|
AxisValue _currentValue { 0.0f, 0 };
|
||||||
Pose _currentPose{};
|
Pose _currentPose{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@ AnyEndpoint::AnyEndpoint(Endpoint::List children) : Endpoint(Input::INVALID_INPU
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The value of an any-point is considered to be the maxiumum absolute value,
|
// The value of an any-point is considered to be the maximum absolute value,
|
||||||
// this handles any's of multiple axis values as well as single values as well
|
// this handles any's of multiple axis values as well as single values as well
|
||||||
float AnyEndpoint::peek() const {
|
AxisValue AnyEndpoint::peek() const {
|
||||||
float result = 0.0f;
|
auto result = AxisValue();
|
||||||
for (auto& child : _children) {
|
for (auto& child : _children) {
|
||||||
auto childValue = child->peek();
|
auto childValue = child->peek();
|
||||||
if (std::abs(childValue) > std::abs(result)) {
|
if (std::abs(childValue.value) > std::abs(result.value)) {
|
||||||
result = childValue;
|
result = childValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,18 +41,18 @@ float AnyEndpoint::peek() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetching the value must trigger any necessary side effects of value() on ALL the children.
|
// Fetching the value must trigger any necessary side effects of value() on ALL the children.
|
||||||
float AnyEndpoint::value() {
|
AxisValue AnyEndpoint::value() {
|
||||||
float result = 0.0f;
|
auto result = AxisValue();
|
||||||
for (auto& child : _children) {
|
for (auto& child : _children) {
|
||||||
auto childValue = child->value();
|
auto childValue = child->value();
|
||||||
if (std::abs(childValue) > std::abs(result)) {
|
if (std::abs(childValue.value) > std::abs(result.value)) {
|
||||||
result = childValue;
|
result.value = childValue.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnyEndpoint::apply(float newValue, const Endpoint::Pointer& source) {
|
void AnyEndpoint::apply(AxisValue newValue, const Endpoint::Pointer& source) {
|
||||||
qFatal("AnyEndpoint is read only");
|
qFatal("AnyEndpoint is read only");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ class AnyEndpoint : public Endpoint {
|
||||||
public:
|
public:
|
||||||
using Endpoint::apply;
|
using Endpoint::apply;
|
||||||
AnyEndpoint(Endpoint::List children);
|
AnyEndpoint(Endpoint::List children);
|
||||||
virtual float peek() const override;
|
virtual AxisValue peek() const override;
|
||||||
virtual float value() override;
|
virtual AxisValue value() override;
|
||||||
virtual void apply(float newValue, const Endpoint::Pointer& source) override;
|
virtual void apply(AxisValue newValue, const Endpoint::Pointer& source) override;
|
||||||
virtual bool writeable() const override;
|
virtual bool writeable() const override;
|
||||||
virtual bool readable() const override;
|
virtual bool readable() const override;
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ public:
|
||||||
using Pointer = std::shared_ptr<ArrayEndpoint>;
|
using Pointer = std::shared_ptr<ArrayEndpoint>;
|
||||||
ArrayEndpoint() : Endpoint(Input::INVALID_INPUT) { }
|
ArrayEndpoint() : Endpoint(Input::INVALID_INPUT) { }
|
||||||
|
|
||||||
virtual float peek() const override { return 0.0f; }
|
virtual AxisValue peek() const override { return AxisValue(); }
|
||||||
|
|
||||||
virtual void apply(float value, const Endpoint::Pointer& source) override {
|
virtual void apply(AxisValue value, const Endpoint::Pointer& source) override {
|
||||||
for (auto& child : _children) {
|
for (auto& child : _children) {
|
||||||
if (child->writeable()) {
|
if (child->writeable()) {
|
||||||
child->apply(value, source);
|
child->apply(value, source);
|
||||||
|
|
|
@ -24,18 +24,18 @@ bool CompositeEndpoint::readable() const {
|
||||||
return first->readable() && second->readable();
|
return first->readable() && second->readable();
|
||||||
}
|
}
|
||||||
|
|
||||||
float CompositeEndpoint::peek() const {
|
AxisValue CompositeEndpoint::peek() const {
|
||||||
float result = first->peek() * -1.0f + second->peek();
|
auto result = AxisValue(first->peek().value * -1.0f + second->peek().value, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetching via value() must trigger any side effects of value() on the children
|
// Fetching via value() must trigger any side effects of value() on the children
|
||||||
float CompositeEndpoint::value() {
|
AxisValue CompositeEndpoint::value() {
|
||||||
float result = first->value() * -1.0f + second->value();
|
auto result = AxisValue(first->value().value * -1.0f + second->value().value, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompositeEndpoint::apply(float newValue, const Pointer& source) {
|
void CompositeEndpoint::apply(AxisValue newValue, const Pointer& source) {
|
||||||
// Composites are read only
|
// Composites are read only
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ namespace controller {
|
||||||
using Endpoint::apply;
|
using Endpoint::apply;
|
||||||
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second);
|
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second);
|
||||||
|
|
||||||
virtual float peek() const override;
|
virtual AxisValue peek() const override;
|
||||||
virtual float value() override;
|
virtual AxisValue value() override;
|
||||||
virtual void apply(float newValue, const Pointer& source) override;
|
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||||
virtual bool readable() const override;
|
virtual bool readable() const override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,19 +14,19 @@
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
float InputEndpoint::peek() const {
|
AxisValue InputEndpoint::peek() const {
|
||||||
if (isPose()) {
|
if (isPose()) {
|
||||||
return peekPose().valid ? 1.0f : 0.0f;
|
return peekPose().valid ? AxisValue(1.0f, 0) : AxisValue(0.0f, 0);
|
||||||
}
|
}
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
auto deviceProxy = userInputMapper->getDevice(_input);
|
auto deviceProxy = userInputMapper->getDevice(_input);
|
||||||
if (!deviceProxy) {
|
if (!deviceProxy) {
|
||||||
return 0.0f;
|
return AxisValue();
|
||||||
}
|
}
|
||||||
return deviceProxy->getValue(_input);
|
return deviceProxy->getValue(_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
float InputEndpoint::value(){
|
AxisValue InputEndpoint::value() {
|
||||||
_read = true;
|
_read = true;
|
||||||
return peek();
|
return peek();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,11 @@ public:
|
||||||
: Endpoint(id) {
|
: Endpoint(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float peek() const override;
|
virtual AxisValue peek() const override;
|
||||||
virtual float value() override;
|
virtual AxisValue value() override;
|
||||||
// FIXME need support for writing back to vibration / force feedback effects
|
// FIXME need support for writing back to vibration / force feedback effects
|
||||||
virtual void apply(float newValue, const Pointer& source) override {}
|
virtual void apply(AxisValue newValue, const Pointer& source) override {}
|
||||||
|
|
||||||
virtual Pose peekPose() const override;
|
virtual Pose peekPose() const override;
|
||||||
virtual Pose pose() override;
|
virtual Pose pose() override;
|
||||||
virtual void apply(const Pose& value, const Pointer& source) override { }
|
virtual void apply(const Pose& value, const Pointer& source) override { }
|
||||||
|
|
|
@ -30,18 +30,18 @@ QString formatException(const QJSValue& exception) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float JSEndpoint::peek() const {
|
AxisValue JSEndpoint::peek() const {
|
||||||
QJSValue result = _callable.call();
|
QJSValue result = _callable.call();
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
qCDebug(controllers).noquote() << formatException(result);
|
qCDebug(controllers).noquote() << formatException(result);
|
||||||
return 0.0f;
|
return AxisValue();
|
||||||
} else {
|
} else {
|
||||||
return (float)result.toNumber();
|
return AxisValue((float)result.toNumber(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSEndpoint::apply(float newValue, const Pointer& source) {
|
void JSEndpoint::apply(AxisValue newValue, const Pointer& source) {
|
||||||
QJSValue result = _callable.call(QJSValueList({ QJSValue(newValue) }));
|
QJSValue result = _callable.call(QJSValueList({ QJSValue(newValue.value) }));
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
qCDebug(controllers).noquote() << formatException(result);
|
qCDebug(controllers).noquote() << formatException(result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ public:
|
||||||
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
|
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float peek() const override;
|
virtual AxisValue peek() const override;
|
||||||
virtual void apply(float newValue, const Pointer& source) override;
|
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QJSValue _callable;
|
mutable QJSValue _callable;
|
||||||
|
|
|
@ -34,9 +34,9 @@ QString formatException(const QScriptValue& exception) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScriptEndpoint::peek() const {
|
AxisValue ScriptEndpoint::peek() const {
|
||||||
const_cast<ScriptEndpoint*>(this)->updateValue();
|
const_cast<ScriptEndpoint*>(this)->updateValue();
|
||||||
return _lastValueRead;
|
return AxisValue(_lastValueRead, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEndpoint::updateValue() {
|
void ScriptEndpoint::updateValue() {
|
||||||
|
@ -58,15 +58,15 @@ void ScriptEndpoint::updateValue() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEndpoint::apply(float value, const Pointer& source) {
|
void ScriptEndpoint::apply(AxisValue value, const Pointer& source) {
|
||||||
if (value == _lastValueWritten) {
|
if (value == _lastValueWritten) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
internalApply(value, source->getInput().getID());
|
_lastValueWritten = value;
|
||||||
|
internalApply(value.value, source->getInput().getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEndpoint::internalApply(float value, int sourceID) {
|
void ScriptEndpoint::internalApply(float value, int sourceID) {
|
||||||
_lastValueWritten = value;
|
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "internalApply", Qt::QueuedConnection,
|
QMetaObject::invokeMethod(this, "internalApply", Qt::QueuedConnection,
|
||||||
Q_ARG(float, value),
|
Q_ARG(float, value),
|
||||||
|
|
|
@ -24,9 +24,8 @@ public:
|
||||||
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
|
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float peek() const override;
|
virtual AxisValue peek() const override;
|
||||||
virtual void apply(float newValue, const Pointer& source) override;
|
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||||
|
|
||||||
|
|
||||||
virtual Pose peekPose() const override;
|
virtual Pose peekPose() const override;
|
||||||
virtual void apply(const Pose& newValue, const Pointer& source) override;
|
virtual void apply(const Pose& newValue, const Pointer& source) override;
|
||||||
|
@ -42,7 +41,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
QScriptValue _callable;
|
QScriptValue _callable;
|
||||||
float _lastValueRead { 0.0f };
|
float _lastValueRead { 0.0f };
|
||||||
float _lastValueWritten { 0.0f };
|
AxisValue _lastValueWritten { 0.0f, 0 };
|
||||||
|
|
||||||
bool _returnPose { false };
|
bool _returnPose { false };
|
||||||
Pose _lastPoseRead;
|
Pose _lastPoseRead;
|
||||||
|
|
|
@ -25,19 +25,19 @@ public:
|
||||||
virtual bool writeable() const override { return !_written; }
|
virtual bool writeable() const override { return !_written; }
|
||||||
virtual bool readable() const override { return !_read; }
|
virtual bool readable() const override { return !_read; }
|
||||||
virtual void reset() override {
|
virtual void reset() override {
|
||||||
apply(0.0f, Endpoint::Pointer());
|
apply(AxisValue(), Endpoint::Pointer());
|
||||||
apply(Pose(), Endpoint::Pointer());
|
apply(Pose(), Endpoint::Pointer());
|
||||||
_written = _read = false;
|
_written = _read = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual float value() override {
|
virtual AxisValue value() override {
|
||||||
_read = true;
|
_read = true;
|
||||||
return VirtualEndpoint::value();
|
return VirtualEndpoint::value();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void apply(float value, const Pointer& source) override {
|
virtual void apply(AxisValue value, const Pointer& source) override {
|
||||||
// For standard endpoints, the first NON-ZERO write counts.
|
// For standard endpoints, the first NON-ZERO write counts.
|
||||||
if (value != 0.0f) {
|
if (value != AxisValue()) {
|
||||||
_written = true;
|
_written = true;
|
||||||
}
|
}
|
||||||
VirtualEndpoint::apply(value, source);
|
VirtualEndpoint::apply(value, source);
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace controller {
|
||||||
public:
|
public:
|
||||||
AccelerationLimiterFilter() {}
|
AccelerationLimiterFilter() {}
|
||||||
|
|
||||||
float apply(float value) const override { return value; }
|
AxisValue apply(AxisValue value) const override { return value; }
|
||||||
Pose apply(Pose value) const override;
|
Pose apply(Pose value) const override;
|
||||||
bool parseParameters(const QJsonValue& parameters) override;
|
bool parseParameters(const QJsonValue& parameters) override;
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ class ClampFilter : public Filter {
|
||||||
REGISTER_FILTER_CLASS(ClampFilter);
|
REGISTER_FILTER_CLASS(ClampFilter);
|
||||||
public:
|
public:
|
||||||
ClampFilter(float min = 0.0, float max = 1.0) : _min(min), _max(max) {};
|
ClampFilter(float min = 0.0, float max = 1.0) : _min(min), _max(max) {};
|
||||||
virtual float apply(float value) const override {
|
virtual AxisValue apply(AxisValue value) const override {
|
||||||
return glm::clamp(value, _min, _max);
|
return { glm::clamp(value.value, _min, _max), value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
|
|
|
@ -19,8 +19,8 @@ class ConstrainToIntegerFilter : public Filter {
|
||||||
public:
|
public:
|
||||||
ConstrainToIntegerFilter() = default;
|
ConstrainToIntegerFilter() = default;
|
||||||
|
|
||||||
virtual float apply(float value) const override {
|
virtual AxisValue apply(AxisValue value) const override {
|
||||||
return glm::sign(value);
|
return { glm::sign(value.value), value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
|
|
|
@ -19,8 +19,8 @@ class ConstrainToPositiveIntegerFilter : public Filter {
|
||||||
public:
|
public:
|
||||||
ConstrainToPositiveIntegerFilter() = default;
|
ConstrainToPositiveIntegerFilter() = default;
|
||||||
|
|
||||||
virtual float apply(float value) const override {
|
virtual AxisValue apply(AxisValue value) const override {
|
||||||
return (value <= 0.0f) ? 0.0f : 1.0f;
|
return { (value.value <= 0.0f) ? 0.0f : 1.0f, value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
#include <QtCore/QJsonArray>
|
#include <QtCore/QJsonArray>
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
float DeadZoneFilter::apply(float value) const {
|
AxisValue DeadZoneFilter::apply(AxisValue value) const {
|
||||||
float scale = ((value < 0.0f) ? -1.0f : 1.0f) / (1.0f - _min);
|
float scale = ((value.value < 0.0f) ? -1.0f : 1.0f) / (1.0f - _min);
|
||||||
float magnitude = std::abs(value);
|
float magnitude = std::abs(value.value);
|
||||||
if (magnitude < _min) {
|
if (magnitude < _min) {
|
||||||
return 0.0f;
|
return { 0.0f, value.timestamp };
|
||||||
}
|
}
|
||||||
return (magnitude - _min) * scale;
|
return { (magnitude - _min) * scale, value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeadZoneFilter::parseParameters(const QJsonValue& parameters) {
|
bool DeadZoneFilter::parseParameters(const QJsonValue& parameters) {
|
||||||
|
|
|
@ -19,7 +19,7 @@ class DeadZoneFilter : public Filter {
|
||||||
public:
|
public:
|
||||||
DeadZoneFilter(float min = 0.0) : _min(min) {};
|
DeadZoneFilter(float min = 0.0) : _min(min) {};
|
||||||
|
|
||||||
virtual float apply(float value) const override;
|
virtual AxisValue apply(AxisValue value) const override;
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace controller {
|
||||||
ExponentialSmoothingFilter(float rotationConstant, float translationConstant) :
|
ExponentialSmoothingFilter(float rotationConstant, float translationConstant) :
|
||||||
_translationConstant(translationConstant), _rotationConstant(rotationConstant) {}
|
_translationConstant(translationConstant), _rotationConstant(rotationConstant) {}
|
||||||
|
|
||||||
float apply(float value) const override { return value; }
|
AxisValue apply(AxisValue value) const override { return value; }
|
||||||
Pose apply(Pose value) const override;
|
Pose apply(Pose value) const override;
|
||||||
bool parseParameters(const QJsonValue& parameters) override;
|
bool parseParameters(const QJsonValue& parameters) override;
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,17 @@ HysteresisFilter::HysteresisFilter(float min, float max) : _min(min), _max(max)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
float HysteresisFilter::apply(float value) const {
|
AxisValue HysteresisFilter::apply(AxisValue value) const {
|
||||||
if (_signaled) {
|
if (_signaled) {
|
||||||
if (value <= _min) {
|
if (value.value <= _min) {
|
||||||
_signaled = false;
|
_signaled = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (value >= _max) {
|
if (value.value >= _max) {
|
||||||
_signaled = true;
|
_signaled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _signaled ? 1.0f : 0.0f;
|
return { _signaled ? 1.0f : 0.0f, value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HysteresisFilter::parseParameters(const QJsonValue& parameters) {
|
bool HysteresisFilter::parseParameters(const QJsonValue& parameters) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ class HysteresisFilter : public Filter {
|
||||||
REGISTER_FILTER_CLASS(HysteresisFilter);
|
REGISTER_FILTER_CLASS(HysteresisFilter);
|
||||||
public:
|
public:
|
||||||
HysteresisFilter(float min = 0.25, float max = 0.75);
|
HysteresisFilter(float min = 0.25, float max = 0.75);
|
||||||
virtual float apply(float value) const override;
|
virtual AxisValue apply(AxisValue value) const override;
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace controller {
|
||||||
LowVelocityFilter(float rotationConstant, float translationConstant) :
|
LowVelocityFilter(float rotationConstant, float translationConstant) :
|
||||||
_translationConstant(translationConstant), _rotationConstant(rotationConstant) {}
|
_translationConstant(translationConstant), _rotationConstant(rotationConstant) {}
|
||||||
|
|
||||||
float apply(float value) const override { return value; }
|
AxisValue apply(AxisValue value) const override { return value; }
|
||||||
Pose apply(Pose newPose) const override;
|
Pose apply(Pose newPose) const override;
|
||||||
bool parseParameters(const QJsonValue& parameters) override;
|
bool parseParameters(const QJsonValue& parameters) override;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,6 @@ using namespace controller;
|
||||||
NotFilter::NotFilter() {
|
NotFilter::NotFilter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
float NotFilter::apply(float value) const {
|
AxisValue NotFilter::apply(AxisValue value) const {
|
||||||
return (value == 0.0f) ? 1.0f : 0.0f;
|
return { (value.value == 0.0f) ? 1.0f : 0.0f, value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ class NotFilter : public Filter {
|
||||||
public:
|
public:
|
||||||
NotFilter();
|
NotFilter();
|
||||||
|
|
||||||
virtual float apply(float value) const override;
|
virtual AxisValue apply(AxisValue value) const override;
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class PostTransformFilter : public Filter {
|
||||||
public:
|
public:
|
||||||
PostTransformFilter() = default;
|
PostTransformFilter() = default;
|
||||||
PostTransformFilter(glm::mat4 transform) : _transform(transform) {}
|
PostTransformFilter(glm::mat4 transform) : _transform(transform) {}
|
||||||
virtual float apply(float value) const override { return value; }
|
virtual AxisValue apply(AxisValue value) const override { return value; }
|
||||||
virtual Pose apply(Pose value) const override { return value.postTransform(_transform); }
|
virtual Pose apply(Pose value) const override { return value.postTransform(_transform); }
|
||||||
virtual bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
virtual bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,21 +15,21 @@ using namespace controller;
|
||||||
|
|
||||||
const float PulseFilter::DEFAULT_LAST_EMIT_TIME = -::std::numeric_limits<float>::max();
|
const float PulseFilter::DEFAULT_LAST_EMIT_TIME = -::std::numeric_limits<float>::max();
|
||||||
|
|
||||||
float PulseFilter::apply(float value) const {
|
AxisValue PulseFilter::apply(AxisValue value) const {
|
||||||
float result = 0.0f;
|
float result = 0.0f;
|
||||||
|
|
||||||
if (0.0f != value) {
|
if (0.0f != value.value) {
|
||||||
float now = secTimestampNow();
|
float now = secTimestampNow();
|
||||||
float delta = now - _lastEmitTime;
|
float delta = now - _lastEmitTime;
|
||||||
if (delta >= _interval) {
|
if (delta >= _interval) {
|
||||||
_lastEmitTime = now;
|
_lastEmitTime = now;
|
||||||
result = value;
|
result = value.value;
|
||||||
}
|
}
|
||||||
} else if (_resetOnZero) {
|
} else if (_resetOnZero) {
|
||||||
_lastEmitTime = DEFAULT_LAST_EMIT_TIME;
|
_lastEmitTime = DEFAULT_LAST_EMIT_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return { result, value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PulseFilter::parseParameters(const QJsonValue& parameters) {
|
bool PulseFilter::parseParameters(const QJsonValue& parameters) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ public:
|
||||||
PulseFilter() = default;
|
PulseFilter() = default;
|
||||||
PulseFilter(float interval) : _interval(interval) {}
|
PulseFilter(float interval) : _interval(interval) {}
|
||||||
|
|
||||||
virtual float apply(float value) const override;
|
virtual AxisValue apply(AxisValue value) const override;
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override { return value; }
|
virtual Pose apply(Pose value) const override { return value; }
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
RotateFilter() = default;
|
RotateFilter() = default;
|
||||||
RotateFilter(glm::quat rotation) : _rotation(rotation) {}
|
RotateFilter(glm::quat rotation) : _rotation(rotation) {}
|
||||||
|
|
||||||
virtual float apply(float value) const override { return value; }
|
virtual AxisValue apply(AxisValue value) const override { return value; }
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override {
|
virtual Pose apply(Pose value) const override {
|
||||||
return value.transform(glm::mat4(glm::quat(_rotation)));
|
return value.transform(glm::mat4(glm::quat(_rotation)));
|
||||||
|
|
|
@ -22,8 +22,8 @@ public:
|
||||||
ScaleFilter() = default;
|
ScaleFilter() = default;
|
||||||
ScaleFilter(float scale) : _scale(scale) {}
|
ScaleFilter(float scale) : _scale(scale) {}
|
||||||
|
|
||||||
virtual float apply(float value) const override {
|
virtual AxisValue apply(AxisValue value) const override {
|
||||||
return value * _scale;
|
return { value.value * _scale, value.timestamp };
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Pose apply(Pose value) const override {
|
virtual Pose apply(Pose value) const override {
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
TransformFilter() = default;
|
TransformFilter() = default;
|
||||||
TransformFilter(glm::mat4 transform) : _transform(transform) {}
|
TransformFilter(glm::mat4 transform) : _transform(transform) {}
|
||||||
|
|
||||||
virtual float apply(float value) const override { return value; }
|
virtual AxisValue apply(AxisValue value) const override { return value; }
|
||||||
virtual Pose apply(Pose value) const override { return value.transform(_transform); }
|
virtual Pose apply(Pose value) const override { return value.transform(_transform); }
|
||||||
virtual bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
virtual bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
TranslateFilter() = default;
|
TranslateFilter() = default;
|
||||||
TranslateFilter(glm::vec3 translate) : _translate(translate) {}
|
TranslateFilter(glm::vec3 translate) : _translate(translate) {}
|
||||||
|
|
||||||
virtual float apply(float value) const override { return value; }
|
virtual AxisValue apply(AxisValue value) const override { return value; }
|
||||||
virtual Pose apply(Pose value) const override { return value.transform(glm::translate(_translate)); }
|
virtual Pose apply(Pose value) const override { return value.transform(glm::translate(_translate)); }
|
||||||
virtual bool parseParameters(const QJsonValue& parameters) override { return parseVec3Parameter(parameters, _translate); }
|
virtual bool parseParameters(const QJsonValue& parameters) override { return parseVec3Parameter(parameters, _translate); }
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,13 @@
|
||||||
const char* KeyboardMouseDevice::NAME = "Keyboard/Mouse";
|
const char* KeyboardMouseDevice::NAME = "Keyboard/Mouse";
|
||||||
bool KeyboardMouseDevice::_enableTouch = true;
|
bool KeyboardMouseDevice::_enableTouch = true;
|
||||||
|
|
||||||
|
void KeyboardMouseDevice::updateDeltaAxisValue(int channel, float value) {
|
||||||
|
// Use timestamps for delta values so that consecutive identical values can be output.
|
||||||
|
if (value != 0.0f || _inputDevice->_axisStateMap[channel].value != 0) {
|
||||||
|
_inputDevice->_axisStateMap[channel] = { value, usecTimestampNow() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KeyboardMouseDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
void KeyboardMouseDevice::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
userInputMapper->withLock([&, this]() {
|
userInputMapper->withLock([&, this]() {
|
||||||
|
@ -31,11 +38,11 @@ void KeyboardMouseDevice::pluginUpdate(float deltaTime, const controller::InputC
|
||||||
_inputDevice->_axisStateMap[MOUSE_AXIS_Y].value = _lastCursor.y();
|
_inputDevice->_axisStateMap[MOUSE_AXIS_Y].value = _lastCursor.y();
|
||||||
|
|
||||||
QPoint currentMove = _lastCursor - _previousCursor;
|
QPoint currentMove = _lastCursor - _previousCursor;
|
||||||
_inputDevice->_axisStateMap[MOUSE_AXIS_X_POS].value = (currentMove.x() > 0 ? currentMove.x() : 0.0f);
|
updateDeltaAxisValue(MOUSE_AXIS_X_POS, currentMove.x() > 0 ? currentMove.x() : 0.0f);
|
||||||
_inputDevice->_axisStateMap[MOUSE_AXIS_X_NEG].value = (currentMove.x() < 0 ? -currentMove.x() : 0.0f);
|
updateDeltaAxisValue(MOUSE_AXIS_X_NEG, currentMove.x() < 0 ? -currentMove.x() : 0.0f);
|
||||||
// Y mouse is inverted positive is pointing up the screen
|
// Y mouse is inverted positive is pointing up the screen
|
||||||
_inputDevice->_axisStateMap[MOUSE_AXIS_Y_POS].value = (currentMove.y() < 0 ? -currentMove.y() : 0.0f);
|
updateDeltaAxisValue(MOUSE_AXIS_Y_POS, currentMove.y() < 0 ? -currentMove.y() : 0.0f);
|
||||||
_inputDevice->_axisStateMap[MOUSE_AXIS_Y_NEG].value = (currentMove.y() > 0 ? currentMove.y() : 0.0f);
|
updateDeltaAxisValue(MOUSE_AXIS_Y_NEG, currentMove.y() > 0 ? currentMove.y() : 0.0f);
|
||||||
_previousCursor = _lastCursor;
|
_previousCursor = _lastCursor;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,9 @@ protected:
|
||||||
std::chrono::high_resolution_clock::time_point _lastTouchTime;
|
std::chrono::high_resolution_clock::time_point _lastTouchTime;
|
||||||
|
|
||||||
static bool _enableTouch;
|
static bool _enableTouch;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateDeltaAxisValue(int channel, float value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_KeyboardMouseDevice_h
|
#endif // hifi_KeyboardMouseDevice_h
|
||||||
|
|
Loading…
Reference in a new issue