Merge pull request #10436 from druiz17/config-ui

Added the ability to choose puck configuration from the general settings
This commit is contained in:
druiz17 2017-05-11 13:39:05 -07:00 committed by GitHub
commit e4df4369ad
4 changed files with 102 additions and 16 deletions

View file

@ -33,6 +33,6 @@ StackView {
TabletPreferencesDialog { TabletPreferencesDialog {
id: root id: root
objectName: "TabletGeneralPreferences" objectName: "TabletGeneralPreferences"
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect"] showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration"]
} }
} }

View file

@ -136,8 +136,8 @@ Item {
for (var i = 0; i < sections.length; i++) { for (var i = 0; i < sections.length; i++) {
totalHeight += sections[i].height + sections[i].getPreferencesHeight(); totalHeight += sections[i].height + sections[i].getPreferencesHeight();
} }
console.log(totalHeight); var bottomPadding = 100;
return totalHeight; return (totalHeight + bottomPadding);
} }
} }
} }

View file

@ -22,6 +22,8 @@
#include <ui-plugins/PluginContainer.h> #include <ui-plugins/PluginContainer.h>
#include <UserActivityLogger.h> #include <UserActivityLogger.h>
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <Preferences.h>
#include <SettingHandle.h>
#include <OffscreenUi.h> #include <OffscreenUi.h>
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <glm/ext.hpp> #include <glm/ext.hpp>
@ -262,14 +264,21 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr
glm::mat4 defaultToReferenceMat = currentHead * glm::inverse(inputCalibration.defaultHeadMat); glm::mat4 defaultToReferenceMat = currentHead * glm::inverse(inputCalibration.defaultHeadMat);
int puckCount = (int)_validTrackedObjects.size(); int puckCount = (int)_validTrackedObjects.size();
if (puckCount == MIN_PUCK_COUNT) { _config = _preferedConfig;
_config = Config::Feet; if (_config != Config::Auto && puckCount < MIN_PUCK_COUNT) {
} else if (puckCount == MIN_FEET_AND_HIPS) { uncalibrate();
_config = Config::FeetAndHips;
} else if (puckCount >= MIN_FEET_HIPS_CHEST) {
_config = Config::FeetHipsAndChest;
} else {
return; return;
} else if (_config == Config::Auto){
if (puckCount == MIN_PUCK_COUNT) {
_config = Config::Feet;
} else if (puckCount == MIN_FEET_AND_HIPS) {
_config = Config::FeetAndHips;
} else if (puckCount >= MIN_FEET_HIPS_CHEST) {
_config = Config::FeetHipsAndChest;
} else {
uncalibrate();
return;
}
} }
std::sort(_validTrackedObjects.begin(), _validTrackedObjects.end(), sortPucksYPosition); std::sort(_validTrackedObjects.begin(), _validTrackedObjects.end(), sortPucksYPosition);
@ -296,19 +305,23 @@ void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibr
if (_config == Config::Feet) { if (_config == Config::Feet) {
// done // done
} else if (_config == Config::FeetAndHips) { } else if (_config == Config::FeetAndHips && puckCount >= MIN_FEET_AND_HIPS) {
_jointToPuckMap[controller::HIPS] = _validTrackedObjects[HIP].first; _jointToPuckMap[controller::HIPS] = _validTrackedObjects[HIP].first;
_pucksOffset[_validTrackedObjects[HIP].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultHips, _validTrackedObjects[HIP].second); _pucksOffset[_validTrackedObjects[HIP].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultHips, _validTrackedObjects[HIP].second);
} else if (_config == Config::FeetHipsAndChest) { } else if (_config == Config::FeetHipsAndChest && puckCount >= MIN_FEET_HIPS_CHEST) {
_jointToPuckMap[controller::HIPS] = _validTrackedObjects[HIP].first; _jointToPuckMap[controller::HIPS] = _validTrackedObjects[HIP].first;
_pucksOffset[_validTrackedObjects[HIP].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultHips, _validTrackedObjects[HIP].second); _pucksOffset[_validTrackedObjects[HIP].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultHips, _validTrackedObjects[HIP].second);
_jointToPuckMap[controller::SPINE2] = _validTrackedObjects[CHEST].first; _jointToPuckMap[controller::SPINE2] = _validTrackedObjects[CHEST].first;
_pucksOffset[_validTrackedObjects[CHEST].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultSpine2, _validTrackedObjects[CHEST].second); _pucksOffset[_validTrackedObjects[CHEST].first] = computeOffset(defaultToReferenceMat, inputCalibration.defaultSpine2, _validTrackedObjects[CHEST].second);
} else {
uncalibrate();
return;
} }
_calibrated = true; _calibrated = true;
} }
void ViveControllerManager::InputDevice::uncalibrate() { void ViveControllerManager::InputDevice::uncalibrate() {
_config = Config::Auto;
_pucksOffset.clear(); _pucksOffset.clear();
_jointToPuckMap.clear(); _jointToPuckMap.clear();
_calibrated = false; _calibrated = false;
@ -544,6 +557,74 @@ void ViveControllerManager::InputDevice::hapticsHelper(float deltaTime, bool lef
} }
} }
void ViveControllerManager::InputDevice::loadSettings() {
Settings settings;
settings.beginGroup("PUCK_CONFIG");
{
_preferedConfig = (Config)settings.value("configuration", QVariant((int)Config::Auto)).toInt();
}
settings.endGroup();
}
void ViveControllerManager::InputDevice::saveSettings() const {
Settings settings;
settings.beginGroup("PUCK_CONFIG");
{
settings.setValue(QString("configuration"), (int)_preferedConfig);
}
settings.endGroup();
}
QString ViveControllerManager::InputDevice::configToString() {
QString currentConfig;
switch (_preferedConfig) {
case Config::Auto:
currentConfig = "Auto";
break;
case Config::Feet:
currentConfig = "Feet";
break;
case Config::FeetAndHips:
currentConfig = "FeetAndHips";
break;
case Config::FeetHipsAndChest:
currentConfig = "FeetHipsAndChest";
break;
}
return currentConfig;
}
void ViveControllerManager::InputDevice::setConfigFromString(const QString& value) {
if (value == "Auto") {
_preferedConfig = Config::Auto;
} else if (value == "Feet") {
_preferedConfig = Config::Feet;
} else if (value == "FeetAndHips") {
_preferedConfig = Config::FeetAndHips;
} else if (value == "FeetHipsAndChest") {
_preferedConfig = Config::FeetHipsAndChest;
}
}
void ViveControllerManager::InputDevice::createPreferences() {
loadSettings();
auto preferences = DependencyManager::get<Preferences>();
static const QString VIVE_PUCKS_CONFIG = "Vive Pucks Configuration";
{
auto getter = [this]()->QString { return configToString(); };
auto setter = [this](const QString& value) { setConfigFromString(value); saveSettings(); };
auto preference = new ComboBoxPreference(VIVE_PUCKS_CONFIG, "Configuration", getter, setter);
QStringList list = (QStringList() << "Auto" << "Feet" << "FeetAndHips" << "FeetHipsAndChest");
preference->setItems(list);
preferences->addPreference(preference);
}
}
controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const { controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const {
using namespace controller; using namespace controller;
QVector<Input::NamedPair> availableInputs{ QVector<Input::NamedPair> availableInputs{

View file

@ -50,14 +50,14 @@ public:
private: private:
class InputDevice : public controller::InputDevice { class InputDevice : public controller::InputDevice {
public: public:
InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) {} InputDevice(vr::IVRSystem*& system) : controller::InputDevice("Vive"), _system(system) { createPreferences(); }
private: private:
// Device functions // Device functions
controller::Input::NamedVector getAvailableInputs() const override; controller::Input::NamedVector getAvailableInputs() const override;
QString getDefaultMappingConfig() const override; QString getDefaultMappingConfig() const override;
void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override; void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override;
void focusOutEvent() override; void focusOutEvent() override;
void createPreferences();
bool triggerHapticPulse(float strength, float duration, controller::Hand hand) override; bool triggerHapticPulse(float strength, float duration, controller::Hand hand) override;
void hapticsHelper(float deltaTime, bool leftHand); void hapticsHelper(float deltaTime, bool leftHand);
void calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration); void calibrateOrUncalibrate(const controller::InputCalibrationData& inputCalibration);
@ -100,8 +100,9 @@ private:
float _timer { 0.0f }; float _timer { 0.0f };
glm::vec2 _stick { 0.0f, 0.0f }; glm::vec2 _stick { 0.0f, 0.0f };
}; };
enum class Config { Feet, FeetAndHips, FeetHipsAndChest, NoConfig }; enum class Config { Feet, FeetAndHips, FeetHipsAndChest, Auto };
Config _config { Config::NoConfig }; Config _config { Config::Auto };
Config _preferedConfig { Config::Auto };
FilteredStick _filteredLeftStick; FilteredStick _filteredLeftStick;
FilteredStick _filteredRightStick; FilteredStick _filteredRightStick;
@ -125,6 +126,10 @@ private:
bool _timeTilCalibrationSet { false }; bool _timeTilCalibrationSet { false };
mutable std::recursive_mutex _lock; mutable std::recursive_mutex _lock;
QString configToString();
void setConfigFromString(const QString& value);
void loadSettings();
void saveSettings() const;
friend class ViveControllerManager; friend class ViveControllerManager;
}; };