int w_Joystick_getAxes(lua_State *L) { Joystick *j = luax_checkjoystick(L, 1); std::vector<float> axes = j->getAxes(); for (size_t i = 0; i < axes.size(); i++) lua_pushnumber(L, axes[i]); return (int) axes.size(); }
static void setPalm(float deltaTime, int index) { MyAvatar* avatar = Application::getInstance()->getAvatar(); Hand* hand = avatar->getHand(); PalmData* palm; bool foundHand = false; for (size_t j = 0; j < hand->getNumPalms(); j++) { if (hand->getPalms()[j].getSixenseID() == index) { palm = &(hand->getPalms()[j]); foundHand = true; } } if (!foundHand) { PalmData newPalm(hand); hand->getPalms().push_back(newPalm); palm = &(hand->getPalms()[hand->getNumPalms() - 1]); palm->setSixenseID(index); } palm->setActive(true); // Read controller buttons and joystick into the hand const QString PRIO_JOYSTICK_NAME = "PrioVR"; Joystick* prioJoystick = JoystickScriptingInterface::getInstance().joystickWithName(PRIO_JOYSTICK_NAME); if (prioJoystick) { const QVector<float> axes = prioJoystick->getAxes(); const QVector<bool> buttons = prioJoystick->getButtons(); if (axes.size() >= 4 && buttons.size() >= 4) { if (index == LEFT_HAND_INDEX) { palm->setControllerButtons(buttons[1] ? BUTTON_FWD : 0); palm->setTrigger(buttons[0] ? 1.0f : 0.0f); palm->setJoystick(axes[0], -axes[1]); } else { palm->setControllerButtons(buttons[3] ? BUTTON_FWD : 0); palm->setTrigger(buttons[2] ? 1.0f : 0.0f); palm->setJoystick(axes[2], -axes[3]); } } } // NOTE: this math is done in the worl-frame with unecessary complexity. // TODO: transfom this to stay in the model-frame. glm::vec3 position; glm::quat rotation; SkeletonModel* skeletonModel = &Application::getInstance()->getAvatar()->getSkeletonModel(); int jointIndex; glm::quat inverseRotation = glm::inverse(Application::getInstance()->getAvatar()->getOrientation()); if (index == LEFT_HAND_INDEX) { jointIndex = skeletonModel->getLeftHandJointIndex(); skeletonModel->getJointRotationInWorldFrame(jointIndex, rotation); rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, PI_OVER_TWO, 0.0f)); } else { jointIndex = skeletonModel->getRightHandJointIndex(); skeletonModel->getJointRotationInWorldFrame(jointIndex, rotation); rotation = inverseRotation * rotation * glm::quat(glm::vec3(0.0f, -PI_OVER_TWO, 0.0f)); } skeletonModel->getJointPositionInWorldFrame(jointIndex, position); position = inverseRotation * (position - skeletonModel->getTranslation()); palm->setRawRotation(rotation); // Compute current velocity from position change glm::vec3 rawVelocity; if (deltaTime > 0.0f) { rawVelocity = (position - palm->getRawPosition()) / deltaTime; } else { rawVelocity = glm::vec3(0.0f); } palm->setRawVelocity(rawVelocity); palm->setRawPosition(position); // Store the one fingertip in the palm structure so we can track velocity const float FINGER_LENGTH = 0.3f; // meters const glm::vec3 FINGER_VECTOR(0.0f, 0.0f, FINGER_LENGTH); const glm::vec3 newTipPosition = position + rotation * FINGER_VECTOR; glm::vec3 oldTipPosition = palm->getTipRawPosition(); if (deltaTime > 0.0f) { palm->setTipVelocity((newTipPosition - oldTipPosition) / deltaTime); } else { palm->setTipVelocity(glm::vec3(0.0f)); } palm->setTipPosition(newTipPosition); }