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

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

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

            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) };
            renderer.Initialize(this);

            motionSimulation = new Common.Motion.Simulation();

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

            scene.Add(CreateBlock(-Vector3.UnitZ, new Vector3(size.Width, size.Height, 1), "grass1.png"));
            InitiateUnits();
        }
 public SceneBVHAutoSyncer(Scene scene, Common.IBoundingVolumeHierarchy<Entity> bvh)
     : this()
 {
     this.scene = scene;
     this.BVH = bvh;
     scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
     scene.EntityRemoved += new Action<Entity>(scene_EntityRemoved);
 }
        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
            };
            //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);

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

            heightmapEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera = scene.Camera,
                Viewport = Viewport,
                SoftwareTexture = new[] {texture},
                Position = ground.Translation,
                Size = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                }
            };
            heightmapEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
                ground.UpdatePatches(e.ChangedRegion);
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera) scene.Camera,
                InputHandler = heightmapEditor
            };

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

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene = scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();
        }
        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()
            {
                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";

            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";

            SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);

            RootScene = new Graphics.Interface.InterfaceScene(this);

            RootScene.Add(windowsCursor);
            RootScene.Add(rawInputCursor);
            RootScene.Add(new Graphics.Interface.TextBox
            {
                Position = new Vector2(10, 10),
                Text = "Windows",
                Size = new Vector2(100, 20),
                Background = null,
                TextAnchor = Orientation.Right
            });
            RootScene.Add(windowsKeyboard);
            RootScene.Add(new Graphics.Interface.TextBox
            {
                Position = new Vector2(10, 30),
                Text = "Raw",
                Size = new Vector2(100, 20),
                Background = null,
                TextAnchor = Orientation.Right
            });
            RootScene.Add(rawInputKeyboard);
            RootScene.Add(rawInputKeyboardTextbox);
            RootScene.Add(windowsKeyboardTextbox);

            InterfaceRenderer = new Graphics.Interface.InterfaceRenderer9(Device9)
            {
                Scene = (Graphics.Interface.InterfaceScene)RootScene,
                StateManager = new Device9StateManager(Device9)
            };
            InterfaceRenderer.Initialize(this);

            rawInputDevice = new Graphics.RawInput();
            rawInputDevice.RegisterKeyboard(Application.MainWindow.Handle, false);
            rawInputDevice.RegisterMouse(Application.MainWindow.Handle);
            rawInputDevice.KeyDown += new System.Windows.Forms.KeyEventHandler(rawInputDevice_KeyDown);
            rawInputDevice.KeyUp += new System.Windows.Forms.KeyEventHandler(rawInputDevice_KeyUp);
            rawInputDevice.MouseMove += new System.Windows.Forms.MouseEventHandler(rawInputDevice_MouseMove);
            rawInputDevice.MousePosition = LocalMousePosition;
            stopwatch.Start();
        }
        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";

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(-5, 5, 5),
                ZFar = 200,
                AspectRatio = AspectRatio
            };
            BinaryFormatter b = new BinaryFormatter();
            string filename = "../../navmesh";
            Common.Pathing.NavMesh navmesh;
            if (File.Exists(filename))
            {
                FileStream f = new FileStream(filename, FileMode.Open);
                try
                {
                    navmesh = (Common.Pathing.NavMesh)b.Deserialize(f);
                }
                catch (Exception e)
                {
                    navmesh = new Common.Pathing.NavMesh();
                    System.Windows.Forms.MessageBox.Show(e.ToString());
                }
            }
            else
                navmesh = new Common.Pathing.NavMesh();

            editor = new Graphics.Editors.BoundingRegionEditor(this,
                new Graphics.WorldViewProbe(this, scene.Camera));
            editor.Region = navmesh.BoundingRegion;
            editorRenderer = new Graphics.Editors.BoundingRegionEditor.Renderer9(editor)
            {
                StateManager = new Device9StateManager(Device9),
                Camera = scene.Camera
            };
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = editor
            };
        }
        public void Render(Graphics.BoundingVolumesRenderer bvRenderer, 
            View view,
            Scene scene,
            Common.Pathing.NavMesh navMesh,
            int activeFrame)
        {
            if (Settings.VisualBoundings)
            {
                foreach (var v in scene.AllEntities)
                    if(v.ActiveInMain == activeFrame)
                        bvRenderer.Draw(Matrix.Identity,
                            v.VisibilityWorldBounding,
                            Color.Orange);
            }

            if (Settings.PhysicsBoundings)
            {
                bvRenderer.DrawFullChains = Settings.PhysicsBoundingsFullChains;
                foreach (var v in scene.AllEntities)
                    if (v is Client.Game.Map.GameEntity &&
                        v.ActiveInMain == activeFrame &&
                        (!Settings.PhysicsBoundingsHideGround || !(v is Client.Game.Map.GroundPiece)))
                        bvRenderer.Draw(Matrix.Identity,
                            ((Client.Game.Map.GameEntity)v).PhysicsLocalBounding != null ?
                            Common.Boundings.Transform(((Client.Game.Map.GameEntity)v).PhysicsLocalBounding, v.WorldMatrix)
                            : null,
                            Color.Blue);
                bvRenderer.DrawFullChains = true;
            }

            if (Settings.PathMesh)
                bvRenderer.Draw(Matrix.Identity, navMesh.BoundingRegion, Color.White);

            if (Settings.AggroRange)
            {
                foreach (var v in scene.AllEntities)
                    if (v.ActiveInMain == activeFrame && v is Map.NPC)
                        view.DrawCircle(scene.Camera, Matrix.Identity,
                            ((Map.NPC)v).Position, ((Map.NPC)v).InRangeRadius, 12, Color.Red);
            }
        }
示例#11
0
        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
            };

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

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            renderer.Initialize(this);

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

            motionSimulation = new Common.Motion.Simulation();

            scene.EntityAdded += new Action<Entity>(scene_EntityAdded);
            CreateGround();
            scene.EntityAdded -= new Action<Entity>(scene_EntityAdded);
        }
示例#12
0
 void AddToScene(Scene scene)
 {
     if (this.scene != null) throw new Exception("This node (" + GetType().Name + ":" + Name + ") already belongs to a scene");
     this.scene = scene;
     foreach (Entity e in children)
         e.AddToScene(scene);
     OnAddedToScene();
     if(scene.View != null)
         Invalidate();
     scene.OnEntityAdded(this);
 }
示例#13
0
        private Mesh ProcessMesh(Assimp.Mesh mesh, Scene scene)
        {
            var vertices = new List <MeshVertex>();
            var indices  = new List <uint>();
            var textures = new List <MeshTexture>();
            var color    = new MeshMaterial();

            for (int i = 0; i < mesh.VertexCount; i++)
            {
                var vertex = new MeshVertex();

                // process vertex positions, normals and texture coordinates
                var pos = mesh.Vertices[i];
                vertex.Position = new Vector3(pos.X, pos.Y, pos.Z);

                var norm = mesh.Normals[i];
                vertex.Normal = new Vector3(norm.X, norm.Y, norm.Z);

                if (mesh.HasTextureCoords(0))  // does the mesh contain texture coordinates?
                {
                    var tex = mesh.TextureCoordinateChannels[0][i];
                    vertex.TexCoords = new Vector2(tex.X, tex.Y);
                }

                vertices.Add(vertex);
            }

            // process indices
            for (int i = 0; i < mesh.FaceCount; i++)
            {
                Face face = mesh.Faces[i];
                for (int j = 0; j < face.IndexCount; j++)
                {
                    indices.Add((uint)face.Indices[j]);
                }
            }

            // process material
            if (mesh.MaterialIndex >= 0)
            {
                Material material = scene.Materials[mesh.MaterialIndex];

                // get all the needed material textures
                if (material.HasTextureDiffuse)
                {
                    List <MeshTexture> diffuseMaps = LoadMaterialTextures(material, TextureType.Diffuse, "texture_diffuse");
                    textures.AddRange(diffuseMaps);
                }
                if (material.HasTextureSpecular)
                {
                    List <MeshTexture> specularMaps = LoadMaterialTextures(material, TextureType.Specular, "texture_specular");
                    textures.AddRange(specularMaps);
                }

                // get all the needed material colors (default values if they're not presented)
                color.Ambient = new Vector4(
                    material.ColorAmbient.R,
                    material.ColorAmbient.G,
                    material.ColorAmbient.B,
                    material.ColorAmbient.A);
                color.Diffuse = new Vector4(
                    material.ColorDiffuse.R,
                    material.ColorDiffuse.G,
                    material.ColorDiffuse.B,
                    material.ColorDiffuse.A);
                color.Specular = new Vector4(
                    material.ColorSpecular.R,
                    material.ColorSpecular.G,
                    material.ColorSpecular.B,
                    material.ColorSpecular.A);
                color.Shininess = material.Shininess;
            }

            return(new Mesh(mesh.Name, vertices.ToArray(), indices.ToArray(), textures.ToArray(), color));
        }
示例#14
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera
            {
                Position = new Vector3(-5, 5, 5),
            };

            foreach (var v in scene.AllEntities)
                v.VisibilityLocalBounding = Content.Acquire<Graphics.Content.StructBoxer<BoundingBox>>(v.MainGraphic).Value;

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

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

            editor = new Graphics.Editors.SceneEditor { Scene = scene };
            editorRenderer = new Graphics.Editors.SceneEditor.Renderer9(editor)
            {
                BoundingVolumesRenderer = new BoundingVolumesRenderer
                {
                    StateManager = stateManager,
                    View = this
                }
            };

            InputHandler = editor;

            Entity e;
            scene.Add(e = new Entity
            {
                MainGraphic = new MetaModel
                {
                    XMesh = new MeshFromFile("Models/Props/Barrel1.x"),
                    Texture = new TextureFromFile("Models/Props/Barrel1.png"),
                    World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * SkinnedMesh.InitSkinnedMeshFromMaya * Matrix.Translation(1, 0, 0)
                },
            });
            e.VisibilityLocalBounding = CreateBoundingBoxFromModel((MetaModel)e.MainGraphic);
            e.PickingLocalBounding = CreateBoundingMeshFromModel(e, (MetaModel)e.MainGraphic);

            scene.Add(e = new Entity
            {
                MainGraphic = new MetaModel
                {
                    SkinnedMesh = new SkinnedMeshFromFile("Models/Props/Bridge1.x"),
                    Texture = new TextureFromFile("Models/Props/Bridge1.png"),
                    World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * SkinnedMesh.InitSkinnedMeshFromMaya *
                        Matrix.Translation(3, 0, 0)
                },
            });
            e.VisibilityLocalBounding = CreateBoundingBoxFromModel((MetaModel)e.MainGraphic);
            e.PickingLocalBounding = CreateBoundingMeshFromModel(e, (MetaModel)e.MainGraphic);
        }
