我试图在混合现实工具包中的铰接式手柄指针的末尾放置一个预览对象。如何得到指针击中几何图形的位置?
我的DefaultControllerPointer设置为铰接式手,但我需要得到它的参考,然后得到转换位置的尖端。
发布于 2019-05-10 17:56:58
下面是一个例子,说明您将如何迭代所有控制器,找到手部射线的铰接式手,然后得到端点(以及射线起始点)的位置,最后确定光线是否击中几何图形(一个对象),因为它有一个默认的长度:
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一样工作。
发布于 2019-05-10 07:12:04
将此作为实例化预览对象,并将其放在更新中:
instantiatedSphere.transform.position = GazeManager.Instance.HitPosition;https://stackoverflow.com/questions/56067810
复制相似问题