mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-13 12:12:13 +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();
|
||||
TriggerState& state = _states[button];
|
||||
// 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);
|
||||
|
||||
if (_previousButtons.find(button) == _previousButtons.end()) {
|
||||
|
|
|
@ -15,4 +15,7 @@ namespace controller {
|
|||
AxisValue::AxisValue(const float value, const quint64 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(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);
|
||||
}
|
||||
|
||||
float InputDevice::getValue(ChannelType channelType, uint16_t channel) const {
|
||||
AxisValue InputDevice::getValue(ChannelType channelType, uint16_t channel) const {
|
||||
switch (channelType) {
|
||||
case ChannelType::AXIS:
|
||||
return getAxis(channel).value;
|
||||
return getAxis(channel);
|
||||
|
||||
case ChannelType::BUTTON:
|
||||
return getButton(channel);
|
||||
return { getButton(channel), 0 };
|
||||
|
||||
case ChannelType::POSE:
|
||||
return getPose(channel).valid ? 1.0f : 0.0f;
|
||||
return { getPose(channel).valid ? 1.0f : 0.0f, 0 };
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
return { 0.0f, 0 };
|
||||
}
|
||||
|
||||
|
||||
float InputDevice::getValue(const Input& input) const {
|
||||
AxisValue InputDevice::getValue(const Input& input) const {
|
||||
return getValue(input.getType(), input.channel);
|
||||
}
|
||||
|
||||
|
|
|
@ -112,8 +112,8 @@ public:
|
|||
AxisValue getAxis(int channel) const;
|
||||
Pose getPose(int channel) const;
|
||||
|
||||
float getValue(const Input& input) const;
|
||||
float getValue(ChannelType channelType, uint16_t channel) const;
|
||||
AxisValue getValue(const Input& input) const;
|
||||
AxisValue getValue(ChannelType channelType, uint16_t channel) const;
|
||||
Pose getPoseValue(uint16_t channel) const;
|
||||
|
||||
const QString& getName() const { return _name; }
|
||||
|
|
|
@ -89,17 +89,17 @@ namespace controller {
|
|||
|
||||
float ScriptingInterface::getValue(const int& source) const {
|
||||
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 {
|
||||
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 {
|
||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
return userInputMapper->getPose(Input((uint32_t)source));
|
||||
return userInputMapper->getPose(Input((uint32_t)source));
|
||||
}
|
||||
|
||||
QVector<Action> ScriptingInterface::getAllActions() {
|
||||
|
|
|
@ -290,17 +290,17 @@ void UserInputMapper::update(float deltaTime) {
|
|||
if ((int)_lastStandardStates.size() != standardInputs.size()) {
|
||||
_lastStandardStates.resize(standardInputs.size());
|
||||
for (auto& lastValue : _lastStandardStates) {
|
||||
lastValue = 0;
|
||||
lastValue = AxisValue();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < standardInputs.size(); ++i) {
|
||||
const auto& input = standardInputs[i].first;
|
||||
float value = getValue(input);
|
||||
float& oldValue = _lastStandardStates[i];
|
||||
AxisValue value = getValue(input);
|
||||
AxisValue& oldValue = _lastStandardStates[i];
|
||||
if (value != oldValue) {
|
||||
oldValue = value;
|
||||
emit inputEvent(input.id, value);
|
||||
emit inputEvent(input.id, value.value);
|
||||
}
|
||||
}
|
||||
inputRecorder->frameTick();
|
||||
|
@ -604,10 +604,10 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
|||
destination->apply(value, source);
|
||||
} else {
|
||||
// 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) {
|
||||
qCDebug(controllers) << "Value was " << value;
|
||||
qCDebug(controllers) << "Value was " << value.value << value.timestamp;
|
||||
}
|
||||
// Apply each of the filters.
|
||||
for (const auto& filter : route->filters) {
|
||||
|
@ -615,7 +615,7 @@ bool UserInputMapper::applyRoute(const Route::Pointer& route, bool force) {
|
|||
}
|
||||
|
||||
if (debugRoutes && route->debug) {
|
||||
qCDebug(controllers) << "Filtered value was " << value;
|
||||
qCDebug(controllers) << "Filtered value was " << value.value << value.timestamp;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
float UserInputMapper::getValue(const Input& input) const {
|
||||
AxisValue UserInputMapper::getValue(const Input& input) const {
|
||||
Locker locker(_lock);
|
||||
auto endpoint = endpointFor(input);
|
||||
if (!endpoint) {
|
||||
return 0;
|
||||
return AxisValue();
|
||||
}
|
||||
return endpoint->value();
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ namespace controller {
|
|||
void unloadMappings(const QStringList& jsonFiles);
|
||||
void unloadMapping(const QString& jsonFile);
|
||||
|
||||
float getValue(const Input& input) const;
|
||||
AxisValue getValue(const Input& input) const;
|
||||
Pose getPose(const Input& input) const;
|
||||
|
||||
// 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> _lastActionStates = std::vector<float>(toInt(Action::NUM_ACTIONS), 0.0f);
|
||||
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);
|
||||
|
||||
friend class RouteBuilderProxy;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "../AxisValue.h"
|
||||
#include "../Input.h"
|
||||
#include "../Pose.h"
|
||||
|
||||
|
@ -36,12 +37,13 @@ namespace controller {
|
|||
using WriteLambda = std::function<void(float)>;
|
||||
|
||||
Endpoint(const Input& input) : _input(input) {}
|
||||
virtual float value() { return peek(); }
|
||||
virtual float peek() const = 0;
|
||||
virtual void apply(float value, const Pointer& source) = 0;
|
||||
virtual AxisValue value() { return peek(); }
|
||||
virtual AxisValue peek() const = 0;
|
||||
virtual void apply(AxisValue value, const Pointer& source) = 0;
|
||||
virtual Pose peekPose() const { return Pose(); };
|
||||
virtual Pose pose() { return peekPose(); }
|
||||
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 writeable() const { return true; }
|
||||
virtual bool readable() const { return true; }
|
||||
|
@ -59,8 +61,8 @@ namespace controller {
|
|||
LambdaEndpoint(ReadLambda readLambda, WriteLambda writeLambda = [](float) {})
|
||||
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) { }
|
||||
|
||||
virtual float peek() const override { return _readLambda(); }
|
||||
virtual void apply(float value, const Pointer& source) override { _writeLambda(value); }
|
||||
virtual AxisValue peek() const override { return AxisValue(_readLambda(), 0); }
|
||||
virtual void apply(AxisValue value, const Pointer& source) override { _writeLambda(value.value); }
|
||||
|
||||
private:
|
||||
ReadLambda _readLambda;
|
||||
|
@ -76,8 +78,8 @@ namespace controller {
|
|||
: Endpoint(Input::INVALID_INPUT), _readLambda(readLambda), _writeLambda(writeLambda) {
|
||||
}
|
||||
|
||||
virtual float peek() const override { return _readLambda(); }
|
||||
virtual void apply(float value, const Pointer& source) override { _writeLambda(value); }
|
||||
virtual AxisValue peek() const override { return AxisValue(_readLambda(), 0); }
|
||||
virtual void apply(AxisValue value, const Pointer& source) override { _writeLambda(value.value); }
|
||||
|
||||
private:
|
||||
const ReadLambda& _readLambda;
|
||||
|
@ -91,15 +93,15 @@ namespace controller {
|
|||
: Endpoint(id) {
|
||||
}
|
||||
|
||||
virtual float peek() const override { return _currentValue; }
|
||||
virtual void apply(float value, const Pointer& source) override { _currentValue = value; }
|
||||
virtual AxisValue peek() const override { return _currentValue; }
|
||||
virtual void apply(AxisValue value, const Pointer& source) override { _currentValue = value; }
|
||||
|
||||
virtual Pose peekPose() const override { return _currentPose; }
|
||||
virtual void apply(const Pose& value, const Pointer& source) override {
|
||||
_currentPose = value;
|
||||
}
|
||||
protected:
|
||||
float _currentValue { 0.0f };
|
||||
AxisValue _currentValue { 0.0f, 0 };
|
||||
Pose _currentPose {};
|
||||
};
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <QtCore/QEasingCurve>
|
||||
|
||||
#include "../AxisValue.h"
|
||||
#include "../Pose.h"
|
||||
|
||||
class QJsonValue;
|
||||
|
@ -37,7 +38,7 @@ namespace controller {
|
|||
|
||||
virtual ~Filter() = default;
|
||||
|
||||
virtual float apply(float value) const = 0;
|
||||
virtual AxisValue apply(AxisValue value) const = 0;
|
||||
virtual Pose apply(Pose value) const = 0;
|
||||
|
||||
// Factory features
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace controller {
|
|||
class EndpointConditional : public Conditional {
|
||||
public:
|
||||
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:
|
||||
Endpoint::Pointer _endpoint;
|
||||
};
|
||||
|
|
|
@ -15,22 +15,22 @@
|
|||
|
||||
using namespace controller;
|
||||
|
||||
void ActionEndpoint::apply(float newValue, const Pointer& source) {
|
||||
void ActionEndpoint::apply(AxisValue newValue, const Pointer& source) {
|
||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||
InputRecorder* inputRecorder = InputRecorder::getInstance();
|
||||
QString actionName;
|
||||
if (inputRecorder->isPlayingback() || inputRecorder->isRecording()) {
|
||||
actionName = userInputMapper->getActionName(Action(_input.getChannel()));
|
||||
if (inputRecorder->isPlayingback()) {
|
||||
newValue = inputRecorder->getActionState(actionName);
|
||||
newValue = AxisValue(inputRecorder->getActionState(actionName), 0);
|
||||
}
|
||||
}
|
||||
|
||||
_currentValue += newValue;
|
||||
_currentValue.value += newValue.value;
|
||||
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) {
|
||||
|
@ -51,7 +51,7 @@ void ActionEndpoint::apply(const Pose& value, const Pointer& source) {
|
|||
}
|
||||
|
||||
void ActionEndpoint::reset() {
|
||||
_currentValue = 0.0f;
|
||||
_currentValue = AxisValue();
|
||||
_currentPose = Pose();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ class ActionEndpoint : public Endpoint {
|
|||
public:
|
||||
ActionEndpoint(const Input& id = Input::INVALID_INPUT) : Endpoint(id) { }
|
||||
|
||||
virtual float peek() const override { return _currentValue; }
|
||||
virtual void apply(float newValue, const Pointer& source) override;
|
||||
virtual AxisValue peek() const override { return _currentValue; }
|
||||
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||
|
||||
virtual Pose peekPose() const override { return _currentPose; }
|
||||
virtual void apply(const Pose& value, const Pointer& source) override;
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
private:
|
||||
float _currentValue{ 0.0f };
|
||||
AxisValue _currentValue { 0.0f, 0 };
|
||||
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
|
||||
float AnyEndpoint::peek() const {
|
||||
float result = 0.0f;
|
||||
AxisValue AnyEndpoint::peek() const {
|
||||
auto result = AxisValue();
|
||||
for (auto& child : _children) {
|
||||
auto childValue = child->peek();
|
||||
if (std::abs(childValue) > std::abs(result)) {
|
||||
if (std::abs(childValue.value) > std::abs(result.value)) {
|
||||
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.
|
||||
float AnyEndpoint::value() {
|
||||
float result = 0.0f;
|
||||
AxisValue AnyEndpoint::value() {
|
||||
auto result = AxisValue();
|
||||
for (auto& child : _children) {
|
||||
auto childValue = child->value();
|
||||
if (std::abs(childValue) > std::abs(result)) {
|
||||
result = childValue;
|
||||
if (std::abs(childValue.value) > std::abs(result.value)) {
|
||||
result.value = childValue.value;
|
||||
}
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ class AnyEndpoint : public Endpoint {
|
|||
public:
|
||||
using Endpoint::apply;
|
||||
AnyEndpoint(Endpoint::List children);
|
||||
virtual float peek() const override;
|
||||
virtual float value() override;
|
||||
virtual void apply(float newValue, const Endpoint::Pointer& source) override;
|
||||
virtual AxisValue peek() const override;
|
||||
virtual AxisValue value() override;
|
||||
virtual void apply(AxisValue newValue, const Endpoint::Pointer& source) override;
|
||||
virtual bool writeable() const override;
|
||||
virtual bool readable() const override;
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ public:
|
|||
using Pointer = std::shared_ptr<ArrayEndpoint>;
|
||||
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) {
|
||||
if (child->writeable()) {
|
||||
child->apply(value, source);
|
||||
|
|
|
@ -24,18 +24,18 @@ bool CompositeEndpoint::readable() const {
|
|||
return first->readable() && second->readable();
|
||||
}
|
||||
|
||||
float CompositeEndpoint::peek() const {
|
||||
float result = first->peek() * -1.0f + second->peek();
|
||||
AxisValue CompositeEndpoint::peek() const {
|
||||
auto result = AxisValue(first->peek().value * -1.0f + second->peek().value, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Fetching via value() must trigger any side effects of value() on the children
|
||||
float CompositeEndpoint::value() {
|
||||
float result = first->value() * -1.0f + second->value();
|
||||
AxisValue CompositeEndpoint::value() {
|
||||
auto result = AxisValue(first->value().value * -1.0f + second->value().value, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CompositeEndpoint::apply(float newValue, const Pointer& source) {
|
||||
void CompositeEndpoint::apply(AxisValue newValue, const Pointer& source) {
|
||||
// Composites are read only
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ namespace controller {
|
|||
using Endpoint::apply;
|
||||
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second);
|
||||
|
||||
virtual float peek() const override;
|
||||
virtual float value() override;
|
||||
virtual void apply(float newValue, const Pointer& source) override;
|
||||
virtual AxisValue peek() const override;
|
||||
virtual AxisValue value() override;
|
||||
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||
virtual bool readable() const override;
|
||||
|
||||
};
|
||||
|
|
|
@ -14,19 +14,19 @@
|
|||
|
||||
using namespace controller;
|
||||
|
||||
float InputEndpoint::peek() const {
|
||||
AxisValue InputEndpoint::peek() const {
|
||||
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 deviceProxy = userInputMapper->getDevice(_input);
|
||||
if (!deviceProxy) {
|
||||
return 0.0f;
|
||||
return AxisValue();
|
||||
}
|
||||
return deviceProxy->getValue(_input);
|
||||
}
|
||||
|
||||
float InputEndpoint::value(){
|
||||
AxisValue InputEndpoint::value() {
|
||||
_read = true;
|
||||
return peek();
|
||||
}
|
||||
|
|
|
@ -20,10 +20,11 @@ public:
|
|||
: Endpoint(id) {
|
||||
}
|
||||
|
||||
virtual float peek() const override;
|
||||
virtual float value() override;
|
||||
virtual AxisValue peek() const override;
|
||||
virtual AxisValue value() override;
|
||||
// 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 pose() override;
|
||||
virtual void apply(const Pose& value, const Pointer& source) override { }
|
||||
|
|
|
@ -30,18 +30,18 @@ QString formatException(const QJSValue& exception) {
|
|||
return result;
|
||||
}
|
||||
|
||||
float JSEndpoint::peek() const {
|
||||
AxisValue JSEndpoint::peek() const {
|
||||
QJSValue result = _callable.call();
|
||||
if (result.isError()) {
|
||||
qCDebug(controllers).noquote() << formatException(result);
|
||||
return 0.0f;
|
||||
return AxisValue();
|
||||
} else {
|
||||
return (float)result.toNumber();
|
||||
return AxisValue((float)result.toNumber(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void JSEndpoint::apply(float newValue, const Pointer& source) {
|
||||
QJSValue result = _callable.call(QJSValueList({ QJSValue(newValue) }));
|
||||
void JSEndpoint::apply(AxisValue newValue, const Pointer& source) {
|
||||
QJSValue result = _callable.call(QJSValueList({ QJSValue(newValue.value) }));
|
||||
if (result.isError()) {
|
||||
qCDebug(controllers).noquote() << formatException(result);
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ public:
|
|||
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
|
||||
}
|
||||
|
||||
virtual float peek() const override;
|
||||
virtual void apply(float newValue, const Pointer& source) override;
|
||||
virtual AxisValue peek() const override;
|
||||
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||
|
||||
private:
|
||||
mutable QJSValue _callable;
|
||||
|
|
|
@ -34,9 +34,9 @@ QString formatException(const QScriptValue& exception) {
|
|||
return result;
|
||||
}
|
||||
|
||||
float ScriptEndpoint::peek() const {
|
||||
AxisValue ScriptEndpoint::peek() const {
|
||||
const_cast<ScriptEndpoint*>(this)->updateValue();
|
||||
return _lastValueRead;
|
||||
return AxisValue(_lastValueRead, 0);
|
||||
}
|
||||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
internalApply(value, source->getInput().getID());
|
||||
_lastValueWritten = value;
|
||||
internalApply(value.value, source->getInput().getID());
|
||||
}
|
||||
|
||||
void ScriptEndpoint::internalApply(float value, int sourceID) {
|
||||
_lastValueWritten = value;
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "internalApply", Qt::QueuedConnection,
|
||||
Q_ARG(float, value),
|
||||
|
|
|
@ -24,9 +24,8 @@ public:
|
|||
: Endpoint(Input::INVALID_INPUT), _callable(callable) {
|
||||
}
|
||||
|
||||
virtual float peek() const override;
|
||||
virtual void apply(float newValue, const Pointer& source) override;
|
||||
|
||||
virtual AxisValue peek() const override;
|
||||
virtual void apply(AxisValue newValue, const Pointer& source) override;
|
||||
|
||||
virtual Pose peekPose() const override;
|
||||
virtual void apply(const Pose& newValue, const Pointer& source) override;
|
||||
|
@ -42,7 +41,7 @@ protected:
|
|||
private:
|
||||
QScriptValue _callable;
|
||||
float _lastValueRead { 0.0f };
|
||||
float _lastValueWritten { 0.0f };
|
||||
AxisValue _lastValueWritten { 0.0f, 0 };
|
||||
|
||||
bool _returnPose { false };
|
||||
Pose _lastPoseRead;
|
||||
|
|
|
@ -25,19 +25,19 @@ public:
|
|||
virtual bool writeable() const override { return !_written; }
|
||||
virtual bool readable() const override { return !_read; }
|
||||
virtual void reset() override {
|
||||
apply(0.0f, Endpoint::Pointer());
|
||||
apply(AxisValue(), Endpoint::Pointer());
|
||||
apply(Pose(), Endpoint::Pointer());
|
||||
_written = _read = false;
|
||||
}
|
||||
|
||||
virtual float value() override {
|
||||
virtual AxisValue value() override {
|
||||
_read = true;
|
||||
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.
|
||||
if (value != 0.0f) {
|
||||
if (value != AxisValue()) {
|
||||
_written = true;
|
||||
}
|
||||
VirtualEndpoint::apply(value, source);
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace controller {
|
|||
public:
|
||||
AccelerationLimiterFilter() {}
|
||||
|
||||
float apply(float value) const override { return value; }
|
||||
AxisValue apply(AxisValue value) const override { return value; }
|
||||
Pose apply(Pose value) const override;
|
||||
bool parseParameters(const QJsonValue& parameters) override;
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ class ClampFilter : public Filter {
|
|||
REGISTER_FILTER_CLASS(ClampFilter);
|
||||
public:
|
||||
ClampFilter(float min = 0.0, float max = 1.0) : _min(min), _max(max) {};
|
||||
virtual float apply(float value) const override {
|
||||
return glm::clamp(value, _min, _max);
|
||||
virtual AxisValue apply(AxisValue value) const override {
|
||||
return { glm::clamp(value.value, _min, _max), value.timestamp };
|
||||
}
|
||||
|
||||
virtual Pose apply(Pose value) const override { return value; }
|
||||
|
|
|
@ -19,8 +19,8 @@ class ConstrainToIntegerFilter : public Filter {
|
|||
public:
|
||||
ConstrainToIntegerFilter() = default;
|
||||
|
||||
virtual float apply(float value) const override {
|
||||
return glm::sign(value);
|
||||
virtual AxisValue apply(AxisValue value) const override {
|
||||
return { glm::sign(value.value), value.timestamp };
|
||||
}
|
||||
|
||||
virtual Pose apply(Pose value) const override { return value; }
|
||||
|
|
|
@ -19,8 +19,8 @@ class ConstrainToPositiveIntegerFilter : public Filter {
|
|||
public:
|
||||
ConstrainToPositiveIntegerFilter() = default;
|
||||
|
||||
virtual float apply(float value) const override {
|
||||
return (value <= 0.0f) ? 0.0f : 1.0f;
|
||||
virtual AxisValue apply(AxisValue value) const override {
|
||||
return { (value.value <= 0.0f) ? 0.0f : 1.0f, value.timestamp };
|
||||
}
|
||||
|
||||
virtual Pose apply(Pose value) const override { return value; }
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
#include <QtCore/QJsonArray>
|
||||
|
||||
using namespace controller;
|
||||
float DeadZoneFilter::apply(float value) const {
|
||||
float scale = ((value < 0.0f) ? -1.0f : 1.0f) / (1.0f - _min);
|
||||
float magnitude = std::abs(value);
|
||||
AxisValue DeadZoneFilter::apply(AxisValue value) const {
|
||||
float scale = ((value.value < 0.0f) ? -1.0f : 1.0f) / (1.0f - _min);
|
||||
float magnitude = std::abs(value.value);
|
||||
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) {
|
||||
|
|
|
@ -19,7 +19,7 @@ class DeadZoneFilter : public Filter {
|
|||
public:
|
||||
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; }
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace controller {
|
|||
ExponentialSmoothingFilter(float rotationConstant, float translationConstant) :
|
||||
_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;
|
||||
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 (value <= _min) {
|
||||
if (value.value <= _min) {
|
||||
_signaled = false;
|
||||
}
|
||||
} else {
|
||||
if (value >= _max) {
|
||||
if (value.value >= _max) {
|
||||
_signaled = true;
|
||||
}
|
||||
}
|
||||
return _signaled ? 1.0f : 0.0f;
|
||||
return { _signaled ? 1.0f : 0.0f, value.timestamp };
|
||||
}
|
||||
|
||||
bool HysteresisFilter::parseParameters(const QJsonValue& parameters) {
|
||||
|
|
|
@ -18,7 +18,7 @@ class HysteresisFilter : public Filter {
|
|||
REGISTER_FILTER_CLASS(HysteresisFilter);
|
||||
public:
|
||||
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; }
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace controller {
|
|||
LowVelocityFilter(float rotationConstant, float translationConstant) :
|
||||
_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;
|
||||
bool parseParameters(const QJsonValue& parameters) override;
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ using namespace controller;
|
|||
NotFilter::NotFilter() {
|
||||
}
|
||||
|
||||
float NotFilter::apply(float value) const {
|
||||
return (value == 0.0f) ? 1.0f : 0.0f;
|
||||
AxisValue NotFilter::apply(AxisValue value) const {
|
||||
return { (value.value == 0.0f) ? 1.0f : 0.0f, value.timestamp };
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ class NotFilter : public Filter {
|
|||
public:
|
||||
NotFilter();
|
||||
|
||||
virtual float apply(float value) const override;
|
||||
virtual AxisValue apply(AxisValue value) const override;
|
||||
virtual Pose apply(Pose value) const override { return value; }
|
||||
};
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class PostTransformFilter : public Filter {
|
|||
public:
|
||||
PostTransformFilter() = default;
|
||||
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 bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
||||
private:
|
||||
|
|
|
@ -15,21 +15,21 @@ using namespace controller;
|
|||
|
||||
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;
|
||||
|
||||
if (0.0f != value) {
|
||||
if (0.0f != value.value) {
|
||||
float now = secTimestampNow();
|
||||
float delta = now - _lastEmitTime;
|
||||
if (delta >= _interval) {
|
||||
_lastEmitTime = now;
|
||||
result = value;
|
||||
result = value.value;
|
||||
}
|
||||
} else if (_resetOnZero) {
|
||||
_lastEmitTime = DEFAULT_LAST_EMIT_TIME;
|
||||
}
|
||||
|
||||
return result;
|
||||
return { result, value.timestamp };
|
||||
}
|
||||
|
||||
bool PulseFilter::parseParameters(const QJsonValue& parameters) {
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
PulseFilter() = default;
|
||||
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; }
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
RotateFilter() = default;
|
||||
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 {
|
||||
return value.transform(glm::mat4(glm::quat(_rotation)));
|
||||
|
|
|
@ -22,8 +22,8 @@ public:
|
|||
ScaleFilter() = default;
|
||||
ScaleFilter(float scale) : _scale(scale) {}
|
||||
|
||||
virtual float apply(float value) const override {
|
||||
return value * _scale;
|
||||
virtual AxisValue apply(AxisValue value) const override {
|
||||
return { value.value * _scale, value.timestamp };
|
||||
}
|
||||
|
||||
virtual Pose apply(Pose value) const override {
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
TransformFilter() = default;
|
||||
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 bool parseParameters(const QJsonValue& parameters) override { return parseMat4Parameter(parameters, _transform); }
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
TranslateFilter() = default;
|
||||
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 bool parseParameters(const QJsonValue& parameters) override { return parseVec3Parameter(parameters, _translate); }
|
||||
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
const char* KeyboardMouseDevice::NAME = "Keyboard/Mouse";
|
||||
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) {
|
||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||
userInputMapper->withLock([&, this]() {
|
||||
|
@ -31,11 +38,11 @@ void KeyboardMouseDevice::pluginUpdate(float deltaTime, const controller::InputC
|
|||
_inputDevice->_axisStateMap[MOUSE_AXIS_Y].value = _lastCursor.y();
|
||||
|
||||
QPoint currentMove = _lastCursor - _previousCursor;
|
||||
_inputDevice->_axisStateMap[MOUSE_AXIS_X_POS].value = (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_POS, 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
|
||||
_inputDevice->_axisStateMap[MOUSE_AXIS_Y_POS].value = (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_POS, currentMove.y() < 0 ? -currentMove.y() : 0.0f);
|
||||
updateDeltaAxisValue(MOUSE_AXIS_Y_NEG, currentMove.y() > 0 ? currentMove.y() : 0.0f);
|
||||
_previousCursor = _lastCursor;
|
||||
});
|
||||
|
||||
|
|
|
@ -130,6 +130,9 @@ protected:
|
|||
std::chrono::high_resolution_clock::time_point _lastTouchTime;
|
||||
|
||||
static bool _enableTouch;
|
||||
|
||||
private:
|
||||
void updateDeltaAxisValue(int channel, float value);
|
||||
};
|
||||
|
||||
#endif // hifi_KeyboardMouseDevice_h
|
||||
|
|
Loading…
Reference in a new issue