mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
Hydra hands deactivate when placed back on controller base, removed measuring non-movement for inactivity
This commit is contained in:
parent
a01ab38f1b
commit
218ae9c9d8
2 changed files with 14 additions and 28 deletions
|
@ -84,10 +84,8 @@ void SixenseManager::initialize() {
|
||||||
#ifdef HAVE_SIXENSE
|
#ifdef HAVE_SIXENSE
|
||||||
|
|
||||||
if (!_isInitialized) {
|
if (!_isInitialized) {
|
||||||
_lastMovement = 0;
|
|
||||||
_amountMoved = glm::vec3(0.0f);
|
|
||||||
_lowVelocityFilter = false;
|
_lowVelocityFilter = false;
|
||||||
|
_controllersAtBase = true;
|
||||||
_calibrationState = CALIBRATION_STATE_IDLE;
|
_calibrationState = CALIBRATION_STATE_IDLE;
|
||||||
// By default we assume the _neckBase (in orb frame) is as high above the orb
|
// By default we assume the _neckBase (in orb frame) is as high above the orb
|
||||||
// as the "torso" is below it.
|
// as the "torso" is below it.
|
||||||
|
@ -146,15 +144,11 @@ void SixenseManager::setFilter(bool filter) {
|
||||||
|
|
||||||
void SixenseManager::update(float deltaTime) {
|
void SixenseManager::update(float deltaTime) {
|
||||||
#ifdef HAVE_SIXENSE
|
#ifdef HAVE_SIXENSE
|
||||||
if (_isInitialized && _isEnabled) {
|
|
||||||
// if the controllers haven't been moved in a while, disable
|
|
||||||
const unsigned int MOVEMENT_DISABLE_SECONDS = 3;
|
|
||||||
if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) {
|
|
||||||
Hand* hand = Application::getInstance()->getAvatar()->getHand();
|
Hand* hand = Application::getInstance()->getAvatar()->getHand();
|
||||||
|
if (_isInitialized && _isEnabled) {
|
||||||
|
// Disable the hands (and return to default pose) if both controllers are at base station
|
||||||
for (std::vector<PalmData>::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) {
|
for (std::vector<PalmData>::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) {
|
||||||
it->setActive(false);
|
it->setActive(!_controllersAtBase);
|
||||||
}
|
|
||||||
_lastMovement = usecTimestampNow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
@ -172,8 +166,6 @@ void SixenseManager::update(float deltaTime) {
|
||||||
_hydrasConnected = true;
|
_hydrasConnected = true;
|
||||||
UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra");
|
UserActivityLogger::getInstance().connectedDevice("spatial_controller", "hydra");
|
||||||
}
|
}
|
||||||
MyAvatar* avatar = Application::getInstance()->getAvatar();
|
|
||||||
Hand* hand = avatar->getHand();
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
SixenseBaseFunction sixenseGetMaxControllers =
|
SixenseBaseFunction sixenseGetMaxControllers =
|
||||||
|
@ -192,7 +184,7 @@ void SixenseManager::update(float deltaTime) {
|
||||||
SixenseTakeIntAndSixenseControllerData sixenseGetNewestData =
|
SixenseTakeIntAndSixenseControllerData sixenseGetNewestData =
|
||||||
(SixenseTakeIntAndSixenseControllerData) _sixenseLibrary->resolve("sixenseGetNewestData");
|
(SixenseTakeIntAndSixenseControllerData) _sixenseLibrary->resolve("sixenseGetNewestData");
|
||||||
#endif
|
#endif
|
||||||
|
int numControllersAtBase = 0;
|
||||||
int numActiveControllers = 0;
|
int numActiveControllers = 0;
|
||||||
for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) {
|
for (int i = 0; i < maxControllers && numActiveControllers < 2; i++) {
|
||||||
if (!sixenseIsControllerEnabled(i)) {
|
if (!sixenseIsControllerEnabled(i)) {
|
||||||
|
@ -221,14 +213,11 @@ void SixenseManager::update(float deltaTime) {
|
||||||
qDebug("Found new Sixense controller, ID %i", data->controller_index);
|
qDebug("Found new Sixense controller, ID %i", data->controller_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
palm->setActive(true);
|
|
||||||
|
|
||||||
// Read controller buttons and joystick into the hand
|
// Read controller buttons and joystick into the hand
|
||||||
palm->setControllerButtons(data->buttons);
|
palm->setControllerButtons(data->buttons);
|
||||||
palm->setTrigger(data->trigger);
|
palm->setTrigger(data->trigger);
|
||||||
palm->setJoystick(data->joystick_x, data->joystick_y);
|
palm->setJoystick(data->joystick_x, data->joystick_y);
|
||||||
|
|
||||||
|
|
||||||
// Emulate the mouse so we can use scripts
|
// Emulate the mouse so we can use scripts
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
||||||
emulateMouse(palm, numActiveControllers - 1);
|
emulateMouse(palm, numActiveControllers - 1);
|
||||||
|
@ -238,6 +227,12 @@ void SixenseManager::update(float deltaTime) {
|
||||||
glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]);
|
glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]);
|
||||||
position *= METERS_PER_MILLIMETER;
|
position *= METERS_PER_MILLIMETER;
|
||||||
|
|
||||||
|
// Check to see if this hand/controller is on the base
|
||||||
|
const float CONTROLLER_AT_BASE_DISTANCE = 0.075f;
|
||||||
|
if (glm::length(position) < CONTROLLER_AT_BASE_DISTANCE) {
|
||||||
|
numControllersAtBase++;
|
||||||
|
}
|
||||||
|
|
||||||
// Transform the measured position into body frame.
|
// Transform the measured position into body frame.
|
||||||
glm::vec3 neck = _neckBase;
|
glm::vec3 neck = _neckBase;
|
||||||
// Zeroing y component of the "neck" effectively raises the measured position a little bit.
|
// Zeroing y component of the "neck" effectively raises the measured position a little bit.
|
||||||
|
@ -274,14 +269,6 @@ void SixenseManager::update(float deltaTime) {
|
||||||
palm->setRawRotation(rotation);
|
palm->setRawRotation(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the velocity to determine whether there's any movement (if the hand isn't new)
|
|
||||||
const float MOVEMENT_DISTANCE_THRESHOLD = 0.003f;
|
|
||||||
_amountMoved += rawVelocity * deltaTime;
|
|
||||||
if (glm::length(_amountMoved) > MOVEMENT_DISTANCE_THRESHOLD && foundHand) {
|
|
||||||
_lastMovement = usecTimestampNow();
|
|
||||||
_amountMoved = glm::vec3(0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the one fingertip in the palm structure so we can track velocity
|
// Store the one fingertip in the palm structure so we can track velocity
|
||||||
const float FINGER_LENGTH = 0.3f; // meters
|
const float FINGER_LENGTH = 0.3f; // meters
|
||||||
const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH);
|
const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH);
|
||||||
|
@ -298,7 +285,7 @@ void SixenseManager::update(float deltaTime) {
|
||||||
if (numActiveControllers == 2) {
|
if (numActiveControllers == 2) {
|
||||||
updateCalibration(controllers);
|
updateCalibration(controllers);
|
||||||
}
|
}
|
||||||
|
_controllersAtBase = (numControllersAtBase == 2);
|
||||||
}
|
}
|
||||||
#endif // HAVE_SIXENSE
|
#endif // HAVE_SIXENSE
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,8 +91,6 @@ private:
|
||||||
bool _isInitialized;
|
bool _isInitialized;
|
||||||
bool _isEnabled;
|
bool _isEnabled;
|
||||||
bool _hydrasConnected;
|
bool _hydrasConnected;
|
||||||
quint64 _lastMovement;
|
|
||||||
glm::vec3 _amountMoved;
|
|
||||||
|
|
||||||
// for mouse emulation with the two controllers
|
// for mouse emulation with the two controllers
|
||||||
bool _triggerPressed[2];
|
bool _triggerPressed[2];
|
||||||
|
@ -101,6 +99,7 @@ private:
|
||||||
int _oldY[2];
|
int _oldY[2];
|
||||||
|
|
||||||
bool _lowVelocityFilter;
|
bool _lowVelocityFilter;
|
||||||
|
bool _controllersAtBase;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_SixenseManager_h
|
#endif // hifi_SixenseManager_h
|
||||||
|
|
Loading…
Reference in a new issue