示例#1
0
        //[TWProfile]
        void gameLoopStep()
        {
            if (!running)
            {
                if (exitAndCleanup())
                {
                    return;
                }
                return;
            }

            if (!Form.Active)
            {
                Thread.Sleep(100);
            }

            updateInput();

            updateElapsed();

            SpectaterCamera.Update(Elapsed, keyboard, mouse);

            Form.Device.ImmediateContext.ClearRenderTargetView(Form.RenderTargetView, new Color4(Color.DeepSkyBlue));

            updateBasicShaders();

            doGameLoopEvent();

            renderAxisLines();

            LineManager3D.Render(Camera);
        }
示例#2
0
 public InventoryView3DTopDown(IInventoryNode rootNode, IInventoryNodeRenderer renderer)
 {
     this.root     = rootNode;
     this.renderer = renderer;
     tree          = new Tree(rootNode);
     camera        = new SpectaterCamera(1, 100);
 }
示例#3
0
        public void InitDirectX()
        {
            Form.InitDirectX();


            keyboard = new SlimDXTWKeyboard();


            diDevice   = new global::SlimDX.DirectInput.DirectInput();
            diKeyboard = new global::SlimDX.DirectInput.Keyboard(diDevice);
            diKeyboard.SetCooperativeLevel(Form.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground);
            diKeyboard.Acquire();


            mouse   = new TWMouse();
            diMouse = new global::SlimDX.DirectInput.Mouse(new DirectInput());
            diMouse.SetCooperativeLevel(Form.Form, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);

            SpectaterCamera = new SpectaterCamera();
            Camera          = SpectaterCamera;



            LineManager3D   = new LineManager3D(Form.Device);
            TextureRenderer = new TextureRenderer(Form.Device);
            HelperStates    = new HelperStatesContainer(Form.Device);
        }
示例#4
0
 public WaterTest()
 {
     game = new XNAGame();
     game.InitializeEvent += new EventHandler(game_InitializeEvent);
     game.DrawEvent       += new XNAGame.XNAGameLoopEventHandler(game_DrawEvent);
     game.UpdateEvent     += new XNAGame.XNAGameLoopEventHandler(game_UpdateEvent);
     specCam         = (SpectaterCamera)game.Camera;
     specCam.FarClip = 10000f;
     camTemp.SetLens(MathHelper.PiOver4, 4f / 3f, specCam.NearClip, specCam.FarClip);
     inCamera = true;
 }
        public void TestSetDirection()
        {
            var cam = new SpectaterCamera();

            checkDirectionSet(cam, new Vector3(1, 0, 0));
            checkDirectionSet(cam, new Vector3(0, 1, 0));
            checkDirectionSet(cam, new Vector3(0, 0, 1));

            checkDirectionSet(cam, new Vector3(-1, 0, 0));
            checkDirectionSet(cam, new Vector3(0, -1, 0));
            checkDirectionSet(cam, new Vector3(0, 0, -1));

            checkDirectionSet(cam, new Vector3(1, 0, 1));
            checkDirectionSet(cam, new Vector3(1, 1, 0));

            checkDirectionSet(cam, new Vector3(1, 1, 0));
            checkDirectionSet(cam, new Vector3(1, -1, 0));

            checkDirectionSet(cam, new Vector3(-1, 1, 0));
            checkDirectionSet(cam, new Vector3(-1, -1, 0));

            checkDirectionSet(cam, new Vector3(0, 1, 1));
            checkDirectionSet(cam, new Vector3(0, -1, 1));
        }
        public FirstPersonCameraSimulator()
        {
            info    = TW.Data.GetSingleton <CameraInfo>();
            cam     = new SpectaterCamera();
            terrain = TW.Data.GetSingleton <VoxelTerrain>();
            camData = TW.Data.GetSingleton <FirstPersonCamera>();

            cam.CameraPosition  = camData.Position;
            camData.LookDir    -= Vector3.UnitX * camData.LookDir.X * 2;
            cam.CameraDirection = camData.LookDir;
            cam.UpdateCameraInfo();

            cam.AngleHorizontal = cam.AngleHorizontal;


            points = new List <Vector3>();
            points.Add(Vector3.UnitX * 0.5f);
            points.Add(Vector3.UnitY * 0.5f);
            points.Add(Vector3.UnitZ * 0.5f);
            points.Add(-Vector3.UnitX * 0.5f);
            points.Add(-Vector3.UnitY * 0.5f);
            points.Add(-Vector3.UnitY * 1.5f);
            points.Add(-Vector3.UnitZ * 0.5f);
        }
