Search code examples
c++htc-viveopenvr

Cannot access play area from VRChaperone


I'm writing some C++ code using the openVR framework. I can successfully extract the positional data from the controllers but I need the width and depth of the play area so I can scale the positional data to my screen.

I've tried

vr::VRChaperone()->GetCalibrationState(); 
vr::VRChaperoneSetup()->RevertWorkingCopy();    
float *posX = 0;    
float *posZ = 0;    
vr::VRChaperoneSetup()->GetWorkingPlayAreaSize(posX, posZ);     
dprintf("PosX:%f PosZ:%f\n", posX, posZ);

but it keeps saying posX and posZ are both 0. Any ideas?


Solution

  • After taking a quick look at github that functions returns a bool so try to check if it actually worked first and then you are not actually printing the values of the floats, you are printing the address's cause they are pointers.
    Change the print statement to this dprintf("PosX:%f PosZ:%f\n", *posX, *posZ); that way you are dereferencing the pointers and getting their value.
    Also I dont know exacly how openvr works but after looking at stark's comment what you probably want to do is
    float posX, posZ;
    vr::VRChaperoneSetup()->GetWorkingPlayAreaSize(&posX, &posZ);
    This way you give the function the address of your variables so it can edit them then you can use printf the way you have
    dprintf("PosX:%f PosZ:%f\n", posX, posZ);