hololens - 如何获取活动 MRTK 指针的位置?
问题描述
我正在尝试将预览对象放置在混合现实工具包中铰接式指针的末尾。如何获得指针撞击几何的位置?
我将 DefaultControllerPointer 设置为铰接手,但我需要获取对它的引用,然后获取尖端的变换位置。
解决方案
这是一个如何迭代所有控制器的示例,找到作为手部光线的关节手,然后获取终点的位置(以及光线起点),最后确定光线是否击中几何体(一个对象),因为它有一个默认长度:
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;
public class HitPointTest : MonoBehaviour
{
// Update is called once per frame
void Update()
{
foreach(var source in MixedRealityToolkit.InputSystem.DetectedInputSources)
{
// Ignore anything that is not a hand because we want articulated hands
if (source.SourceType == Microsoft.MixedReality.Toolkit.Input.InputSourceType.Hand)
{
foreach (var p in source.Pointers)
{
if (p is IMixedRealityNearPointer)
{
// Ignore near pointers, we only want the rays
continue;
}
if (p.Result != null)
{
var startPoint = p.Position;
var endPoint = p.Result.Details.Point;
var hitObject = p.Result.Details.Object;
if (hitObject)
{
var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.localScale = Vector3.one * 0.01f;
sphere.transform.position = endPoint;
}
}
}
}
}
}
}
请注意,这是最新的 mrtk_development 代码库,也应该从 RC1 开始工作。
推荐阅读
- html - 是否有必要包含 width="auto" 因为这是默认设置?
- jquery - 查找给定“this”对象的 HTML 元素,该对象不是其子对象
- c# - 如何启用弹出提交的视图状态
- javascript - 加载不同的 jquery 版本时,条件注释不起作用(一个用于 IE8)
- swift - 如何使用 Swift 在控制台应用程序上进行非阻塞键盘输入?
- c# - 我需要“UWP 的 Windows 桌面扩展”,但我在参考窗口中没有找到它
- typescript - 如何在泛型类中编写“K extends keyof T”然后使用 K
- byte - Hexdump:在字节和两字节十进制之间转换
- memory - TCL中的RAM内存
- geolocation - 如何将地理坐标转换为具有特定起点的米?