More baseball test code

This commit is contained in:
Clément Brisset 2015-11-03 10:11:25 -08:00 committed by Atlante45
parent 40ce2416e8
commit c63fc8557c
2 changed files with 46 additions and 39 deletions

View file

@ -52,32 +52,35 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
glm::vec3 offset;
glm::vec3 palmPosition;
glm::quat palmRotation;
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<ViveControllerManager>();
auto index = (_hand == "right") ? 0 : 1;
#ifdef Q_OS_WIN
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<ViveControllerManager>();
auto index = (_hand == "left") ? 0 : 1;
auto userInputMapper = DependencyManager::get<UserInputMapper>();
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 {
palmPosition = holdingAvatar->getLeftPalmPosition();
palmRotation = holdingAvatar->getLeftPalmRotation();
}
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 * glm::angleAxis(PI, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::angleAxis(PI_OVER_TWO, glm::vec3(0.0f, 0.0f, 1.0f));
} else
#endif
if (_hand == "right") {
palmPosition = holdingAvatar->getRightPalmPosition();
palmRotation = holdingAvatar->getRightPalmRotation();
} else {
palmPosition = holdingAvatar->getLeftPalmPosition();
palmRotation = holdingAvatar->getLeftPalmRotation();
}
rotation = palmRotation * _relativeRotation;
offset = rotation * _relativePosition;
position = palmPosition + offset;

View file

@ -278,12 +278,18 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
//qDebug() << "Trackpad: " << controllerState.rAxis[0].x << " " << controllerState.rAxis[0].y;
//qDebug() << "Trigger: " << controllerState.rAxis[1].x << " " << controllerState.rAxis[1].y;
for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) {
auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i);
bool pressed = 0 != (controllerState.ulButtonPressed & mask);
auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i);
bool pressed = 0 != (controllerState.ulButtonPressed & mask);
handleButtonEvent(i, pressed, left);
}
for (uint32_t i = 0; i < vr::k_unControllerStateAxisCount; i++) {
handleAxisEvent(i, controllerState.rAxis[i].x, controllerState.rAxis[i].y, left);
for (uint32_t i = 0; i < vr::k_unControllerStateAxisCount; i++) {
auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)(i + vr::k_EButton_Axis0));
bool pressed = 0 != (controllerState.ulButtonPressed & mask);
if (pressed || true) {
handleAxisEvent(i, controllerState.rAxis[i].x, controllerState.rAxis[i].y, left);
} else {
handleAxisEvent(i, 0.0f, 0.0f, left);
}
}
}
}
@ -412,16 +418,14 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, bool left) {
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 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 * 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}
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 * translationOffset;
rotation = rotation * rotationOffset;
_poseStateMap[left ? controller::LEFT_HAND : controller::RIGHT_HAND] = controller::Pose(position, rotation);
}