Oculus OVR_CAPI.cpp error

Oculus OVR_CAPI.cpp error

本文关键字:cpp error CAPI OVR Oculus      更新时间:2023-10-16

我目前正在做一个项目,我需要读取Oculus Rift DK2传感器。我已经在网上搜索了可用的样本,遗憾的是,我能找到的唯一样本导致我在SDK版本等方面遇到了很多麻烦。我找到了一个教程,关于如何实现一些基本的c++代码来读取pitch, roll & &;偏航。我使用了Windows V1.8.0的SDK。

#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;
}

(据我所知)这部分没有问题。

当我包含OVR_CAPI.h时,OVR_CAPI.cpp神奇地出现在OVR_CAPI.h所在的文件夹中。该CPP文件包含以下内容:

#include "stdafx.h"
#include "OVR_CAPI.h"
OVR_PUBLIC_FUNCTION(ovrResult) ovr_Initialize(const ovrInitParams * params)
{
    return OVR_PUBLIC_FUNCTION(ovrResult)();
}
当我试图构建

时,错误:"期望的表达式"answers"C2062(类型'int' unexpected)"出现,都在第6行。有人熟悉这个问题吗,或者有人能给我一些建议,告诉我如何开始使用Oculus软件吗?

您已经包含了LibOVR的源代码。你必须在visual studio中将LibOVR编译为.lib文件,然后将其添加到你的项目中。

步骤1

在LibOVR文件夹中,应该有一个"Projects文件夹"。打开visual studio版本的版本。

步骤2

编译LibOVR项目(在发布模式下),这应该不会给出任何错误。如果是,则库可能已损坏。请尝试从oculus网站重新下载源代码或尝试不同的版本。

步骤3

成功时复制LibOVR。从build文件夹和"Include"文件夹中创建"lib "文件到你自己的项目(我建议在你的项目目录中创建一个新的"libs"文件夹)。

步骤4

关闭LibOVR项目并打开自己的项目。打开项目的属性窗口,在vc++目录中添加"Include"文件夹到"Include Directories"。同时将.lib文件所在的文件夹添加到"Library Directories"中。

最后在"链接器->输入"设置中添加LibOVR。

步骤5

添加到main.cpp文件

#include <OVR_CAPI.h>

尝试编译您的项目。