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); }
void CreateMirrorTexture(Control control) { OculusWrap.OVR.ovrResult result; // Define the texture used to display the rendered result on the computer monitor. Texture2DDescription mirrorTextureDescription = DefineMirrorTextureDescription(control); // Convert the SharpDX texture description to the native Direct3D texture description. OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC mirrorTextureDescriptionD3D11 = SharpDXHelpers.CreateTexture2DDescription(mirrorTextureDescription); OculusWrap.D3D11.MirrorTexture mirrorTexture; // Create the texture used to display the rendered result on the computer monitor. result = hmd.CreateMirrorTextureD3D11(device.NativePointer, ref mirrorTextureDescriptionD3D11, out mirrorTexture); WriteErrorDetails(oculus, result, "Failed to create mirror texture."); mtex = new Texture2D(mirrorTexture.Texture.Texture); }
void CreateEyeTextures() { for (int eye_idx = 0; eye_idx < 2; eye_idx++) { OculusWrap.OVR.EyeType eye = (OculusWrap.OVR.EyeType)eye_idx; EyeTexture eye_tex = new EyeTexture(); eye_texes[eye_idx] = eye_tex; // Retrieve size and position of the texture for the current eye. eye_tex.FieldOfView = hmd.DefaultEyeFov[eye_idx]; eye_tex.TextureSize = hmd.GetFovTextureSize(eye, hmd.DefaultEyeFov[eye_idx], 1.0f); eye_tex.RenderDescription = hmd.GetRenderDesc(eye, hmd.DefaultEyeFov[eye_idx]); eye_tex.HmdToEyeViewOffset = eye_tex.RenderDescription.HmdToEyeViewOffset; eye_tex.ViewportSize.Position = new OculusWrap.OVR.Vector2i(0, 0); eye_tex.ViewportSize.Size = eye_tex.TextureSize; eye_tex.Viewport = new Viewport(0, 0, eye_tex.TextureSize.Width, eye_tex.TextureSize.Height, 0.0f, 1.0f); // Define a texture at the size recommended for the eye texture. eye_tex.Texture2DDescription = DefineEyeTextureDescription(eye_tex); // Convert the SharpDX texture description to the native Direct3D texture description. OculusWrap.OVR.D3D11.D3D11_TEXTURE2D_DESC swapTextureDescriptionD3D11 = SharpDXHelpers.CreateTexture2DDescription(eye_tex.Texture2DDescription); // Create a SwapTextureSet, which will contain the textures to render to, for the current eye. var result = hmd.CreateSwapTextureSetD3D11(device.NativePointer, ref swapTextureDescriptionD3D11, out eye_tex.SwapTextureSet); WriteErrorDetails(oculus, result, "Failed to create swap texture set."); // Create room for each DirectX texture in the SwapTextureSet. eye_tex.Textures = new Texture2D[eye_tex.SwapTextureSet.TextureCount]; eye_tex.RenderTargetViews = new RenderTargetView[eye_tex.SwapTextureSet.TextureCount]; // Create a texture 2D and a render target view, for each unmanaged texture contained in the SwapTextureSet. for (int tex_idx = 0; tex_idx < eye_tex.SwapTextureSet.TextureCount; tex_idx++) { // Retrieve the current textureData object. OculusWrap.OVR.D3D11.D3D11TextureData textureData = eye_tex.SwapTextureSet.Textures[tex_idx]; // Create a managed Texture2D, based on the unmanaged texture pointer. eye_tex.Textures[tex_idx] = new Texture2D(textureData.Texture); // Create a render target view for the current Texture2D. eye_tex.RenderTargetViews[tex_idx] = new RenderTargetView(device, eye_tex.Textures[tex_idx]); } // Define the depth buffer, at the size recommended for the eye texture. eye_tex.DepthBufferDescription = DefineEyeDepthBufferDescription(eye_tex); // Create the depth buffer. eye_tex.DepthBuffer = new Texture2D(device, eye_tex.DepthBufferDescription); eye_tex.DepthStencilView = new DepthStencilView(device, eye_tex.DepthBuffer); // Specify the texture to show on the HMD. layer_eye_fov.ColorTexture[eye_idx] = eye_tex.SwapTextureSet.SwapTextureSetPtr; layer_eye_fov.Viewport[eye_idx].Position = new OculusWrap.OVR.Vector2i(0, 0); layer_eye_fov.Viewport[eye_idx].Size = eye_tex.TextureSize; layer_eye_fov.Fov[eye_idx] = eye_tex.FieldOfView; layer_eye_fov.Header.Flags = OculusWrap.OVR.LayerFlags.None; } }