Beispiel #1
0
		protected override async void Start()
		{
			ResourceCache.AutoReloadResources = true;
			base.Start();

			EnableGestureTapped = true;

			busyIndicatorNode = Scene.CreateChild();
			busyIndicatorNode.SetScale(0.06f);
			busyIndicatorNode.CreateComponent<BusyIndicator>();

			mediaCapture = new MediaCapture();
			await mediaCapture.InitializeAsync();
			await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);
			await RegisterCortanaCommands(new Dictionary<string, Action> {
					{"Describe", () => CaptureAndShowResult(false)},
					{"Read this text", () => CaptureAndShowResult(true)}, 
					{"Enable preview", () => EnablePreview(true) },
					{"Disable preview", () => EnablePreview(false) },
					{"Help", Help }
				});
			
			ShowBusyIndicator(true);
			await TextToSpeech("Welcome to the Microsoft Cognitive Services sample for HoloLens and UrhoSharp.");
			ShowBusyIndicator(false);

			inited = true;
		}
Beispiel #2
0
		protected override async void Init()
		{
			var cache = Application.ResourceCache;
			var node = Node;
			var model = node.CreateComponent<StaticModel>();
			model.Model = cache.GetModel(Assets.Models.Player);
			var material = cache.GetMaterial(Assets.Materials.Player).Clone("");
			model.SetMaterial(material);

			node.SetScale(0.45f);
			node.Position = new Vector3(0f, -6f, 0f);
			node.Rotation = new Quaternion(-40, 0, 0);

			//TODO: rotor should be defined in the model + animation
			rotor = node.CreateChild();
			var rotorModel = rotor.CreateComponent<StaticModel>();
			rotorModel.Model = cache.GetModel(Assets.Models.Box);
			rotorModel.SetMaterial(cache.GetMaterial(Assets.Materials.Black));
			rotor.Scale = new Vector3(0.1f, 1.4f, 0.1f);
			rotor.Rotation = new Quaternion(0, 0, 0);
			rotor.Position = new Vector3(0, -0.15f, 1.2f);
			rotor.RunActionsAsync(new RepeatForever(new RotateBy(1f, 0, 0, 360f * 4))); //RPM

			// Load weapons
			node.AddComponent(new MachineGun());
			node.AddComponent(new Missile());

			await node.RunActionsAsync(new EaseOut(new MoveBy(0.5f, new Vector3(0, 3, 0)), 2));
			MoveRandomly();
		}
Beispiel #3
0
		protected override void Start()
		{
			// base.Start() creates a basic scene
			base.Start();

			// Create a node for the Earth
			earthNode = Scene.CreateChild();
			earthNode.Position = new Vector3(0, 0, 1); // One meter away
			earthNode.SetScale(0.2f); // 20cm

			// Create a static model component - Sphere:
			var earth = earthNode.CreateComponent<Sphere>();
			// Materials are usually more complicated than just textures, but for such
			// simple cases we can use quick FromImage method to create a material from an image.
			earth.SetMaterial(Material.FromImage("Textures/Earth.jpg"));

			// Same steps for the Moon
			var moonNode = earthNode.CreateChild();
			moonNode.SetScale(0.27f); // Relative size of the Moon is 1738.1km/6378.1km
			moonNode.Position = new Vector3(1.2f, 0, 0);
			var moon = moonNode.CreateComponent<Sphere>();
			moon.SetMaterial(Material.FromImage("Textures/Moon.jpg"));

			// Run a an action to spin the Earth (5 degrees per second)
			earthNode.RunActions(new RepeatForever(new RotateBy(duration: 1f, deltaAngleX: 0, deltaAngleY: -5, deltaAngleZ: 0)));
		}
Beispiel #4
0
		protected override async void Start()
		{
			base.Start();

			EnableGestureManipulation = true;
			EnableGestureTapped = true;

			Log.LogLevel = LogLevel.Warning;
			Log.LogMessage += l => { Debug.WriteLine(l.Level + ":  " + l.Message); };

			// Create a node for the Earth
			earthNode = Scene.CreateChild();
			earthNode.Position = new Vector3(0, 0, 1.5f);
			earthNode.SetScale(0.3f);

			DirectionalLight.Brightness = 1f;
			DirectionalLight.Node.SetDirection(new Vector3(-1, 0, 0.5f));

			var earth = earthNode.CreateComponent<Sphere>();
			earthMaterial = ResourceCache.GetMaterial("Materials/Earth.xml");
			earth.SetMaterial(earthMaterial);

			var moonNode = earthNode.CreateChild();
			moonNode.SetScale(0.27f);
			moonNode.Position = new Vector3(1.2f, 0, 0);
			var moon = moonNode.CreateComponent<Sphere>();
			moon.SetMaterial(ResourceCache.GetMaterial("Materials/Moon.xml"));

			// Run a few actions to spin the Earth, the Moon and the clouds.
			earthNode.RunActions(new RepeatForever(new RotateBy(duration: 1f, deltaAngleX: 0, deltaAngleY: -4, deltaAngleZ: 0)));
		}
