【问题标题】:How do I get the position of an active MRTK pointer?如何获取活动 MRTK 指针的位置?
【发布时间】:2019-05-11 01:56:58
【问题描述】:

我正在尝试将预览对象放置在混合现实工具包中铰接式指针的末尾。如何获得指针撞击几何的位置?

我将 DefaultControllerPointer 设置为铰接手,但我需要获取它的引用,然后获取笔尖的变换位置。

【问题讨论】:

    标签: hololens mrtk


    【解决方案1】:

    这是一个示例,说明您将如何遍历所有控制器,找到属于手部光线的关节手,然后获取结束点(以及光线起点)的位置,最后确定光线是否正在命中几何体(一个对象),因为它具有默认长度:

    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。

    【讨论】:

    【解决方案2】:

    将此作为您实例化的预览对象并将其放在更新中:

    instantiatedSphere.transform.position = GazeManager.Instance.HitPosition;
    

    【讨论】:

    • 注视管理器?这只得到头指针吗?我想要右手的控制器指针。
    猜你喜欢
    • 2012-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 2012-04-08
    • 2012-06-30
    相关资源
    最近更新 更多