当前位置: 首页>>代码示例>>C#>>正文


C# Scene.CreateChild方法代码示例

本文整理汇总了C#中Scene.CreateChild方法的典型用法代码示例。如果您正苦于以下问题:C# Scene.CreateChild方法的具体用法?C# Scene.CreateChild怎么用?C# Scene.CreateChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scene的用法示例。


在下文中一共展示了Scene.CreateChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteScene

        public void WriteScene(string outputFile, string contentDir, string rootName)
        {
            Scene scene = new Scene(rootName);

            Node entRoot = scene.CreateChild("Entities");

            // Write 'void' entity nodes
            foreach (Map.Entity entity in map.Entities)
            {
                if (entity.Brushes.Count == 0)
                {
                    Node brushNode = entRoot.CreateChild();
                    brushNode.WriteVariables(entity.Properties);
                }
            }

            // Write world geometry elements
            Node geoNode = scene.CreateChild("Geometry");
            foreach (Map.Entity entity in map.Entities)
            {
                Node entNode = geoNode.CreateChild();
                entNode.WriteVariables(entity.Properties);
                // Geometry entity
                if (entity.Brushes.Count != 0)
                {
                    Node brush = geoNode.CreateChild();
                }
            }

            scene.Save(outputFile);
        }
开发者ID:JoshEngebretson,项目名称:QMapConverter,代码行数:31,代码来源:SceneBuilder.cs

示例2: CreateScene

        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.2f * 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.2) is set for full visibility at 1280x800 resolution)

            var cache = ResourceCache;
            ParticleEffect2D particleEffect = cache.GetParticleEffect2D("Urho2D/sun.pex");
            if (particleEffect == null)
                return;

            particleNode = scene.CreateChild("ParticleEmitter2D");
            ParticleEmitter2D particleEmitter = particleNode.CreateComponent<ParticleEmitter2D>();
            particleEmitter.Effect=particleEffect;

            ParticleEffect2D greenSpiralEffect = cache.GetParticleEffect2D("Urho2D/greenspiral.pex");
            if (greenSpiralEffect == null)
                return;

            Node greenSpiralNode = scene.CreateChild("GreenSpiral");
            ParticleEmitter2D greenSpiralEmitter = greenSpiralNode.CreateComponent<ParticleEmitter2D>();
            greenSpiralEmitter.Effect=greenSpiralEffect;
        }
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:34,代码来源:Urho2DParticle.cs

示例3: Start

		protected override async void Start()
		{
			base.Start();
			Input.SubscribeToKeyDown(k => { if (k.Key == Key.Esc) Exit(); });
			Input.SubscribeToTouchEnd(OnTouched);

			// 3D scene with Octree
			var scene = new Scene(Context);
			octree = scene.CreateComponent<Octree>();

			// Camera
			var cameraNode = scene.CreateChild(name: "camera");
			cameraNode.Position = new Vector3(10, 14, 10);
			cameraNode.Rotation = new Quaternion(-0.121f, 0.878f, -0.305f, -0.35f);
			camera = cameraNode.CreateComponent<Camera>();

			// Light
			Node lightNode = cameraNode.CreateChild(name: "light");
			var light = lightNode.CreateComponent<Light>();
			light.LightType = LightType.Point;
			light.Range = 100;
			light.Brightness = 1.3f;

			// Viewport
			var viewport = new Viewport(Context, scene, camera, null);
			Renderer.SetViewport(0, viewport);
			viewport.SetClearColor(new Color(0.4f, 0.4f, 0.4f));

			plotNode = scene.CreateChild();
			var baseNode = plotNode.CreateChild().CreateChild();
			var plane = baseNode.CreateComponent<StaticModel>();
			plane.Model = ResourceCache.GetModel("Models/Plane.mdl");

			int size = 5;
			baseNode.Scale = new Vector3(size * 1.5f, 1, size * 1.5f);
			for (var i = 0f; i < size * 1.5f; i += 1.5f)
			{
				for (var j = 0f; j < size * 1.5f; j += 1.5f)
				{
					var boxNode = plotNode.CreateChild();
					boxNode.Position = new Vector3(size / 2f - i + 0.5f, 0, size / 2f - j + 0.5f);
					var box = new Bar(h => Math.Round(h, 1).ToString(), new Color(Sample.NextRandom(), Sample.NextRandom(), Sample.NextRandom(), 0.9f));
					boxNode.AddComponent(box);
					box.Value = (Math.Abs(i) + Math.Abs(j) + 1) / 2f;
				}
			}
			await plotNode.RunActionsAsync(new EaseBackOut(new RotateBy(2f, 0, 360, 0)));
			movementsEnabled = true;
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:49,代码来源:Charts.cs

示例4: TestIssue129

		public async Task TestIssue129()
		{

			var app = await Task.Run(() => SimpleApplication.RunAsync(1, 1));

			var scene = new Scene();
			var node = scene.CreateChild();
			await node.RunActionsAsync(new EaseIn(new MoveBy(1f, new Vector3(-10, -2, -10)), 1));

			node.Remove();

			await scene.CreateChild().RunActionsAsync(new EaseOut(new MoveBy(0.5f, new Vector3(0, 3, 0)), 1));

			await app.Exit();
		}
开发者ID:Zamir7,项目名称:urho,代码行数:15,代码来源:ActionManager.cs

示例5: CreateScene

		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=graphics.Height * PixelSize;
			camera.Zoom = 1.5f * Math.Min(graphics.Width / 1280.0f, graphics.Height / 800.0f); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)

			var cache = ResourceCache;
			AnimationSet2D animationSet = cache.GetAnimationSet2D("Urho2D/imp/imp.scml");
			if (animationSet == null)
				return;

			spriteNode = scene.CreateChild("SpriterAnimation");

			AnimatedSprite2D animatedSprite = spriteNode.CreateComponent<AnimatedSprite2D>();
			animatedSprite.AnimationSet = animationSet;
			animatedSprite.SetAnimation(AnimationNames[animationIndex], LoopMode2D.Default);
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:28,代码来源:Urho2DSpriterAnimation.cs