Beispiel #5
0
		protected override async void Start()
		{
			base.Start();
			clientConnection = new ClientConnection();
			clientConnection.Disconnected += ClientConnection_Disconnected;
			clientConnection.RegisterForRealtimeUpdate(GetCurrentPositionDto);
			clientConnection.RegisterFor<PointerPositionChangedDto>(OnClientPointerChanged);

			Zone.AmbientColor = new Color(0.3f, 0.3f, 0.3f);
			DirectionalLight.Brightness = 0.5f;

			environmentNode = Scene.CreateChild();
			EnableGestureTapped = true;

			cubeNode = environmentNode.CreateChild();
			cubeNode.SetScale(0.2f);
			cubeNode.Position = new Vector3(1000, 1000, 1000);
			var box = cubeNode.CreateComponent<Box>();
			box.Color = Color.White;

			var moveAction = new MoveBy(0.5f, new Vector3(0, 0.005f, 0));
			cubeNode.RunActions(new RepeatForever(new RotateBy(1f, 0, 120, 0)));
			cubeNode.RunActions(new RepeatForever(moveAction, moveAction.Reverse()));

			//material = Material.FromColor(Color.Gray); //-- debug mode
			material = Material.FromColor(Color.Transparent, true);

			await RegisterCortanaCommands(new Dictionary<string, Action> {
				{ "stop spatial mapping", StopSpatialMapping}
			});

			while (!await ConnectAsync()) { }
		}
Beispiel #6
0
		protected override void OnExplode(Node explodeNode)
		{
			rotor.RemoveAllActions();
			rotor.Remove();
			var particleEmitter = explodeNode.CreateComponent<ParticleEmitter2D>();
			explodeNode.SetScale(1.5f);
			particleEmitter.Effect = Application.ResourceCache.GetParticleEffect2D(Assets.Particles.PlayerExplosion);
		}
        public static void CreateCityText(Node textNode, string name)
        {
            var text = textNode.CreateComponent <Text3D>();

            text.SetFont(CoreAssets.Fonts.AnonymousPro, 150);
            text.EffectColor = Color.Black;
            text.TextEffect  = TextEffect.Shadow;
            text.Text        = name;
        }
Beispiel #8
0
		protected override void Start()
		{
			base.Start();

			EnableGestureManipulation = true;

			Zone.AmbientColor = new Color(0.8f, 0.8f, 0.8f);
			DirectionalLight.Brightness = 1;

			mutantNode = Scene.CreateChild();
			mutantNode.Position = new Vector3(0, 0, 2f);
			mutantNode.SetScale(0.2f);
			var mutant = mutantNode.CreateComponent<AnimatedModel>();

			mutant.Model = ResourceCache.GetModel("Models/Mutant.mdl");
			mutant.SetMaterial(ResourceCache.GetMaterial("Materials/mutant_M.xml"));
			animation = mutantNode.CreateComponent<AnimationController>();
			PlayAnimation(IdleAni);

			RegisterCortanaCommands(new Dictionary<string, Action>
				{
					//play animations using Cortana
					{"idle", () => PlayAnimation(IdleAni)},
					{"die", () => PlayAnimation(KillAni)},
					{"dance", () => PlayAnimation(HipHopAni)},
					{"jump", () => PlayAnimation(JumpAni)},
					{"jump attack", () => PlayAnimation(JumpAttack)},
					{"kick", () => PlayAnimation(KickAni)},
					{"punch", () => PlayAnimation(PunchAni)},
					{"run", () => PlayAnimation(RunAni)},
					{"swipe", () => PlayAnimation(SwipeAni)},
					{"walk", () => PlayAnimation(WalkAni)},

					{"bigger", () => mutantNode.ScaleNode(1.2f)},
					{"smaller", () => mutantNode.ScaleNode(0.8f)},
					{"increase the brightness", () => IncreaseBrightness(1.2f)},
					{"decrease the brightness", () => IncreaseBrightness(0.8f)},
					{"look at me", LookAtMe },
					{"turn around", () => mutantNode.RunActions(new RotateBy(1f, 0, 180, 0))},
					{"help", Help }
				});
		}
