mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 10:47:53 +02:00
Add "enabled" setting for Sixense; bail in update if note enabled
This commit is contained in:
parent
31714675c3
commit
72d712ac76
4 changed files with 46 additions and 12 deletions
|
@ -17,7 +17,7 @@ PreferencesDialog {
|
|||
id: root
|
||||
objectName: "GeneralPreferencesDialog"
|
||||
title: "General Settings"
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "SDL2 Joystick", "Perception Neuron", "Kinect"]
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "SDL2 Joystick", "Sixense Controllers", "Perception Neuron", "Kinect"]
|
||||
property var settings: Settings {
|
||||
category: root.objectName
|
||||
property alias x: root.x
|
||||
|
|
|
@ -32,6 +32,6 @@ StackView {
|
|||
TabletPreferencesDialog {
|
||||
id: root
|
||||
objectName: "TabletGeneralPreferences"
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "SDL2 Joystick", "Perception Neuron", "Kinect", "Vive Pucks Configuration"]
|
||||
showCategories: ["UI", "Snapshots", "Scripts", "Privacy", "Octree", "HMD", "SDL2 Joystick", "Sixense Controllers", "Perception Neuron", "Kinect", "Vive Pucks Configuration"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <PathUtils.h>
|
||||
#include <PerfStat.h>
|
||||
#include <ui-plugins/PluginContainer.h>
|
||||
#include <Preferences.h>
|
||||
#include <SettingHandle.h>
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
@ -46,19 +47,26 @@ static const unsigned int BUTTON_TRIGGER = 1U << 8;
|
|||
|
||||
const glm::vec3 SixenseManager::DEFAULT_AVATAR_POSITION { -0.25f, -0.35f, -0.3f }; // in hydra frame
|
||||
const float SixenseManager::CONTROLLER_THRESHOLD { 0.35f };
|
||||
|
||||
bool SixenseManager::_isEnabled = false;
|
||||
bool SixenseManager::_sixenseLoaded = false;
|
||||
|
||||
#define BAIL_IF_NOT_ENABLED \
|
||||
if (!_isEnabled) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define BAIL_IF_NOT_LOADED \
|
||||
if (!_sixenseLoaded) { \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char* SixenseManager::NAME { "Sixense" };
|
||||
const char* SixenseManager::HYDRA_ID_STRING { "Razer Hydra" };
|
||||
const char* SixenseManager::SIXENSE_ID_STRING { "Sixense" };
|
||||
|
||||
const char* MENU_PARENT { "Developer" };
|
||||
const bool DEFAULT_ENABLED = false;
|
||||
|
||||
const char* MENU_PARENT{ "Developer" };
|
||||
const char* MENU_NAME { "Sixense" };
|
||||
const char* MENU_PATH { "Developer" ">" "Sixense" };
|
||||
const char* TOGGLE_SMOOTH { "Smooth Sixense Movement" };
|
||||
|
@ -73,6 +81,22 @@ bool SixenseManager::isSupported() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
void SixenseManager::init() {
|
||||
loadSettings();
|
||||
|
||||
auto preferences = DependencyManager::get<Preferences>();
|
||||
static const QString SIXENSE_PLUGIN { "Sixense Controllers" };
|
||||
{
|
||||
auto getter = [this]()->bool { return _isEnabled; };
|
||||
auto setter = [this](bool value) {
|
||||
_isEnabled = value;
|
||||
saveSettings();
|
||||
};
|
||||
auto preference = new CheckPreference(SIXENSE_PLUGIN, "Enabled", getter, setter);
|
||||
preferences->addPreference(preference);
|
||||
}
|
||||
}
|
||||
|
||||
bool SixenseManager::activate() {
|
||||
InputPlugin::activate();
|
||||
|
||||
|
@ -133,6 +157,7 @@ void SixenseManager::setSixenseFilter(bool filter) {
|
|||
}
|
||||
|
||||
void SixenseManager::pluginUpdate(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) {
|
||||
BAIL_IF_NOT_ENABLED
|
||||
BAIL_IF_NOT_LOADED
|
||||
|
||||
#ifdef HAVE_SIXENSE
|
||||
|
@ -553,14 +578,19 @@ QString SixenseManager::InputDevice::getDefaultMappingConfig() const {
|
|||
return MAPPING_JSON;
|
||||
}
|
||||
|
||||
const char* SETTINGS_ENABLED_KEY = "enabled";
|
||||
const char* SETTINGS_AVATAR_POSITION_KEY = "avatarPosition";
|
||||
const char* SETTINGS_AVATAR_ROTATION_KEY = "avatarPosition";
|
||||
|
||||
// virtual
|
||||
void SixenseManager::saveSettings() const {
|
||||
Settings settings;
|
||||
QString idString = getID();
|
||||
settings.beginGroup(idString);
|
||||
{
|
||||
settings.setVec3Value(QString("avatarPosition"), _inputDevice->_avatarPosition);
|
||||
settings.setQuatValue(QString("avatarRotation"), _inputDevice->_avatarRotation);
|
||||
settings.setValue(QString(SETTINGS_ENABLED_KEY), _isEnabled);
|
||||
settings.setVec3Value(QString(SETTINGS_AVATAR_POSITION_KEY), _inputDevice->_avatarPosition);
|
||||
settings.setQuatValue(QString(SETTINGS_AVATAR_ROTATION_KEY), _inputDevice->_avatarRotation);
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
@ -570,8 +600,9 @@ void SixenseManager::loadSettings() {
|
|||
QString idString = getID();
|
||||
settings.beginGroup(idString);
|
||||
{
|
||||
settings.getVec3ValueIfValid(QString("avatarPosition"), _inputDevice->_avatarPosition);
|
||||
settings.getQuatValueIfValid(QString("avatarRotation"), _inputDevice->_avatarRotation);
|
||||
_isEnabled = settings.value(SETTINGS_ENABLED_KEY, QVariant(DEFAULT_ENABLED)).toBool();
|
||||
settings.getVec3ValueIfValid(QString(SETTINGS_AVATAR_POSITION_KEY), _inputDevice->_avatarPosition);
|
||||
settings.getQuatValueIfValid(QString(SETTINGS_AVATAR_ROTATION_KEY), _inputDevice->_avatarRotation);
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ public:
|
|||
// Plugin functions
|
||||
virtual bool isSupported() const override;
|
||||
virtual const QString getName() const override { return NAME; }
|
||||
virtual const QString getID() const override { return HYDRA_ID_STRING; }
|
||||
virtual const QString getID() const override { return SIXENSE_ID_STRING; }
|
||||
|
||||
// Sixense always seems to initialize even if the hydras are not present. Is there
|
||||
// a way we can properly detect whether the hydras are present?
|
||||
// bool isHandController() const override { return true; }
|
||||
|
||||
virtual void init() override;
|
||||
|
||||
virtual bool activate() override;
|
||||
virtual void deactivate() override;
|
||||
|
||||
|
@ -93,8 +95,9 @@ private:
|
|||
std::shared_ptr<InputDevice> _inputDevice { std::make_shared<InputDevice>() };
|
||||
|
||||
static const char* NAME;
|
||||
static const char* HYDRA_ID_STRING;
|
||||
static const char* SIXENSE_ID_STRING;
|
||||
|
||||
static bool _isEnabled;
|
||||
static bool _sixenseLoaded;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue