void CreateScene() { scene = new Scene(); scene.CreateComponent <Octree>(); // Create camera node CameraNode = scene.CreateChild("Camera"); // Set camera's position CameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f)); Camera camera = CameraNode.CreateComponent <Camera>(); camera.Orthographic = true; var graphics = Graphics; camera.OrthoSize = (float)graphics.Height * PixelSize; camera.Zoom = (1.0f * Math.Min((float)graphics.Width / 1280.0f, (float)graphics.Height / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution) var cache = ResourceCache; // Get tmx file TmxFile2D tmxFile = cache.GetTmxFile2D("Urho2D/isometric_grass_and_water.tmx"); if (tmxFile == null) { return; } Node tileMapNode = scene.CreateChild("TileMap"); tileMapNode.Position = new Vector3(0.0f, 0.0f, -1.0f); TileMap2D tileMap = tileMapNode.CreateComponent <TileMap2D>(); // Set animation tileMap.TmxFile = tmxFile; // Set camera's position TileMapInfo2D info = tileMap.Info; float x = info.MapWidth * 0.5f; float y = info.MapHeight * 0.5f; CameraNode.Position = new Vector3(x, y, -10.0f); }
void CreateScene() { scene = new Scene(); scene.CreateComponent <Octree>(); // Create camera node CameraNode = scene.CreateChild("Camera"); // Set camera's position CameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f)); Camera camera = CameraNode.CreateComponent <Camera>(); camera.Orthographic = true; var graphics = Graphics; camera.OrthoSize = (float)graphics.Height * PixelSize; // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.0) is set for full visibility at 1280x800 resolution) camera.Zoom = (1.0f * Math.Min((float)graphics.Width / 1280.0f, (float)graphics.Height / 800.0f)); var cache = ResourceCache; // Get tmx file TmxFile2D tmxFile = cache.GetTmxFile2D("data/isometric_grass_and_water.tmx"); if (tmxFile == null) { return; } /*var n = tmxFile.NumLayers; * for (uint i=0; i<n; i++) * { * TmxLayer2D layer = tmxFile.GetLayer(i); * layer. * }*/ Node tileMapNode = scene.CreateChild("TileMap"); tileMapNode.Position = new Vector3(0.0f, 0.0f, -1.0f); TileMap2D tileMap = tileMapNode.CreateComponent <TileMap2D>(); // Set animation tileMap.TmxFile = tmxFile; var n = tileMap.NumLayers; var layer = tileMap.GetLayer(0); var node = tileMap.Node; var name = node.Name; while (node.GetNumChildren() == 1) { node = node.Children[0]; name = node.Name; } var n0 = node.GetNumChildren(); int ii = 0; var result = from Node xx in node.Children /*where (ii++ > n / 3) && (ii < n * 2 / 3)*/ select xx; foreach (var nn in result) { nn.Remove(); } var nx = result.Count(); var n1 = node.GetNumChildren(); //node.GetChild() // Set camera's position TileMapInfo2D info = tileMap.Info; float x = info.MapWidth * 0.5f; float y = info.MapHeight * 0.5f; CameraNode.Position = new Vector3(x, y, -10.0f); // Create a Zone component for ambient lighting & fog control var zoneNode = scene.CreateChild("Zone"); var zone = zoneNode.CreateComponent <Zone>(); zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); zone.AmbientColor = new Color(0.15f, 0.15f, 0.15f); zone.FogColor = new Color(0.5f, 0.5f, 0.7f); zone.FogStart = 100.0f; zone.FogEnd = 300.0f; // Create a directional light to the world. Enable cascaded shadows on it var lightNode = scene.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); var light = lightNode.CreateComponent <Light>(); light.LightType = LightType.Directional; light.CastShadows = true; light.ShadowBias = new BiasParameters(0.00025f, 0.5f); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f); // Create some mushrooms const uint numMushrooms = 240; for (uint i = 0; i < numMushrooms; ++i) { var mushroomNode = scene.CreateChild("Mushroom"); mushroomNode.Position = new Vector3(NextRandom(90.0f) - 45.0f, 0.0f, NextRandom(90.0f) - 45.0f); mushroomNode.Rotation = new Quaternion(0.0f, NextRandom(360.0f), 0.0f); mushroomNode.SetScale(0.5f + NextRandom(2.0f)); StaticModel mushroomObject = mushroomNode.CreateComponent <StaticModel>(); mushroomObject.Model = cache.GetModel("data/Mushroom.mdl"); mushroomObject.SetMaterial(cache.GetMaterial("data/Mushroom.xml")); mushroomObject.CastShadows = true; } { mobileMushroom = scene.CreateChild("Mushroom"); mobileMushroom.Position = new Vector3(20.0f, 10.0f, -10.0f); mobileMushroom.Rotation = new Quaternion(0.0f, NextRandom(360.0f), 0.0f); mobileMushroom.SetScale(0.5f + NextRandom(2.0f)); StaticModel mushroomObject = mobileMushroom.CreateComponent <StaticModel>(); mushroomObject.Model = cache.GetModel("data/Mushroom.mdl"); mushroomObject.SetMaterial(cache.GetMaterial("data/Mushroom.xml")); mushroomObject.CastShadows = true; } }