Beispiel #9
0
		protected override async void Start()
		{
			base.Start();
			environmentNode = Scene.CreateChild();

			// Allow tap gesture
			EnableGestureTapped = true;

			// Create a bucket
			bucketNode = Scene.CreateChild();
			bucketNode.SetScale(0.1f);

			// Create instructions
			textNode = bucketNode.CreateChild();
			var text3D = textNode.CreateComponent<Text3D>();
			text3D.HorizontalAlignment = HorizontalAlignment.Center;
			text3D.VerticalAlignment = VerticalAlignment.Top;
			text3D.ViewMask = 0x80000000; //hide from raycasts
			text3D.Text = "Place on a horizontal\n  surface and click";
			text3D.SetFont(CoreAssets.Fonts.AnonymousPro, 26);
			text3D.SetColor(Color.White);
			textNode.Translate(new Vector3(0, 3f, -0.5f));

			// Model and Physics for the bucket
			var bucketModel = bucketNode.CreateComponent<StaticModel>();
			bucketMaterial = Material.FromColor(validPositionColor);
			bucketModel.Model = ResourceCache.GetModel("Models/bucket.mdl");
			bucketModel.SetMaterial(bucketMaterial);
			bucketModel.ViewMask = 0x80000000; //hide from raycasts
			bucketNode.CreateComponent<RigidBody>();
			var shape = bucketNode.CreateComponent<CollisionShape>();
			shape.SetTriangleMesh(bucketModel.Model, 0, Vector3.One, Vector3.Zero, Quaternion.Identity);

			// Material for spatial surfaces
			spatialMaterial = new Material();
			spatialMaterial.SetTechnique(0, CoreAssets.Techniques.NoTextureUnlitVCol, 1, 1);

			// make sure 'spatialMapping' capabilaty is enabled in the app manifest.
			var spatialMappingAllowed = await StartSpatialMapping(new Vector3(50, 50, 10), 1200);
		}
Beispiel #10
0
		public async Task ShowStartMenu(bool gameOver)
		{
			var cache = Application.ResourceCache;
			bigAircraft = Node.CreateChild();
			var model = bigAircraft.CreateComponent<StaticModel>();

			if (gameOver)
			{
				model.Model = cache.GetModel(Assets.Models.Enemy1);
				model.SetMaterial(cache.GetMaterial(Assets.Materials.Enemy1).Clone(""));
				bigAircraft.SetScale(0.3f);
				bigAircraft.Rotate(new Quaternion(180, 90, 20), TransformSpace.Local);
			}
			else
			{
				model.Model = cache.GetModel(Assets.Models.Player);
				model.SetMaterial(cache.GetMaterial(Assets.Materials.Player).Clone(""));
				bigAircraft.SetScale(1f);
				bigAircraft.Rotate(new Quaternion(0, 40, -50), TransformSpace.Local);
			}

			bigAircraft.Position = new Vector3(10, 2, 10);
			bigAircraft.RunActions(new RepeatForever(new Sequence(new RotateBy(1f, 0f, 0f, 5f), new RotateBy(1f, 0f, 0f, -5f))));

			//TODO: rotor should be defined in the model + animation
			rotor = bigAircraft.CreateChild();
			var rotorModel = rotor.CreateComponent<Box>();
			rotorModel.Color = Color.White;
			rotor.Scale = new Vector3(0.1f, 1.5f, 0.1f);
			rotor.Position = new Vector3(0, 0, -1.3f);
			var rotorAction = new RepeatForever(new RotateBy(1f, 0, 0, 360f*6)); //RPM
			rotor.RunActions(rotorAction);
			
			menuLight = bigAircraft.CreateChild();
			menuLight.Position = new Vector3(-3, 6, 2);
			menuLight.AddComponent(new Light { LightType = LightType.Point, Brightness = 0.3f });

			await bigAircraft.RunActionsAsync(new EaseIn(new MoveBy(1f, new Vector3(-10, -2, -10)), 2));

			textBlock = new Text();
			textBlock.HorizontalAlignment = HorizontalAlignment.Center;
			textBlock.VerticalAlignment = VerticalAlignment.Bottom;
			textBlock.Value = gameOver ? "GAME OVER" : "TAP TO START";
			textBlock.SetFont(cache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 15);
			Application.UI.Root.AddChild(textBlock);

			menuTaskSource = new TaskCompletionSource<bool>();
			finished = false;
			await menuTaskSource.Task;
		}
