Unity Cardboard Orientation Landscape Right Up
嗨,我有一个Unity应用程序,它使用谷歌Cardboard SDK启用立体视图,所以我将有一个支持VR的应用程序。 我的应用程序运行完美。
但是如果我将播放器设置方向设置为自动方向,只有横向左侧和横向右侧允许,则会出现问题。 当它处于横向左侧时,一切都按照正常情况工作,但当它处于横向右侧时,纸板视图将转动180度(设置按钮移动到屏幕底部),但我的统一对象没有。 因此,我有一个颠倒的对象。
有什么办法来解决这个问题
谢谢。
看起来SDK用于读取陀螺仪的本机代码仅针对Landscape Left方向进行了硬编码。 这可以通过编辑BaseCardboardDevice.cs并使用以下代码替换UpdateState()的定义来解决:
private Quaternion fixOrientation; public override void UpdateState() { GetHeadPose(headData, Time.smoothDeltaTime); ExtractMatrix(ref headView, headData); headPose.SetRightHanded(headView.inverse); // Fix head pose based on device orientation (since native code assumes Landscape Left). switch (Input.deviceOrientation) { case DeviceOrientation.LandscapeLeft: fixOrientation = Quaternion.identity; return; case DeviceOrientation.LandscapeRight: fixOrientation = Quaternion.Euler(0, 0, 180); break; } headPose.Set(headPose.Position, headPose.Orientation * fixOrientation); }
我建议在Cardboard设置中关闭Neck Model Scale(将其设置为0),因为它不会出现在此代码中。
我已经解决了这个问题,这是解决方案(适用于Cardboard v0.5.2)
首先,根据smd的建议,您需要在BaseCardboardDevice / UpdateState()中应用方向调整。 但是,您应该检查ScreenOrientation而不是DeviceOrientation。 代码如下:
public override void UpdateState() { ProcessEvents(); GetHeadPose(headData); ExtractMatrix(ref headView, headData); headPose.SetRightHanded(headView.inverse); if (Screen.orientation == ScreenOrientation.LandscapeRight) { headPose.Set(headPose.Position, headPose.Orientation * Quaternion.Euler(0, 0, 180)); // Workaround }
这将修复方向,但这还不够,因为在Cardboard Recenter()之后你将面临错误的方向。 要解决此问题,您还需要在CardboardHead / UpdateHead()方法中应用旋转,代码如下:
private void UpdateHead() { if (updated) { // Only one update per frame, please. return; } updated = true; Cardboard.SDK.UpdateState(); if (trackRotation) { var rot = Cardboard.SDK.HeadPose.Orientation; if (Screen.orientation == ScreenOrientation.LandscapeRight) { rot = Quaternion.Euler(0, 180, 0) * rot; // << Workaround } if (target == null) { transform.localRotation = rot; } else { transform.rotation = target.rotation * rot; } } if (trackPosition) { Vector3 pos = Cardboard.SDK.HeadPose.Position; if (target == null) { transform.localPosition = pos; } else { transform.position = target.position + target.rotation * pos; } } if (OnHeadUpdated != null) { OnHeadUpdated(gameObject); } }
你可以添加:
headPose.Set(headPose.Position, headPose.Orientation * Quaternion.Euler(0,0,180));
在BaseCardboardDevice类的UpdateState()和。 无论我如何转动我试过的设备,它都为我解决了这个问题。 Unity 5纸板SDK v0.5.1
var fixOrientation = Quaternion.identity; // Fix head pose based on device orientation (since native code assumes Landscape Left). switch (Input.deviceOrientation) { case DeviceOrientation.LandscapeLeft: fixOrientation = Quaternion.identity; break; case DeviceOrientation.LandscapeRight: fixOrientation = Quaternion.Euler(0, 0, 180); break; default: Debug.Log ("Error No Orientation" + Input.deviceOrientation.ToString ()); break; } headPose.Set(headPose.Position, headPose.Orientation * fixOrientation);
现在,Cardboard SDK成为了GoogleVR,所以我在GvrDevice.cs上这样写了
让您的应用程序同时出现在LandscapeLeft和LandscapeRight中的一种方法是,在Start方法中按以下顺序启用屏幕设置:
void Start () { Screen.orientation = ScreenOrientation.Landscape; Screen.orientation = ScreenOrientation.AutoRotation; Screen.autorotateToPortrait = false; Screen.autorotateToPortraitUpsideDown = false; }
基本上你强制一侧,然后启用自动旋转,然后防止旋转成为肖像。
请注意,这样您的应用程序可以在两个横向上工作,因此您只需要向左或向右旋转屏幕。
–
另请注意,这也适用于一个带有Cardboard的VR应用程序 。
- 将ObservableCollection绑定到MVVM中的DataGrid
- 如何控制带有外观“按钮”的单选按钮的大小
- 未声明’AssemblyInfoFileMask’。 由于其保护级别,它可能无法访问
- 使用自定义DataAnnotationsModelValidatorProvider进行服务器端validation
- C#和ASP.NET中的换行符变化是什么? (\ r \ n vs. \ n)
- 使用复杂的GUI编写跨平台应用程序
- 将“SQL”导出移植到T-SQL
- 与JSON WebMethods的SoapExtension相同的是什么?
- 如何在2.0内置的应用程序中使用WCF wsHttpBinding服务?