mirror of
https://github.com/overte-org/overte.git
synced 2025-07-14 15:16:38 +02:00
Merge pull request #6148 from jherico/controllerFunctions
Fixing controller functions & makeAxis
This commit is contained in:
commit
2ebf862da9
9 changed files with 106 additions and 55 deletions
|
@ -1,29 +1,63 @@
|
||||||
ControllerTest = function() {
|
ControllerTest = function() {
|
||||||
var standard = Controller.Standard;
|
var standard = Controller.Standard;
|
||||||
var actions = Controller.Actions;
|
var actions = Controller.Actions;
|
||||||
|
var xbox = Controller.Hardware.GamePad;
|
||||||
this.mappingEnabled = false;
|
this.mappingEnabled = false;
|
||||||
this.mapping = Controller.newMapping();
|
this.mapping = Controller.newMapping();
|
||||||
this.mapping.from(standard.RX).to(actions.StepYaw);
|
this.mapping.from(standard.RX).to(actions.StepYaw);
|
||||||
|
this.mapping.from(standard.RY).invert().to(actions.Pitch);
|
||||||
|
|
||||||
|
|
||||||
|
var testMakeAxis = false;
|
||||||
|
if (testMakeAxis) {
|
||||||
|
this.mapping.makeAxis(standard.LB, standard.RB).pulse(0.25).scale(40.0).to(actions.StepYaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testStepYaw = false;
|
||||||
|
if (!testMakeAxis && testStepYaw){
|
||||||
|
this.mapping.from(standard.LB).pulse(0.10).invert().scale(40.0).to(actions.StepYaw);
|
||||||
|
this.mapping.from(standard.RB).pulse(0.10).scale(15.0).to(actions.StepYaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testFunctionSource = false;
|
||||||
|
if (testFunctionSource) {
|
||||||
|
this.mapping.from(function(){
|
||||||
|
return Math.sin(Date.now() / 250);
|
||||||
|
}).to(actions.Yaw);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testFunctionDest = true;
|
||||||
|
if (testFunctionDest) {
|
||||||
|
this.mapping.from(standard.DU).pulse(1.0).to(function(value){
|
||||||
|
if (value != 0.0) {
|
||||||
|
print(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
this.mapping.enable();
|
this.mapping.enable();
|
||||||
this.mappingEnabled = true;
|
this.mappingEnabled = true;
|
||||||
|
|
||||||
|
var dumpInputs = false;
|
||||||
print("Actions");
|
if (dumpInputs) {
|
||||||
for (var prop in Controller.Actions) {
|
print("Actions");
|
||||||
print("\t" + prop);
|
for (var prop in Controller.Actions) {
|
||||||
}
|
print("\t" + prop);
|
||||||
print("Standard");
|
|
||||||
for (var prop in Controller.Standard) {
|
|
||||||
print("\t" + prop);
|
|
||||||
}
|
|
||||||
print("Hardware");
|
|
||||||
for (var prop in Controller.Hardware) {
|
|
||||||
print("\t" + prop);
|
|
||||||
for (var prop2 in Controller.Hardware[prop]) {
|
|
||||||
print("\t\t" + prop2);
|
|
||||||
}
|
}
|
||||||
|
print("Standard");
|
||||||
|
for (var prop in Controller.Standard) {
|
||||||
|
print("\t" + prop);
|
||||||
|
}
|
||||||
|
print("Hardware");
|
||||||
|
for (var prop in Controller.Hardware) {
|
||||||
|
print("\t" + prop);
|
||||||
|
for (var prop2 in Controller.Hardware[prop]) {
|
||||||
|
print("\t\t" + prop2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("Done");
|
||||||
}
|
}
|
||||||
print("Done");
|
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
Script.scriptEnding.connect(function() {
|
Script.scriptEnding.connect(function() {
|
||||||
|
|
|
@ -25,12 +25,15 @@ HifiControls.VrDialog {
|
||||||
|
|
||||||
function buildMapping() {
|
function buildMapping() {
|
||||||
testMapping = Controller.newMapping();
|
testMapping = Controller.newMapping();
|
||||||
testMapping.from(standard.RY).invert().to(actions.Pitch);
|
testMapping.fromQml(standard.RY).invert().toQml(actions.Pitch);
|
||||||
|
testMapping.fromQml(function(){
|
||||||
|
return Math.sin(Date.now() / 250);
|
||||||
|
}).toQml(actions.Yaw);
|
||||||
//testMapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
|
//testMapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
|
||||||
// Step yaw takes a number of degrees
|
// Step yaw takes a number of degrees
|
||||||
testMapping.from(standard.LB).invert().scale(15.0).to(actions.StepYaw);
|
testMapping.fromQml(standard.LB).pulse(0.10).invert().scale(40.0).toQml(actions.StepYaw);
|
||||||
testMapping.from(standard.RB).scale(15.0).to(actions.StepYaw);
|
testMapping.fromQml(standard.RB).pulse(0.10).scale(15.0).toQml(actions.StepYaw);
|
||||||
testMapping.from(standard.RX).scale(15.0).to(actions.StepYaw);
|
testMapping.fromQml(standard.RX).scale(15.0).toQml(actions.StepYaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleMapping() {
|
function toggleMapping() {
|
||||||
|
@ -88,8 +91,9 @@ HifiControls.VrDialog {
|
||||||
Hydra { device: root.hydra; width: 180 }
|
Hydra { device: root.hydra; width: 180 }
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Grid {
|
||||||
spacing: 8
|
columns: 6
|
||||||
|
spacing: 4
|
||||||
ScrollingGraph {
|
ScrollingGraph {
|
||||||
controlId: Controller.Actions.Yaw
|
controlId: Controller.Actions.Yaw
|
||||||
label: "Yaw"
|
label: "Yaw"
|
||||||
|
|
|
@ -10,10 +10,9 @@
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
const Input Input::INVALID_INPUT = Input(UINT32_MAX);
|
const uint16_t Input::INVALID_DEVICE = 0xffff;
|
||||||
const uint16_t Input::INVALID_DEVICE = INVALID_INPUT.getDevice();
|
const uint16_t Input::INVALID_CHANNEL = 0x1fff;
|
||||||
const uint16_t Input::INVALID_CHANNEL = INVALID_INPUT.getChannel();
|
const uint16_t Input::INVALID_TYPE = (uint16_t)ChannelType::INVALID;
|
||||||
const uint16_t Input::INVALID_TYPE = (uint16_t)INVALID_INPUT.getType();
|
const Input Input::INVALID_INPUT = Input(INVALID_DEVICE, INVALID_CHANNEL, ChannelType::INVALID);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
enum class ChannelType {
|
enum class ChannelType {
|
||||||
UNKNOWN = 0,
|
INVALID = 0,
|
||||||
BUTTON = 1,
|
BUTTON = 1,
|
||||||
AXIS,
|
AXIS,
|
||||||
POSE,
|
POSE,
|
||||||
|
|
|
@ -145,10 +145,17 @@ void ScriptEndpoint::internalApply(float newValue, float oldValue, int sourceID)
|
||||||
QScriptValueList({ QScriptValue(newValue), QScriptValue(oldValue), QScriptValue(sourceID) }));
|
QScriptValueList({ QScriptValue(newValue), QScriptValue(oldValue), QScriptValue(sourceID) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const Input INVALID_STANDARD_INPUT = Input(UserInputMapper::STANDARD_DEVICE, Input::INVALID_CHANNEL, ChannelType::INVALID);
|
||||||
|
|
||||||
class CompositeEndpoint : public Endpoint, Endpoint::Pair {
|
class CompositeEndpoint : public Endpoint, Endpoint::Pair {
|
||||||
public:
|
public:
|
||||||
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second)
|
CompositeEndpoint(Endpoint::Pointer first, Endpoint::Pointer second)
|
||||||
: Endpoint(Input::INVALID_INPUT), Pair(first, second) { }
|
: Endpoint(Input::INVALID_INPUT), Pair(first, second) {
|
||||||
|
if (first->getInput().device == UserInputMapper::STANDARD_DEVICE &&
|
||||||
|
second->getInput().device == UserInputMapper::STANDARD_DEVICE) {
|
||||||
|
this->_input = INVALID_STANDARD_INPUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual float value() {
|
virtual float value() {
|
||||||
float result = first->value() * -1.0f + second->value();
|
float result = first->value() * -1.0f + second->value();
|
||||||
|
@ -188,7 +195,20 @@ class AnyEndpoint : public Endpoint {
|
||||||
friend class UserInputMapper;
|
friend class UserInputMapper;
|
||||||
public:
|
public:
|
||||||
using Pointer = std::shared_ptr<AnyEndpoint>;
|
using Pointer = std::shared_ptr<AnyEndpoint>;
|
||||||
AnyEndpoint() : Endpoint(Input::INVALID_INPUT) {}
|
AnyEndpoint(Endpoint::List children) : Endpoint(Input::INVALID_INPUT), _children(children) {
|
||||||
|
bool standard = true;
|
||||||
|
// Ensure if we're building a composite of standard devices the composite itself
|
||||||
|
// is treated as a standard device for rule processing order
|
||||||
|
for (auto endpoint : children) {
|
||||||
|
if (endpoint->getInput().device != UserInputMapper::STANDARD_DEVICE) {
|
||||||
|
standard = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (standard) {
|
||||||
|
this->_input = INVALID_STANDARD_INPUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual float value() override {
|
virtual float value() override {
|
||||||
float result = 0;
|
float result = 0;
|
||||||
|
@ -1013,15 +1033,15 @@ Endpoint::Pointer UserInputMapper::parseDestination(const QJsonValue& value) {
|
||||||
|
|
||||||
Endpoint::Pointer UserInputMapper::parseSource(const QJsonValue& value) {
|
Endpoint::Pointer UserInputMapper::parseSource(const QJsonValue& value) {
|
||||||
if (value.isArray()) {
|
if (value.isArray()) {
|
||||||
AnyEndpoint::Pointer result = std::make_shared<AnyEndpoint>();
|
Endpoint::List children;
|
||||||
for (auto arrayItem : value.toArray()) {
|
for (auto arrayItem : value.toArray()) {
|
||||||
Endpoint::Pointer destination = parseEndpoint(arrayItem);
|
Endpoint::Pointer destination = parseEndpoint(arrayItem);
|
||||||
if (!destination) {
|
if (!destination) {
|
||||||
return Endpoint::Pointer();
|
return Endpoint::Pointer();
|
||||||
}
|
}
|
||||||
result->_children.push_back(destination);
|
children.push_back(destination);
|
||||||
}
|
}
|
||||||
return result;
|
return std::make_shared<AnyEndpoint>(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseEndpoint(value);
|
return parseEndpoint(value);
|
||||||
|
|
|
@ -20,13 +20,7 @@
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
QObject* MappingBuilderProxy::from(int input) {
|
QObject* MappingBuilderProxy::fromQml(const QJSValue& source) {
|
||||||
qCDebug(controllers) << "Creating new Route builder proxy from " << input;
|
|
||||||
auto sourceEndpoint = _parent.endpointFor(Input(input));
|
|
||||||
return from(sourceEndpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject* MappingBuilderProxy::from(const QJSValue& source) {
|
|
||||||
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
|
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
|
||||||
auto sourceEndpoint = _parent.endpointFor(source);
|
auto sourceEndpoint = _parent.endpointFor(source);
|
||||||
return from(sourceEndpoint);
|
return from(sourceEndpoint);
|
||||||
|
@ -49,7 +43,13 @@ QObject* MappingBuilderProxy::from(const Endpoint::Pointer& source) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* MappingBuilderProxy::makeAxis(const QJSValue& source1, const QJSValue& source2) {
|
QObject* MappingBuilderProxy::makeAxisQml(const QJSValue& source1, const QJSValue& source2) {
|
||||||
|
auto source1Endpoint = _parent.endpointFor(source1);
|
||||||
|
auto source2Endpoint = _parent.endpointFor(source2);
|
||||||
|
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject* MappingBuilderProxy::makeAxis(const QScriptValue& source1, const QScriptValue& source2) {
|
||||||
auto source1Endpoint = _parent.endpointFor(source1);
|
auto source1Endpoint = _parent.endpointFor(source1);
|
||||||
auto source2Endpoint = _parent.endpointFor(source2);
|
auto source2Endpoint = _parent.endpointFor(source2);
|
||||||
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
|
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
|
||||||
|
|
|
@ -32,10 +32,11 @@ public:
|
||||||
MappingBuilderProxy(UserInputMapper& parent, Mapping::Pointer mapping)
|
MappingBuilderProxy(UserInputMapper& parent, Mapping::Pointer mapping)
|
||||||
: _parent(parent), _mapping(mapping) { }
|
: _parent(parent), _mapping(mapping) { }
|
||||||
|
|
||||||
Q_INVOKABLE QObject* from(int sourceInput);
|
Q_INVOKABLE QObject* fromQml(const QJSValue& source);
|
||||||
Q_INVOKABLE QObject* from(const QJSValue& source);
|
Q_INVOKABLE QObject* makeAxisQml(const QJSValue& source1, const QJSValue& source2);
|
||||||
|
|
||||||
Q_INVOKABLE QObject* from(const QScriptValue& source);
|
Q_INVOKABLE QObject* from(const QScriptValue& source);
|
||||||
Q_INVOKABLE QObject* makeAxis(const QJSValue& source1, const QJSValue& source2);
|
Q_INVOKABLE QObject* makeAxis(const QScriptValue& source1, const QScriptValue& source2);
|
||||||
|
|
||||||
Q_INVOKABLE QObject* enable(bool enable = true);
|
Q_INVOKABLE QObject* enable(bool enable = true);
|
||||||
Q_INVOKABLE QObject* disable() { return enable(false); }
|
Q_INVOKABLE QObject* disable() { return enable(false); }
|
||||||
|
|
|
@ -20,13 +20,7 @@
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
void RouteBuilderProxy::to(int destinationInput) {
|
void RouteBuilderProxy::toQml(const QJSValue& destination) {
|
||||||
qCDebug(controllers) << "Completing route " << destinationInput;
|
|
||||||
auto destinationEndpoint = _parent.endpointFor(Input(destinationInput));
|
|
||||||
return to(destinationEndpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RouteBuilderProxy::to(const QJSValue& destination) {
|
|
||||||
qCDebug(controllers) << "Completing route " << destination.toString();
|
qCDebug(controllers) << "Completing route " << destination.toString();
|
||||||
auto destinationEndpoint = _parent.endpointFor(destination);
|
auto destinationEndpoint = _parent.endpointFor(destination);
|
||||||
return to(destinationEndpoint);
|
return to(destinationEndpoint);
|
||||||
|
@ -45,7 +39,7 @@ void RouteBuilderProxy::to(const Endpoint::Pointer& destination) {
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* RouteBuilderProxy::filter(const QJSValue& expression) {
|
QObject* RouteBuilderProxy::filterQml(const QJSValue& expression) {
|
||||||
if (expression.isCallable()) {
|
if (expression.isCallable()) {
|
||||||
addFilter([=](float value) {
|
addFilter([=](float value) {
|
||||||
QJSValue originalExpression = expression;
|
QJSValue originalExpression = expression;
|
||||||
|
|
|
@ -31,11 +31,10 @@ class RouteBuilderProxy : public QObject {
|
||||||
RouteBuilderProxy(UserInputMapper& parent, Mapping::Pointer mapping, Route::Pointer route)
|
RouteBuilderProxy(UserInputMapper& parent, Mapping::Pointer mapping, Route::Pointer route)
|
||||||
: _parent(parent), _mapping(mapping), _route(route) { }
|
: _parent(parent), _mapping(mapping), _route(route) { }
|
||||||
|
|
||||||
Q_INVOKABLE void to(int destination);
|
Q_INVOKABLE void toQml(const QJSValue& destination);
|
||||||
Q_INVOKABLE void to(const QJSValue& destination);
|
Q_INVOKABLE QObject* filterQml(const QJSValue& expression);
|
||||||
Q_INVOKABLE void to(const QScriptValue& destination);
|
|
||||||
|
|
||||||
Q_INVOKABLE QObject* filter(const QJSValue& expression);
|
Q_INVOKABLE void to(const QScriptValue& destination);
|
||||||
Q_INVOKABLE QObject* filter(const QScriptValue& expression);
|
Q_INVOKABLE QObject* filter(const QScriptValue& expression);
|
||||||
Q_INVOKABLE QObject* clamp(float min, float max);
|
Q_INVOKABLE QObject* clamp(float min, float max);
|
||||||
Q_INVOKABLE QObject* pulse(float interval);
|
Q_INVOKABLE QObject* pulse(float interval);
|
||||||
|
|
Loading…
Reference in a new issue