} // Render(sunColor) #endregion #region Unit Testing #if DEBUG /// <summary> /// Test lens flare /// </summary> public static void TestLensFlare() { Vector3 sunPos = LensFlare.DefaultSunPos; LensFlare lensFlare = null; TestGame.Start("TestLensFlare", delegate // Init { lensFlare = new LensFlare(sunPos); }, delegate // Render loop { BaseGame.GlowShader.Start(); // Render sky cube map as our background. BaseGame.skyCube.RenderSky(1.0f, BaseGame.SkyBackgroundColor); lensFlare.Render(Color.White); TextureFont.WriteText(1, 30, "Sun pos to 2d=" + BaseGame.Convert3DPointTo2D(sunPos)); TextureFont.WriteText(1, 60, "Sun pos in front=" + BaseGame.IsInFrontOfCamera(sunPos)); Vector4 resultVector4 = Vector4.Transform( new Vector4(sunPos.X, sunPos.Y, sunPos.Z, 1), BaseGame.ViewMatrix * BaseGame.ProjectionMatrix); TextureFont.WriteText(1, 90, "result=" + resultVector4); }); } // TestLensFlare()
} // Dispose(someObject) /// <summary> /// Dispose /// </summary> /// <param name="someObject">Some object</param> public static void Dispose(ref RocketCommanderXna.Graphics.LensFlare someObject) { if (someObject != null) { someObject.Dispose(); } someObject = null; } // Dispose(someObject)
} // BaseGame() /// <summary> /// Initialize /// </summary> protected override void Initialize() { #if !XBOX360 // Add screenshot capturer. Works only on windows platform. // Note: Don't do this in constructor, // we need the correct window name for screenshots! this.Components.Add(new ScreenshotCapturer(this)); #endif // Remember device device = graphics.GraphicsDevice; // Remember resolution width = graphics.GraphicsDevice.Viewport.Width; height = graphics.GraphicsDevice.Viewport.Height; // It is very important that we initialize the render to texture // stuff, e.g. the remDepthBuffer variable needs to be set. RenderToTexture.InitializeDepthBufferFormatAndMultisampling( graphics.PreferredDepthStencilFormat); // Update resolution if it changes and restore device after it was lost Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged); graphics.DeviceReset += new EventHandler(graphics_DeviceReset); graphics_DeviceReset(null, EventArgs.Empty); // Create matrices for our shaders, this makes it much easier to manage // all the required matrices and we have to do this ourselfs since there // is no fixed function support and theirfore no Device.Transform class. WorldMatrix = Matrix.Identity; aspectRatio = (float)width / (float)height; ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView( FieldOfView, aspectRatio, NearPlane, FarPlane); // ViewMatrix is updated in camera class ViewMatrix = Matrix.CreateLookAt( new Vector3(0, 0, 15), Vector3.Zero, Vector3.Up); // Init global manager classes, which will be used all over the place ^^ lineManager2D = new LineManager2D(); lineManager3D = new LineManager3D(); // Create font font = new TextureFont(); // Make sure we can use PS1 or PS2, see UsePS and UsePS20 if (device.GraphicsDeviceCapabilities.PixelShaderVersion.Major >= 2 && GameSettings.Default.PerformanceSettings < 2) GameSettings.Default.PerformanceSettings = 2; else if ( device.GraphicsDeviceCapabilities.PixelShaderVersion.Major >= 1 && GameSettings.Default.PerformanceSettings < 1) GameSettings.Default.PerformanceSettings = 1; // Init post screen glow glowShader = new PostScreenGlow(); skyCube = new PreScreenSkyCubeMapping(); lensFlare = new LensFlare(LensFlare.DefaultSunPos); ParallaxShader = new ParallaxShader(); base.Initialize(); } // Initialize()
/// <summary> /// Test lens flare /// </summary> public static void TestLensFlare() { Vector3 sunPos = LensFlare.DefaultSunPos; LensFlare lensFlare = null; TestGame.Start("TestLensFlare", delegate // Init { lensFlare = new LensFlare(sunPos); }, delegate // Render loop { BaseGame.GlowShader.Start(); // Render sky cube map as our background. BaseGame.skyCube.RenderSky(1.0f, BaseGame.SkyBackgroundColor); lensFlare.Render(Color.White); TextureFont.WriteText(1, 30, "Sun pos to 2d=" + BaseGame.Convert3DPointTo2D(sunPos)); TextureFont.WriteText(1, 60, "Sun pos in front=" + BaseGame.IsInFrontOfCamera(sunPos)); Vector4 resultVector4 = Vector4.Transform( new Vector4(sunPos.X, sunPos.Y, sunPos.Z, 1), BaseGame.ViewMatrix * BaseGame.ProjectionMatrix); TextureFont.WriteText(1, 90, "result=" + resultVector4); }); }