Fixing namespace usage in input-plugins

This commit is contained in:
Brad Davis 2015-10-14 13:40:22 -07:00
parent f051a84dc6
commit 619fce0d7f
5 changed files with 468 additions and 464 deletions

View file

@ -1,167 +1,167 @@
//
// Joystick.cpp
// input-plugins/src/input-plugins
//
// Created by Stephen Birarda on 2014-09-23.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <limits>
#include <glm/glm.hpp>
#include "Joystick.h"
#include "StandardControls.h"
const float CONTROLLER_THRESHOLD = 0.3f;
#ifdef HAVE_SDL2
const float MAX_AXIS = 32768.0f;
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
InputDevice(name),
_sdlGameController(sdlGameController),
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
_instanceId(instanceId)
{
}
#endif
Joystick::~Joystick() {
closeJoystick();
}
void Joystick::closeJoystick() {
#ifdef HAVE_SDL2
SDL_GameControllerClose(_sdlGameController);
#endif
}
void Joystick::update(float deltaTime, bool jointsCaptured) {
for (auto axisState : _axisStateMap) {
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
_axisStateMap[axisState.first] = 0.0f;
}
}
}
void Joystick::focusOutEvent() {
_axisStateMap.clear();
_buttonPressedMap.clear();
};
#ifdef HAVE_SDL2
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
_axisStateMap[makeInput((Controllers::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
}
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
auto input = makeInput((Controllers::StandardButtonChannel)event.button);
bool newValue = event.state == SDL_PRESSED;
if (newValue) {
_buttonPressedMap.insert(input.getChannel());
} else {
_buttonPressedMap.erase(input.getChannel());
}
}
#endif
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
// Grab the current free device ID
_deviceID = mapper.getFreeDeviceID();
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
QVector<UserInputMapper::InputPair> availableInputs;
// Buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "A"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "B"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "X"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Y"));
// DPad
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "DU"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "DD"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "DL"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "DR"));
// Bumpers
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "LB"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "RB"));
// Stick press
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "LS"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "RS"));
// Center buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::START), "Start"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Back"));
// Analog sticks
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LY), "LY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LX), "LX"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RY), "RY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RX), "RX"));
// Triggers
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "LT"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "RT"));
// Aliases, PlayStation style names
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "L1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "R1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "L2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "R2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "L3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "R3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Select"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "Cross"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "Circle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "Square"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Triangle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "Up"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "Down"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "Left"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "Right"));
return availableInputs;
};
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
mapper.removeAllInputChannelsForDevice(_deviceID);
this->assignDefaultInputMapping(mapper);
return true;
};
mapper.registerDevice(_deviceID, proxy);
}
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
#ifdef HAVE_SDL2
const float JOYSTICK_MOVE_SPEED = 1.0f;
const float DPAD_MOVE_SPEED = 0.5f;
const float JOYSTICK_YAW_SPEED = 0.5f;
const float JOYSTICK_PITCH_SPEED = 0.25f;
const float BOOM_SPEED = 0.1f;
#endif
}
UserInputMapper::Input Joystick::makeInput(Controllers::StandardButtonChannel button) {
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
}
UserInputMapper::Input Joystick::makeInput(Controllers::StandardAxisChannel axis) {
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
}
//
// Joystick.cpp
// input-plugins/src/input-plugins
//
// Created by Stephen Birarda on 2014-09-23.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <limits>
#include <glm/glm.hpp>
#include "Joystick.h"
#include "StandardControls.h"
const float CONTROLLER_THRESHOLD = 0.3f;
#ifdef HAVE_SDL2
const float MAX_AXIS = 32768.0f;
Joystick::Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController) :
InputDevice(name),
_sdlGameController(sdlGameController),
_sdlJoystick(SDL_GameControllerGetJoystick(_sdlGameController)),
_instanceId(instanceId)
{
}
#endif
Joystick::~Joystick() {
closeJoystick();
}
void Joystick::closeJoystick() {
#ifdef HAVE_SDL2
SDL_GameControllerClose(_sdlGameController);
#endif
}
void Joystick::update(float deltaTime, bool jointsCaptured) {
for (auto axisState : _axisStateMap) {
if (fabsf(axisState.second) < CONTROLLER_THRESHOLD) {
_axisStateMap[axisState.first] = 0.0f;
}
}
}
void Joystick::focusOutEvent() {
_axisStateMap.clear();
_buttonPressedMap.clear();
};
#ifdef HAVE_SDL2
void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) {
SDL_GameControllerAxis axis = (SDL_GameControllerAxis) event.axis;
_axisStateMap[makeInput((controller::StandardAxisChannel)axis).getChannel()] = (float)event.value / MAX_AXIS;
}
void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
auto input = makeInput((controller::StandardButtonChannel)event.button);
bool newValue = event.state == SDL_PRESSED;
if (newValue) {
_buttonPressedMap.insert(input.getChannel());
} else {
_buttonPressedMap.erase(input.getChannel());
}
}
#endif
void Joystick::registerToUserInputMapper(UserInputMapper& mapper) {
// Grab the current free device ID
_deviceID = mapper.getFreeDeviceID();
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
QVector<UserInputMapper::InputPair> availableInputs;
// Buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
// DPad
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
// Bumpers
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
// Stick press
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
// Center buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
// Analog sticks
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
// Triggers
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
// Aliases, PlayStation style names
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
return availableInputs;
};
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
mapper.removeAllInputChannelsForDevice(_deviceID);
this->assignDefaultInputMapping(mapper);
return true;
};
mapper.registerDevice(_deviceID, proxy);
}
void Joystick::assignDefaultInputMapping(UserInputMapper& mapper) {
#ifdef HAVE_SDL2
const float JOYSTICK_MOVE_SPEED = 1.0f;
const float DPAD_MOVE_SPEED = 0.5f;
const float JOYSTICK_YAW_SPEED = 0.5f;
const float JOYSTICK_PITCH_SPEED = 0.25f;
const float BOOM_SPEED = 0.1f;
#endif
}
UserInputMapper::Input Joystick::makeInput(controller::StandardButtonChannel button) {
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
}
UserInputMapper::Input Joystick::makeInput(controller::StandardAxisChannel axis) {
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
}