示例#7
0
        public void TestLineManager3D()
        {
            var keyboard = new SlimDXTWKeyboard();
            var dev      = new SlimDX.DirectInput.DirectInput();
            var kb       = new SlimDX.DirectInput.Keyboard(dev);

            kb.Acquire();

            var mouse = new TWMouse();
            var m     = new SlimDX.DirectInput.Mouse(dev);

            m.Acquire();



            var game = new DX11Form();

            game.InitDirectX();
            var device = game.Device;

            var rasterizerState = RasterizerState.FromDescription(device, new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid
            });

            device.ImmediateContext.Rasterizer.State = rasterizerState;


            var cam = new SpectaterCamera();

            var lineManager = new LineManager3D(device);

            game.GameLoopEvent += delegate
            {
                mouse.UpdateMouseState(m.GetCurrentState());
                keyboard.UpdateKeyboardState(kb.GetCurrentState());
                cam.Update(0.001f, keyboard, mouse);

                for (int num = 0; num < 200; num++)
                {
                    lineManager.AddLine(
                        new Vector3(-12.0f + num / 4.0f, 13.0f, 0),
                        new Vector3(-17.0f + num / 4.0f, -13.0f, 0),
                        new Color4((byte)(255 - num) / 255f, 14 / 255f, (byte)num / 255f));
                } // for

                lineManager.DrawGroundShadows = true;
                lineManager.AddCenteredBox(new Vector3(4, 4, 4), 2, new Color4(1, 0, 0));

                lineManager.WorldMatrix =
                    Matrix.Translation(MathHelper.Up * 30);

                for (int num = 0; num < 200; num++)
                {
                    lineManager.AddLine(
                        new Vector3(-12.0f + num / 4.0f, 13.0f, 0),
                        new Vector3(-17.0f + num / 4.0f, -13.0f, 0),
                        new Color4((byte)(255 - num) / 255f, 14 / 255f, (byte)num / 255f));
                } // for



                lineManager.Render(cam);
                if (keyboard.IsKeyDown(Key.Escape))
                {
                    game.Exit();
                }
            };

            game.Run();

            rasterizerState.Dispose();
            kb.Dispose();
            m.Dispose();
            dev.Dispose();
        }
