本文主要讲解如何使用Unity来实现屏蔽Oculus的陀螺仪的功能。
屏蔽Oculus陀螺仪的目的是用于做VR动捕开发,因为动捕中会给Oculus头盔相关的移动和旋转的参数,所以不需要Oculus自身的旋转参数,如果不屏蔽Oculus自身参数,那么我们和得到双倍的旋转值。
下面我门来讲解具体的操作步骤:
方法/步骤
-
1
打开Unity,PlayerSetting设置虚拟现实技术支持,勾选Oculus。
-
2
连接Oculus头盔,并打开Oculus应用,设置允许未知来源(unknown sources)使用
-
3
导入OculusUtilities插件,然后Unity中会多两个文件夹,分别为OVR和Plugins。
-
4
在OVR中找到Scenes文件夹,打开Cubes场景
-
5
创建FakeTracking脚本,代码如下:
using UnityEngine;
using System.Collections;
public class FakeTracking : MonoBehaviour {
public OVRPose centerEyePose = OVRPose.identity;
public OVRPose leftEyePose = OVRPose.identity;
public OVRPose rightEyePose = OVRPose.identity;
public OVRPose leftHandPose = OVRPose.identity;
public OVRPose rightHandPose = OVRPose.identity;
public OVRPose trackerPose = OVRPose.identity;
void Awake()
{
OVRCameraRig rig = GameObject.FindObjectOfType<OVRCameraRig>();
if (rig != null)
rig.UpdatedAnchors += OnUpdatedAnchors;
}
void OnUpdatedAnchors(OVRCameraRig rig)
{
if (!enabled)
return;
//This doesn't work because VR camera poses are read-only.
//rig.centerEyeAnchor.FromOVRPose(OVRPose.identity);
//Instead, invert out the current pose and multiply in the desired pose.
OVRPose pose = rig.centerEyeAnchor.ToOVRPose(true).Inverse();
pose = centerEyePose * pose; rig.trackingSpace.FromOVRPose(pose, true);
//OVRPose referenceFrame = pose.Inverse();
//The rest of the nodes are updated by OVRCameraRig, not Unity, so they're easy.
//forums.oculus.com/vip/discussion/comment/446956/
rig.leftEyeAnchor.FromOVRPose(leftEyePose);
rig.rightEyeAnchor.FromOVRPose(rightEyePose);
rig.leftHandAnchor.FromOVRPose(leftHandPose);
rig.rightHandAnchor.FromOVRPose(rightHandPose);
rig.trackerAnchor.FromOVRPose(trackerPose);
}
}
-
6
将FakeTracking脚本挂载到与OVRManager脚本同一个物体下
-
7
佩戴Oculus头盔,运行项目,此时场景画面将不会随着Oculus旋转而旋转,如果会发现Oculus显示的画面会有点抖动,这个官方暂时还无法解决。
END
文章评论