示例#15
0
        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
            };
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            texture = new Graphics.Software.Texture<Graphics.Software.Texel.A8R8G8B8>(new Graphics.Software.Texel.A8R8G8B8[250, 250]);

            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                //Texture = new SingleColorTexture(Color.Orange),
                NPieces = new Size(20, 20),

            });
            ground.ConstructPieces();

            dxTexture = texture.ToTexture9(Device9);

            ground.Texture = new UnmanagedResource<SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D> { Resource9 = dxTexture };

            groundTextureEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera = scene.Camera,
                Viewport = Viewport,
                SoftwareTexture = new[] {texture},
                Texture9 = new[] {dxTexture},
                Position = ground.Translation,
                Size = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                },
                Pencil = new Graphics.Editors.GroundTexturePencil
                {
                    Color = new Vector4(0, 0, 1, 0),
                    Radius = 5,
                    Type = Graphics.Editors.GroundTexturePencilType.AddSaturate
                }
            };
            groundTextureEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = groundTextureEditor,
            };

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

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene = scene
            };
            sceneRendererConnector.Initialize();
        }
        void Setup()
        {
            Scene = new Scene();
            GameState = GameState.Playing;
            InterfaceIngameScene = new Scene();
            Scene.View = InterfaceIngameScene.View = Program.Instance;
            Scene.Camera = InterfaceIngameScene.Camera = new LookatSphericalCamera()
            {
                Lookat = new Vector3(0, 0, 0),
                Position = new Vector3(10, 10, 10),
                FOV = Program.Settings.CameraFOV,
                ZFar = 20,
                ZNear = Program.Settings.CameraZNear,
                AspectRatio = Program.Instance.AspectRatio
            };
            CameraController = new CameraController { Camera = (LookatSphericalCamera)Scene.Camera };
            Scene.EntityAdded += scene_EntityAdded;

            Program.Instance.Interface.Layer1.AddChild(
                SceneControl = new GameSceneControl
                {
                    InnerScene = Scene,
                    Size = Program.Instance.Interface.Size
                });

            InterfaceIngameRenderer = new Graphics.Interface.InterfaceRenderer9(Program.Instance.Device9)
            {
                Scene = InterfaceIngameScene,
                StateManager = Program.Instance.StateManager,
            };
            InterfaceIngameRenderer.Initialize(Scene.View);

            if (Program.Settings.OutputPNGSequence)
                Directory.CreateDirectory(OutputPNGSequencePath);

            if (Program.Settings.UseDummyRenderer)
            {
                throw new NotSupportedException("Dummy renderer is no longer supported.");
            }
            else
            {
                Renderer = new Graphics.Renderer.Renderer(Program.Instance.Device9)
                {
                    Scene = Scene,
                    StateManager = Program.Instance.StateManager,
                    Settings = Program.Settings.RendererSettings,
                };
                SceneRendererConnector = new SortedTestSceneRendererConnector
                {
                    Scene = Scene,
                    Renderer = Renderer
                };
            }

            Graphics.Renderer.Results result = Renderer.Initialize(Scene.View);
            SceneRendererConnector.Initialize();
            if (result == Graphics.Renderer.Results.OutOfVideoMemory)
            {
                System.Windows.Forms.MessageBox.Show(Locale.Resource.ErrorOutOfVideoMemory);
                Application.Log("User ran out of video memory according to renderer. This is probably due to having too high shadow quality.");
                System.Windows.Forms.Application.Exit();
            }

            RendererSettingsController = new RendererSettingsController();

            var s = Program.Settings.GraphicsDeviceSettings.Resolution;
            Program.Instance.Interface.Layer1.AddChild(Interface = new Interface.Interface
            {
                Size = new Vector2(s.Width, s.Height),
                Visible = false
            });
        }
示例#17
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            Instance = this;
            nParticles = 0;

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

            stateManager = new DummyDevice9StateManager(Device9);

            renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene = scene,
                StateManager = stateManager,
                Settings = new Graphics.Renderer.Settings
                {
                    CullMode = Cull.Counterclockwise,
                    FogDistance = 1500,
                }
            };
            renderer.Initialize(this);

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

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

            ground = new MetaModel
            {
                AlphaRef = 0,
                HasAlpha = false,
                Texture = new TextureFromFile("Models/GroundTextures/Grass1.png"),
                XMesh = new MeshConcretize
                {
                    MeshDescription = new Graphics.Software.Meshes.IndexedPlane
                    {
                        Position = new Vector3(-5f, -5f, -1),
                        Size = new Vector2(10, 10),
                        UVMin = Vector2.Zero,
                        UVMax = new Vector2(1, 1),
                        Facings = Facings.Frontside
                    },
                    Layout = Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                },
            };

            scene.Add(new Entity
            {
                MainGraphic = ground,
                VisibilityLocalBounding = new Common.Bounding.NonfittableBounding(Vector3.Zero, false, true),
                Translation = Vector3.UnitZ
            });
        }
示例#18
0
        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,
            });
        }
 public void EditorCreateNewName(Scene scene)
 {
     EditorCreateNewName(scene, GetType().Name);
 }
示例#20
0
 private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
 {
     StartCoroutine(InitializeLight(scene));
     CullingMaskExtensions.RefreshLayers();
 }
示例#21
0
        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
            };
        }
