Actions working from the Controller layer

This commit is contained in:
samcake 2015-10-16 12:24:12 -07:00
parent 43d7fe491e
commit f0034844e7
5 changed files with 39 additions and 37 deletions

View file

@ -15,32 +15,26 @@
myFirstMapping = function() {
return {
"name": "example",
"channels": [ {
"from": "Keyboard.A",
"filters": [ {
"type": "clamp",
"params": [0, 1],
}
],
"to": "Actions.LONGITUDINAL_FORWARD",
}, {
"from": "Keyboard.Left",
"filters": [ {
"type": "clamp",
"params": [0, 1],
}, {
"type": "invert"
}
],
"to": "Actions.LONGITUDINAL_BACKWARD",
}, {
"from": "Keyboard.C",
"channels": [
{ "from": "Keyboard.W", "to": "Actions.LONGITUDINAL_FORWARD" },
{ "from": "Keyboard.S", "to": "Actions.LONGITUDINAL_BACKWARD" },
{ "from": "Keyboard.Left", "to": "Actions.LATERAL_LEFT" },
{ "from": "Keyboard.Right", "to": "Actions.LATERAL_RIGHT" },
{ "from": "Keyboard.A", "to": "Actions.YAW_LEFT" },
{ "from": "Keyboard.D", "to": "Actions.YAW_RIGHT" },
{ "from": "Keyboard.C", "to": "Actions.VERTICAL_DOWN" },
{ "from": "Keyboard.E", "to": "Actions.VERTICAL_UP" },
{
"from": "Standard.LX",
"filters": [ {
"type": "scale",
"params": [2.0],
}
],
"to": "Actions.Yaw",
"to": "Actions.LATERAL_LEFT",
}, {
"from": "Keyboard.B",
"to": "Actions.Yaw"
@ -57,7 +51,7 @@ print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON));
var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON));
Controller.enableMapping("example");
/*
Object.keys(Controller.Standard).forEach(function (input) {
print("Controller.Standard." + input + ":" + Controller.Standard[input]);
});
@ -71,3 +65,4 @@ Object.keys(Controller.Hardware).forEach(function (deviceName) {
Object.keys(Controller.Actions).forEach(function (actionName) {
print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]);
});
*/

View file

@ -2692,7 +2692,7 @@ void Application::update(float deltaTime) {
auto myAvatar = getMyAvatar();
auto userInputMapper = DependencyManager::get<UserInputMapper>();
userInputMapper->setSensorToWorldMat(myAvatar->getSensorToWorldMatrix());
userInputMapper->update(deltaTime);
// userInputMapper->update(deltaTime);
// This needs to go after userInputMapper->update() because of the keyboard
bool jointsCaptured = false;

View file

@ -103,10 +103,10 @@ namespace controller {
virtual float value() override { return _currentValue; }
virtual void apply(float newValue, float oldValue, const Pointer& source) override {
_currentValue = newValue;
_currentValue += newValue;
if (!(_id == UserInputMapper::Input::INVALID_INPUT)) {
auto userInputMapper = DependencyManager::get<UserInputMapper>();
userInputMapper->setActionState(UserInputMapper::Action(_id.getChannel()), newValue);
userInputMapper->deltaActionState(UserInputMapper::Action(_id.getChannel()), newValue);
}
}
@ -159,7 +159,7 @@ namespace controller {
// Create the endpoints
// FIXME action endpoints need to accumulate values, and have them cleared at each frame
// _endpoints[actionInput] = std::make_shared<VirtualEndpoint>();
_endpoints[actionInput] = std::make_shared<ActionEndpoint>();
_endpoints[actionInput] = std::make_shared<ActionEndpoint>(actionInput);
}
updateMaps();

View file

@ -295,7 +295,12 @@ void UserInputMapper::update(float deltaTime) {
// Scale all the channel step with the scale
static const float EPSILON = 0.01f;
for (auto i = 0; i < NUM_ACTIONS; i++) {
if (_externalActionStates[i] != 0) {
_actionStates[i] += _externalActionStates[i];
_externalActionStates[i] = 0.0f;
}
_actionStates[i] *= _actionScales[i];
// Emit only on change, and emit when moving back to 0
if (fabsf(_actionStates[i] - _lastActionStates[i]) > EPSILON) {
_lastActionStates[i] = _actionStates[i];
@ -359,15 +364,15 @@ void UserInputMapper::assignDefaulActionScales() {
_actionScales[RIGHT_HAND] = 1.0f; // default
_actionScales[LEFT_HAND_CLICK] = 1.0f; // on
_actionScales[RIGHT_HAND_CLICK] = 1.0f; // on
_actionStates[SHIFT] = 1.0f; // on
_actionStates[ACTION1] = 1.0f; // default
_actionStates[ACTION2] = 1.0f; // default
_actionStates[TRANSLATE_X] = 1.0f; // default
_actionStates[TRANSLATE_Y] = 1.0f; // default
_actionStates[TRANSLATE_Z] = 1.0f; // default
_actionStates[ROLL] = 1.0f; // default
_actionStates[PITCH] = 1.0f; // default
_actionStates[YAW] = 1.0f; // default
_actionScales[SHIFT] = 1.0f; // on
_actionScales[ACTION1] = 1.0f; // default
_actionScales[ACTION2] = 1.0f; // default
_actionScales[TRANSLATE_X] = 1.0f; // default
_actionScales[TRANSLATE_Y] = 1.0f; // default
_actionScales[TRANSLATE_Z] = 1.0f; // default
_actionScales[ROLL] = 1.0f; // default
_actionScales[PITCH] = 1.0f; // default
_actionScales[YAW] = 1.0f; // default
}
// This is only necessary as long as the actions are hardcoded

View file

@ -138,7 +138,7 @@ public:
uint16 getFreeDeviceID() { return _nextFreeDeviceID++; }
bool registerDevice(uint16 deviceID, const DeviceProxy::Pointer& device);
bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; return true; }
bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; _registeredDevices[getStandardDeviceID()] = device; return true; }
DeviceProxy::Pointer getDeviceProxy(const Input& input);
QString getDeviceName(uint16 deviceID);
QVector<InputPair> getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); }
@ -214,7 +214,8 @@ public:
QVector<QString> getActionNames() const;
void assignDefaulActionScales();
void setActionState(Action action, float value) { _actionStates[action] = value; }
void setActionState(Action action, float value) { _externalActionStates[action] = value; }
void deltaActionState(Action action, float delta) { _externalActionStates[action] += delta; }
// Add input channel to the mapper and check that all the used channels are registered.
// Return true if theinput channel is created correctly, false either
@ -297,6 +298,7 @@ protected:
ActionToInputsMap _actionToInputsMap;
std::vector<float> _actionStates = std::vector<float>(NUM_ACTIONS, 0.0f);
std::vector<float> _externalActionStates = std::vector<float>(NUM_ACTIONS, 0.0f);
std::vector<float> _actionScales = std::vector<float>(NUM_ACTIONS, 1.0f);
std::vector<float> _lastActionStates = std::vector<float>(NUM_ACTIONS, 0.0f);
std::vector<PoseValue> _poseStates = std::vector<PoseValue>(NUM_ACTIONS);