【问题标题】:Google IO Tango Unity example not workingGoogle IO Tango Unity 示例不起作用
【发布时间】:2015-05-30 04:15:52
【问题描述】:

我在 Tango https://io2015codelabs.appspot.com/codelabs/project-tango#1 的 Google IO 代码实验室遇到了很多问题

我完成后,它会运行,但它只是转动,它不像 Play 商店中的其他探戈应用程序那样前进和后退。

我昨天开始做这个,但即使经过两天的调试,我也无法让它正常工作。今天我很沮丧,我删除了所有内容并从头开始,它仍然坏了。我可以获得权限,所以我认为探戈已经启动并运行,但没有移动。我已启用运动跟踪并禁用/删除了教程中指定的脚本和代码。我的 PoseController 看起来像这样:

using UnityEngine;
using System.Collections;
using Tango;
using System;

public class PoseController : MonoBehaviour , ITangoPose {
private TangoApplication m_tangoApplication; // Instance for Tango Client
private Vector3 m_tangoPosition; // Position from Pose Callback
private Quaternion m_tangoRotation; // Rotation from Pose Callback
private Vector3 m_startPosition; // Start Position of the camera
private Vector3 m_lastPosition; // last position returned in Unity coordinates.

// Controls movement scale, use 1.0f to be metric accurate
// For the codelab, we adjust the scale so movement results in larger movements in the
// virtual world.
private float m_movementScale = 10.0f;

// Use this for initialization
void Start ()
{
    // Initialize some variables
    m_tangoRotation = Quaternion.identity;
    m_tangoPosition = Vector3.zero;
    m_lastPosition = Vector3.zero;
    m_startPosition = transform.position;
    m_tangoApplication = FindObjectOfType<TangoApplication>();
    if(m_tangoApplication != null)
    {
        RequestPermissions();
    }
    else
    {
        Debug.Log("No Tango Manager found in scene.");
    }
}

// Permissions callback
private void PermissionsCallback(bool success)
{
    if(success)
    {
        m_tangoApplication.InitApplication(); // Initialize Tango Client
        m_tangoApplication.InitProviders(string.Empty); // Initialize listeners
        m_tangoApplication.ConnectToService(); // Connect to Tango Service
    }
    else
    {
        AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true);
    }

}

private void RequestPermissions()
{
    // Request Tango permissions
    m_tangoApplication.RegisterPermissionsCallback(PermissionsCallback);
    m_tangoApplication.RequestNecessaryPermissionsAndConnect();
    m_tangoApplication.Register(this);
}

// Pose callbacks from Project Tango
public void OnTangoPoseAvailable(Tango.TangoPoseData pose)
{


    // Do nothing if we don't get a pose
    if (pose == null) {
        Debug.Log("TangoPoseData is null.");
        return;
    }
    // The callback pose is for device with respect to start of service pose.
    if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE &&
        pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE)
    {
        if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID)
        {
            // Cache the position and rotation to be set in the update function.
            m_tangoPosition = new Vector3((float)pose.translation [0],
                                          (float)pose.translation [1],
                                          (float)pose.translation [2]);

            m_tangoRotation = new Quaternion((float)pose.orientation [0],
                                             (float)pose.orientation [1],
                                             (float)pose.orientation [2],
                                             (float)pose.orientation [3]);
        }
        else // if the current pose is not valid we set the pose to identity
        {
            m_tangoPosition = Vector3.zero;
            m_tangoRotation = Quaternion.identity;
        }
    }
}

