ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.07k stars 1.28k forks source link

Overlay Mouse Input method doesn't work for VRApplication_Background #740

Open GimpMaster opened 6 years ago

GimpMaster commented 6 years ago

Valve Team,

In order to help you chase down this bug I created the smallest program I could think of that creates an overlay and calls SetOverlayInputMethod(gOverlayHandle, vr::VROverlayInputMethod_Mouse);

This worked in the Dec 2017 Steam but has not worked in any new betas or any releases in January. I've also tested this with OpenVR SDK 1.0.9 and 1.0.12 and I get the same results.

If you use the openvr-input-emulator beta it will work just fine.

Attached is the single source main file that shows the regression.

Let me know if you have any questions. Thanks!

main.txt <---- File to test.

@JoeLudwig

GimpMaster commented 6 years ago

In case the main.txt attachment doesn't work here is the entire file contents

#include <openvr.h>
#include <conio.h>
#include <stdio.h>
#include <memory.h>
#include <Windows.h>

vr::VROverlayHandle_t gOverlayHandle = -1;

int main(int argc, char *argv[])
{
    vr::EVRInitError eVRInitError;
    vr::VR_Init(&eVRInitError, vr::VRApplication_Background);
    if (!vr::VRSystem() || eVRInitError != vr::VRInitError_None)
    {
        printf("Error init openVR sdk\n");
        vr::VR_Shutdown();
        return 1;
    }
    printf("OpenVR SDK attached");

    // Create overlay
    vr::EVROverlayError error = vr::VROverlay()->CreateOverlay("overlay_test", "overlay_test", &gOverlayHandle);

    // Setup transform matrix
    vr::HmdMatrix34_t trackedDevToOverlayTransform;
    memset(&trackedDevToOverlayTransform, 0, sizeof(trackedDevToOverlayTransform));
    trackedDevToOverlayTransform.m[0][0] = 1;
    trackedDevToOverlayTransform.m[1][1] = 1;
    trackedDevToOverlayTransform.m[2][2] = 1;
    trackedDevToOverlayTransform.m[2][3] = -1.2;
    error = vr::VROverlay()->SetOverlayTransformTrackedDeviceRelative(gOverlayHandle, vr::k_unTrackedDeviceIndex_Hmd, &trackedDevToOverlayTransform);
    error = vr::VROverlay()->SetOverlayInputMethod(gOverlayHandle, vr::VROverlayInputMethod_Mouse);
    error = vr::VROverlay()->SetOverlayFromFile(gOverlayHandle, "C:\\test.jpg");
    error = vr::VROverlay()->ShowOverlay(gOverlayHandle);

    while (_kbhit() == 0)
    {
        vr::VREvent_t Event;
        while (vr::VROverlay()->PollNextOverlayEvent(gOverlayHandle, &Event, sizeof(Event)))
        {
            switch (Event.eventType)
            {
                case vr::VREvent_MouseMove:
                {
                    printf("Mouse Move: %f, %f\n", Event.data.mouse.x, Event.data.mouse.y);
                    break;
                }
                case vr::VREvent_MouseButtonDown:
                {
                    printf("Mouse button down\n");
                    break;
                }
            }
        }

        Sleep(100);
    }
}
Bohica1 commented 6 years ago

I just downloaded the code and I see the same issue. @JoeLudwig

hyungjunk commented 6 years ago

Having the same problem here too.

GimpMaster commented 6 years ago

@hyungjunk - unfortunately it seems Valve does not plan on supporting background application overlay mouse interaction any time soon. @JoeLudwig mentioned that it worked before on mistake and that it will take some time to put it back in. I've already figured out another means of input using the trackpad for selection.