基于htc vive设备的UE4 VR项目开发需要修改源码的地方

来源:互联网 发布:淳安县教育局网络办公 编辑:程序博客网 时间:2024/05/19 04:07

1、显示器全屏去两旁黑边。

在源码的解决方案里搜索SteamVRRender


找到SteamVRRender.cpp,定位到if (WindowMirrorMode == 1),做如下修改

if (WindowMirrorMode == 1){// need to clear when rendering only one eye since the borders won't be touched by the DrawRect belowRHICmdList.ClearColorTexture(BackBuffer, FLinearColor::Black, FIntRect());/*RendererModule->DrawRectangle(RHICmdList,ViewportWidth / 4, 0,ViewportWidth / 2, ViewportHeight,0.1f, 0.2f,0.3f, 0.6f,FIntPoint(ViewportWidth, ViewportHeight),FIntPoint(1, 1),*VertexShader,EDRF_Default);*/RendererModule->DrawRectangle(RHICmdList,0, 0,ViewportWidth, ViewportHeight,0.05f, 0.3f,0.4f, 0.4f,FIntPoint(ViewportWidth, ViewportHeight),FIntPoint(1, 1),*VertexShader,EDRF_Default);}


原理如下图:


参考连接:传送门

2、ResetOrientationAndPosition重置头显朝向和位置时(头显设备移动时,playerpawn位置是不动的,所以切换关卡时等操作时有重置的需求)头显位置Z坐标不对,不能重置Z坐标,找到SteamVRHDM.cpp,定位到ResetPosition方法,做如下修改:

void FSteamVRHMD::ResetPosition(){const FTrackingFrame& TrackingFrame = GetTrackingFrame();FMatrix Pose = ToFMatrix(TrackingFrame.RawPoses[vr::k_unTrackedDeviceIndex_Hmd]);/*BaseOffset = FVector(-Pose.M[3][2], Pose.M[3][0], Pose.M[3][1]);*/BaseOffset = FVector(-Pose.M[3][2], Pose.M[3][0], 0);}