【发布时间】:2017-08-21 13:17:46
【问题描述】:
我刚刚开始学习有关 Google Tango 的知识,但在理解如何实施局部区域描述学习方面遇到了一些麻烦。我遵循了文档中的操作指南之一,即在 AR 中放置虚拟对象,我希望应用程序记住放置这些小猫的位置。我将附上 Unity 中的场景和我尝试为 AreaDEscription 启用 SaveCurrent 方法的脚本。 The scene from Unity 和以下代码主要是来自 How-To-Guide 的代码,我在其中尝试创建另一个线程来保存当前的 AreaDescription
public class KittyUIController : MonoBehaviour
{
Thread thread;
public GameObject m_kitten;
private TangoPointCloud m_pointCloud;
void Start()
{
m_pointCloud = FindObjectOfType<TangoPointCloud>();
thread = new Thread(Thread123);
}
void Update()
{
if (Input.touchCount == 1)
{
// Trigger place kitten function when single touch ended.
Touch t = Input.GetTouch(0);
if (t.phase == TouchPhase.Ended)
{
PlaceKitten(t.position);
thread.Start();
}
}
}
void PlaceKitten(Vector2 touchPosition)
{
// Find the plane.
Camera cam = Camera.main;
Vector3 planeCenter;
Plane plane;
if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
{
Debug.Log("cannot find plane.");
return;
}
// Place kitten on the surface, and make it always face the camera.
if (Vector3.Angle(plane.normal, Vector3.up) < 30.0f)
{
Vector3 up = plane.normal;
Vector3 right = Vector3.Cross(plane.normal, cam.transform.forward).normalized;
Vector3 forward = Vector3.Cross(right, plane.normal).normalized;
Instantiate(m_kitten, planeCenter, Quaternion.LookRotation(forward, up));
}
else
{
Debug.Log("surface is too steep for kitten to stand on.");
}
}
void Thread123()
{
AreaDescription.SaveCurrent();
}
public void OnApplicationQuit()
{
thread.Abort();
}
}
【问题讨论】:
标签: augmented-reality google-project-tango