View file

@ -1,73 +1,73 @@
//
// Joystick.h
// input-plugins/src/input-plugins
//
// Created by Stephen Birarda on 2014-09-23.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Joystick_h
#define hifi_Joystick_h
#include <qobject.h>
#include <qvector.h>
#ifdef HAVE_SDL2
#include <SDL.h>
#undef main
#endif
#include "InputDevice.h"
#include "StandardControls.h"
class Joystick : public QObject, public InputDevice {
Q_OBJECT
Q_PROPERTY(QString name READ getName)
#ifdef HAVE_SDL2
Q_PROPERTY(int instanceId READ getInstanceId)
#endif
public:
const QString& getName() const { return _name; }
// Device functions
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
virtual void update(float deltaTime, bool jointsCaptured) override;
virtual void focusOutEvent() override;
Joystick() : InputDevice("Joystick") {}
~Joystick();
UserInputMapper::Input makeInput(Controllers::StandardButtonChannel button);
UserInputMapper::Input makeInput(Controllers::StandardAxisChannel axis);
#ifdef HAVE_SDL2
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
#endif
void closeJoystick();
#ifdef HAVE_SDL2
void handleAxisEvent(const SDL_ControllerAxisEvent& event);
void handleButtonEvent(const SDL_ControllerButtonEvent& event);
#endif
#ifdef HAVE_SDL2
int getInstanceId() const { return _instanceId; }
#endif
private:
#ifdef HAVE_SDL2
SDL_GameController* _sdlGameController;
SDL_Joystick* _sdlJoystick;
SDL_JoystickID _instanceId;
#endif
};
#endif // hifi_Joystick_h
//
// Joystick.h
// input-plugins/src/input-plugins
//
// Created by Stephen Birarda on 2014-09-23.
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Joystick_h
#define hifi_Joystick_h
#include <qobject.h>
#include <qvector.h>
#ifdef HAVE_SDL2
#include <SDL.h>
#undef main
#endif
#include "InputDevice.h"
#include "StandardControls.h"
class Joystick : public QObject, public InputDevice {
Q_OBJECT
Q_PROPERTY(QString name READ getName)
#ifdef HAVE_SDL2
Q_PROPERTY(int instanceId READ getInstanceId)
#endif
public:
const QString& getName() const { return _name; }
// Device functions
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
virtual void update(float deltaTime, bool jointsCaptured) override;
virtual void focusOutEvent() override;
Joystick() : InputDevice("Joystick") {}
~Joystick();
UserInputMapper::Input makeInput(controller::StandardButtonChannel button);
UserInputMapper::Input makeInput(controller::StandardAxisChannel axis);
#ifdef HAVE_SDL2
Joystick(SDL_JoystickID instanceId, const QString& name, SDL_GameController* sdlGameController);
#endif
void closeJoystick();
#ifdef HAVE_SDL2
void handleAxisEvent(const SDL_ControllerAxisEvent& event);
void handleButtonEvent(const SDL_ControllerButtonEvent& event);
#endif
#ifdef HAVE_SDL2
int getInstanceId() const { return _instanceId; }
#endif
private:
#ifdef HAVE_SDL2
SDL_GameController* _sdlGameController;
SDL_Joystick* _sdlJoystick;
SDL_JoystickID _instanceId;
#endif
};
#endif // hifi_Joystick_h

