public void LoadScene(Scene scene) { _scene = scene; scene.OnObjectAdded += new EventHandler<Engine.Events.GameObjectAddedEvent>(scene_OnObjectAdded); RefreshScene(); }
public void SetScene(Scene scene) { scene.Game = this; _scene = scene; }
public void Play() { if (IsPlaying && IsPaused) { IsPaused = false; return; } if (IsPlaying) return; var scene = new Scene(new PhysicsFarseer(), ShaderProgram.ProgramType.POINTLIGHT); iGL.Engine.Game.InDesignMode = false; var xml = Game.SaveScene(); Game.SetScene(scene); Game.PopulateScene(xml); Game.Load(); IsPlaying = true; //if (PreStabilizePhysics) //{ // /* stabilize physics */ // int iterations = 0; // var physics2 = scene.Physics as Physics2d; // scene.Physics.Step(0.001f); // while (!physics2.CheckAllSleeping() && ++iterations < 10000) // { // scene.Physics.Step(0.001f); // } // if (physics2.CheckAllSleeping()) // { // MessageBox.Show("Stable"); // } //} }
public void LoadScene(string xml) { ClearSelection(); var physics = new DesignFarseerPhysics(); //physics.OnCollision += new EventHandler<EventArgs>(physics_OnCollision); WorkingScene = new Scene(physics, ShaderProgram.ProgramType.POINTLIGHT); WorkingScene.OnMouseMove += new EventHandler<Engine.Events.MouseMoveEvent>(_scene_OnMouseMove); Game.SetScene(WorkingScene); /* origin gizmo */ var gizmo = new Gizmo() { ArrowLength = 30.0f, ShowUniformSphere = false }; WorkingScene.AddGameObject(gizmo); _selectionGizmo = new Gizmo(); _selectionGizmo.Visible = false; _selectionGizmo.Enabled = false; _selectionGizmo.XDirectionArrow.OnMouseDown += (a, b) => EditAxis = EditAxisType.XAXIS; _selectionGizmo.XDirectionArrow.OnMouseUp += (a, b) => EditAxis = null; _selectionGizmo.XDirectionArrow.OnMouseIn += (a, b) => Cursor = Cursors.Hand; _selectionGizmo.XDirectionArrow.OnMouseOut += (a, b) => Cursor = Cursors.Arrow; _selectionGizmo.YDirectionArrow.OnMouseDown += (a, b) => EditAxis = EditAxisType.YAXIS; _selectionGizmo.YDirectionArrow.OnMouseUp += (a, b) => EditAxis = null; _selectionGizmo.YDirectionArrow.OnMouseIn += (a, b) => Cursor = Cursors.Hand; _selectionGizmo.YDirectionArrow.OnMouseOut += (a, b) => Cursor = Cursors.Arrow; _selectionGizmo.ZDirectionArrow.OnMouseDown += (a, b) => EditAxis = EditAxisType.ZAXIS; _selectionGizmo.ZDirectionArrow.OnMouseUp += (a, b) => EditAxis = null; _selectionGizmo.ZDirectionArrow.OnMouseIn += (a, b) => Cursor = Cursors.Hand; _selectionGizmo.ZDirectionArrow.OnMouseOut += (a, b) => Cursor = Cursors.Arrow; _selectionGizmo.UniformSphere.OnMouseDown += (a, b) => EditAxis = EditAxisType.ALL; _selectionGizmo.UniformSphere.OnMouseUp += (a, b) => EditAxis = null; _selectionGizmo.UniformSphere.OnMouseIn += (a, b) => Cursor = Cursors.Hand; _selectionGizmo.UniformSphere.OnMouseOut += (a, b) => Cursor = Cursors.Arrow; WorkingScene.AddGameObject(_selectionGizmo); WorkingScene.OnObjectAdded += _workingScene_OnObjectAdded; if (!string.IsNullOrEmpty(xml)) { Game.PopulateScene(xml); } else { /* new scene, create a camera */ var camera = new PerspectiveCamera() { Name = "PerspectiveCamera" }; WorkingScene.AddGameObject(camera); WorkingScene.SetDesignCamera(camera); WorkingScene.SetPlayCamera(camera); Game.LoadScene(); } Game.Load(); if (_sceneLoadedEvent != null) _sceneLoadedEvent(this, new SceneLoadedEvent() { Scene = Game.Scene }); }
private void InternalPopulateScene(string xml, List<Resource> jumpStartResources, Dictionary<string, int[]> bufferCache, Scene scene) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; if (jumpStartResources == null) jumpStartResources = new List<Resource>(); if (bufferCache == null) bufferCache = new Dictionary<string, int[]>(); scene.MeshBufferCache = bufferCache; using (var reader = new StringReader(xml)) { XDocument doc = XDocument.Load(reader); if (doc.Root.Name == "Scene") { var objects = doc.Root.Elements().FirstOrDefault(e => e.Name == "Objects"); if (objects != null) { foreach (var element in objects.Elements()) { /* deserialize game objects */ var gameObject = XmlHelper.FromXml(element, typeof(GameObject)) as GameObject; scene.AddGameObject(gameObject); } } var resources = doc.Root.Elements().FirstOrDefault(e => e.Name == "Resources"); if (resources != null) { foreach (var resource in resources.Elements()) { var resourceFromXml = XmlHelper.FromXml(resource, typeof(Resource)) as Resource; var loadedResource = jumpStartResources.FirstOrDefault(r => r.ResourceName == resourceFromXml.ResourceName); if (loadedResource != null) { scene.AddResource(loadedResource); jumpStartResources.Remove(loadedResource); } else { scene.AddResource(resourceFromXml); } } } var triggers = doc.Root.Elements().FirstOrDefault(e => e.Name == "Triggers"); if (triggers != null) { foreach (var trigger in triggers.Elements()) { scene.AddTrigger(XmlHelper.FromXml(trigger, typeof(Trigger)) as Trigger); } } var currentCam = doc.Root.Elements().FirstOrDefault(e => e.Name == "PlayCameraId"); if (currentCam != null && !string.IsNullOrEmpty(currentCam.Value)) { scene.SetPlayCamera(scene.GameObjects.Single(g => g.Id == currentCam.Value)); } else { scene.SetPlayCamera(null); } currentCam = doc.Root.Elements().FirstOrDefault(e => e.Name == "DesignCameraId"); if (currentCam != null && !string.IsNullOrEmpty(currentCam.Value)) { scene.SetDesignCamera(scene.GameObjects.Single(g => g.Id == currentCam.Value)); } else { scene.SetDesignCamera(null); } var currentLight = doc.Root.Elements().FirstOrDefault(e => e.Name == "LightId"); if (currentLight != null && !string.IsNullOrEmpty(currentLight.Value)) { scene.SetCurrentLight(scene.GameObjects.Single(g => g.Id == currentLight.Value)); } else { scene.SetCurrentLight(null); } var playerObject = doc.Root.Elements().FirstOrDefault(e => e.Name == "PlayerObjectId"); if (playerObject != null && !string.IsNullOrEmpty(playerObject.Value)) { scene.SetPlayerObject(scene.GameObjects.Single(g => g.Id == playerObject.Value)); } else { scene.SetPlayerObject(null); } var ambient = doc.Root.Elements().FirstOrDefault(e => e.Name == "AmbientColor"); scene.AmbientColor = (Vector4)XmlHelper.FromXml(ambient, typeof(Vector4)); } } jumpStartResources.ForEach(r => { r.Dispose(); int[] buffers; if (bufferCache.TryGetValue(r.ResourceName, out buffers)) { GL.DeleteBuffers(2, buffers); } }); scene.Load(); }
public void SetUIScene(Scene scene) { scene.Game = this; UIScene = scene; }