Beispiel #11
0
        public override void OnAttachedToNode(Node node)
        {
            barNode = node.CreateChild();
            barNode.Scale = new Vector3(1, 0, 1);
            var box = barNode.CreateComponent<Box>();
            box.Color = color;

            textNode = node.CreateChild();
            textNode.Position = new Vector3(0, 3, 0);
            var text3D = textNode.CreateComponent<Text3D>();
            text3D.SetFont(CoreAssets.Fonts.AnonymousPro, 60);
            text3D.TextEffect = TextEffect.Stroke;
            text3D.Text = name;

            base.OnAttachedToNode(node);
        }
Beispiel #12
0
		protected override void Start()
		{
			debugHud = new MonoDebugHud(this) { FpsOnly = true };
			debugHud.Show();

			scene = new Scene();
			scene.CreateComponent<Octree>();
			var zone = scene.CreateComponent<Zone>();
			zone.AmbientColor = new Color(0.5f, 0.5f, 0.5f);

			cameraNode = scene.CreateChild();
			var camera = cameraNode.CreateComponent<Camera>();

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

			lightNode = scene.CreateChild();
			lightNode.Position = new Vector3(0, 3, 0);
			var light = lightNode.CreateComponent<Light>();
			light.LightType = LightType.Directional;
			light.Brightness = 0.6f;
			light.Range = 200;

			environmentNode = scene.CreateChild();
			environmentNode.SetScale(0.1f);

			humanNode = environmentNode.CreateChild();
			humanNode.Position = new Vector3(0, -1f, 0);
			humanNode.SetScale(1f);
			var model = humanNode.CreateComponent<StaticModel>();
			model.Model = ResourceCache.GetModel("Jack.mdl");

			material = Material.FromColor(new Color(72/255f, 99/255f, 142/255f));

			yaw = -65;
			pitch = 55;
			cameraNode.Position = new Vector3(0.6f, 1.3f, -0.4f);
			cameraNode.Rotation = new Quaternion(pitch, yaw, 0);

			lightNode.SetDirection(new Vector3(-1, -1f, 0));
			InitTouchInput();
			var pointer = scene.CreateComponent<CubePointer>();
			pointer.PositionChanged += Pointer_PositionChanged;
		}
Beispiel #13
0
        public override void OnAttachedToNode(Node node)
        {
            barNode       = node.CreateChild();
            barNode.Scale = new Vector3(1, 0, 1);
            var box = barNode.CreateComponent <Box>();

            box.Color = color;

            textNode          = node.CreateChild();
            textNode.Position = new Vector3(0, 3, 0);
            var text3D = textNode.CreateComponent <Text3D>();

            text3D.SetFont(CoreAssets.Fonts.AnonymousPro, 60);
            text3D.TextEffect = TextEffect.Stroke;
            text3D.Text       = name;

            base.OnAttachedToNode(node);
        }
Beispiel #14
0
		public override void OnAttachedToNode(Node node)
		{
			base.OnAttachedToNode(node);
			Application.Input.TouchEnd += Input_TouchEnd;
			Application.Input.TouchBegin += Input_TouchBegin;

			cubeNode = node.CreateChild();
			cubeNode.Position = new Vector3(1000, 1000, 1000);
			cubeNode.SetScale(0.02f);
			var box = cubeNode.CreateComponent<Box>();
			box.Color = Color.White;

			var moveAction = new MoveBy(0.5f, new Vector3(0, 0.005f, 0));
			cubeNode.RunActionsAsync(new RepeatForever(new RotateBy(1f, 0, 120, 0)));
			cubeNode.RunActionsAsync(new RepeatForever(moveAction, moveAction.Reverse()));

			camera = Scene.GetChildrenWithComponent<Camera>(true).First().GetComponent<Camera>();
			octree = Scene.GetComponent<Octree>(true);
		}
Beispiel #15
0
        void Reload()
        {
            if (geom != null && !geom.IsDeleted)
            {
                geom.Remove();
            }

            if (Node == null || Node.IsDeleted)
            {
                return;
            }

            geom = Node.CreateComponent <CustomGeometry>();
            geom.BeginGeometry(0, PrimitiveType.LineList);
            var material = new Material();

            material.SetTechnique(0, CoreAssets.Techniques.NoTextureUnlitVCol, MaterialQuality.Medium, 1);
            geom.SetMaterial(material);

            var halfSize = Size / 2;

            for (int i = -halfSize; i <= halfSize; i++)
            {
                //x
                geom.DefineVertex(new Vector3(i, 0, -halfSize) * Scale);
                geom.DefineColor(Color);
                geom.DefineVertex(new Vector3(i, 0, halfSize) * Scale);
                geom.DefineColor(Color);

                //z
                geom.DefineVertex(new Vector3(-halfSize, 0, i) * Scale);
                geom.DefineColor(Color);
                geom.DefineVertex(new Vector3(halfSize, 0, i) * Scale);
                geom.DefineColor(Color);
            }

            geom.Commit();
        }