View file

@ -1,121 +1,121 @@
//
// StandardController.cpp
// input-plugins/src/input-plugins
//
// Created by Brad Hefta-Gaub on 2015-10-11.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <limits>
#include <glm/glm.hpp>
#include "StandardController.h"
const float CONTROLLER_THRESHOLD = 0.3f;
StandardController::~StandardController() {
}
void StandardController::update(float deltaTime, bool jointsCaptured) {
}
void StandardController::focusOutEvent() {
_axisStateMap.clear();
_buttonPressedMap.clear();
};
void StandardController::registerToUserInputMapper(UserInputMapper& mapper) {
// Grab the current free device ID
_deviceID = mapper.getStandardDeviceID();
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
QVector<UserInputMapper::InputPair> availableInputs;
// Buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "A"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "B"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "X"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Y"));
// DPad
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "DU"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "DD"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "DL"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "DR"));
// Bumpers
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "LB"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "RB"));
// Stick press
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "LS"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "RS"));
// Center buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::START), "Start"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Back"));
// Analog sticks
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LY), "LY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LX), "LX"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RY), "RY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RX), "RX"));
// Triggers
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "LT"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "RT"));
// Poses
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LeftPose), "LeftPose"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RightPose), "RightPose"));
// Aliases, PlayStation style names
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LB), "L1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RB), "R1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LT), "L2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RT), "R2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::LS), "L3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::RS), "R3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::BACK), "Select"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::A), "Cross"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::B), "Circle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::X), "Square"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::Y), "Triangle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DU), "Up"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DD), "Down"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DL), "Left"));
availableInputs.append(UserInputMapper::InputPair(makeInput(Controllers::DR), "Right"));
return availableInputs;
};
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
mapper.removeAllInputChannelsForDevice(_deviceID);
this->assignDefaultInputMapping(mapper);
return true;
};
mapper.registerStandardDevice(proxy);
}
void StandardController::assignDefaultInputMapping(UserInputMapper& mapper) {
}
UserInputMapper::Input StandardController::makeInput(Controllers::StandardButtonChannel button) {
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
}
UserInputMapper::Input StandardController::makeInput(Controllers::StandardAxisChannel axis) {
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
}
UserInputMapper::Input StandardController::makeInput(Controllers::StandardPoseChannel pose) {
return UserInputMapper::Input(_deviceID, pose, UserInputMapper::ChannelType::POSE);
}
//
// StandardController.cpp
// input-plugins/src/input-plugins
//
// Created by Brad Hefta-Gaub on 2015-10-11.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <limits>
#include <glm/glm.hpp>
#include "StandardController.h"
const float CONTROLLER_THRESHOLD = 0.3f;
StandardController::~StandardController() {
}
void StandardController::update(float deltaTime, bool jointsCaptured) {
}
void StandardController::focusOutEvent() {
_axisStateMap.clear();
_buttonPressedMap.clear();
};
void StandardController::registerToUserInputMapper(UserInputMapper& mapper) {
// Grab the current free device ID
_deviceID = mapper.getStandardDeviceID();
auto proxy = std::make_shared<UserInputMapper::DeviceProxy>(_name);
proxy->getButton = [this] (const UserInputMapper::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
proxy->getAxis = [this] (const UserInputMapper::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
proxy->getAvailabeInputs = [this] () -> QVector<UserInputMapper::InputPair> {
QVector<UserInputMapper::InputPair> availableInputs;
// Buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "A"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "B"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "X"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Y"));
// DPad
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "DU"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "DD"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "DL"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "DR"));
// Bumpers
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "LB"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "RB"));
// Stick press
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "LS"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "RS"));
// Center buttons
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::START), "Start"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Back"));
// Analog sticks
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LY), "LY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LX), "LX"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RY), "RY"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RX), "RX"));
// Triggers
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "LT"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT"));
// Poses
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LEFT), "LeftPose"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RIGHT), "RightPose"));
// Aliases, PlayStation style names
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RB), "R1"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LT), "L2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "R2"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LS), "L3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RS), "R3"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::BACK), "Select"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::A), "Cross"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::B), "Circle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::X), "Square"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::Y), "Triangle"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DU), "Up"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DD), "Down"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DL), "Left"));
availableInputs.append(UserInputMapper::InputPair(makeInput(controller::DR), "Right"));
return availableInputs;
};
proxy->resetDeviceBindings = [this, &mapper] () -> bool {
mapper.removeAllInputChannelsForDevice(_deviceID);
this->assignDefaultInputMapping(mapper);
return true;
};
mapper.registerStandardDevice(proxy);
}
void StandardController::assignDefaultInputMapping(UserInputMapper& mapper) {
}
UserInputMapper::Input StandardController::makeInput(controller::StandardButtonChannel button) {
return UserInputMapper::Input(_deviceID, button, UserInputMapper::ChannelType::BUTTON);
}
UserInputMapper::Input StandardController::makeInput(controller::StandardAxisChannel axis) {
return UserInputMapper::Input(_deviceID, axis, UserInputMapper::ChannelType::AXIS);
}
UserInputMapper::Input StandardController::makeInput(controller::StandardPoseChannel pose) {
return UserInputMapper::Input(_deviceID, pose, UserInputMapper::ChannelType::POSE);
}

