Resolving ambiguity between functions and inputs differently

This commit is contained in:
Brad Davis 2015-10-22 09:40:41 -07:00
parent 4938e5ea84
commit 5d4cbfdacb
6 changed files with 49 additions and 51 deletions

View file

@ -17,9 +17,9 @@ ControllerTest = function() {
this.mapping.from(standard.RB).pulse(0.10).scale(15.0).to(actions.StepYaw);
}
var testFunctionSource = false;
var testFunctionSource = true;
if (testFunctionSource) {
this.mapping.fromFunction(function(){
this.mapping.from(function(){
return Math.sin(Date.now() / 250);
}).to(actions.Yaw);
}
@ -27,22 +27,25 @@ ControllerTest = function() {
this.mapping.enable();
this.mappingEnabled = true;
print("Actions");
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);
var dumpInputs = false;
if (dumpInputs) {
print("Actions");
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("Done");
}
print("Done");
var that = this;
Script.scriptEnding.connect(function() {

View file

@ -25,15 +25,15 @@ HifiControls.VrDialog {
function buildMapping() {
testMapping = Controller.newMapping();
testMapping.from(standard.RY).invert().to(actions.Pitch);
testMapping.fromQmlFunction(function(){
testMapping.fromQml(standard.RY).invert().toQml(actions.Pitch);
testMapping.fromQml(function(){
return Math.sin(Date.now() / 250);
}).to(actions.Yaw);
}).toQml(actions.Yaw);
//testMapping.makeAxis(standard.LB, standard.RB).to(actions.Yaw);
// Step yaw takes a number of degrees
testMapping.from(standard.LB).pulse(0.10).invert().scale(40.0).to(actions.StepYaw);
testMapping.from(standard.RB).pulse(0.10).scale(15.0).to(actions.StepYaw);
testMapping.from(standard.RX).scale(15.0).to(actions.StepYaw);
testMapping.fromQml(standard.LB).pulse(0.10).invert().scale(40.0).toQml(actions.StepYaw);
testMapping.fromQml(standard.RB).pulse(0.10).scale(15.0).toQml(actions.StepYaw);
testMapping.fromQml(standard.RX).scale(15.0).toQml(actions.StepYaw);
}
function toggleMapping() {
@ -91,8 +91,9 @@ HifiControls.VrDialog {
Hydra { device: root.hydra; width: 180 }
}
Row {
spacing: 8
Grid {
columns: 6
spacing: 4
ScrollingGraph {
controlId: Controller.Actions.Yaw
label: "Yaw"

View file

@ -20,19 +20,13 @@
using namespace controller;
QObject* MappingBuilderProxy::from(int input) {
qCDebug(controllers) << "Creating new Route builder proxy from " << input;
auto sourceEndpoint = _parent.endpointFor(Input(input));
return from(sourceEndpoint);
}
QObject* MappingBuilderProxy::fromQmlFunction(const QJSValue& source) {
QObject* MappingBuilderProxy::fromQml(const QJSValue& source) {
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
auto sourceEndpoint = _parent.endpointFor(source);
return from(sourceEndpoint);
}
QObject* MappingBuilderProxy::fromFunction(const QScriptValue& source) {
QObject* MappingBuilderProxy::from(const QScriptValue& source) {
qCDebug(controllers) << "Creating new Route builder proxy from " << source.toString();
auto sourceEndpoint = _parent.endpointFor(source);
return from(sourceEndpoint);
@ -49,9 +43,15 @@ QObject* MappingBuilderProxy::from(const Endpoint::Pointer& source) {
}
}
QObject* MappingBuilderProxy::makeAxis(int source1, int source2) {
auto source1Endpoint = _parent.endpointFor(Input(source1));
auto source2Endpoint = _parent.endpointFor(Input(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 source2Endpoint = _parent.endpointFor(source2);
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
}

View file

@ -32,10 +32,11 @@ public:
MappingBuilderProxy(UserInputMapper& parent, Mapping::Pointer mapping)
: _parent(parent), _mapping(mapping) { }
Q_INVOKABLE QObject* from(int sourceInput);
Q_INVOKABLE QObject* fromQmlFunction(const QJSValue& source);
Q_INVOKABLE QObject* fromFunction(const QScriptValue& source);
Q_INVOKABLE QObject* makeAxis(int source1, const int source2);
Q_INVOKABLE QObject* fromQml(const QJSValue& source);
Q_INVOKABLE QObject* makeAxisQml(const QJSValue& source1, const QJSValue& source2);
Q_INVOKABLE QObject* from(const QScriptValue& source);
Q_INVOKABLE QObject* makeAxis(const QScriptValue& source1, const QScriptValue& source2);
Q_INVOKABLE QObject* enable(bool enable = true);
Q_INVOKABLE QObject* disable() { return enable(false); }

View file

@ -20,13 +20,7 @@
using namespace controller;
void RouteBuilderProxy::to(int destinationInput) {
qCDebug(controllers) << "Completing route " << destinationInput;
auto destinationEndpoint = _parent.endpointFor(Input(destinationInput));
return to(destinationEndpoint);
}
void RouteBuilderProxy::to(const QJSValue& destination) {
void RouteBuilderProxy::toQml(const QJSValue& destination) {
qCDebug(controllers) << "Completing route " << destination.toString();
auto destinationEndpoint = _parent.endpointFor(destination);
return to(destinationEndpoint);
@ -45,7 +39,7 @@ void RouteBuilderProxy::to(const Endpoint::Pointer& destination) {
deleteLater();
}
QObject* RouteBuilderProxy::filter(const QJSValue& expression) {
QObject* RouteBuilderProxy::filterQml(const QJSValue& expression) {
if (expression.isCallable()) {
addFilter([=](float value) {
QJSValue originalExpression = expression;

View file

@ -31,11 +31,10 @@ class RouteBuilderProxy : public QObject {
RouteBuilderProxy(UserInputMapper& parent, Mapping::Pointer mapping, Route::Pointer route)
: _parent(parent), _mapping(mapping), _route(route) { }
Q_INVOKABLE void to(int destination);
Q_INVOKABLE void to(const QJSValue& destination);
Q_INVOKABLE void to(const QScriptValue& destination);
Q_INVOKABLE void toQml(const QJSValue& destination);
Q_INVOKABLE QObject* filterQml(const QJSValue& expression);
Q_INVOKABLE QObject* filter(const QJSValue& expression);
Q_INVOKABLE void to(const QScriptValue& destination);
Q_INVOKABLE QObject* filter(const QScriptValue& expression);
Q_INVOKABLE QObject* clamp(float min, float max);
Q_INVOKABLE QObject* pulse(float interval);