-
设备的冲突 一但打开这追踪器 将会有某一只VR手柄无法启动, 关闭这追踪器 两只VR手柄都能启动
-
程序中设备的检测 因为是占用手柄的位, 所以可以用手柄的检测方式, 能检测到, 设备号是2 没检测到则为-1
// 右手手柄的设备号一般是3 左手手柄的设备号一般是4
int rightNumber = m_vrSystem->GetTrackedDeviceIndexForControllerRole(vr::ETrackedControllerRole::TrackedControllerRole_RightHand);
int leftNumber = m_vrSystem->GetTrackedDeviceIndexForControllerRole(vr::ETrackedControllerRole::TrackedControllerRole_LeftHand);
std::cout << "右手号数:" << rightNumber << std::endl;
std::cout << "左手号数:" << leftNumber << std::endl;
if (rightNumber != 2 && leftNumber != 2)
{
continue;
}
- 输出位置信息: 与手柄的一样:
vr::VRCompositor()->SetTrackingSpace(vr::TrackingUniverseStanding);
vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; ++i) poses[i].bPoseIsValid = false;
vr::VRCompositor()->WaitGetPoses(poses, vr::k_unMaxTrackedDeviceCount, NULL, 0);
//// 0是头显, 其它设置是1到64
//for (int i = 1; i < vr::k_unMaxTrackedDeviceCount; ++i)
//{
// if (poses[i].bPoseIsValid)
// {
// //poses[i].
//
// }
//}
std::cout << "#### " << 2 << ":" << poses[2].mDeviceToAbsoluteTracking.m[3][3] << std::endl;
- 完整代码:
#include "pch.h"
#include <iostream>
#include <openvr.h>
int main()
{
vr::EVRApplicationType _type = vr::EVRApplicationType::VRApplication_Scene;
vr::HmdError *peError = new vr::HmdError;
vr::VR_Init(peError, _type);
std::cout.precision(4);
vr::IVRSystem* m_vrSystem = vr::VR_Init(peError, vr::VRApplication_Scene);
while(true)
{
// 右手手柄的设备号一般是3 左手手柄的设备号一般是4
int rightNumber = m_vrSystem->GetTrackedDeviceIndexForControllerRole(vr::ETrackedControllerRole::TrackedControllerRole_RightHand);
int leftNumber = m_vrSystem->GetTrackedDeviceIndexForControllerRole(vr::ETrackedControllerRole::TrackedControllerRole_LeftHand);
std::cout << "右手号数:" << rightNumber << std::endl;
std::cout << "左手号数:" << leftNumber << std::endl;
if (rightNumber != 2 && leftNumber != 2)
{
continue;
}
vr::VRCompositor()->SetTrackingSpace(vr::TrackingUniverseStanding);
vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; ++i) poses[i].bPoseIsValid = false;
vr::VRCompositor()->WaitGetPoses(poses, vr::k_unMaxTrackedDeviceCount, NULL, 0);
//// 0是头显, 其它设置是1到64
//for (int i = 1; i < vr::k_unMaxTrackedDeviceCount; ++i)
//{
// if (poses[i].bPoseIsValid)
// {
// //poses[i].
//
// }
//}
std::cout << "#### " << 2 << ":" << poses[2].mDeviceToAbsoluteTracking.m[3][3] << std::endl;
}
}