我在Tango https://io2015codelabs.appspot.com/codelabs/project-tango#1
的Google IO codelab上遇到了很多麻烦在我完成它之后,它会运行,但它只会转动,它不会像游戏商店中的其他探戈应用程序一样前进和后撤。
我昨天开始这样做,但即使经过两天的调试,我也无法让它正常工作。今天我非常沮丧,我删除了一切,从头开始,它仍然被打破。我可以获得权限,所以我认为探戈正在运行,但没有移动。我已启用运动跟踪并禁用/删除了本教程中指定的脚本和代码。我的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;
}
}
这只是代码库中的内容的复制和粘贴,所以此时没有我自己的代码,但仍然无法正确运行。我做错了什么????
我在探戈之前做了一些android开发但是我对团结还是比较新的。但是,我对所有内容进行了两次和三次检查,而且我的设备也说一切都是最新的。
提前致谢!
答案 0 :(得分:1)
看起来codelab已经更新,并且FixedUpdate中的最后一行被注释掉了“//GameManager.Instance.PlayerPosition = transform.position;”。
https://io2015codelabs.appspot.com/codelabs/project-tango#7
希望有所帮助。