Skip to content
Snippets Groups Projects
Commit 078da71f authored by Christian Mattes's avatar Christian Mattes
Browse files

Can now disable individual hands in the RopeLocomotion.

parent 497564db
No related branches found
No related tags found
No related merge requests found
#include "RopeLocomotion.hh"
#include <openvr.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/transform.hpp>
......@@ -8,30 +9,27 @@
#include <lava-extras/openvr/OpenVRControllerInput.hh>
#include <lava-extras/openvr/OpenVRHmd.hh>
#include <lava-extras/openvr/OpenVRTypes.hh>
#include <openvr.h>
namespace lava {
namespace vr {
RopeLocomotion::RopeLocomotion(const lava::openvr::SharedOpenVRHmd &output)
: mOpenVR(output), mPressed({{false, false}}) {}
namespace lava
{
namespace vr
{
RopeLocomotion::RopeLocomotion(const lava::openvr::SharedOpenVRHmd &output) : mOpenVR(output), mPressed({{false, false}}) {}
glm::mat4 RopeLocomotion::updateMatrix(glm::mat4 old) {
static auto triggerMask =
::vr::ButtonMaskFromId(::vr::EVRButtonId::k_EButton_SteamVR_Trigger);
static auto touchpadMask =
::vr::ButtonMaskFromId(::vr::EVRButtonId::k_EButton_SteamVR_Touchpad);
glm::mat4 RopeLocomotion::updateMatrix(glm::mat4 old)
{
static auto triggerMask = ::vr::ButtonMaskFromId(::vr::EVRButtonId::k_EButton_SteamVR_Trigger);
static auto touchpadMask = ::vr::ButtonMaskFromId(::vr::EVRButtonId::k_EButton_SteamVR_Touchpad);
std::array<::vr::ETrackedControllerRole, 2> roles = {
::vr::TrackedControllerRole_RightHand,
::vr::TrackedControllerRole_LeftHand};
std::array<::vr::ETrackedControllerRole, 2> roles = {::vr::TrackedControllerRole_RightHand, ::vr::TrackedControllerRole_LeftHand};
auto oldPoses = mLastPos;
auto oldPressed = mPressed;
auto touched = std::array<bool, 2>{{false, false}};
auto system = ::vr::VRSystem();
for (size_t i = 0; i < 2; i++) {
for (size_t i = 0; i < 2; i++)
{
auto hand = system->GetTrackedDeviceIndexForControllerRole(roles[i]);
if (hand == ::vr::k_unTrackedDeviceIndexInvalid)
continue;
......@@ -42,14 +40,14 @@ glm::mat4 RopeLocomotion::updateMatrix(glm::mat4 old) {
::vr::VRControllerState_t state;
system->GetControllerState(hand, &state, sizeof(state));
auto mat =
glm::transpose(lava::vrToGlm(pose.mDeviceToAbsoluteTracking));
auto mat = glm::transpose(lava::vrToGlm(pose.mDeviceToAbsoluteTracking));
mLastPos[i] = glm::vec3(mat[3]);
mPressed[i] = state.ulButtonPressed & triggerMask;
mPressed[i] = (state.ulButtonPressed & triggerMask) && !mConfig.disableHand[i];
touched[i] = state.ulButtonTouched & touchpadMask;
}
if (mPressed[0] && mPressed[1]) {
if (mPressed[0] && mPressed[1])
{
auto old_cog = 0.5f * (oldPoses[0] + oldPoses[1]);
auto new_cog = 0.5f * (mLastPos[0] + mLastPos[1]);
......@@ -59,24 +57,22 @@ glm::mat4 RopeLocomotion::updateMatrix(glm::mat4 old) {
auto old_dir = glm::normalize(old_ray);
auto new_dir = glm::normalize(new_ray);
auto scale = (mConfig.allowZoom)
? glm::length(new_ray) / glm::length(old_ray)
: 1.0f;
auto scale = (mConfig.allowZoom) ? glm::length(new_ray) / glm::length(old_ray) : 1.0f;
auto axis = glm::vec3{0.f, 1.f, 0.f};
auto angle = (mConfig.allowRotation)
? glm::orientedAngle(old_dir, new_dir, axis)
: 0.0f;
auto angle = (mConfig.allowRotation) ? glm::orientedAngle(old_dir, new_dir, axis) : 0.0f;
auto rot = glm::rotate(angle, axis);
auto combined = glm::translate(new_cog) * rot *
glm::scale(glm::vec3{scale, scale, scale}) *
glm::translate(-old_cog);
auto combined = glm::translate(new_cog) * rot * glm::scale(glm::vec3{scale, scale, scale}) * glm::translate(-old_cog);
old = combined * old;
} else if (mPressed[0]) {
}
else if (mPressed[0])
{
old[3] += glm::vec4(mLastPos[0] - oldPoses[0], 0.f);
} else if (mPressed[1]) {
}
else if (mPressed[1])
{
old[3] += glm::vec4(mLastPos[1] - oldPoses[1], 0.f);
}
......
......@@ -12,6 +12,8 @@ class RopeLocomotion {
struct Config {
bool allowZoom = true;
bool allowRotation = true;
bool disableHand[2] = {false, false};
};
RopeLocomotion(lava::openvr::SharedOpenVRHmd const &output);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment