History

Breaking up UserInputMapper, restoring some mappings

Brad Davis committed 11 years ago

Commit 734a39f1 parent a75316f21 files · +670 −630Browse files

Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 21 files). Show all

Unified · Split

interface/src/scripting/ControllerScriptingInterface.cpp+0−315
@@ -23,109 +23,6 @@ · 22 unmodified lines
23// TODO: this needs to be removed, as well as any related controller-specific information23// TODO: this needs to be removed, as well as any related controller-specific information
24#include <input-plugins/SixenseManager.h>24#include <input-plugins/SixenseManager.h>
25 25
26ControllerScriptingInterface::ControllerScriptingInterface() :
27 _mouseCaptured(false),
28 _touchCaptured(false),
29 _wheelCaptured(false),
30 _actionsCaptured(false)
31{
32
33}
34
35ControllerScriptingInterface::~ControllerScriptingInterface() {
36}
37
38
39static int actionMetaTypeId = qRegisterMetaType<UserInputMapper::Action>();
40static int inputChannelMetaTypeId = qRegisterMetaType<UserInputMapper::InputChannel>();
41static int inputMetaTypeId = qRegisterMetaType<UserInputMapper::Input>();
42static int inputPairMetaTypeId = qRegisterMetaType<UserInputMapper::InputPair>();
43
44QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::Input& input);
45void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input);
46QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel);
47void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel);
48QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action);
49void actionFromScriptValue(const QScriptValue& object, UserInputMapper::Action& action);
50QScriptValue inputPairToScriptValue(QScriptEngine* engine, const UserInputMapper::InputPair& inputPair);
51void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::InputPair& inputPair);
52
53QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::Input& input) {
54 QScriptValue obj = engine->newObject();
55 obj.setProperty("device", input.getDevice());
56 obj.setProperty("channel", input.getChannel());
57 obj.setProperty("type", (unsigned short) input.getType());
58 obj.setProperty("id", input.getID());
59 return obj;
60}
61
62void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input) {
63 input.setDevice(object.property("device").toUInt16());
64 input.setChannel(object.property("channel").toUInt16());
65 input.setType(object.property("type").toUInt16());
66 input.setID(object.property("id").toInt32());
67}
68
69QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel) {
70 QScriptValue obj = engine->newObject();
71 obj.setProperty("input", inputToScriptValue(engine, inputChannel.getInput()));
72 obj.setProperty("modifier", inputToScriptValue(engine, inputChannel.getModifier()));
73 obj.setProperty("action", inputChannel.getAction());
74 obj.setProperty("scale", inputChannel.getScale());
75 return obj;
76}
77
78void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel) {
79 UserInputMapper::Input input;
80 UserInputMapper::Input modifier;
81 inputFromScriptValue(object.property("input"), input);
82 inputChannel.setInput(input);
83 inputFromScriptValue(object.property("modifier"), modifier);
84 inputChannel.setModifier(modifier);
85 inputChannel.setAction(UserInputMapper::Action(object.property("action").toVariant().toInt()));
86 inputChannel.setScale(object.property("scale").toVariant().toFloat());
87}
88
89QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) {
90 QScriptValue obj = engine->newObject();
91 auto userInputMapper = DependencyManager::get<UserInputMapper>();
92 QVector<UserInputMapper::InputChannel> inputChannels = userInputMapper->getInputChannelsForAction(action);
93 QScriptValue _inputChannels = engine->newArray(inputChannels.size());
94 for (int i = 0; i < inputChannels.size(); i++) {
95 _inputChannels.setProperty(i, inputChannelToScriptValue(engine, inputChannels[i]));
96 }
97 obj.setProperty("action", (int) action);
98 obj.setProperty("actionName", userInputMapper->getActionName(action));
99 obj.setProperty("inputChannels", _inputChannels);
100 return obj;
101}
102
103void actionFromScriptValue(const QScriptValue& object, UserInputMapper::Action& action) {
104 action = UserInputMapper::Action(object.property("action").toVariant().toInt());
105}
106
107QScriptValue inputPairToScriptValue(QScriptEngine* engine, const UserInputMapper::InputPair& inputPair) {
108 QScriptValue obj = engine->newObject();
109 obj.setProperty("input", inputToScriptValue(engine, inputPair.first));
110 obj.setProperty("inputName", inputPair.second);
111 return obj;
112}
113
114void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::InputPair& inputPair) {
115 inputFromScriptValue(object.property("input"), inputPair.first);
116 inputPair.second = QString(object.property("inputName").toVariant().toString());
117}
118
119void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine) {
120 qScriptRegisterSequenceMetaType<QVector<UserInputMapper::Action> >(engine);
121 qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputChannel> >(engine);
122 qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine);
123 qScriptRegisterMetaType(engine, actionToScriptValue, actionFromScriptValue);
124 qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue);
125 qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
126 qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
127}
128
129void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {26void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) {
130 if (event->type() == HFActionEvent::startType()) {27 if (event->type() == HFActionEvent::startType()) {
131 emit actionStartEvent(static_cast<HFActionEvent&>(*event));28 emit actionStartEvent(static_cast<HFActionEvent&>(*event));
@@ -183,162 +80,6 @@ const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const · 51 unmodified lines
183 return NULL;80 return NULL;
184}81}
185 82
186/*
187bool ControllerScriptingInterface::isPrimaryButtonPressed() const {
188 const PalmData* primaryPalm = getPrimaryPalm();
189 if (primaryPalm) {
190 if (primaryPalm->getControllerButtons() & BUTTON_FWD) {
191 return true;
192 }
193 }
194
195 return false;
196}
197
198glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const {
199 const PalmData* primaryPalm = getPrimaryPalm();
200 if (primaryPalm) {
201 return glm::vec2(primaryPalm->getJoystickX(), primaryPalm->getJoystickY());
202 }
203
204 return glm::vec2(0);
205}
206
207int ControllerScriptingInterface::getNumberOfButtons() const {
208 return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM;
209}
210
211bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const {
212 int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM;
213 int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM;
214 const PalmData* palmData = getActivePalm(palmIndex);
215 if (palmData) {
216 switch (buttonOnPalm) {
217 case 0:
218 return palmData->getControllerButtons() & BUTTON_0;
219 case 1:
220 return palmData->getControllerButtons() & BUTTON_1;
221 case 2:
222 return palmData->getControllerButtons() & BUTTON_2;
223 case 3:
224 return palmData->getControllerButtons() & BUTTON_3;
225 case 4:
226 return palmData->getControllerButtons() & BUTTON_4;
227 case 5:
228 return palmData->getControllerButtons() & BUTTON_FWD;
229 }
230 }
231 return false;
232}
233
234int ControllerScriptingInterface::getNumberOfTriggers() const {
235 return getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM;
236}
237
238float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const {
239 // we know there's one trigger per palm, so the triggerIndex is the palm Index
240 int palmIndex = triggerIndex;
241 const PalmData* palmData = getActivePalm(palmIndex);
242 if (palmData) {
243 return palmData->getTrigger();
244 }
245 return 0.0f;
246}
247
248int ControllerScriptingInterface::getNumberOfJoysticks() const {
249 return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM;
250}
251
252glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const {
253 // we know there's one joystick per palm, so the joystickIndex is the palm Index
254 int palmIndex = joystickIndex;
255 const PalmData* palmData = getActivePalm(palmIndex);
256 if (palmData) {
257 return glm::vec2(palmData->getJoystickX(), palmData->getJoystickY());
258 }
259 return glm::vec2(0);
260}
261
262int ControllerScriptingInterface::getNumberOfSpatialControls() const {
263 return getNumberOfActivePalms() * NUMBER_OF_SPATIALCONTROLS_PER_PALM;
264}
265
266glm::vec3 ControllerScriptingInterface::getSpatialControlPosition(int controlIndex) const {
267 int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM;
268 int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM;
269 const PalmData* palmData = getActivePalm(palmIndex);
270 if (palmData) {
271 switch (controlOfPalm) {
272 case PALM_SPATIALCONTROL:
273 return palmData->getPosition();
274 case TIP_SPATIALCONTROL:
275 return palmData->getTipPosition();
276 }
277 }
278 return glm::vec3(0); // bad index
279}
280
281glm::vec3 ControllerScriptingInterface::getSpatialControlVelocity(int controlIndex) const {
282 int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM;
283 int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM;
284 const PalmData* palmData = getActivePalm(palmIndex);
285 if (palmData) {
286 switch (controlOfPalm) {
287 case PALM_SPATIALCONTROL:
288 return palmData->getVelocity();
289 case TIP_SPATIALCONTROL:
290 return palmData->getTipVelocity();
291 }
292 }
293 return glm::vec3(0); // bad index
294}
295
296glm::quat ControllerScriptingInterface::getSpatialControlRawRotation(int controlIndex) const {
297 int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM;
298 int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM;
299 const PalmData* palmData = getActivePalm(palmIndex);
300 if (palmData) {
301 switch (controlOfPalm) {
302 case PALM_SPATIALCONTROL:
303 return palmData->getRawRotation();
304 case TIP_SPATIALCONTROL:
305 return palmData->getRawRotation(); // currently the tip doesn't have a unique rotation, use the palm rotation
306 }
307 }
308 return glm::quat(); // bad index
309}
310
311glm::vec3 ControllerScriptingInterface::getSpatialControlRawAngularVelocity(int controlIndex) const {
312 int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM;
313 int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM;
314 const PalmData* palmData = getActivePalm(palmIndex);
315 if (palmData) {
316 switch (controlOfPalm) {
317 case PALM_SPATIALCONTROL:
318 return palmData->getRawAngularVelocity();
319 case TIP_SPATIALCONTROL:
320 return palmData->getRawAngularVelocity(); // Tip = palm angular velocity
321 }
322 }
323 return glm::vec3(0); // bad index
324}
325
326glm::vec3 ControllerScriptingInterface::getSpatialControlNormal(int controlIndex) const {
327 int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM;
328 int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM;
329 const PalmData* palmData = getActivePalm(palmIndex);
330 if (palmData) {
331 switch (controlOfPalm) {
332 case PALM_SPATIALCONTROL:
333 return palmData->getNormal();
334 case TIP_SPATIALCONTROL:
335 return palmData->getFingerDirection();
336 }
337 }
338 return glm::vec3(0); // bad index
339}
340*/
341
342bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const {83bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const {
343 return isKeyCaptured(KeyEvent(*event));84 return isKeyCaptured(KeyEvent(*event));
344}85}
@@ -448,62 +189,6 @@ void ControllerScriptingInterface::update() { · 103 unmodified lines
448 controller::ScriptingInterface::update();189 controller::ScriptingInterface::update();
449}190}
450 191
451QVector<UserInputMapper::Action> ControllerScriptingInterface::getAllActions() {
452 return DependencyManager::get<UserInputMapper>()->getAllActions();
453}
454
455QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getInputChannelsForAction(UserInputMapper::Action action) {
456 return DependencyManager::get<UserInputMapper>()->getInputChannelsForAction(action);
457}
458
459QString ControllerScriptingInterface::getDeviceName(unsigned int device) {
460 return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
461}
462
463QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getAllInputsForDevice(unsigned int device) {
464 return DependencyManager::get<UserInputMapper>()->getAllInputsForDevice(device);
465}
466
467bool ControllerScriptingInterface::addInputChannel(UserInputMapper::InputChannel inputChannel) {
468 return DependencyManager::get<UserInputMapper>()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale);
469}
470
471bool ControllerScriptingInterface::removeInputChannel(UserInputMapper::InputChannel inputChannel) {
472 return DependencyManager::get<UserInputMapper>()->removeInputChannel(inputChannel);
473}
474
475QVector<UserInputMapper::InputPair> ControllerScriptingInterface::getAvailableInputs(unsigned int device) {
476 return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
477}
478
479void ControllerScriptingInterface::resetAllDeviceBindings() {
480 DependencyManager::get<UserInputMapper>()->resetAllDeviceBindings();
481}
482
483void ControllerScriptingInterface::resetDevice(unsigned int device) {
484 DependencyManager::get<UserInputMapper>()->resetDevice(device);
485}
486
487int ControllerScriptingInterface::findDevice(QString name) {
488 return DependencyManager::get<UserInputMapper>()->findDevice(name);
489}
490
491QVector<QString> ControllerScriptingInterface::getDeviceNames() {
492 return DependencyManager::get<UserInputMapper>()->getDeviceNames();
493}
494
495float ControllerScriptingInterface::getActionValue(int action) {
496 return DependencyManager::get<UserInputMapper>()->getActionState(UserInputMapper::Action(action));
497}
498
499int ControllerScriptingInterface::findAction(QString actionName) {
500 return DependencyManager::get<UserInputMapper>()->findAction(actionName);
501}
502
503QVector<QString> ControllerScriptingInterface::getActionNames() const {
504 return DependencyManager::get<UserInputMapper>()->getActionNames();
505}
506
507InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :192InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :
508 _deviceTrackerId(deviceTrackerId),193 _deviceTrackerId(deviceTrackerId),
509 _subTrackerId(subTrackerId),194 _subTrackerId(subTrackerId),