VIVE 追踪器 VIVE Tracker VR设备研究

旧城冷巷雨未停 提交于 2019-11-30 01:33:22

  • 设备的冲突 一但打开这追踪器 将会有某一只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;

	}
}

基于我之前的文章: https://my.oschina.net/u/235558/blog/1579273

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!