View file

@ -1,48 +1,48 @@
//
// StandardController.h
// input-plugins/src/input-plugins
//
// Created by Brad Hefta-Gaub on 2015-10-11.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_StandardController_h
#define hifi_StandardController_h
#include <qobject.h>
#include <qvector.h>
#include "InputDevice.h"
#include "StandardControls.h"
typedef std::shared_ptr<StandardController> StandardControllerPointer;
class StandardController : public QObject, public InputDevice {
Q_OBJECT
Q_PROPERTY(QString name READ getName)
public:
const QString& getName() const { return _name; }
// Device functions
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
virtual void update(float deltaTime, bool jointsCaptured) override;
virtual void focusOutEvent() override;
StandardController() : InputDevice("Standard") {}
~StandardController();
UserInputMapper::Input makeInput(Controllers::StandardButtonChannel button);
UserInputMapper::Input makeInput(Controllers::StandardAxisChannel axis);
UserInputMapper::Input makeInput(Controllers::StandardPoseChannel pose);
private:
};
#endif // hifi_StandardController_h
//
// StandardController.h
// input-plugins/src/input-plugins
//
// Created by Brad Hefta-Gaub on 2015-10-11.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_StandardController_h
#define hifi_StandardController_h
#include <qobject.h>
#include <qvector.h>
#include "InputDevice.h"
#include "StandardControls.h"
typedef std::shared_ptr<StandardController> StandardControllerPointer;
class StandardController : public QObject, public InputDevice {
Q_OBJECT
Q_PROPERTY(QString name READ getName)
public:
const QString& getName() const { return _name; }
// Device functions
virtual void registerToUserInputMapper(UserInputMapper& mapper) override;
virtual void assignDefaultInputMapping(UserInputMapper& mapper) override;
virtual void update(float deltaTime, bool jointsCaptured) override;
virtual void focusOutEvent() override;
StandardController() : InputDevice("Standard") {}
~StandardController();
UserInputMapper::Input makeInput(controller::StandardButtonChannel button);
UserInputMapper::Input makeInput(controller::StandardAxisChannel axis);
UserInputMapper::Input makeInput(controller::StandardPoseChannel pose);
private:
};
#endif // hifi_StandardController_h

View file

@ -1,55 +1,59 @@
//
// Created by Bradley Austin Davis 2015/10/09
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
namespace Controllers {
// Needs to match order and values of SDL_GameControllerButton
enum StandardButtonChannel {
// Button quad
A = 0,
B,
X,
Y,
// Center buttons
BACK,
GUIDE,
START,
// Stick press
LS,
RS,
// Bumper press
LB,
RB,
// DPad
DU,
DD,
DL,
DR
};
// Needs to match order and values of SDL_GameControllerAxis
enum StandardAxisChannel {
// Left Analog stick
LX = 0,
LY,
// Right Analog stick
RX,
RY,
// Triggers
LT,
RT
};
// No correlation to SDL
enum StandardPoseChannel {
LeftPose = 0,
RightPose
};
}
//
// Created by Bradley Austin Davis 2015/10/09
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#pragma once
namespace controller {
// Needs to match order and values of SDL_GameControllerButton
enum StandardButtonChannel {
// Button quad
A = 0,
B,
X,
Y,
// Center buttons
BACK,
GUIDE,
START,
// Stick press
LS,
RS,
// Bumper press
LB,
RB,
// DPad
DU,
DD,
DL,
DR,
NUM_STANDARD_BUTTONS
};
// Needs to match order and values of SDL_GameControllerAxis
enum StandardAxisChannel {
// Left Analog stick
LX = 0,
LY,
// Right Analog stick
RX,
RY,
// Triggers
LT,
RT,
NUM_STANDARD_AXES
};
// No correlation to SDL
enum StandardPoseChannel {
LEFT = 0,
RIGHT,
HEAD,
NUM_STANDARD_POSES
};
}