示例#22
0
        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
            };
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            texture = new Graphics.Software.Texture<Graphics.Software.Texel.A8R8G8B8>(
                new Graphics.Software.Texel.A8R8G8B8[250, 250]);

            var r = new Random();
            for(int y=0; y < texture.Size.Height; y++)
                for(int x=0; x < texture.Size.Width; x++)
                    texture[y, x] =
                        new Graphics.Software.Texel.A8R8G8B8
                            {
                                //R = 1f,//(float)r.NextDouble(),
                                //G = (float)r.NextDouble(),
                                //B = (float)r.NextDouble(),
                                A = 1f,
                            };

            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                //Texture = new SingleColorTexture(Color.Orange),
                NPieces = new Size(20, 20),
            });
            ground.ConstructPieces();

            dxTexture = texture.ToTexture9(Device9);
            UpdateTexture();

            groundTextureEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera = scene.Camera,
                Viewport = Viewport,
                SoftwareTexture = new ITexture[] { texture },
                Texture9 = new[] {dxTexture},
                Position = ground.Translation,
                Size = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                },
                Pencil = new Graphics.Editors.GroundTexturePencil
                {
                    Color = new Vector4(1, 0, 0, 0),
                    Radius = 30,
                    Type = Graphics.Editors.GroundTexturePencilType.Add
                }
            };
            groundTextureEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
                UpdateTexture();
                foreach (var v in ground.Children)
                    v.Invalidate();
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = groundTextureEditor
            };

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

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene =  scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();
        }
示例#23
0
        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
                });
            }
        }
示例#24
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(-5, 5, 5),
                AspectRatio = AspectRatio
            };

            foreach (var v in scene.AllEntities)
                v.VisibilityLocalBounding = Vector3.Zero;

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

            bvr = new BoundingVolumesRenderer
            {
                View = this,
                StateManager = sm
            };

            BVEntity t;
            scene.Add(t = new BVEntity
            {
                MainGraphic = new MetaModel
                {
                    XMesh = new MeshFromFile("Models/Props/Barrel1.x"),
                    Texture = new TextureFromFile("Models/Props/Barrel1.png"),
                    World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * SkinnedMesh.InitSkinnedMeshFromMaya,
                },
                WorldMatrix = Matrix.Translation(1, 0, 0)
            });
            t.BoundingVolume = Graphics.Boundings.Transform(new Graphics.MetaBoundingBox { Mesh = ((MetaModel)t.MainGraphic).XMesh },
                ((MetaModel)t.MainGraphic).World);
            scene.Add(t = new BVEntity
            {
                MainGraphic = new MetaModel
                {
                    SkinnedMesh = new SkinnedMeshFromFile("Models/Props/Bridge1.x"),
                    Texture = new TextureFromFile("Models/Props/Bridge1.png"),
                    World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * SkinnedMesh.InitSkinnedMeshFromMaya
                },
                WorldMatrix = Matrix.Translation(3, 0, 0)
            });
            scene.Add(t = new BVEntity
            {
                MainGraphic = new MetaModel
                {
                    SkinnedMesh = new SkinnedMeshFromFile("Models/Props/Bridge1.x"),
                    Texture = new TextureFromFile("Models/Props/Bridge1.png"),
                    World = Matrix.Scaling(0.1f, 0.1f, 0.1f) * SkinnedMesh.InitSkinnedMeshFromMaya
                },
                WorldMatrix = Matrix.Translation(-3, -3, 0)
            });
            t.BoundingVolume = Vector3.Zero;
        }
示例#25
0
        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
            };

            viewport = new Graphics.GraphicsDevice.Viewport(Device9.Viewport);

            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 } };
            //renderer = new Graphics.DummyRenderer.Renderer { Scene = scene, StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9), Settings = new Graphics.Renderer.Settings { WaterEnable = false } };
            renderer.Initialize(this);

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

            motionSimulation = new Common.Motion.Simulation();

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

            var sim = (Common.Motion.Simulation)motionSimulation;

            npcs = new List<Common.IMotion.INPC>();
            Vector2 startingPosition = new Vector2(size.Width / 2f, size.Height / 2f);
            CreateGround(true);
            scene.Add(controlledUnit = CreateUnit(startingPosition));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(2, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(-4, 2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(4, -2)), new Vector3(1, 1, 1.5f)));
            scene.Add(CreateBlock(Common.Math.ToVector3(startingPosition + new Vector2(7, -1)), new Vector3(1, 1, 1.5f)));
            //scene.Add(CreateNPC(startingPosition + new Vector2(3, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(3, -1)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-5, 3)));
            scene.Add(CreateNPC(startingPosition + new Vector2(-2, 1)));
            Vector2 unitGroupStartingPosition = startingPosition + new Vector2(3, 3);
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    scene.Add(CreateNPC(unitGroupStartingPosition + new Vector2(x, y)));
                }
            }

            BulletCreation = (() =>
            {
                scene.Add(CreateBullet(controlledUnit.Translation + Vector3.UnitZ,
                    bulletSpeed,
                    controlledUnit.MotionObject.Rotation.Angle,
                    bulletAcceleration));
            });

            foreach (var npc in npcs)
                npc.Pursue(controlledUnit.MotionObject, 1f);
        }