示例#8
0
        public void TestDirectX11SpecaterCamera()
        {
            var keyboard = new SlimDXTWKeyboard();
            var dev      = new SlimDX.DirectInput.DirectInput();
            var kb       = new SlimDX.DirectInput.Keyboard(dev);

            kb.Acquire();

            var mouse = new TWMouse();
            var m     = new SlimDX.DirectInput.Mouse(dev);

            m.Acquire();



            var game = new DX11Form();

            game.InitDirectX();
            var device    = game.Device;
            var bytecode  = ShaderBytecode.CompileFromFile("../../Common.Core/Shaders/MiniTri.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None);
            var effect    = new Effect(device, bytecode);
            var technique = effect.GetTechniqueByName("RenderTransform");
            var pass      = technique.GetPassByIndex(0);
            var layout    = new InputLayout(device, pass.Description.Signature,
                                            new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 32, 0)
            });

            var vertexStride = (16 + 16 + 8);
            var stream       = new DataStream(3 * vertexStride, true, true);

            stream.WriteRange(new[] {
                new VertexCustom(new Vector4(-1.0f, 0, 0, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector2(0.5f, 0)),
                new VertexCustom(new Vector4(0f, 1f, 0, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector2(0f, 1f)),
                new VertexCustom(new Vector4(1f, 0f, 0, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), new Vector2(1f, 1f))
            });
            stream.Position = 0;



            var vertices = new SlimDX.Direct3D11.Buffer(device, stream, new BufferDescription()
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                SizeInBytes    = 3 * vertexStride,
                Usage          = ResourceUsage.Default
            });

            stream.Dispose();

            //var world = Matrix.Translation(MathHelper.Forward);

            /*var viewProjection = Matrix.LookAtRH(Vector3.UnitZ * 5, -Vector3.UnitZ, MathHelper.Up)
             * Matrix.PerspectiveFovRH(MathHelper.PiOver4, 4f / 3f, 0.1f, 1000f);*/


            var diffuseShaderVariable = effect.GetVariableByName("txDiffuse").AsResource();
            var worldParam            = effect.GetVariableByName("world").AsMatrix();
            //worldParam.AsMatrix().SetMatrix(world);


            var viewProjParam = effect.GetVariableBySemantic("viewprojection").AsMatrix();

            /*viewProjParam.SetMatrix(
             *  viewProjection);*/

            //worldParam.SetMatrix(Matrix.Identity);
            //effect.GetVariableBySemantic("viewprojection").AsMatrix().SetMatrix(Matrix.Identity);

            var texturePath = Wallpaper001_png;

            var diffuseTexture = Texture2D.FromFile(device, texturePath);

            var diffuseTextureRv = new ShaderResourceView(device, diffuseTexture);


            diffuseShaderVariable.SetResource(diffuseTextureRv);


            var rasterizerState = RasterizerState.FromDescription(device, new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid
            });

            device.ImmediateContext.Rasterizer.State = rasterizerState;


            var cam = new SpectaterCamera();

            game.GameLoopEvent += delegate
            {
                mouse.UpdateMouseState(m.GetCurrentState());
                keyboard.UpdateKeyboardState(kb.GetCurrentState());
                cam.Update(0.001f, keyboard, mouse);

                device.ImmediateContext.InputAssembler.InputLayout       = layout;
                device.ImmediateContext.InputAssembler.PrimitiveTopology =
                    PrimitiveTopology.TriangleList;
                device.ImmediateContext.InputAssembler.SetVertexBuffers(0,
                                                                        new VertexBufferBinding
                                                                            (vertices,
                                                                            vertexStride, 0));

                for (int i = 0; i < technique.Description.PassCount; ++i)
                {
                    pass.Apply(device.ImmediateContext);
                    device.ImmediateContext.Draw(3, 0);
                }

                viewProjParam.SetMatrix(cam.ViewProjection);
                worldParam.SetMatrix(Matrix.Identity);
                if (keyboard.IsKeyDown(Key.Escape))
                {
                    game.Exit();
                }
            };

            game.Run();

            bytecode.Dispose();
            effect.Dispose();
            layout.Dispose();
            vertices.Dispose();
            diffuseTexture.Dispose();
            diffuseTextureRv.Dispose();
            rasterizerState.Dispose();
            kb.Dispose();
            m.Dispose();
            dev.Dispose();
        }
示例#9
0
        public void TestCullerVisibility()
        {
            var           game   = new DX11Game();
            Vector3       radius = new Vector3(100, 1000, 100);
            FrustumCuller culler = new FrustumCuller(new BoundingBox(-radius, radius), 6);



            QuadTreeVisualizer visualizer = new QuadTreeVisualizer();

            List <TestCullObject> cullObjects = new List <TestCullObject>();


            TestCullObject obj;


            for (int i = 0; i < cullObjects.Count; i++)
            {
                culler.AddCullable(cullObjects[i]);
            }



            SpectaterCamera cullCam = new SpectaterCamera(10f, 80);

            cullCam.Positie         = new Vector3(8, 10, 8);
            cullCam.EnableUserInput = false;

            bool rotate = true;

            int selectedNode = -1;

            var view = culler.CreateView();


            game.GameLoopEvent +=
                delegate
            {
                view.UpdateVisibility(cullCam.ViewProjection);
                if (rotate)
                {
                    cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPadPlus))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Key.NumberPadMinus))
                {
                    selectedNode--;
                }

                if (game.Keyboard.IsKeyPressed(Key.Return))
                {
                    int count = -1;
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color4 col)
                    {
                        col = Color.Red.dx();
                        count++;
                        if (count == selectedNode)
                        {
                            node.Tag = "SELECTED!";
                        }
                        return(count == selectedNode);
                    });
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPad0))
                {
                    rotate = !rotate;
                }



                game.LineManager3D.AddViewFrustum(new global::DirectX11.BoundingFrustum(cullCam.ViewProjection), Color.Black.dx());
                for (int i = 0; i < cullObjects.Count; i++)
                {
                    game.LineManager3D.AddBox(cullObjects[i].BoundingBox, Color.Red.dx());
                }
                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Green.dx();

                    return(!view.IsNodeVisible(node));
                });

                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Orange.dx();

                    return(view.IsNodeVisible(node));
                });

                cullCam.Update(game.Elapsed, game.Keyboard, game.Mouse);

                /*int count = -1;
                 * visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                 * delegate(Culler.CullNode node, out Color col)
                 * {
                 *  col = Color.Red;
                 *  count++;
                 *  return count == selectedNode;
                 * });*/
            };



            game.Run();
        }
