public void TestSimpleRenderer() { XNAGame game = new XNAGame(); SimpleRenderer renderer = new SimpleRenderer(game, new CullerNoCull()); renderer.RenderCamera = game.SpectaterCamera; game.AddXNAObject(renderer); SimpleBoxMesh box = renderer.CreateBoxMesh(); box.WorldMatrix = Matrix.CreateTranslation(new Vector3(5, 0, 5)); SimplePlaneMesh plane = renderer.CreatePlaneMesh(); game.InitializeEvent += delegate { SimpleSphereMesh sphere = renderer.CreateSphereMesh(); sphere.WorldMatrix = Matrix.CreateTranslation(new Vector3(1, 0, -2)); }; game.Run(); }
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(); }