Beispiel #16
0
		public override void OnAttachedToNode(Node node)
		{
			barNode = node.CreateChild();
			barNode.Scale = new Vector3(1, 0, 1); //means zero height
			var box = barNode.CreateComponent<Box>();
			box.Color = color;

			textNode = node.CreateChild();
			textNode.Rotate(new Quaternion(0, 180, 0), TransformSpace.World);
			textNode.Position = new Vector3(0, 10, 0);
			text3D = textNode.CreateComponent<Text3D>();
			text3D.SetFont(Application.ResourceCache.GetFont("Fonts/Anonymous Pro.ttf"), 60);
			text3D.TextEffect = TextEffect.Stroke;
			//textNode.LookAt() //Look at camera

			base.OnAttachedToNode(node);
		}
 public static Skybox CreateSkybox(Node node)
 {
     return(node.CreateComponent <Skybox>());
 }
 public static Camera CreateCamera(Node node)
 {
     return(node.CreateComponent <Camera>());
 }
 public static Light CreateLight(Node node)
 {
     return(node.CreateComponent <Light>());
 }
Beispiel #20
0
		protected virtual void OnExplode(Node explodeNode)
		{
			explodeNode.SetScale(2f);
			var particleEmitter = explodeNode.CreateComponent<ParticleEmitter2D>();
			particleEmitter.Effect = Application.ResourceCache.GetParticleEffect2D(Assets.Particles.Explosion);
		}
Beispiel #21
0
		void CreateVideoTexturePlaceholder(int width, int height)
		{
			cameraTexture = new Texture2D(this.Context);
			cameraTexture.SetNumLevels(1);
			cameraTexture.SetSize(width, height, Urho.Graphics.RGBFormat, TextureUsage.Dynamic);
			var material = new Material();
			material.SetTexture(TextureUnit.Diffuse, cameraTexture);
			material.SetTechnique(0, CoreAssets.Techniques.Diff, 0, 0);
			planeNode = scene.CreateChild();
			planeNode.Position = new Vector3(0, 0, 7);
			const float xScale = 5;
			planeNode.Scale = new Vector3(xScale, xScale * height / width, xScale);
			var planeModel = planeNode.CreateComponent<StaticModel>();
			planeModel.Model = CoreAssets.Models.Box;
			planeModel.SetMaterial(material);
		}
 public static Sphere CreateSphereComponent(Node node)
 {
     return(node.CreateComponent <Sphere>());
 }
Beispiel #23
0
        async Task CreateScene()
        {
            // Create a top-level _scene, must add the Octree
            // to visualize any 3D content.
            _scene = new Scene();
            _scene.CreateComponent<Octree>();
            _scene.CreateComponent<DebugRenderer>();

            // Get parameter payload
            _currentMapping = _dataExchangeService.Payload["CurrentMapping"] as Mapping;
            if (_currentMapping == null)
            {
                await Task.Delay(1000).ConfigureAwait(true);
                _currentMapping = _dataExchangeService.Payload["CurrentMapping"] as Mapping;
            }

            // Add boxes and images
            await PlaceBoxes();
            PlaceImages();

            // Zone
            var zoneNode = _scene.CreateChild(name: "zoneNode");
            zoneNode.Position = new Vector3(0, 0, 0);

            var zone = zoneNode.CreateComponent<Zone>();
            zone.SetBoundingBox(new BoundingBox(-1000, 1000));
            zone.AmbientColor = new Color(0.1f, 0.2f, 0.4f);
            //zone.FogColor = new Color(0.1f, 0.2f, 0.3f);
            //zone.FogStart = 10;
            //zone.FogEnd = 100;


            // Camera
            CameraNode = _scene.CreateChild("Camera");
            Camera camera = CameraNode.CreateComponent<Camera>();
            CameraNode.Position = new Vector3(0f, 0f, 0);
            camera.Fov = 90f;

            // Add a light to the camera node
            var cameraLight = CameraNode.CreateComponent<Light>();
            cameraLight.Range = 200;
            cameraLight.LightType = LightType.Point;
            cameraLight.Color = Color.Yellow;


            // Viewport
            Renderer.SetViewport(0, new Viewport(_scene, camera, null));
            Renderer.DrawDebugGeometry(true);
        }