Fixes and PR comments

This commit is contained in:
Brad Davis 2015-10-14 16:51:52 -07:00
parent 0063f9ae1d
commit e39219c2b5
10 changed files with 69 additions and 29 deletions

View file

@ -11,6 +11,16 @@
// Assumes you only have the default keyboard connected
function findAction(name) {
var actions = Controller.getAllActions();
for (var i = 0; i < actions.length; i++) {
if (actions[i].actionName == name) {
return i;
}
}
// If the action isn't found, it will default to the first available action
return 0;
}
var hydra = Controller.Hardware.Hydra2;
@ -46,44 +56,48 @@ Controller.resetAllDeviceBindings();
// Query all actions
print("All Actions: \n" + Controller.getAllActions());
var actionId = findAction("YAW_LEFT")
print("Yaw Left action ID: " + actionId)
// Each action stores:
// action: int representation of enum
print("Action 5 int: \n" + Controller.getAllActions()[5].action);
print("Action int: \n" + Controller.getAllActions()[actionId].action);
// actionName: string representation of enum
print("Action 5 name: \n" + Controller.getAllActions()[5].actionName);
print("Action name: \n" + Controller.getAllActions()[actionId].actionName);
// inputChannels: list of all inputchannels that control that action
print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n");
print("Action input channels: \n" + Controller.getAllActions()[actionId].inputChannels + "\n");
// Each input channel stores:
// action: Action that this InputChannel maps to
print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action);
print("Input channel action: \n" + Controller.getAllActions()[actionId].inputChannels[0].action);
// scale: sensitivity of input
print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale);
print("Input channel scale: \n" + Controller.getAllActions()[actionId].inputChannels[0].scale);
// input and modifier: Inputs
print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n");
print("Input channel input and modifier: \n" + Controller.getAllActions()[actionId].inputChannels[0].input + "\n" + Controller.getAllActions()[actionId].inputChannels[0].modifier + "\n");
// Each Input stores:
// device: device of input
print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device);
print("Input device: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.device);
// channel: channel of input
print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel);
print("Input channel: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.channel);
// type: type of input (Unknown, Button, Axis, Joint)
print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type);
print("Input type: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.type);
// id: id of input
print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n");
print("Input id: \n" + Controller.getAllActions()[actionId].inputChannels[0].input.id + "\n");
// You can get the name of a device from its id
print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id));
print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[actionId].inputChannels[0].input.id));
// You can also get all of a devices input channels
print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n");
@ -119,7 +133,7 @@ for (i = 0; i < availableInputs.length; i++) {
// You can modify key bindings by using these avaiable inputs
// This will replace e (up) with 6
var e = Controller.getAllActions()[5].inputChannels[0];
var e = Controller.getAllActions()[actionId].inputChannels[0];
Controller.removeInputChannel(e);
e.input = availableInputs[6].input;
Controller.addInputChannel(e);

View file

@ -38,7 +38,7 @@ var mouseLook = (function () {
keyboardID = 0;
function onKeyPressEvent(event) {
if (event.text == 'M') {
if (event.text == 'm') {
active = !active;
updateMapping();
}

View file

@ -15,6 +15,7 @@
#include <avatar/MyAvatar.h>
#include <HandData.h>
#include <HFBackEvent.h>
#include <plugins/PluginManager.h>
#include "Application.h"
#include "devices/MotionTracker.h"
@ -115,7 +116,7 @@ void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::Input
inputPair.second = QString(object.property("inputName").toVariant().toString());
}
void ControllerScriptingInterface::registerControllerTypes(ScriptEngine* engine) {
void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine) {
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::Action> >(engine);
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputChannel> >(engine);
qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine);
@ -426,11 +427,25 @@ void ControllerScriptingInterface::releaseInputController(controller::InputContr
}
void ControllerScriptingInterface::update() {
controller::ScriptingInterface::update();
static float last = secTimestampNow();
float now = secTimestampNow();
float delta = now - last;
last = now;
for(auto inputPlugin : PluginManager::getInstance()->getInputPlugins()) {
if (inputPlugin->isActive()) {
inputPlugin->pluginUpdate(delta, false);
}
}
auto userInputMapper = DependencyManager::get<UserInputMapper>();
userInputMapper->update(delta);
for (auto entry : _inputControllers) {
entry.second->update();
}
controller::ScriptingInterface::update();
}
QVector<UserInputMapper::Action> ControllerScriptingInterface::getAllActions() {

View file

@ -88,7 +88,7 @@ public:
Q_INVOKABLE QVector<QString> getActionNames() const;
virtual void registerControllerTypes(ScriptEngine* engine);
virtual void registerControllerTypes(QScriptEngine* engine);
void emitKeyPressEvent(QKeyEvent* event);
void emitKeyReleaseEvent(QKeyEvent* event);

View file

@ -357,7 +357,7 @@ namespace controller {
}
int ScriptingInterface::getNumberOfTriggers() const {
return 2;
return StandardCounts::TRIGGERS;
}
float ScriptingInterface::getTriggerValue(int triggerIndex) const {
@ -365,7 +365,7 @@ namespace controller {
}
int ScriptingInterface::getNumberOfJoysticks() const {
return 2;
return StandardCounts::ANALOG_STICKS;
}
glm::vec2 ScriptingInterface::getJoystickPosition(int joystickIndex) const {
@ -382,22 +382,26 @@ namespace controller {
}
int ScriptingInterface::getNumberOfSpatialControls() const {
return 2;
return StandardCounts::POSES;
}
glm::vec3 ScriptingInterface::getSpatialControlPosition(int controlIndex) const {
// FIXME extract the position from the standard pose
return vec3();
}
glm::vec3 ScriptingInterface::getSpatialControlVelocity(int controlIndex) const {
// FIXME extract the velocity from the standard pose
return vec3();
}
glm::vec3 ScriptingInterface::getSpatialControlNormal(int controlIndex) const {
// FIXME extract the normal from the standard pose
return vec3();
}
glm::quat ScriptingInterface::getSpatialControlRawRotation(int controlIndex) const {
// FIXME extract the rotation from the standard pose
return quat();
}
} // namespace controllers

View file

@ -99,7 +99,7 @@ namespace controller {
public slots:
virtual void update();
//virtual void registerControllerTypes(ScriptEngine* engine) = 0;
virtual void registerControllerTypes(QScriptEngine* engine) = 0;
private:
friend class MappingBuilderProxy;

View file

@ -56,4 +56,9 @@ namespace controller {
NUM_STANDARD_POSES
};
enum StandardCounts {
TRIGGERS = 2,
ANALOG_STICKS = 2,
POSES = 2, // FIXME 3? if we want to expose the head?
};
}

View file

@ -22,8 +22,8 @@ InputPluginList getInputPlugins() {
InputPlugin* PLUGIN_POOL[] = {
new KeyboardMouseDevice(),
new SDL2Manager(),
//new SixenseManager(),
//new ViveControllerManager(),
new SixenseManager(),
new ViveControllerManager(),
nullptr
};

View file

@ -76,7 +76,6 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) {
out = qobject_cast<AvatarData*>(object.toQObject());
}
QScriptValue inputControllerToScriptValue(QScriptEngine *engine, controller::InputController* const &in) {
return engine->newQObject(in);
}
@ -85,7 +84,8 @@ void inputControllerFromScriptValue(const QScriptValue &object, controller::Inpu
out = qobject_cast<controller::InputController*>(object.toQObject());
}
ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, controller::ScriptingInterface* controllerScriptingInterface, bool wantSignals) :
ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString,
controller::ScriptingInterface* controllerScriptingInterface, bool wantSignals) :
_scriptContents(scriptContents),
_isFinished(false),
@ -93,6 +93,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
_isInitialized(false),
_timerFunctionMap(),
_wantSignals(wantSignals),
_controllerScriptingInterface(controllerScriptingInterface),
_fileNameString(fileNameString),
_quatLibrary(),
_vec3Library(),
@ -300,7 +301,7 @@ void ScriptEngine::init() {
globalObject().setProperty("AudioEffectOptions", audioEffectOptionsConstructorValue);
qScriptRegisterMetaType(this, injectorToScriptValue, injectorFromScriptValue);
//qScriptRegisterMetaType(this, inputControllerToScriptValue, inputControllerFromScriptValue);
qScriptRegisterMetaType(this, inputControllerToScriptValue, inputControllerFromScriptValue);
qScriptRegisterMetaType(this, avatarDataToScriptValue, avatarDataFromScriptValue);
qScriptRegisterMetaType(this, animationDetailsToScriptValue, animationDetailsFromScriptValue);
qScriptRegisterMetaType(this, webSocketToScriptValue, webSocketFromScriptValue);
@ -309,7 +310,7 @@ void ScriptEngine::init() {
registerGlobalObject("Script", this);
registerGlobalObject("Audio", &AudioScriptingInterface::getInstance());
// registerGlobalObject("Controller", _controllerScriptingInterface);
registerGlobalObject("Controller", _controllerScriptingInterface);
registerGlobalObject("Entities", entityScriptingInterface.data());
registerGlobalObject("Quat", &_quatLibrary);
registerGlobalObject("Vec3", &_vec3Library);
@ -319,9 +320,9 @@ void ScriptEngine::init() {
// constants
globalObject().setProperty("TREE_SCALE", newVariant(QVariant(TREE_SCALE)));
//if (_controllerScriptingInterface) {
// _controllerScriptingInterface->registerControllerTypes(this);
//}
if (_controllerScriptingInterface) {
_controllerScriptingInterface->registerControllerTypes(this);
}
}

View file

@ -184,6 +184,7 @@ private:
QObject* setupTimerWithInterval(const QScriptValue& function, int intervalMS, bool isSingleShot);
void stopTimer(QTimer* timer);
controller::ScriptingInterface* _controllerScriptingInterface;
QString _fileNameString;
Quat _quatLibrary;
Vec3 _vec3Library;