[英]Recenter or Reorient view with Cardboard SDK on Unity
With Unity, the CardboardHead script is added to the main camera and that handles everything quite nicely, but I need to be able to "recenter" the view on demand and the only option I see so far is to rorate the entire scene and it seems like this is something the would address first-hand and I can't find anything in the docs. 使用Unity,CardboardHead脚本被添加到主摄像头并且可以很好地处理所有内容,但我需要能够按需“重新定位”视图,而我到目前为止看到的唯一选项是漫游整个场景,似乎像这样是第一手资料,我在文档中找不到任何东西。
With Oculus Mobile SDK (GearVR), it would be OVRCamera.ResetCameraPositionOrientation(Vector3.one, Vector3.zero, Vector3.up, Vector3.zero); 使用Oculus Mobile SDK(GearVR),它将是OVRCamera.ResetCameraPositionOrientation(Vector3.one,Vector3.zero,Vector3.up,Vector3.zero); though they handle it nicely each time the viewer is put on so it's rarely needed there. 虽然每次观看者佩戴时都能很好地处理,所以很少需要它。
There's a "target" parameter on the CardboardHead that lets you use to another gameobject as a reference for rotation. CardboardHead上有一个“目标”参数,可让您使用另一个游戏对象作为旋转参考。 Or you can use a dummy parent gameobject. 或者你可以使用虚拟父游戏对象。 Either way, when you want to recenter, you set this reference object's rotation so that the CardboardHead is now pointing forward. 无论哪种方式,当您想要重新定位时,您可以设置此参考对象的旋转,以便CardboardHead现在指向前方。 Add this function to an script on the CardboardHead (or just add it into that script): 将此函数添加到CardboardHead上的脚本(或者只是将其添加到该脚本中):
public void Recenter() {
Transform reference = target != null ? target : transform.parent;
if (reference != null) {
reference.rotation = Quaternion.Inverse(transform.rotation) * reference.rotation;
// next line is optional -- try it with and without
reference.rotation = Quaternion.FromToRotation(reference.up, Vector3.up) * reference.rotation;
}
}
Cardboard.SDK.Recenter ();
should do the trick. 应该做的伎俩。
Recenter orientation Added Recenter() function to Cardboard.SDK, which resets the head tracker so the phone's current heading becomes the forward direction (+Z axis). Recenter orientation将Cardnter.SDK添加到Receboard()功能,重置头部跟踪器,使手机的当前标题成为正向(+ Z轴)。
Couldn't find the docs for the API/SDK but it's in the release notes for the v0.4.5 Update. 无法找到API / SDK的文档,但它位于v0.4.5更新的发行说明中。
You can rotate the Cardboard Main to point in a certain direction. 您可以旋转Cardboard Main以指向某个方向。
This is what worked for me when I wanted the app to start up pointing a certain way. 当我希望应用程序以某种方式启动时,这对我有用。 Since the CardboardHead points at Vector3.zero on startup if no target is assigned, I ran a function during Start() for the CardboardMain that would point in the direction I wanted. 由于如果没有分配目标,CardboardHead在启动时指向Vector3.zero,我在Start()期间为CardboardMain运行了一个函数,该函数将指向我想要的方向。
Of course, if you're already rotating CardboardMain for some other reason, it may be possible to use this same method by creating a parent of the CardboardHead (child of CardboardMain) and doing the same thing. 当然,如果你因为其他原因已经在旋转CardboardMain,可以通过创建CardboardHead的父级(CardboardMain的子级)并执行相同的操作来使用相同的方法。
This question is a bit old but for Google VR SDK 1.50+ you can do 这个问题有点旧,但对于Google VR SDK 1.50+,你可以做到
transform.eulerAngles = new Vector3(newRot.x, newRot.y, newRot.z);
UnityEngine.VR.InputTracking.Recenter();
also, if you don't want to get confused you also need to catch the GvrEditorEmulator instance and Recenter it as well. 此外,如果您不想让您感到困惑,您还需要捕获GvrEditorEmulator实例并同时重新启动它。
#if UNITY_EDITOR
gvrEditorEmulator.Recenter();
#endif
Recentering GvrEditorEmulator though doesn't seem to work very well at the moment but if you disable it you'll see the recentering works for the main camera. 虽然接收GvrEditorEmulator目前似乎不能很好地工作,但如果你禁用它,你会看到主摄像机的重新调整工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.