如何使用unity和ARKit将职位转换为应用程序的起点? [英] How to convert a position into starting point for app using unity and ARKit?

查看:63
本文介绍了如何使用unity和ARKit将职位转换为应用程序的起点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试开发AR应用程序.打开该应用程序时,此时设备位置为(0,0,0),即如果我打印或显示坐标,则该设备位置为(0,0,0).我想创建一个门入口处的起点.当其他使用我的应用程序的用户可以在任何地方打开该应用程序.

Trying to develop an AR app.When the app is opened,at that point the device location is (0,0,0) that is if I print or display my coordinates it will be (0,0,0).I want to create a starting point like at the entrance of a door.When other users using my app can open the app anywhere.

我想做的是我已经在门的入口处保留了一个AR.用户在任意位置打开应用程序成为起点,所有AR对象都会出现.当他们通过该AR对象时,我想要其设备的坐标为(0,0,0).但是,如果我在统一编辑器中运行以下代码,它会将摄像头移至应用启动的位置.我希望转换入口定位到应用的起点.

What I am trying to do is I already kept an AR at the entrance of the door.Users open app at random position which become their starting point, all AR objects will appear.When they pass through the AR object ,I want the coordinates of their device be(0,0,0).But if I run the below code in unity editor it takes the camera to the position where app has started.I am looking to convert the entrance position into App starting point.

            Camera.main.transform.position=new Vector3(0,0,0);

据我了解,如果我们更改相机在应用中的位置,它可能会显示毛刺

From what I understand if we change the position of camera in app it can show glitches

推荐答案

您的问题非常不清楚-.-

Your question is very unclear -.-

但是如果尝试将摄像机重置为(0,0,0),同时将所有游戏对象保持在相同的相对位置上,则可以尝试:

    var localToCamera = Camera.main.transform.worldToLocalMatrix;
    var obj = GameObject.FindSceneObjectsOfType(typeof(GameObject));
    foreach (var o in obj)
    {
        var go = (o as GameObject);
        go.transform.FromMatrix(localToCamera * go.transform.localToWorldMatrix);
    }

_

上面的 UGLY 代码应该做什么: 它将爬过所有GameObject,并以如下方式重新放置它们:如果将摄像机设置为位置(0,0,0)并面向(0,0,1),则它们将相对于相机.

what the UGLY code above is supposed to do: it's going to crawl through all GameObjects and reposition them in such a way that if you set the camera to position (0,0,0) and facing (0,0,1), they will remain at the same position and orientation relatively to the camera.

请注意,执行此代码后,相机本身将重新定位为(0,0,0)并面向(0,0,1),因为

notice that the camera itself WILL get repositioned to (0,0,0) and facing (0,0,1) after this code is executed because

Camera.main.transform.worldToLocalMatrix * localToWorldMatrix ==身份

Camera.main.transform.worldToLocalMatrix * localToWorldMatrix == identity

编辑:

我不能将这段代码放在注释中,因为它太长了.

I can't put this code in the comments because it's too long.

尝试

// code from the top of my head here, syntax or function names might not be exact
var forward = arcamera.transform.forward;
forward.y = 0;
arcamera.transform.rotation = Quaternion.LookDirection(forward);
// now the camera forward should be in the (x,z) plane
UnityARSessionNativeInterface.GetARSessionNativeInterface().SetWorldOrigin(arcamera.transform);
// since you did not tilt the horizontal plane, hopefully the plane detection still detected vertical and horizontal planes

这篇关于如何使用unity和ARKit将职位转换为应用程序的起点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