C# Unity3D Vuforia摄影机在真实世界中的位置单位
我正在使用Vuforia和Unity3D开发应用程序。为此,我需要在使用手机跟踪图像的同时,从图像目标获取真实世界单位中的相机位置(x、y、z)。我想知道是否有可能在Vuforia获得这样的职位信息。如果是,任何示例代码都将不胜感激 试试这样的东西C# Unity3D Vuforia摄影机在真实世界中的位置单位,c#,unity3d,vuforia,C#,Unity3d,Vuforia,我正在使用Vuforia和Unity3D开发应用程序。为此,我需要在使用手机跟踪图像的同时,从图像目标获取真实世界单位中的相机位置(x、y、z)。我想知道是否有可能在Vuforia获得这样的职位信息。如果是,任何示例代码都将不胜感激 试试这样的东西 public class ExampleClass : MonoBehaviour { public Transform target; Camera camera; void Start() { camera = GetComponent
public class ExampleClass : MonoBehaviour {
public Transform target;
Camera camera;
void Start() {
camera = GetComponent<Camera>();
}
void Update() {
Vector3 screenPos = camera.WorldToScreenPoint(target.position);
Debug.Log("target is " + screenPos.x + " pixels from the left");
}
}
请注意,返回的位置受刻度的影响。如果要处理方向向量,请使用Transform.TransformDirection。您可以使用Transform.InverseTransformPoint执行相反的转换,从世界空间到局部空间。谢谢您的快速帮助reply@MNM. 是的,这段代码非常有助于从目标图像获取信息,因为这将为我提供屏幕空间中的目标位置。我想知道是否有可能在真实世界单位中获得目标位置。请参阅我发布的编辑,该编辑将解决此问题。您是否拥有相对于世界中图像目标的位置?是的。。。移动电话摄像头在目标图像中的位置MNM的回答是否有效?
public class ExampleClass : MonoBehaviour {
public GameObject someObject;
public Vector3 thePosition;
void Start() {
// Instantiate an object to the right of the current object
thePosition = transform.TransformPoint(Vector3.right * 2);
Instantiate(someObject, thePosition, someObject.transform.rotation);
}
}