public override void Init()
        {
            Content.ContentPath = "Data";

            Instance = this;

            Scene = new Scene();
            Scene.View = this;
            Scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            sceneQuadtree = new Common.Quadtree<Entity>(0, 0, 100, 100, 10);
            sbau = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            StateManager = new Device9StateManager(Device9);

            Graphics.Renderer.IRenderer Renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene = Scene,
                StateManager = StateManager,
                Settings = new Graphics.Renderer.Settings()
                {
                    FogDistance = 100,
                    WaterLevel = -55
                }
            };

            SRC = new SortedTestSceneRendererConnector
            {
                Scene = Scene,
                Renderer = Renderer,
            };

            Renderer.Initialize(Scene.View);
            SRC.Initialize();

            Scene.Add(exquemelin = new Entity
            {
                MainGraphic = new Graphics.Content.MetaModel
                {
                    SkinnedMesh = new Graphics.Content.SkinnedMeshFromFile("Models/Units/MainCharacter1.x"),
                    Texture = new Graphics.Content.TextureFromFile("Models/Units/MainCharacter1.png"),
                    World = Matrix.Scaling(0.5f, 0.5f, 0.5f) * Graphics.Content.SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Translation(0, 0, -4f),
                },
                VisibilityLocalBounding = new Common.Bounding.NonfittableBounding(Vector3.Zero, false, true)

            });

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)Scene.Camera,
            };
        }
        public override void Init()
        {
            Content.ContentPath = "Data";

            Scene = new Scene();
            Scene.View = this;
            Scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            sceneQuadtree = new Common.Quadtree<Entity>(10);
            sbau = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            StateManager = new Device9StateManager(Device9);

            Renderer = new Graphics.Renderer.Renderer(Device9) { Scene = Scene, StateManager = StateManager, Settings = new Graphics.Renderer.Settings { ShadowQuality = Graphics.Renderer.Settings.ShadowQualities.NoShadows } };
            Renderer.Initialize(this);
            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene = Scene,
                Renderer = Renderer
            };
            sceneRendererConnector.Initialize();

            Scene.Add(exquemelin = new Entity
            {
                MainGraphic = new Graphics.Content.MetaModel
                {
                    SkinnedMesh = new Graphics.Content.SkinnedMeshFromFile("Models/Units/Zombie1.x"),
                    Texture = new Graphics.Content.TextureFromFile("Models/Units/Zombie1.png"),
                    World = Graphics.Content.SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Scaling(0.5f, 0.5f, 0.5f),
                    HasAlpha = false,
                },
                VisibilityLocalBounding = new Common.Bounding.NonfittableBounding(Vector3.Zero, false, true)
            });

            Graphics.Renderer.Renderer.EntityAnimation ea = Scene.View.Content.Peek<Graphics.Renderer.Renderer.EntityAnimation>(exquemelin.MetaEntityAnimation);

            ea.PlayAnimation(new AnimationPlayParameters("Idle1", true));

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)Scene.Camera,
            };
        }
        public override void Init()
        {
            Content.ContentPath = "Data";
            Instance = this;

            scene = new Scene();
            scene.DesignMode = true;
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            ((LookatCamera)scene.Camera).Lookat = new Vector3(SceneSize.Width / 2f, SceneSize.Height / 2f, 0);
            ((LookatCamera)scene.Camera).Position = ((LookatCamera)scene.Camera).Lookat + new Vector3(10, 10, 10);
            scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
            scene.EntityRemoved += new Action<Entity>(scene_EntityRemoved);
            sceneQuadtree = new Common.Quadtree<Entity>(0, 0, SceneSize.Width, SceneSize.Height, 10);
            sbau = new SceneBVHAutoSyncer(scene, sceneQuadtree);

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Device9StateManager(Device9) };
            renderer.Initialize(this);
            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene = scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = new Graphics.InteractiveSceneManager { Scene = scene },
            };

            timer = new System.Windows.Forms.Timer();
            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 1;
            timer.Enabled = true;

            RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("Starting to add initial objects");
            for (int i = 0; i < nInitialEntities; i++)
                CreateRandomTestEntity();
            RedGate.Profiler.UserEvents.ProfilerEvent.SignalEvent("Starting CRUSHING!");
        }
        public override void Init()
        {
            Content.ContentPath = "Data";

            Instance = this;

            Scene = new Scene();
            Scene.View = this;
            Scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            sceneQuadtree = new Common.Quadtree<Entity>(-1, -1, 100, 100, 10);
            sbau = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            StateManager = new Device9StateManager(Device9);

            rand = new Random();

            nBillboards = 2000;
            billboards = new Entity[nBillboards];
            directions = new Vector3[nBillboards];

            for (int i = 0; i < nBillboards; i++)
                directions[i] = new Vector3((float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)Scene.Camera
            };

            Renderer = new Graphics.Renderer.Renderer(Device9) { Scene = Scene, StateManager = StateManager, Settings = new Graphics.Renderer.Settings { FogDistance = 500 } };
            Renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = Renderer,
                Scene = Scene
            };
            sceneRendererConnector.Initialize();

            for (int i = 0; i < nBillboards; i++)
            {
                Scene.Add(billboards[i] = new Entity
                {
                    MainGraphic = new MetaModel
                    {
                        AlphaRef = 0,
                        BaseTexture = null,
                        CastShadows = Priority.Never,
                        HasAlpha = true,
                        IsBillboard = true,
                        IsWater = false,
                        MaterialTexture = null,
                        Mesh = null,
                        ReceivesAmbientLight = Priority.Never,
                        ReceivesDiffuseLight = Priority.Never,
                        ReceivesShadows = Priority.Never,
                        SkinnedMesh = null,
                        SplatMapped = false,
                        SplatTexutre = null,
                        Texture = new TextureFromFile("checker.png"),
                        Visible = Priority.High,
                        World = Matrix.Identity,
                        XMesh = new MeshConcretize
                        {
                            MeshDescription = new Meshes.IndexedPlane
                            {
                                Facings = Facings.Backside | Facings.Frontside,
                                Position = Vector3.Zero,
                                Size = new Vector2(5, 5),
                                UVMin = Vector2.Zero,
                                UVMax = new Vector2(1, 1)
                            },
                            Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                        }
                    },
                    VisibilityLocalBounding = Vector3.Zero,
                    WorldMatrix = Matrix.Identity
                });
            }
        }
        public override void Init()
        {
            Content.ContentPath = "Data";

            Instance = this;

            Scene = new Scene();
            Scene.View = this;
            Scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 10000,
                AspectRatio = AspectRatio
            };
            sceneQuadtree = new Common.Quadtree<Entity>(-1, -1, 100, 100, 10);
            sbau = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            StateManager = new Device9StateManager(Device9);

            arrow = new MetaModel
            {
                HasAlpha = true,
                IsAxialBillboard = true,
                AxialDirection = new Vector3(0.5f, 0.5f, 0),
                XMesh = new Graphics.Content.MeshFromFile("Arrow.x"),
                Texture = new TextureFromFile("green.png"),
                Visible = Priority.High,
                World = Matrix.Identity,
            };

            direction = new Vector3(1, 0, 0);

            axialBillboard = new MetaModel
            {
                HasAlpha = true,
                IsAxialBillboard = true,
                AxialDirection = direction,
                XMesh = new MeshConcretize
                {
                    MeshDescription = new Graphics.Software.Meshes.IndexedPlane
                    {
                        Facings = Facings.Frontside | Facings.Backside,
                        Position = new Vector3(-0.5f, -0.5f, 0),
                        Size = new Vector2(1, 1),
                        UVMin = Vector2.Zero,
                        UVMax = new Vector2(1, 1)
                    },
                    Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                },
                Texture = new TextureFromFile("Models/Effects/MuzzleFlash1.png"),
                World = Matrix.RotationX((float) Math.PI /2.0f) * Matrix.RotationY((float)Math.PI / 2.0f) * Matrix.Translation(direction * 0.5f)
            };

            rand = new Random();

            //axialBillboard.World.Invert();

            nBillboards = 1;
            billboards = new Entity[nBillboards];
            directions = new Vector3[nBillboards];

            for (int i = 0; i < nBillboards; i++)
                directions[i] = new Vector3((float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1, (float)rand.NextDouble() * 2 - 1);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)Scene.Camera
            };

            Renderer = new Graphics.Renderer.Renderer(Device9) { Scene = Scene, StateManager = StateManager, Settings = new Graphics.Renderer.Settings { FogDistance = 50000, WaterLevel = 0 } };
            Renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = Renderer,
                Scene = Scene
            };
            sceneRendererConnector.Initialize();

            for (int i = 0; i < nBillboards; i++)
            {
                Scene.Add(billboards[i] = new Entity
                {
                    MainGraphic = axialBillboard,
                    VisibilityLocalBounding = Vector3.Zero,
                    WorldMatrix = Matrix.Identity
                });
            }
        }
        public override void Init()
        {
            Content.ContentPath = "Data";
            Instance = this;

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            sceneQuadtree = new Common.Quadtree<Entity>(0, 0, 100, 100, 10);
            sbau = new SceneBVHAutoSyncer(scene, sceneQuadtree);
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            heightmap = new Graphics.Software.Texel.R32F[250, 250];
            texture = new Graphics.Software.Texture<Graphics.Software.Texel.R32F>(heightmap);

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Device9StateManager(Device9) };
            renderer.Settings.ShadowQuality = Settings.ShadowQualities.NoShadows;
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene = scene
            };
            sceneRendererConnector.Initialize();

            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                Heightmap = heightmap,
                NPieces = new Size(20, 20),
                Height = 1
            });
            ground.ConstructPieces();

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera
            };
        }
        public void InitMap(Client.Game.Map.Map map)
        {
            Scene.Root.ClearChildren();
            if (sceneQuadtreeAutoSyncer != null)
                sceneQuadtreeAutoSyncer.Disconnect();

            Renderer.Settings.WaterLevel = map.Settings.WaterHeight;

            sceneQuadtree = new Common.Quadtree<Entity>(10);
            sceneQuadtreeAutoSyncer = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            PlacementBoundings = new Common.Quadtree<Entity>(10);
            placementBoundingsSyncer = new SceneBVHAutoSyncer(Scene, PlacementBoundings);
            placementBoundingsSyncer.GetLocalBounding =
                (e) => e is Client.Game.Map.GameEntity ? ((Client.Game.Map.GameEntity)e).EditorPlacementLocalBounding : null;
            placementBoundingsSyncer.GetWorldBounding =
                (e) => e is Client.Game.Map.GameEntity ? ((Client.Game.Map.GameEntity)e).EditorPlacementWorldBounding : null;
            placementBoundingsSyncer.RegisterLocalBoundingChangedEvent = (e, eh) => { };
            placementBoundingsSyncer.UnregisterLocalBoundingChangedEvent = (e, eh) => { };

            Scene.Root.AddChild(map.Ground);
            Scene.Root.AddChild(map.StaticsRoot);
            Scene.Root.AddChild(map.DynamicsRoot);
            Scene.Root.AddChild(new Client.Game.Water(map));
            ((Graphics.LookatSphericalCamera)Scene.Camera).Lookat = map.MainCharacter.Translation;
            //cameraInputHandler.UpdateCamera();

            GroundProbe = new WorldViewProbe(this, Scene.Camera)
            {
                WorldProbe = new Client.Game.GroundProbe(map)
            };

            foreach (var v in Scene.AllEntities)
            {
                var ge = v as Client.Game.Map.GameEntity;
                if (ge != null)
                {
                    var ray = new Ray(ge.Translation + Vector3.UnitZ * 1000, -Vector3.UnitZ);
                    float d;
                    if (GroundProbe.Intersect(ray, this, out d))
                    {
                        var p = ray.Position + ray.Direction * d;
                        ge.EditorHeight = (ge.Translation - p).Z;
                    }
                }
            }

            StartDefaultMode();
        }
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat = new Vector3(size.Width / 2f, size.Height / 2f, 0),
                Position = new Vector3(10, 10, 10),
                FOV = 0.5f,
                ZFar = 100,
                AspectRatio = AspectRatio
            };

            sceneQuadtree = new Common.Quadtree<Entity>(10);
            sbau = new SceneBVHAutoSyncer(scene, sceneQuadtree);

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager { Scene = scene },
            };

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false, FogDistance = float.MaxValue, ShadowQuality = Graphics.Renderer.Settings.ShadowQualities.Lowest } };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene = scene
            };
            sceneRendererConnector.Initialize();

            motionSimulation = new Common.Motion.Simulation();
            //motionSimulation = new Common.Motion.ThreadSimulationProxy(new Common.Motion.Simulation());
            //System.Windows.Forms.Application.ApplicationExit += ((sender, o) => { ((Common.Motion.ThreadSimulationProxy)motionSimulation).Shutdown(); });

            scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
            scene.EntityRemoved += new Action<Entity>(scene_EntityRemoved);

            heightMap = CreateGround();

            //((Common.Motion.Simulation)((Common.Motion.ThreadSimulationProxy)motionSimulation).InnerSimulation).SetHeightMap(heightMap, new Vector2(size.Width, size.Height), Vector2.Zero);
            //scene.Add(CreateBlock(-Vector3.UnitZ, new Vector3(size.Width, size.Height, 1), "grass1.png"));

            Random r = new Random();
            for (int i = 0; i < 0; i++)
                InsertUnit(r);
            //var unit = CreateUnit(new Vector3(size.Width/2f, size.Height/2f, -5f));
            //scene.Add(unit);
            //units.Add(unit);
            foreach (var u in units)
                ((Common.IMotion.IUnit)u.MotionObject).VelocityImpulse(new Vector3(0, 0, 0.00001f));
        }
        public override void Init()
        {
            Content.ContentPath = "Data";

            Instance = this;

            Scene = new Scene();
            Scene.View = this;
            Scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 10000,
                AspectRatio = AspectRatio
            };
            sceneQuadtree = new Common.Quadtree<Entity>(0, 0, 100, 100, 10);
            sbau = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            StateManager = new Device9StateManager(Device9);

            int nVertices = 10;
            int nFaces = nVertices*2 - 4;
            int nIndices = nFaces * 3;

            List<int> indices = new List<int>();
            List<Graphics.Software.Vertex.Position3Normal3Texcoord3> vertices = new List<Graphics.Software.Vertex.Position3Normal3Texcoord3>();

            for (int i = 0; i < (nVertices / 2) - 1; i++)
            {
                indices.Add(i * 2);
                indices.Add(i * 2 + 2);
                indices.Add(i * 2 + 1);

                indices.Add(i * 2 + 1);
                indices.Add(i * 2 + 2);
                indices.Add(i * 2 + 3);

                indices.Add(i * 2 + 0);
                indices.Add(i * 2 + 1);
                indices.Add(i * 2 + 3);

                indices.Add(i * 2 + 0);
                indices.Add(i * 2 + 3);
                indices.Add(i * 2 + 2);
            }

            for (int i = 0; i < nVertices / 2; i++)
            {
                float texturecoord = 1 - ((float)i / (float)nVertices);

                if (texturecoord > 0.99f)
                    texturecoord = 0.99f;

                vertices.Add(new Graphics.Software.Vertex.Position3Normal3Texcoord3(Vector3.UnitX * i, Vector3.Zero, new Vector3(texturecoord, 1, 0)));
                vertices.Add(new Graphics.Software.Vertex.Position3Normal3Texcoord3(Vector3.UnitX * i + Vector3.UnitY*4.0f, Vector3.Zero, new Vector3(texturecoord, 0, 0)));
            }

            arrow = new MetaModel
            {
                HasAlpha = true,
                Opacity = 0.4f,
                XMesh = new MeshConcretize
                {
                    Mesh = new Graphics.Software.Mesh
                    {
                        IndexBuffer = new Graphics.Software.IndexBuffer(indices.ToArray()),
                        VertexBuffer = new VertexBuffer<Graphics.Software.Vertex.Position3Normal3Texcoord3>(vertices.ToArray()),
                        NVertices = nVertices,
                        NFaces = nFaces,
                        VertexStreamLayout = global::Graphics.Software.Vertex.Position3Normal3Texcoord3.Instance,
                    },
                    Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                },
                Texture = new TextureFromFile("green.png"),
            };

            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)Scene.Camera
            };

            Renderer = new Graphics.Renderer.Renderer(Device9) { Scene = Scene, StateManager = StateManager, Settings = new Graphics.Renderer.Settings { FogDistance = 50000, WaterLevel = 0 } };
            Renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = Renderer,
                Scene = Scene
            };
            sceneRendererConnector.Initialize();

            Scene.Add(new Entity
            {
                MainGraphic = arrow,
                VisibilityLocalBounding = Vector3.Zero,
            });
        }