public void Render() { if (hmd == null) { return; } OculusWrap.OVR.Vector3f[] hmdToEyeViewOffsets = { eye_texes[0].HmdToEyeViewOffset, eye_texes[1].HmdToEyeViewOffset }; OculusWrap.OVR.FrameTiming frameTiming = hmd.GetFrameTiming(0); OculusWrap.OVR.TrackingState trackingState = hmd.GetTrackingState(frameTiming.DisplayMidpointSeconds); OculusWrap.OVR.Posef[] exe_poses = new OculusWrap.OVR.Posef[2]; // Calculate the position and orientation of each eye. oculus.CalcEyePoses(trackingState.HeadPose.ThePose, hmdToEyeViewOffsets, ref exe_poses); UVSCR_variable.Set(UVSCR()); for (int eye_idx = 0; eye_idx < 2; eye_idx++) { OculusWrap.OVR.EyeType eye = (OculusWrap.OVR.EyeType)eye_idx; EyeTexture eye_tex = eye_texes[eye_idx]; layer_eye_fov.RenderPose[eye_idx] = exe_poses[eye_idx]; // Retrieve the index of the active texture and select the next texture as being active next. int tex_idx = eye_tex.SwapTextureSet.CurrentIndex++; ctx.OutputMerger.SetRenderTargets(eye_tex.DepthStencilView, eye_tex.RenderTargetViews[tex_idx]); ctx.ClearDepthStencilView(eye_tex.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ctx.ClearRenderTargetView(eye_tex.RenderTargetViews[tex_idx], ScreenColor); ctx.Rasterizer.SetViewport(eye_tex.Viewport); UpdateTransform(exe_poses[eye_idx], eye_tex.FieldOfView); DrawFigure(); } hmd.SubmitFrame(0, layers); ctx.CopyResource(mtex, buf0); swap_chain.Present(0, PresentFlags.None); }
void UpdateTransform(OculusWrap.OVR.Posef eye_pose, OculusWrap.OVR.FovPort fov) { // Retrieve the eye rotation quaternion and use it to calculate the LookAt direction and the LookUp direction. Camera camera = new Camera() { Position = main_camera.Position + Vector3.Transform(eye_pose.Position.ToVector3(), main_camera.Rotation), Rotation = main_camera.Rotation * SharpDXHelpers.ToQuaternion(eye_pose.Orientation), }; world_matrix = Matrix.Scaling(ocu_config.Scale); Transform_View = camera.GetViewMatrix(); Transform_Projection = OculusWrap.OVR.ovrMatrix4f_Projection(fov, ocu_config.Znear, ocu_config.Zfar, OculusWrap.OVR.ProjectionModifier.RightHanded).ToMatrix(); Transform_Projection.Transpose(); Matrix world_view_matrix = world_matrix * Transform_View; world_view_projection_matrix = world_view_matrix * Transform_Projection; World_variable.SetMatrix(world_matrix); WorldView_variable.SetMatrix(world_view_matrix); WorldViewProjection_variable.SetMatrix(world_view_projection_matrix); /* for HUD */ Projection_variable.SetMatrix(Transform_Projection); }
public void Render() { if (hmd == null) return; OculusWrap.OVR.Vector3f[] hmdToEyeViewOffsets = { eye_texes[0].HmdToEyeViewOffset, eye_texes[1].HmdToEyeViewOffset }; OculusWrap.OVR.FrameTiming frameTiming = hmd.GetFrameTiming(0); OculusWrap.OVR.TrackingState trackingState = hmd.GetTrackingState(frameTiming.DisplayMidpointSeconds); OculusWrap.OVR.Posef[] exe_poses = new OculusWrap.OVR.Posef[2]; // Calculate the position and orientation of each eye. oculus.CalcEyePoses(trackingState.HeadPose.ThePose, hmdToEyeViewOffsets, ref exe_poses); UVSCR_variable.Set(UVSCR()); for (int eye_idx = 0; eye_idx < 2; eye_idx++) { OculusWrap.OVR.EyeType eye = (OculusWrap.OVR.EyeType)eye_idx; EyeTexture eye_tex = eye_texes[eye_idx]; layer_eye_fov.RenderPose[eye_idx] = exe_poses[eye_idx]; // Retrieve the index of the active texture and select the next texture as being active next. int tex_idx = eye_tex.SwapTextureSet.CurrentIndex++; ctx.OutputMerger.SetRenderTargets(eye_tex.DepthStencilView, eye_tex.RenderTargetViews[tex_idx]); ctx.ClearDepthStencilView(eye_tex.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); ctx.ClearRenderTargetView(eye_tex.RenderTargetViews[tex_idx], ScreenColor); ctx.Rasterizer.SetViewport(eye_tex.Viewport); UpdateTransform(exe_poses[eye_idx], eye_tex.FieldOfView); DrawFigure(); } hmd.SubmitFrame(0, layers); ctx.CopyResource(mtex, buf0); swap_chain.Present(0, PresentFlags.None); }