示例#10
0
        public void TestCullerObjects()
        {
            var game = new DX11Game();

            game.InitDirectX();
            Vector3       radius = new Vector3(100, 1000, 100);
            FrustumCuller culler = new FrustumCuller(new BoundingBox(-radius, radius), 6);

            var mesh = RenderingTestsHelper.CreateSimpleTestMesh();

            var texturePool = new TexturePool(game);

            var gBuffer = new GBuffer(game.Device, 800, 600);

            var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool);
            var final    = new CombineFinalRenderer(game, gBuffer);



            DeferredMeshElement middle = null;

            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 50; j++)
                {
                    var el = renderer.AddMesh(mesh);
                    el.WorldMatrix = Matrix.Translation(MathHelper.Right * i * 2 + Vector3.UnitZ * j * 2);

                    if (i > 20 && i < 30 && j > 20 && j < 30)
                    {
                        el.Delete();
                    }
                    else
                    {
                        culler.AddCullable(el);
                    }
                }
            }

            QuadTreeVisualizer visualizer = new QuadTreeVisualizer();

            List <TestCullObject> cullObjects = new List <TestCullObject>();



            SpectaterCamera cullCam = new SpectaterCamera(10f, 80);

            cullCam.Positie         = new Vector3(8, 10, 8);
            cullCam.EnableUserInput = false;

            bool rotate = true;

            int selectedNode = -1;

            var view = culler.CreateView();


            game.GameLoopEvent +=
                delegate
            {
                view.UpdateVisibility(cullCam.ViewProjection);
                var visibleCullables = view.GetVisibleCullables();

                if (rotate)
                {
                    cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPadPlus))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Key.NumberPadMinus))
                {
                    selectedNode--;
                }

                if (game.Keyboard.IsKeyPressed(Key.Return))
                {
                    int count = -1;
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color4 col)
                    {
                        col = Color.Red.dx();
                        count++;
                        if (count == selectedNode)
                        {
                            node.Tag = "SELECTED!";
                        }
                        return(count == selectedNode);
                    });
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPad0))
                {
                    rotate = !rotate;
                }



                gBuffer.Clear();
                gBuffer.SetTargetsToOutputMerger();
                renderer.Draw();

                game.Device.ImmediateContext.ClearState();
                game.SetBackbuffer();

                final.DrawCombined();


                game.LineManager3D.AddViewFrustum(new BoundingFrustum(cullCam.ViewProjection), Color.White.dx());
                for (int i = 0; i < visibleCullables.Count; i++)
                {
                    game.LineManager3D.AddBox(visibleCullables[i].BoundingBox, Color.Red.dx());
                }
                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Green.dx();

                    return(!view.IsNodeVisible(node));
                });

                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color4 col)
                {
                    col = Color.Orange.dx();

                    return(view.IsNodeVisible(node));
                });

                cullCam.Update(game.Elapsed, game.Keyboard, game.Mouse);


                /*int count = -1;
                 * visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                 * delegate(Culler.CullNode node, out Color col)
                 * {
                 *  col = Color.Red;
                 *  count++;
                 *  return count == selectedNode;
                 * });*/
            };



            game.Run();
        }
 private void checkDirectionSet(SpectaterCamera cam, Vector3 dir)
 {
     dir = Vector3.Normalize(dir);
     cam.CameraDirection = dir;
     Assert.True(Vector3.Distance(cam.CameraDirection, dir) < 0.001f);
 }
        public void TestRendererFrustumCulling()
        {
            XNAGame             game     = new XNAGame();
            Vector3             radius   = new Vector3(100, 1000, 100);
            FrustumCullerSimple culler   = new FrustumCullerSimple(new BoundingBox(-radius, radius).dx(), 5);
            SimpleRenderer      renderer = new SimpleRenderer(game, culler);

            game.AddXNAObject(renderer);

            game.DrawFps         = true;
            game.IsFixedTimeStep = false;

            QuadTreeVisualizerXNA visualizer  = new QuadTreeVisualizerXNA();
            List <TestCullObject> cullObjects = new List <TestCullObject>();


            SpectaterCamera cullCam = new SpectaterCamera(game, 10f, 80);

            cullCam.Positie         = new Vector3(8, 10, 8);
            cullCam.EnableUserInput = false;


            SpectaterCamera renderCam = game.SpectaterCamera;


            renderer.CullCamera   = cullCam;
            renderer.RenderCamera = renderCam;

            bool rotate       = true;
            int  selectedNode = -1;



            Seeder seeder = new Seeder(2);

            for (int i = 0; i < 1000; i++)
            {
                Vector3 pos;
                pos.X = seeder.NextFloat(-90, 90);
                pos.Y = seeder.NextFloat(9, 11);
                pos.Z = seeder.NextFloat(-90, 90);

                float iRadius = seeder.NextFloat(0.3f, 2);

                if (seeder.NextInt(0, 2) == 0)
                {
                    SimpleBoxMesh mesh = renderer.CreateBoxMesh();
                    mesh.WorldMatrix = Matrix.CreateTranslation(pos);
                    mesh.Dimensions  = Vector3.One * iRadius;
                    renderer.UpdateRenderable(mesh);
                }
                else
                {
                    SimpleSphereMesh mesh = renderer.CreateSphereMesh();
                    mesh.WorldMatrix = Matrix.CreateTranslation(pos);
                    mesh.Radius      = iRadius;
                    renderer.UpdateRenderable(mesh);
                }
            }


            game.UpdateEvent +=
                delegate
            {
                if (rotate)
                {
                    cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }

                if (game.Keyboard.IsKeyPressed(Keys.Add))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Keys.Subtract))
                {
                    selectedNode--;
                }

                if (game.Keyboard.IsKeyPressed(Keys.Enter))
                {
                    int count = -1;
                    visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                       delegate(FrustumCuller.CullNode node, out Color col)
                    {
                        col = Color.Red;
                        count++;
                        if (count == selectedNode)
                        {
                            node.Tag = "SELECTED!";
                        }
                        return(count == selectedNode);
                    });
                }

                if (game.Keyboard.IsKeyPressed(Keys.NumPad0))
                {
                    rotate = !rotate;
                }
            };

            game.DrawEvent +=
                delegate
            {
                game.LineManager3D.AddViewFrustum(new BoundingFrustum(cullCam.ViewProjection), Color.Black);
                for (int i = 0; i < cullObjects.Count; i++)
                {
                    game.LineManager3D.AddBox(cullObjects[i].BoundingBox.xna(), Color.Red);
                }
                visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                                                   delegate(FrustumCuller.CullNode node, out Color col)
                {
                    if (culler.View.IsNodeVisible(node))
                    {
                        col = Color.Orange;
                    }
                    else
                    {
                        col = Color.Green;
                    }

                    return(true);
                });


                /*int count = -1;
                 * visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                 * delegate(Culler.CullNode node, out Color col)
                 * {
                 *  col = Color.Red;
                 *  count++;
                 *  return count == selectedNode;
                 * });*/
            };



            game.Run();
        }
        public void TestMeshRendererSimpleCulling()
        {
            var game = new DX11Game();

            game.InitDirectX();
            var context = game.Device.ImmediateContext;

            var mesh = RenderingTestsHelper.CreateSimpleTestMesh();

            var texturePool = new TexturePool(game);

            var gBuffer = new GBuffer(game.Device, 800, 600);

            var renderer = new DeferredMeshesRenderer(game, gBuffer, texturePool);


            DeferredMeshElement middle = null;



            Vector3             radius = new Vector3(100, 1000, 100);
            FrustumCullerSimple culler = new FrustumCullerSimple(new BoundingBox(-radius, radius), 5);

            //QuadTreeVisualizer visualizer = new QuadTreeVisualizer();


            SpectaterCamera cullCam = new SpectaterCamera(10f, 80);

            cullCam.Positie         = new Vector3(8, 10, 8);
            cullCam.EnableUserInput = false;

            SpectaterCamera renderCam = game.SpectaterCamera;

            culler.CullCamera = cullCam;

            throw new NotImplementedException();
            //renderer.Culler = culler;

            bool rotate       = true;
            int  selectedNode = -1;



            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 50; j++)
                {
                    var el = renderer.AddMesh(mesh);
                    el.WorldMatrix = Matrix.Translation(MathHelper.Right * i * 2 + Vector3.UnitZ * j * 2);

                    if (i > 20 && i < 30 && j > 20 && j < 30)
                    {
                        el.Delete();
                    }
                }
            }
            game.GameLoopEvent += delegate
            {
                culler.UpdateVisibility();

                if (rotate)
                {
                    cullCam.AngleHorizontal += game.Elapsed * MathHelper.Pi * (1 / 8f);
                }
                cullCam.Update(game.Elapsed, game.Keyboard, game.Mouse);
                if (game.Keyboard.IsKeyPressed(Key.NumberPadPlus))
                {
                    selectedNode++;
                }
                if (game.Keyboard.IsKeyPressed(Key.NumberPadMinus))
                {
                    selectedNode--;
                }

                if (game.Keyboard.IsKeyPressed(Key.Return))
                {
                    int count = -1;
                    //visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                    //delegate(FrustumCuller.CullNode node, out Color col)
                    //{
                    //    col = Color.Red;
                    //    count++;
                    //    if (count == selectedNode)
                    //    {
                    //        node.Tag = "SELECTED!";
                    //    }
                    //    return count == selectedNode;
                    //});
                }

                if (game.Keyboard.IsKeyPressed(Key.NumberPad0))
                {
                    rotate = !rotate;
                }


                game.LineManager3D.AddViewFrustum(new BoundingFrustum(cullCam.ViewProjection), new Color4());
                //for (int i = 0; i < cullObjects.Count; i++)
                //{
                //    game.LineManager3D.AddBox(cullObjects[i].BoundingBox, Color.Red);
                //}
                //visualizer.RenderNodeGroundBoundig(game, culler.RootNode,
                //    delegate(FrustumCuller.CullNode node, out Color col)
                //    {
                //        if (node.Visible)
                //        {
                //            col = Color.Orange;
                //        }
                //        else
                //        {
                //            col = Color.Green;

                //        }

                //        return true;
                //    });



                gBuffer.Clear();
                gBuffer.SetTargetsToOutputMerger();

                context.Rasterizer.State = game.HelperStates.RasterizerShowAll;

                renderer.Draw();

                context.ClearState();
                game.SetBackbuffer();

                GBufferTest.DrawGBuffer(game, gBuffer);
            };

            game.Run();
        }
