diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index eebd26c3c3..8f9fc9b16e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -950,8 +950,8 @@ void Application::initializeGL() { checkFPStimer.start(1000); // call our idle function whenever we can - connect(&idleTimer, &QTimer::timeout, this, &Application::idle); - idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS); + // connect(&idleTimer, &QTimer::timeout, this, &Application::idle); + // idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS); _idleLoopStdev.reset(); // update before the first render @@ -1023,6 +1023,10 @@ void Application::paintGL() { if (_inPaint) { return; } + + // this is a good idea + idle(); + _inPaint = true; Finally clearFlagLambda([this] { _inPaint = false; }); @@ -2070,7 +2074,7 @@ void Application::idle() { float secondsSinceLastUpdate = timeSinceLastUpdateUs / USECS_PER_SECOND; if (isThrottled && (timeSinceLastUpdateUs / USECS_PER_MSEC) < THROTTLED_SIM_FRAME_PERIOD_MS) { - return; // bail early, we're throttled and not enough time has elapsed + //return; // bail early, we're throttled and not enough time has elapsed } _lastTimeUpdated.start(); diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index 59bfd88be6..941e876075 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -35,7 +35,8 @@ AvatarActionHold::~AvatarActionHold() { qDebug() << "AvatarActionHold::~AvatarActionHold"; #endif } - +#include +#include void AvatarActionHold::updateActionWorker(float deltaTimeStep) { bool gotLock = false; glm::quat rotation; @@ -51,7 +52,24 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { glm::vec3 offset; glm::vec3 palmPosition; glm::quat palmRotation; - if (_hand == "right") { + + const auto& plugins = PluginManager::getInstance()->getInputPlugins(); + auto it = std::find_if(std::begin(plugins), std::end(plugins), [](const InputPluginPointer& plugin) { + return plugin->getName() == ViveControllerManager::NAME; + }); + + if (it != std::end(plugins)) { + const auto& vive = it->dynamicCast(); + auto index = (_hand == "right") ? 0 : 1; auto userInputMapper = DependencyManager::get(); + auto translation = extractTranslation(userInputMapper->getSensorToWorldMat()); + auto rotation = glm::quat_cast(userInputMapper->getSensorToWorldMat()); + + + const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f)); + const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); + palmPosition = translation + rotation * vive->getPosition(index); + palmRotation = rotation * vive->getRotation(index) * yFlip * quarterX; + } else if (_hand == "right") { palmPosition = holdingAvatar->getRightPalmPosition(); palmRotation = holdingAvatar->getRightPalmRotation(); } else { diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp index bb8267b616..28e001208c 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp @@ -217,6 +217,15 @@ void ViveControllerManager::renderHand(UserInputMapper::PoseValue pose, gpu::Bat batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0); } +glm::vec3 ViveControllerManager::getPosition(int hand) const { + const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4]; + return extractTranslation(mat); +} +glm::quat ViveControllerManager::getRotation(int hand) const { + const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4]; + return glm::quat_cast(mat); +} + void ViveControllerManager::update(float deltaTime, bool jointsCaptured) { #ifdef Q_OS_WIN _poseStateMap.clear(); @@ -250,7 +259,7 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) { numTrackedControllers++; const mat4& mat = _trackedDevicePoseMat4[device]; - + if (!jointsCaptured) { handlePoseEvent(mat, numTrackedControllers - 1); } @@ -372,16 +381,23 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, int index) { // Q = (deltaQ * QOffset) * (yFlip * quarterTurnAboutX) // // Q = (deltaQ * inverse(deltaQForAlignedHand)) * (yFlip * quarterTurnAboutX) - + + float sign = (index == LEFT_HAND) ? -1.0f : 1.0f; + const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f)); const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); - float sign = (index == LEFT_HAND) ? -1.0f : 1.0f; const glm::quat signedQuaterZ = glm::angleAxis(sign * PI / 2.0f, glm::vec3(0.0f, 0.0f, 1.0f)); const glm::quat eighthX = glm::angleAxis(PI / 4.0f, glm::vec3(1.0f, 0.0f, 0.0f)); - const glm::quat offset = glm::inverse(signedQuaterZ * eighthX); - rotation = rotation * offset * yFlip * quarterX; + + + const glm::quat rotationOffset = glm::inverse(signedQuaterZ * eighthX) * yFlip * quarterX; + const glm::vec3 translationOffset = glm::vec3(sign * CONTROLLER_LENGTH_OFFSET / 2.0f, + CONTROLLER_LENGTH_OFFSET / 2.0f, + 2.0f * CONTROLLER_LENGTH_OFFSET); - position += rotation * glm::vec3(0, 0, -CONTROLLER_LENGTH_OFFSET); + position += rotation * translationOffset; + rotation = rotation * rotationOffset; + //{quat, x = 0.653281, y = -0.270598, z = 0.653281, w = 0.270598}{vec3, x = 0.0381, y = -0.0381, z = -0.1524} _poseStateMap[makeInput(JointChannel(index)).getChannel()] = UserInputMapper::PoseValue(position, rotation); } diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.h b/libraries/input-plugins/src/input-plugins/ViveControllerManager.h index 5cae8daaf4..f6220ca97a 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.h +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.h @@ -27,6 +27,8 @@ class ViveControllerManager : public InputPlugin, public InputDevice { Q_OBJECT public: + static const QString NAME; + enum JoystickAxisChannel { AXIS_Y_POS = 1U << 1, AXIS_Y_NEG = 1U << 2, @@ -74,6 +76,10 @@ public: UserInputMapper::Input makeInput(unsigned int button, int index); UserInputMapper::Input makeInput(JoystickAxisChannel axis, int index); UserInputMapper::Input makeInput(JointChannel joint); + + int getNumDevices() const; + glm::vec3 getPosition(int device) const; + glm::quat getRotation(int device) const; private: void renderHand(UserInputMapper::PoseValue pose, gpu::Batch& batch, int index); @@ -92,8 +98,6 @@ private: int _rightHandRenderID; bool _renderControllers; - - static const QString NAME; }; #endif // hifi__ViveControllerManager diff --git a/libraries/shared/src/PhysicsHelpers.h b/libraries/shared/src/PhysicsHelpers.h index 7ceafea915..3b6fccdc99 100644 --- a/libraries/shared/src/PhysicsHelpers.h +++ b/libraries/shared/src/PhysicsHelpers.h @@ -16,7 +16,7 @@ #include const int PHYSICS_ENGINE_MAX_NUM_SUBSTEPS = 6; // Bullet will start to "lose time" at 10 FPS. -const float PHYSICS_ENGINE_FIXED_SUBSTEP = 1.0f / 60.0f; +const float PHYSICS_ENGINE_FIXED_SUBSTEP = 1.0f / 90.0f; // return incremental rotation (Bullet-style) caused by angularVelocity over timeStep glm::quat computeBulletRotationStep(const glm::vec3& angularVelocity, float timeStep);