示例6: CreateScene

		void CreateScene ()
		{
			var cache = ResourceCache;
			scene = new Scene ();

			// Create the Octree component to the scene. This is required before adding any drawable components, or else nothing will
			// show up. The default octree volume will be from (-1000, -1000, -1000) to (1000, 1000, 1000) in world coordinates; it
			// is also legal to place objects outside the volume but their visibility can then not be checked in a hierarchically
			// optimizing manner
			scene.CreateComponent<Octree> ();

			// Create a child scene node (at world origin) and a StaticModel component into it. Set the StaticModel to show a simple
			// plane mesh with a "stone" material. Note that naming the scene nodes is optional. Scale the scene node larger
			// (100 x 100 world units)
			var planeNode = scene.CreateChild("Plane");
			planeNode.Scale = new Vector3 (100, 1, 100);
			var planeObject = planeNode.CreateComponent<StaticModel> ();
			planeObject.Model = cache.GetModel ("Models/Plane.mdl");
			planeObject.SetMaterial (cache.GetMaterial ("Materials/StoneTiled.xml"));

			// Create a directional light to the world so that we can see something. The light scene node's orientation controls the
			// light direction; we will use the SetDirection() function which calculates the orientation from a forward direction vector.
			// The light will use default settings (white light, no shadows)
			var lightNode = scene.CreateChild("DirectionalLight");
			lightNode.SetDirection (new Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
			var light = lightNode.CreateComponent<Light>();
			light.LightType = LightType.Directional;

			var rand = new Random();
			for (int i = 0; i < 200; i++)
			{
				var mushroom = scene.CreateChild ("Mushroom");
				mushroom.Position = new Vector3 (rand.Next (90)-45, 0, rand.Next (90)-45);
				mushroom.Rotation = new Quaternion (0, rand.Next (360), 0);
				mushroom.SetScale (0.5f+rand.Next (20000)/10000.0f);
				var mushroomObject = mushroom.CreateComponent<StaticModel>();
				mushroomObject.Model = cache.GetModel ("Models/Mushroom.mdl");
				mushroomObject.SetMaterial (cache.GetMaterial ("Materials/Mushroom.xml"));
			}
			CameraNode = scene.CreateChild ("camera");
			camera = CameraNode.CreateComponent<Camera>();
			CameraNode.Position = new Vector3 (0, 5, 0);
		}
开发者ID:jiailiuyan,项目名称:urho-samples,代码行数:43,代码来源:StaticScene.cs

示例7: CreateScene

		void CreateScene()
		{
			scene = new Scene();

			// Load scene content prepared in the editor (XML format). GetFile() returns an open file from the resource system
			// which scene.LoadXML() will read
			scene.LoadXml(FileSystem.ProgramDir + "Data/Scenes/PBRExample.xml");

			// Create the camera (not included in the scene file)
			CameraNode = scene.CreateChild("Camera");
			CameraNode.CreateComponent<Camera>();

			// Set an initial position for the camera scene node above the plane
			CameraNode.Position = new Vector3(0.0f, 4.0f, 0.0f);
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:15,代码来源:PBRMaterials.cs

示例8: CreateScene

		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);
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:36,代码来源:Urho2DTileMap.cs

示例9: CreateScene

		void CreateScene()
		{
			var cache = ResourceCache;

			scene = new Scene();

			// Load scene content prepared in the editor (XML format). GetFile() returns an open file from the resource system
			// which scene.LoadXML() will read
			scene.LoadXmlFromCache(cache, "Scenes/SceneLoadExample.xml");

			// Create the camera (not included in the scene file)
			CameraNode = scene.CreateChild("Camera");
			CameraNode.CreateComponent<Camera>();

			// Set an initial position for the camera scene node above the plane
			CameraNode.Position = new Vector3(0.0f, 2.0f, -10.0f);
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:17,代码来源:SceneAndUILoad.cs

示例10: WriteMap

        public override void WriteMap(BrushMap map)
        {
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine(" Urho3D Prefab Writer");
            Console.WriteLine("----------------------------------------------------------------");

            Console.WriteLine("Building material database");
            MaterialDatabase matDb = new MaterialDatabase(Settings.ContentDir);

            Scene scene = new Scene("node");
            Node entRoot = scene.CreateChild("Entities");

            // Write 'void' entity nodes
            using (QMapConverter.Util.ConsoleProgress prog = new QMapConverter.Util.ConsoleProgress("Writing entities", map.Entities.Count))
                for (int i = 0; i < map.Entities.Count; ++i)
                {
                    prog.Increment();
                    prog.Write();
                    Entity entity = map.Entities[i];
                    if (entity.Brushes.Count == 0)
                    {
                        Node brushNode = entRoot.CreateChild();
                        brushNode.WriteVariables(entity.Properties);
                    }
                }

            // Write world geometry elements
            Node geoNode = scene.CreateChild("Geometry");

            string outputPath = System.IO.Path.Combine(Settings.ContentDir, "Data");
            outputPath = System.IO.Path.Combine(outputPath, "Models");
            outputPath = System.IO.Path.Combine(outputPath, System.IO.Path.GetFileNameWithoutExtension(outputFile));
            outputPath = System.IO.Path.Combine(outputPath, "geo.mdl");

            SceneBuilder sb = new SceneBuilder(map, QMapConverter.Settings.CellSize);
            List<string> materials = new List<string>();
            sb.WriteModel(outputPath, materials);

            using (QMapConverter.Util.ConsoleProgress prog = new QMapConverter.Util.ConsoleProgress("Writing geometry", map.Entities.Count))
            {
                Component staticModel = geoNode.CreateComponent("StaticModel");
                string relPath = outputPath.Replace(Settings.ContentDir + "\\", "").Replace("\\","/");
                staticModel.SetAttribute("Model", String.Format("Model;{0}", relPath));
                StringBuilder matString = new StringBuilder();
                foreach (string m in materials)
                {
                    string matFile = matDb.GetMaterial(m);
                    if (matFile != null && matFile.Length > 0)
                    {
                        if (matString.Length > 0)
                            matString.AppendFormat(";Material;{0}", matFile);
                        else
                            matString.AppendFormat("Material;{0}", matFile);
                    }
                }
                if (matString.Length > 0)
                    staticModel.SetAttribute("Material", matString.ToString());
            }

            using (QMapConverter.Util.ConsoleProgress prog = new QMapConverter.Util.ConsoleProgress("Writing file", map.Entities.Count))
                scene.Save(outputFile);

            Console.WriteLine("File written: " + outputFile);
        }
开发者ID:JoshEngebretson,项目名称:QMapConverter,代码行数:64,代码来源:PrefabWriter.cs

示例11: CreateScene

		void CreateScene()
		{
			scene = new Scene();
			scene.CreateComponent<Octree>();
			scene.CreateComponent<DebugRenderer>();
			// 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.2f * 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.2) is set for full visibility at 1280x800 resolution)

			// Create 2D physics world component
			scene.CreateComponent<PhysicsWorld2D>();

			var cache = ResourceCache;
			Sprite2D boxSprite = cache.GetSprite2D("Urho2D/Box.png");
			Sprite2D ballSprite = cache.GetSprite2D("Urho2D/Ball.png");

			// Create ground.
			Node groundNode = scene.CreateChild("Ground");
			groundNode.Position = (new Vector3(0.0f, -3.0f, 0.0f));
			groundNode.Scale=new Vector3(200.0f, 1.0f, 0.0f);

			// Create 2D rigid body for gound
			/*RigidBody2D groundBody = */
			groundNode.CreateComponent<RigidBody2D>();

			StaticSprite2D groundSprite = groundNode.CreateComponent<StaticSprite2D>();
			groundSprite.Sprite=boxSprite;

			// Create box collider for ground
			CollisionBox2D groundShape = groundNode.CreateComponent<CollisionBox2D>();
			// Set box size
			groundShape.Size=new Vector2(0.32f, 0.32f);
			// Set friction
			groundShape.Friction = 0.5f;

			for (uint i = 0; i < NumObjects; ++i)
			{
				Node node = scene.CreateChild("RigidBody");
				node.Position = (new Vector3(NextRandom(-0.1f, 0.1f), 5.0f + i * 0.4f, 0.0f));

				// Create rigid body
				RigidBody2D body = node.CreateComponent<RigidBody2D>();
				body.BodyType = BodyType2D.Dynamic; 
				StaticSprite2D staticSprite = node.CreateComponent<StaticSprite2D>();

				if (i % 2 == 0)
				{
					staticSprite.Sprite = boxSprite;

					// Create box
					CollisionBox2D box = node.CreateComponent<CollisionBox2D>();
					// Set size
					box.Size=new Vector2(0.32f, 0.32f);
					// Set density
					box.Density=1.0f;
					// Set friction
					box.Friction = 0.5f;
					// Set restitution
					box.Restitution=0.1f;
				}
				else
				{
					staticSprite.Sprite=ballSprite;

					// Create circle
					CollisionCircle2D circle = node.CreateComponent<CollisionCircle2D>();
					// Set radius
					circle.Radius=0.16f;
					// Set density
					circle.Density=1.0f;
					// Set friction.
					circle.Friction = 0.5f;
					// Set restitution
					circle.Restitution=0.1f;
				}
			}
		}
开发者ID:cianmulville,项目名称:urho-samples,代码行数:85,代码来源:Urho2DPhysics.cs

示例12: CreateScene

        void CreateScene()
        {
            scene = new Scene();
            scene.CreateComponent<Octree>();
            scene.CreateComponent<DebugRenderer>();
            PhysicsWorld2D physicsWorld = scene.CreateComponent<PhysicsWorld2D>(); // Create 2D physics world component
            physicsWorld.DrawJoint=true; // Display the joints (Note that DrawDebugGeometry() must be set to true to acually draw the joints)
            drawDebug = true; // Set DrawDebugGeometry() to true

            // Create camera
            CameraNode = scene.CreateChild("Camera");
            // Set camera's position
            CameraNode.Position = (new Vector3(0.0f, 0.0f, 0.0f)); // Note that Z setting is discarded; use camera.zoom instead (see MoveCamera() below for example)

            camera = CameraNode.CreateComponent<Camera>();
            camera.Orthographic = true;

            var graphics = Graphics;

            camera.OrthoSize=(float)graphics.Height * PixelSize;
            camera.Zoom=1.2f * 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.2) is set for full visibility at 1280x800 resolution)

            // Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
            Viewport viewport=new Viewport(Context, scene, camera, null);
            Renderer renderer = Renderer;
            renderer.SetViewport(0, viewport);

            Zone zone = renderer.DefaultZone;
            zone.FogColor = (new Color(0.1f, 0.1f, 0.1f)); // Set background color for the scene

            // Create 4x3 grid
            for (uint i = 0; i < 5; ++i)
            {
                Node edgeNode = scene.CreateChild("VerticalEdge");
                RigidBody2D edgeBody = edgeNode.CreateComponent<RigidBody2D>();
                if (dummyBody == null)
                    dummyBody = edgeBody; // Mark first edge as dummy body (used by mouse pick)
                CollisionEdge2D edgeShape = edgeNode.CreateComponent<CollisionEdge2D>();
                edgeShape.SetVertices(new Vector2(i * 2.5f - 5.0f, -3.0f), new Vector2(i * 2.5f - 5.0f, 3.0f));
                edgeShape.Friction=0.5f; // Set friction
            }

            for (uint j = 0; j < 4; ++j)
            {
                Node edgeNode = scene.CreateChild("HorizontalEdge");
                /*RigidBody2D edgeBody = */
                edgeNode.CreateComponent<RigidBody2D>();
                CollisionEdge2D edgeShape = edgeNode.CreateComponent<CollisionEdge2D>();
                edgeShape.SetVertices(new Vector2(-5.0f, j * 2.0f - 3.0f), new Vector2(5.0f, j * 2.0f - 3.0f));
                edgeShape.Friction=0.5f; // Set friction
            }

            var cache = ResourceCache;

            // Create a box (will be cloned later)
            Node box = scene.CreateChild("Box");
            box.Position = (new Vector3(0.8f, -2.0f, 0.0f));
            StaticSprite2D boxSprite = box.CreateComponent<StaticSprite2D>();
            boxSprite.Sprite=cache.GetSprite2D("Urho2D/Box.png");
            RigidBody2D boxBody = box.CreateComponent<RigidBody2D>();
            boxBody.BodyType= BodyType2D.Dynamic;
            boxBody.LinearDamping=0.0f;
            boxBody.AngularDamping=0.0f;
            CollisionBox2D shape = box.CreateComponent<CollisionBox2D>(); // Create box shape
            shape.Size=new Vector2(0.32f, 0.32f); // Set size
            shape.Density=1.0f; // Set shape density (kilograms per meter squared)
            shape.Friction=0.5f; // Set friction
            shape.Restitution=0.1f; // Set restitution (slight bounce)

            // Create a ball (will be cloned later)
            Node ball = scene.CreateChild("Ball");
            ball.Position = (new Vector3(1.8f, -2.0f, 0.0f));
            StaticSprite2D ballSprite = ball.CreateComponent<StaticSprite2D>();
            ballSprite.Sprite=cache.GetSprite2D("Urho2D/Ball.png");
            RigidBody2D ballBody = ball.CreateComponent<RigidBody2D>();
            ballBody.BodyType= BodyType2D.Dynamic;
            ballBody.LinearDamping=0.0f;
            ballBody.AngularDamping=0.0f;
            CollisionCircle2D ballShape = ball.CreateComponent<CollisionCircle2D>(); // Create circle shape
            ballShape.Radius=0.16f; // Set radius
            ballShape.Density=1.0f; // Set shape density (kilograms per meter squared)
            ballShape.Friction=0.5f; // Set friction
            ballShape.Restitution=0.6f; // Set restitution: make it bounce

            // Create a polygon
            Node polygon = scene.CreateChild("Polygon");
            polygon.Position = (new Vector3(1.6f, -2.0f, 0.0f));
            polygon.SetScale(0.7f);
            StaticSprite2D polygonSprite = polygon.CreateComponent<StaticSprite2D>();
            polygonSprite.Sprite=cache.GetSprite2D("Urho2D/Aster.png");
            RigidBody2D polygonBody = polygon.CreateComponent<RigidBody2D>();
            polygonBody.BodyType= BodyType2D.Dynamic;
            CollisionPolygon2D polygonShape = polygon.CreateComponent<CollisionPolygon2D>();
            polygonShape.VertexCount=6; // Set number of vertices (mandatory when using SetVertex())
            polygonShape.SetVertex(0, new Vector2(-0.8f, -0.3f));
            polygonShape.SetVertex(1, new Vector2(0.5f, -0.8f));
            polygonShape.SetVertex(2, new Vector2(0.8f, -0.3f));
            polygonShape.SetVertex(3, new Vector2(0.8f, 0.5f));
            polygonShape.SetVertex(4, new Vector2(0.5f, 0.9f));
            polygonShape.SetVertex(5, new Vector2(-0.5f, 0.7f));
//.........这里部分代码省略.........
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:101,代码来源:Urho2DConstraints.cs

示例13: CreateScene

        void CreateScene()
        {
            var cache = ResourceCache;
            scene = new Scene();

            // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
            // Create a physics simulation world with default parameters, which will update at 60fps. Like the Octree must
            // exist before creating drawable components, the PhysicsWorld must exist before creating physics components.
            // Finally, create a DebugRenderer component so that we can draw physics debug geometry
            scene.CreateComponent<Octree>();
            scene.CreateComponent<PhysicsWorld>();
            scene.CreateComponent<DebugRenderer>();

            // Create a Zone component for ambient lighting & fog control
            Node zoneNode = scene.CreateChild("Zone");
            Zone 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(1.0f, 1.0f, 1.0f);
            zone.FogStart=300.0f;
            zone.FogEnd=500.0f;

            // Create a directional light to the world. Enable cascaded shadows on it
            Node lightNode = scene.CreateChild("DirectionalLight");
            lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
            Light 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 skybox. The Skybox component is used like StaticModel, but it will be always located at the camera, giving the
            // illusion of the box planes being far away. Use just the ordinary Box model and a suitable material, whose shader will
            // generate the necessary 3D texture coordinates for cube mapping
            Node skyNode = scene.CreateChild("Sky");
            skyNode.SetScale(500.0f); // The scale actually does not matter
            Skybox skybox = skyNode.CreateComponent<Skybox>();
            skybox.Model=cache.GetModel("Models/Box.mdl");
            skybox.SetMaterial(cache.GetMaterial("Materials/Skybox.xml"));

            {
                // Create a floor object, 1000 x 1000 world units. Adjust position so that the ground is at zero Y
                Node floorNode = scene.CreateChild("Floor");
                floorNode.Position=new Vector3(0.0f, -0.5f, 0.0f);
                floorNode.Scale=new Vector3(1000.0f, 1.0f, 1000.0f);
                StaticModel floorObject = floorNode.CreateComponent<StaticModel>();
                floorObject.Model=cache.GetModel("Models/Box.mdl");
                floorObject.SetMaterial(cache.GetMaterial("Materials/StoneTiled.xml"));

                // Make the floor physical by adding RigidBody and CollisionShape components. The RigidBody's default
                // parameters make the object static (zero mass.) Note that a CollisionShape by itself will not participate
                // in the physics simulation

                floorNode.CreateComponent<RigidBody>();
                CollisionShape shape = floorNode.CreateComponent<CollisionShape>();
                // Set a box shape of size 1 x 1 x 1 for collision. The shape will be scaled with the scene node scale, so the
                // rendering and physics representation sizes should match (the box model is also 1 x 1 x 1.)
                shape.SetBox(Vector3.One, Vector3.Zero, Quaternion.Identity);
            }

            {
                // Create a pyramid of movable physics objects
                for (int y = 0; y < 8; ++y)
                {
                    for (int x = -y; x <= y; ++x)
                    {
                        Node boxNode = scene.CreateChild("Box");
                        boxNode.Position=new Vector3((float)x, -(float)y + 8.0f, 0.0f);
                        StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
                        boxObject.Model=cache.GetModel("Models/Box.mdl");
                        boxObject.SetMaterial(cache.GetMaterial("Materials/StoneEnvMapSmall.xml"));
                        boxObject.CastShadows=true;

                        // Create RigidBody and CollisionShape components like above. Give the RigidBody mass to make it movable
                        // and also adjust friction. The actual mass is not important; only the mass ratios between colliding
                        // objects are significant
                        RigidBody body = boxNode.CreateComponent<RigidBody>();
                        body.Mass=1.0f;
                        body.Friction=0.75f;
                        CollisionShape shape = boxNode.CreateComponent<CollisionShape>();
                        shape.SetBox(Vector3.One, Vector3.Zero, Quaternion.Identity);
                    }
                }
            }

            // Create the camera. Limit far clip distance to match the fog. Note: now we actually create the camera node outside
            // the scene, because we want it to be unaffected by scene load / save
            CameraNode = new Node();
            Camera camera = CameraNode.CreateComponent<Camera>();
            camera.FarClip = 500.0f;

            // Set an initial position for the camera scene node above the floor
            CameraNode.Position = (new Vector3(0.0f, 5.0f, -20.0f));
        }
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:95,代码来源:Physics.cs

示例14: CreateScene

        void CreateScene()
        {
            var cache = ResourceCache;

            {
                rttScene = new Scene();
                // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
                rttScene.CreateComponent<Octree>();

                // Create a Zone for ambient light & fog control
                Node zoneNode = rttScene.CreateChild("Zone");
                Zone zone = zoneNode.CreateComponent<Zone>();
                // Set same volume as the Octree, set a close bluish fog and some ambient light
                zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f));
                zone.AmbientColor = new Color(0.05f, 0.1f, 0.15f);
                zone.FogColor = new Color(0.1f, 0.2f, 0.3f);
                zone.FogStart = 10.0f;
                zone.FogEnd = 100.0f;

                // Create randomly positioned and oriented box StaticModels in the scene
                const uint numObjects = 2000;
                for (uint i = 0; i < numObjects; ++i)
                {
                    Node boxNode = rttScene.CreateChild("Box");
                    boxNode.Position = new Vector3(NextRandom(200.0f) - 100.0f, NextRandom(200.0f) - 100.0f,
                        NextRandom(200.0f) - 100.0f);
                    // Orient using random pitch, yaw and roll Euler angles
                    boxNode.Rotation = new Quaternion(NextRandom(360.0f), NextRandom(360.0f), NextRandom(360.0f));
                    StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
                    boxObject.Model = cache.GetModel("Models/Box.mdl");
                    boxObject.SetMaterial(cache.GetMaterial("Materials/Stone.xml"));

                    // Add our custom Rotator component which will rotate the scene node each frame, when the scene sends its update event.
                    // Simply set same rotation speed for all objects
                    Rotator rotator = new Rotator();
                    boxNode.AddComponent(rotator);
                    rotator.SetRotationSpeed(new Vector3(10.0f, 20.0f, 30.0f));
                }

                // Create a camera for the render-to-texture scene. Simply leave it at the world origin and let it observe the scene
                rttCameraNode = rttScene.CreateChild("Camera");
                Camera camera = rttCameraNode.CreateComponent<Camera>();
                camera.FarClip = 100.0f;

                // Create a point light to the camera scene node
                Light light = rttCameraNode.CreateComponent<Light>();
                light.LightType = LightType.Point;
                light.Range = 30.0f;
            }

            {
                // Create the scene in which we move around

                scene = new Scene();

                // Create octree, use also default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
                scene.CreateComponent<Octree>();

                // Create a Zone component for ambient lighting & fog control
                Node zoneNode = scene.CreateChild("Zone");
                Zone zone = zoneNode.CreateComponent<Zone>();
                zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f));
                zone.AmbientColor = new Color(0.1f, 0.1f, 0.1f);
                zone.FogStart = 100.0f;
                zone.FogEnd = 300.0f;

                // Create a directional light without shadows
                Node lightNode = scene.CreateChild("DirectionalLight");
                lightNode.SetDirection(new Vector3(0.5f, -1.0f, 0.5f));
                Light light = lightNode.CreateComponent<Light>();
                light.LightType = LightType.Directional;
                light.Color = new Color(0.2f, 0.2f, 0.2f);
                light.SpecularIntensity = 1.0f;

                // Create a "floor" consisting of several tiles
                for (int y = -5; y <= 5; ++y)
                {
                    for (int x = -5; x <= 5; ++x)
                    {
                        Node floorNode = scene.CreateChild("FloorTile");
                        floorNode.Position = new Vector3(x*20.5f, -0.5f, y*20.5f);
                        floorNode.Scale = new Vector3(20.0f, 1.0f, 20.0f);
                        StaticModel floorObject = floorNode.CreateComponent<StaticModel>();
                        floorObject.Model = cache.GetModel("Models/Box.mdl");
                        floorObject.SetMaterial(cache.GetMaterial("Materials/Stone.xml"));
                    }
                }

                // Create a "screen" like object for viewing the second scene. Construct it from two StaticModels, a box for the frame
                // and a plane for the actual view
                {
                    Node boxNode = scene.CreateChild("ScreenBox");
                    boxNode.Position = new Vector3(0.0f, 10.0f, 0.0f);
                    boxNode.Scale = new Vector3(21.0f, 16.0f, 0.5f);
                    StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
                    boxObject.Model = cache.GetModel("Models/Box.mdl");
                    boxObject.SetMaterial(cache.GetMaterial("Materials/Stone.xml"));

                    Node screenNode = scene.CreateChild("Screen");
                    screenNode.Position = new Vector3(0.0f, 10.0f, -0.27f);
//.........这里部分代码省略.........
开发者ID:ZENG-Yuhao,项目名称:Xamarin-CrossPlatform,代码行数:101,代码来源:RenderToTexture.cs

示例15: CreateScene

		void CreateScene()
		{
			var cache = ResourceCache;

			scene = new Scene();

			// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
			// Also create a DebugRenderer component so that we can draw debug geometry
			scene.CreateComponent<Octree>();
			scene.CreateComponent<DebugRenderer>();

			// Create scene node & StaticModel component for showing a static plane
			Node planeNode = scene.CreateChild("Plane");
			planeNode.Scale = new Vector3(100.0f, 1.0f, 100.0f);
			StaticModel planeObject = planeNode.CreateComponent<StaticModel>();
			planeObject.Model = (cache.GetModel("Models/Plane.mdl"));
			planeObject.SetMaterial(cache.GetMaterial("Materials/StoneTiled.xml"));

			// Create a Zone component for ambient lighting & fog control
			Node zoneNode = scene.CreateChild("Zone");
			Zone 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
			Node lightNode = scene.CreateChild("DirectionalLight");
			lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
			Light 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 randomly sized boxes. If boxes are big enough, make them occluders
			const uint numBoxes = 20;
			Node boxGroup = scene.CreateChild("Boxes");
			for (uint i = 0; i < numBoxes; ++i)
			{
				Node boxNode = boxGroup.CreateChild("Box");
				float size = 1.0f + NextRandom(10.0f);
				boxNode.Position = (new Vector3(NextRandom(80.0f) - 40.0f, size * 0.5f, NextRandom(80.0f) - 40.0f));
				boxNode.SetScale(size);
				StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
				boxObject.Model = (cache.GetModel("Models/Box.mdl"));
				boxObject.SetMaterial(cache.GetMaterial("Materials/Stone.xml"));
				boxObject.CastShadows = true;
				if (size >= 3.0f)
					boxObject.Occluder = true;
			}

			// Create a DynamicNavigationMesh component to the scene root
			DynamicNavigationMesh navMesh = scene.CreateComponent<DynamicNavigationMesh>();
			// Set the agent height large enough to exclude the layers under boxes
			navMesh.AgentHeight = 10.0f;
			navMesh.CellHeight = 0.05f;
			navMesh.DrawObstacles = true;
			navMesh.DrawOffMeshConnections = true;
			// Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
			// navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
			scene.CreateComponent<Navigable>();
			// Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
			// in the scene and still update the mesh correctly
			navMesh.Padding = new Vector3(0.0f, 10.0f, 0.0f);
			// Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
			// physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
			// it will use renderable geometry instead
			navMesh.Build();

			// Create an off-mesh connection to each box to make them climbable (tiny boxes are skipped). A connection is built from 2 nodes.
			// Note that OffMeshConnections must be added before building the navMesh, but as we are adding Obstacles next, tiles will be automatically rebuilt.
			// Creating connections post-build here allows us to use FindNearestPoint() to procedurally set accurate positions for the connection
			CreateBoxOffMeshConnections(navMesh, boxGroup);

			// Create some mushrooms
			const uint numMushrooms = 100;
			for (uint i = 0; i < numMushrooms; ++i)
				CreateMushroom(new Vector3(NextRandom(90.0f) - 45.0f, 0.0f, NextRandom(90.0f) - 45.0f));


			// Create a CrowdManager component to the scene root
			crowdManager = scene.CreateComponent<CrowdManager>();
			var parameters = crowdManager.GetObstacleAvoidanceParams(0);
			// Set the params to "High (66)" setting
			parameters.VelBias = 0.5f;
			parameters.AdaptiveDivs = 7;
			parameters.AdaptiveRings = 3;
			parameters.AdaptiveDepth = 3;
			crowdManager.SetObstacleAvoidanceParams(0, parameters);

			// Create some movable barrels. We create them as crowd agents, as for moving entities it is less expensive and more convenient than using obstacles
			CreateMovingBarrels(navMesh);

			// Create Jack node that will follow the path
			SpawnJack(new Vector3(-5.0f, 0.0f, 20.0f), scene.CreateChild("Jacks"));

			// Create the camera. Limit far clip distance to match the fog
//.........这里部分代码省略.........
开发者ID:xamarin,项目名称:urho-samples,代码行数:101,代码来源:CrowdNavigation.cs


注:本文中的Scene.CreateChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。