Beispiel #1
0
			protected override void OnRenderFrame(FrameEventArgs e)
			{
				base.OnRenderFrame(e);
				GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

				Vector3 camPos = new Vector3(0, 2, 5);
				Quaternion camOri = Quaternion.Identity;


#if RENDER_OCULUS
				for (int i = 0; i < 2; i++)
				{
					//zoom field of view
					var fov = new FovPort
					{
						DownTan = eyes[i].desc.Fov.DownTan / zoomFactor,
						UpTan = eyes[i].desc.Fov.UpTan / zoomFactor,
						LeftTan = eyes[i].desc.Fov.LeftTan / zoomFactor,
						RightTan = eyes[i].desc.Fov.RightTan / zoomFactor
					};


					eyes[i].proj = OvrDLL.ovrMatrix4f_Projection(fov, 0.1f, 1000.0f, ProjectionModifier.ClipRangeOpenGL);

					//bind eye fbo
					bindFbo(eyes[i]);

					//combine the "camera" position/rotation with the position/rotation of the eye
					Vector3 finalPos = camPos + (camOri * eyes[i].pose.Position);
					Matrix4 finalRot = Matrix4.CreateFromQuaternion(camOri * eyes[i].pose.Orientation);

					//create the view matrix with a lookat basis vectors
					Vector3 up = eyes[i].pose.Orientation * Vector3.UnitY;
					Vector3 fwd = eyes[i].pose.Orientation * -Vector3.UnitZ;
					Matrix4 view = Matrix4.LookAt(finalPos, finalPos + fwd, up);

					//draw the scene
					drawScene(view, eyes[i].proj);

					//commit the swapchain
					OvrDLL.ovr_CommitTextureSwapChain(session, eyes[i].swapChain);
				}

				//send to Oculus
				LayerEyeFov eyeFov = layers[0] as LayerEyeFov;
				eyeFov.Header.Flags = LayerFlags.TextureOriginAtBottomLeft;
				eyeFov.ColorTexture[0] = eyes[0].swapChain;
				eyeFov.ColorTexture[1] = eyes[1].swapChain;
				eyeFov.Fov[0] = eyes[0].desc.Fov;
				eyeFov.Fov[1] = eyes[1].desc.Fov;
				eyeFov.Viewport[0] = new Recti(new Vector2i(0,0), eyes[0].renderTargetSize);
				eyeFov.Viewport[1] = new Recti(new Vector2i(0, 0), eyes[1].renderTargetSize);
				eyeFov.RenderPose[0] = eyes[0].pose;
				eyeFov.RenderPose[1] = eyes[1].pose;

 				ViewScaleDesc viewScale = new ViewScaleDesc();
				result = OvrDLL.ovr_SubmitFrame(session, 0, ref viewScale, layers.GetUnmanagedLayers(), 1);
				if (result < 0)
				{
					Console.WriteLine("Error submitting frame");
					OvrDLL.ovr_GetLastErrorInfo(ref error);
					Console.WriteLine("Last Error Info: {0}-{1}", error.result, error.ErrorString);
				}

				//blit mirror to fbo
				OvrDLL.ovr_GetMirrorTextureBufferGL(session, mirror, ref myMirrorTexture);
				blitMirror((int)myMirrorTexture);
#else
				Matrix4 view = Matrix4.CreateTranslation(-camPos);
				Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(60.0f), 1.0f, 0.1f, 1000.0f);
				drawScene(view, proj);
#endif
				SwapBuffers();
			}