Mark6028
Mark6028

Reputation: 45

Oculus OVR_CAPI.cpp error

I'm currently working on a project where I need to read the Oculus Rift DK2 sensors. I have searched the web for usable samples, sadly the only samples I can find cause me a lot of trouble with SDK vesions and such. I found a tutorial on how to implement some basic C++ code to read the pitch, roll & yaw. I used the SDK for Windows V1.8.0.

#include "stdafx.h"
#include <iostream>
#include "../../OculusSDK/LibOVR/Include/OVR_CAPI.h"
#include <thread>
#include <iomanip>

#define COLW setw(15)

using namespace std;

int main()
{  

// Initialize our session with the Oculus HMD.
if (ovr_Initialize(nullptr) == ovrSuccess)
{
    ovrSession session = nullptr;
    ovrGraphicsLuid luid;
    ovrResult result = ovr_Create(&session, &luid);

    if (result == ovrSuccess)
    {   // Then we're connected to an HMD!

        // Let's take a look at some orientation data.
        ovrTrackingState ts;

        while (true)
        {
            ts = ovr_GetTrackingState(session, 0, true);

            ovrPoseStatef tempHeadPose = ts.HeadPose;
            ovrPosef tempPose = tempHeadPose.ThePose;
            ovrQuatf tempOrient = tempPose.Orientation;

            cout << "Orientation (x,y,z):  " << COLW << tempOrient.x << ","
                << COLW << tempOrient.y << "," << COLW << tempOrient.z
                << endl;

            // Wait a bit to let us actually read stuff.
            std::this_thread::sleep_for(std::chrono::milliseconds(100));
        }

        ovr_Destroy(session);
    }

    ovr_Shutdown();
    // If we've fallen through to this point, the HMD is no longer
    // connected.
}

return 0;
}

there are (as far as I know) no problems with this part.

when I included the OVR_CAPI.h the OVR_CAPI.cpp magically appears in the folder where OVR_CAPI.h is located. this cpp file contains the following:

#include "stdafx.h"
#include "OVR_CAPI.h"

OVR_PUBLIC_FUNCTION(ovrResult) ovr_Initialize(const ovrInitParams * params)
{
    return OVR_PUBLIC_FUNCTION(ovrResult)();
}

when I try to build it errors:"expected an expression" and " C2062(type 'int' unexpected)" occur,both on Line 6. is anyone familiar with this problem or can someone give me advice on how to get started with Oculus software?

Upvotes: 1

Views: 577

Answers (1)

wuppie367
wuppie367

Reputation: 362

You have included the source of the LibOVR. You have to compile LibOVR to a .lib file in visual studio and add that to your project instead.

Step 1

In the LibOVR folder, there should be a "Projects folder". Open the version for your visual studio version.

Step 2

Compile the LibOVR project (in release mode), this shouldn't give any errors. If it does, the library might be corrupted. Try downloading the source again from the oculus website or try a different version.

Step 3

When successful copy the LibOVR.lib file from the build folder and the "Include" folder to your own project (I suggest creating a new "libs" folder in your project directory).

Step 4

Close the LibOVR project and open your own. Open the property window for your project and in VC++ Directories add the "Include" folder to the "Include Directories". Also add the the folder where the .lib file is located to the "Library Directories".

Finally in the "Linker->Input" settings add LibOVR.lib to the "Additional Dependencies" if you didn't already.

Step 5

Add this to your main.cpp file

#include <OVR_CAPI.h>

Try compiling your project. Everything should work now.

Upvotes: 1

Related Questions