OpenVR read from devices

Hello all,

this code will start and display the viewport on my HTC Vive:

void OccView::cameraStereoVR()
{
    Aspect_OpenVRSession* openVR = new Aspect_OpenVRSession();

    m_view->View()->SetXRSession(openVR);
    m_view->View()->XRSession()->SetUnitFactor(1000);
    m_view->View()->XRSession()->SetTrackingOrigin(Aspect_OpenVRSession::TrackingUniverseOrigin::TrackingUniverseOrigin_Standing);
    m_view->View()->XRSession()->Open();

    m_view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Stereo);
    m_view->ChangeRenderingParams().StereoMode = Graphic3d_StereoMode_OpenVR;

    openVR->ProcessEvents();

    NCollection_Vec2< int > viewPorts = openVR->RecommendedViewport();
    qDebug() << viewPorts[0] << viewPorts[1];

    //NCollection_Mat4<double> coll = openVR->EyeToHeadTransform(Aspect_Eye::Aspect_Eye_Left);
    //qDebug() << coll.GetRow(1);

    //NCollection_Mat4<double> projection = openVR->ProjectionMatrix	(Aspect_Eye::Aspect_Eye_Left, 10, 100);
    //qDebug() << projection.GetRow(1);

    //qDebug() << "NamedTrackedDevice" << openVR->NamedTrackedDevice(Aspect_XRTrackedDeviceRole::Aspect_XRTrackedDeviceRole_Head);

    while (true)
    {
        m_view->Redraw();
        //m_view->View()->XRSession()->ProcessEvents();

        if (openVR->WaitPoses())
        {
            qDebug() << "pose";
        }

        QApplication::processEvents();
    }
}

But I can not ready any information

openVR->EyeToHeadTransform(Aspect_Eye::Aspect_Eye_Left)

and

openVR->ProjectionMatrix	(Aspect_Eye::Aspect_Eye_Left, 10, 100);

will crash.

Question: How can I "look around" with the headset?

I assume I have to read the position/rotation of the headset and then adjust the camera? Is that not automatically done?

Thanks for pointing me in the right direction!

Cheers!

PS: I am using MinGW

Daniel Duesentrieb's picture

Doooh,

I was only looking in Aspect_OpenVRSession but all those functions are found in Aspect_XRSession - so all good.

Wondering if this is working of the shelf with windows compiler? I had similar problems with GI rendering where I also have to run in a loop to get rendering going?

gkv311 n's picture

The for-loop in your code snippet is not how this API is expected to be used. There is a lot of logic in AIS_ViewController - so it is better relying on this tool, or check it source code to see how XR could be managed (methods like AIS_ViewController::handleXRInput() and similar).

Daniel Duesentrieb's picture

The class is using AIS_ViewController:

class OccView : public QWidget, protected AIS_ViewController

but this

 Aspect_OpenVRSession* openVR = new Aspect_OpenVRSession();

    m_view->View()->SetXRSession(openVR);
    m_view->View()->XRSession()->SetUnitFactor(1000);
    m_view->View()->XRSession()->SetTrackingOrigin(Aspect_OpenVRSession::TrackingUniverseOrigin::TrackingUniverseOrigin_Standing);
    m_view->View()->XRSession()->Open();

    SetDisplayXRHands(true);
    SetDisplayXRAuxDevices(true);

    m_view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Stereo);
    m_view->ChangeRenderingParams().StereoMode = Graphic3d_StereoMode_OpenVR;

    openVR->ProcessEvents();

    NCollection_Vec2< int > viewPorts = openVR->RecommendedViewport();
    qDebug() << viewPorts[0] << viewPorts[1];

    SetContinuousRedraw(true);

is just showing one picture. And when I move the headset the picture is disapearing and comes back when the headset ist back in same position.

Also those lines

SetDisplayXRHands(true);
SetDisplayXRAuxDevices(true);

Do nothing - I can't see any controller/hands or whatever may should be there

My loop is the only way I get a continues picture.

while (true)
    {

        gp_Trsf trsfHead = openVR->HeadPose();
        gp_Trsf trsfLeftHand = openVR->LeftHandPose();
        gp_Trsf trsfRightHand = openVR->RightHandPose();

        gp_Dir dir;
        dir.Transform(trsfHead);
        m_view->Camera()->SetDirectionFromEye(dir);

        //qDebug() << "head" << trsfHead.TranslationPart().X() << "left hand" << trsfLeftHand.TranslationPart().X() << "right hand" << trsfRightHand.TranslationPart().X();

        m_view->Redraw();
        QApplication::processEvents();
        openVR->ProcessEvents();
    }

If there is an better way please let me know.

I am using MinGW64, QT5 under windows.

Thanks!