示例#14
0
        public void TestDeferredRendererCastsShadowsField()
        {
            var game = new DX11Game();

            game.InitDirectX();

            var renderer = new DeferredRenderer(game);

            var otherCam = new SpectaterCamera(1, 10000);

            var mesh = RenderingTestsHelper.CreateMerchantsHouseMesh(new OBJToRAMMeshConverter(new RAMTextureFactory()));


            var el = renderer.CreateMeshElement(mesh);

            el.CastsShadows = false;
            var directional = renderer.CreateDirectionalLight();

            directional.ShadowsEnabled = true;
            var point = renderer.CreatePointLight();

            point.LightRadius   *= 2;
            point.ShadowsEnabled = true;
            var spot = renderer.CreateSpotLight();

            spot.LightRadius   *= 2;
            spot.ShadowsEnabled = true;

            int state = 0;

            var camState = false;

            game.GameLoopEvent += delegate
            {
                if (game.Keyboard.IsKeyPressed(Key.D1))
                {
                    state = 0;
                }
                if (game.Keyboard.IsKeyPressed(Key.D2))
                {
                    state = 1;
                }
                if (game.Keyboard.IsKeyPressed(Key.D3))
                {
                    state = 2;
                }
                if (game.Keyboard.IsKeyPressed(Key.D4))
                {
                    state = 3;
                }

                switch (state)
                {
                case 0:
                    break;

                case 1:
                    directional.LightDirection = game.SpectaterCamera.CameraDirection;
                    break;

                case 2:
                    point.LightPosition = game.SpectaterCamera.CameraPosition;

                    break;

                case 3:
                    spot.LightPosition = game.SpectaterCamera.CameraPosition;
                    spot.SpotDirection = game.SpectaterCamera.CameraDirection;
                    break;
                }

                if (game.Keyboard.IsKeyPressed(Key.C))
                {
                    camState = !camState;
                }

                if (camState)
                {
                    game.Camera = game.SpectaterCamera;
                    renderer.DEBUG_SeperateCullCamera = null;
                }
                else
                {
                    game.Camera = otherCam;
                    renderer.DEBUG_SeperateCullCamera = game.SpectaterCamera;
                }
                game.SpectaterCamera.EnableUserInput = camState;
                otherCam.EnableUserInput             = !camState;
                otherCam.Update(game.Elapsed, game.Keyboard, game.Mouse);
                renderer.Draw();
            };

            game.Run();
        }