示例#26
0
        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 void Release()
        {
            scene.EntityAdded -= new Action<Entity>(scene_EntityAdded);
            scene.EntityRemoved -= new Action<Entity>(scene_EntityRemoved);
            scene.View.GraphicsDevice.LostDevice -= new Action(GraphicsDevice_LostDevice);
            scene.View.GraphicsDevice.ResetDevice -= new Action(GraphicsDevice_ResetDevice);

            scene = null;
            renderer = null;

            if (resources != null)
            {
                resources.Clear();
                resources = null;
            }
            if (cachedEntities != null)
            {
                cachedEntities.Clear();
                cachedEntities = null;
            }
            if (cachedShadowEntities != null)
            {
                cachedShadowEntities.Clear();
                cachedShadowEntities = null;
            }
            if (EntityAnimations != null)
            {
                EntityAnimations.Clear();
                EntityAnimations = null;
            }
            if (metaModelIdToEntity != null)
            {
                metaModelIdToEntity.Clear();
                metaModelIdToEntity = null;
            }
        }
 public void EditorCreateNewName(Scene scene, String baseName)
 {
     int i = 1;
     foreach (var v in scene.Root.Offspring)
         if (v.GetType() == GetType() && v.Name != null && v.Name.Length > baseName.Length)
         {
             int l;
             if (int.TryParse(v.Name.Substring(baseName.Length), out l))
                 i = Math.Max(i, l) + 1;
         }
     Name = baseName + i;
 }
示例#29
0
        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
            };

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

            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            Random r = new Random();
            heightmap = new Graphics.Software.Texel.R32F[64, 64];
            for (int y = 0; y < 64; y++)
                for (int x = 0; x < 64; x++)
                    heightmap[y, x] = new Graphics.Software.Texel.R32F((float)r.NextDouble());

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

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

            SizeF patches = new SizeF(20, 20);
            SizeF patchSize = new SizeF(1f / 20f, 1f / 20f);
            SizeF groundSize = new SizeF(100, 100);

            for(int y=0; y < patches.Height; y++)
                for (int x = 0; x < patches.Width; x++)
                    scene.Add(e = new Entity
                    {
                        MainGraphic = new MetaModel
                        {
                            XMesh = new MeshConcretize
                            {
                                MeshDescription = new Graphics.Software.Meshes.MeshFromHeightmap
                                {
                                    Grid = new Graphics.Software.Meshes.Grid
                                    {
                                        Position = Vector3.Zero,
                                        MeshType = MeshType.Indexed,
                                        Size = new Vector2(patchSize.Width * groundSize.Width, patchSize.Height * groundSize.Height),
                                        NWidth = (int)((heightmap.GetLength(1) - 1) * patchSize.Width),
                                        NHeight = (int)((heightmap.GetLength(0) - 1) * patchSize.Height),
                                        UVMin = new Vector2(0, 0),
                                        UVMax = new Vector2(1, 1)
                                    },
                                    Height = 5,
                                    Heightmap = heightmap,
                                    Rectangle = new RectangleF(x * patchSize.Width, y * patchSize.Height, patchSize.Width, patchSize.Height),
                                    PointSample = true
                                },
                                Layout = global::Graphics.Software.Vertex.PositionNormalTexcoord.Instance
                            },
                            Texture = new TextureFromFile("Models/GroundTextures/Grass1.png")
                        },
                        Translation = new Vector3(x * groundSize.Width/patches.Width, y*groundSize.Height/patches.Height, 0),
                        VisibilityLocalBounding = Vector3.Zero
                    });
        }