Oculus OVR_CAPI.cpp 错误
Oculus OVR_CAPI.cpp error
我目前正在进行一个项目,我需要读取 Oculus Rift DK2 传感器。我在网上搜索了可用的示例,遗憾的是我能找到的唯一示例导致我在 SDK 版本等方面遇到很多麻烦。我找到了一个教程,介绍如何实现一些基本的 C++ 代码来读取俯仰、滚动和偏航。我用的SDK是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;
}
这部分(据我所知)没有问题。
当我包含 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)();
}
当我尝试构建它时出现错误:"expected an expression" 和“C2062(type 'int' unexpected)”,都在第 6 行。
有没有人熟悉这个问题,或者有人可以给我关于如何开始使用 Oculus 软件的建议吗?
您已经包含了 LibOVR 的来源。您必须将 LibOVR 编译为 visual studio 中的 .lib 文件并将其添加到您的项目中。
第 1 步
在LibOVR文件夹中,应该有一个"Projects folder"。打开您的 visual studio 版本。
第 2 步
编译 LibOVR 项目(在发布模式下),这应该不会出现任何错误。如果是这样,库可能已损坏。尝试从 oculus 网站重新下载源代码或尝试其他版本。
第 3 步
成功后将 LibOVR.lib 文件从构建文件夹和 "Include" 文件夹复制到您自己的项目中(我建议在您的项目目录中创建一个新的 "libs" 文件夹)。
第 4 步
关闭 LibOVR 项目并打开您自己的项目。打开项目的 属性 window,然后在 VC++ 目录中将 "Include" 文件夹添加到 "Include Directories"。还要将 .lib 文件所在的文件夹添加到 "Library Directories".
最后在 "Linker->Input" 设置中将 LibOVR.lib 添加到 "Additional Dependencies" 如果您还没有的话。
第 5 步
将此添加到您的 main.cpp 文件
#include <OVR_CAPI.h>
尝试编译您的项目。现在应该一切正常了。
我目前正在进行一个项目,我需要读取 Oculus Rift DK2 传感器。我在网上搜索了可用的示例,遗憾的是我能找到的唯一示例导致我在 SDK 版本等方面遇到很多麻烦。我找到了一个教程,介绍如何实现一些基本的 C++ 代码来读取俯仰、滚动和偏航。我用的SDK是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;
}
这部分(据我所知)没有问题。
当我包含 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)();
}
当我尝试构建它时出现错误:"expected an expression" 和“C2062(type 'int' unexpected)”,都在第 6 行。 有没有人熟悉这个问题,或者有人可以给我关于如何开始使用 Oculus 软件的建议吗?
您已经包含了 LibOVR 的来源。您必须将 LibOVR 编译为 visual studio 中的 .lib 文件并将其添加到您的项目中。
第 1 步
在LibOVR文件夹中,应该有一个"Projects folder"。打开您的 visual studio 版本。
第 2 步
编译 LibOVR 项目(在发布模式下),这应该不会出现任何错误。如果是这样,库可能已损坏。尝试从 oculus 网站重新下载源代码或尝试其他版本。
第 3 步
成功后将 LibOVR.lib 文件从构建文件夹和 "Include" 文件夹复制到您自己的项目中(我建议在您的项目目录中创建一个新的 "libs" 文件夹)。
第 4 步
关闭 LibOVR 项目并打开您自己的项目。打开项目的 属性 window,然后在 VC++ 目录中将 "Include" 文件夹添加到 "Include Directories"。还要将 .lib 文件所在的文件夹添加到 "Library Directories".
最后在 "Linker->Input" 设置中将 LibOVR.lib 添加到 "Additional Dependencies" 如果您还没有的话。
第 5 步
将此添加到您的 main.cpp 文件
#include <OVR_CAPI.h>
尝试编译您的项目。现在应该一切正常了。