/// <summary>
/// Transforms the Tango pose which is in Start of Service to Device frame to Unity coordinate system.
/// </summary>
/// <returns>The Tango Pose in unity coordinate system.</returns>
/// <param name="translation">Translation.</param>
/// <param name="rotation">Rotation.</param>
/// <param name="scale">Scale.</param>
Matrix4x4 TransformTangoPoseToUnityCoordinateSystem(Vector3 translation,
                                                    Quaternion rotation, Vector3 scale)
{

    // Matrix for Tango coordinate frame to Unity coordinate frame conversion.
    // Start of service frame with respect to Unity world frame.
    Matrix4x4 m_uwTss;
    // Unity camera frame with respect to device frame.
    Matrix4x4 m_dTuc;

    m_uwTss = new Matrix4x4();
    m_uwTss.SetColumn (0, new Vector4 (1.0f, 0.0f, 0.0f, 0.0f));
    m_uwTss.SetColumn (1, new Vector4 (0.0f, 0.0f, 1.0f, 0.0f));
    m_uwTss.SetColumn (2, new Vector4 (0.0f, 1.0f, 0.0f, 0.0f));
    m_uwTss.SetColumn (3, new Vector4 (0.0f, 0.0f, 0.0f, 1.0f));

    m_dTuc = new Matrix4x4();
    m_dTuc.SetColumn (0, new Vector4 (1.0f, 0.0f, 0.0f, 0.0f));
    m_dTuc.SetColumn (1, new Vector4 (0.0f, 1.0f, 0.0f, 0.0f));
    m_dTuc.SetColumn (2, new Vector4 (0.0f, 0.0f, -1.0f, 0.0f));
    m_dTuc.SetColumn (3, new Vector4 (0.0f, 0.0f, 0.0f, 1.0f));

    Matrix4x4 ssTd = Matrix4x4.TRS(translation, rotation, scale);
    return m_uwTss * ssTd * m_dTuc;
}


// FixedUpdate is called at a fixed rate
void FixedUpdate()
{
    // Convert position and rotation from Tango's coordinate system to Unity's.
    Matrix4x4 uwTuc = TransformTangoPoseToUnityCoordinateSystem(m_tangoPosition,
                                                                m_tangoRotation, Vector3.one);
    Vector3 newPosition = (uwTuc.GetColumn(3))* m_movementScale;
    Quaternion newRotation = Quaternion.LookRotation(uwTuc.GetColumn(2),
                                                     uwTuc.GetColumn(1));

    // Calculate the difference in the poses received.  This allows us
    // to recover when we hit something in the virtual world.
    Vector3 delta = newPosition - m_lastPosition;
    m_lastPosition = newPosition;
    Vector3 destination = rigidbody.position + delta;
    Vector3 vectorToTargetPosition = destination - transform.position;
    // If there is motion, move the player around the scene.
    if(vectorToTargetPosition.magnitude > 0.1f)
    {
        vectorToTargetPosition.Normalize();
        // Set the movement vector based on the axis input.
        Vector3 movement = vectorToTargetPosition;
        // Normalise the movement vector and make it proportional to the speed per second.
        movement = movement.normalized * 5f * Time.deltaTime;

        // Move the player to it's current position plus the movement.
        rigidbody.MovePosition (transform.position + movement);
    }
    else {
        rigidbody.velocity = Vector3.zero;
    }
    // always rotate, even if we don't move.
    rigidbody.MoveRotation (newRotation);
    // finally, let the game manager know the position of the player.
    GameManager.Instance.PlayerPosition = transform.position;
}

}

这只是对 codelab 中内容的复制和粘贴,所以此时没有我自己的代码,我仍然无法正确运行它。我做错了什么???

我在 tango 之前做过一些 android 开发,但我对 unity 还很陌生。但是,我已经两次和三次检查了所有内容,并且我的设备显示所有内容都是最新的。

提前致谢!

【问题讨论】:

  • 我没有看到足够的答案 - 但我可以给出提示 - 从 Tango 返回的姿势信息包含位置和姿态 - 如果您的旋转与您操作 Tango 的方式一致,那么问题就来了介于收集姿势和设置相机位置之间 - 我建议逐步完成它(有耐心,使用 Unity 调试 Tango 需要通过网络传输所有调试数据)

标签: google-project-tango


【解决方案1】:

codelab 好像已经更新了,FixedUpdate 的最后一行被注释掉了“//GameManager.Instance.PlayerPosition = transform.position;”。

https://io2015codelabs.appspot.com/codelabs/project-tango#7

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2017-12-22
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多