rotationvirtual-realityglm-mathopenvr

OpenVR Teleportation Problem (Forward direction calculation)


So I am trying to implement teleportation in my VR application (not in Unity). I am able to get the pose matrices for each controller from

if (auto error = vr::VRInput()->GetPoseActionDataForNextFrame(hand[eHand].pose_handle, vr::TrackingUniverseStanding, &poseData, sizeof(poseData), vr::k_ulInvalidInputValueHandle) != vr::VRInputError_None
        || !poseData.bActive || !poseData.pose.bPoseIsValid)
    {
        std::cerr << "pose invalid " << error << std::endl;
    }
    else
    {
        hand[eHand].pose = ConvertSteamVRMatrixToMatrix4(poseData.pose.mDeviceToAbsoluteTracking);
    }

I then use glm::decompose() to get the position and orientation (orientation must be conjugated). Then I try to get the forward direction from it by multiplying the orientation matrix by vec4(0,0,1,0) but the resultant vector is incorrect. Is there a flaw in my logic?


Solution

  • So it turns out I had a few issues with my methodology. Firstly, OpenVR defines the forward direction of the controllers as vec4(0,0,-1,0), and secondly, it is defined with respect to the HMD camera. In order to move around the scene, I use a second camera matrix for translation and rotation. Thus had to take this into account.

    My final calculation is as follows

    auto forward = glm::normalize(glm::inverse(nonHMDViewMat) *
                                  vr.GetControllerPose(Right) * glm::vec4(0,0,-1,0));
    

    Where vr.GetControllerPose(Right) returns the matrix in hand[eHand].pose for the right hand.