Advertisement
vitareinforce

Contoh Gesture dengan Gaze Icon

Feb 13th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Windows.ApplicationModel.Core;
  4. using Urho;
  5. using Urho.Actions;
  6. using Urho.SharpReality;
  7. using Urho.Shapes;
  8. using Urho.Resources;
  9. using Urho.Gui;
  10.  
  11. namespace HoloUrhoSharp9
  12. {
  13. internal class Program
  14. {
  15. [MTAThread]
  16. static void Main()
  17. {
  18. var appViewSource = new UrhoAppViewSource<HelloWorldApplication>(new ApplicationOptions("Data"));
  19. appViewSource.UrhoAppViewCreated += OnViewCreated;
  20. CoreApplication.Run(appViewSource);
  21. }
  22.  
  23. static void OnViewCreated(UrhoAppView view)
  24. {
  25. view.WindowIsSet += View_WindowIsSet;
  26. }
  27.  
  28. static void View_WindowIsSet(Windows.UI.Core.CoreWindow coreWindow)
  29. {
  30. // you can subscribe to CoreWindow events here
  31. }
  32. }
  33.  
  34. public class HelloWorldApplication : StereoApplication
  35. {
  36. Node earthNode;
  37.  
  38. public HelloWorldApplication(ApplicationOptions opts) : base(opts) { }
  39.  
  40. protected override async void Start()
  41. {
  42. // Create a basic scene, see StereoApplication
  43. base.Start();
  44.  
  45. // Enable input
  46. EnableGestureManipulation = true;
  47. EnableGestureTapped = true;
  48.  
  49. // Create a node for the Earth
  50. earthNode = Scene.CreateChild();
  51. earthNode.Position = new Vector3(0, 0, 1.5f); //1.5m away
  52. earthNode.SetScale(0.3f); //D=30cm
  53. earthNode.Name = "Bumi";
  54.  
  55. // Scene has a lot of pre-configured components, such as Cameras (eyes), Lights, etc.
  56. DirectionalLight.Brightness = 1f;
  57. DirectionalLight.Node.SetDirection(new Vector3(-1, 0, 0.5f));
  58.  
  59. //Sphere is just a StaticModel component with Sphere.mdl as a Model.
  60. var earth = earthNode.CreateComponent<Sphere>();
  61. earth.Material = Material.FromImage("Textures/Earth.jpg");
  62.  
  63. var moonNode = earthNode.CreateChild();
  64. moonNode.SetScale(0.27f); //27% of the Earth's size
  65. moonNode.Position = new Vector3(1.2f, 0, 0);
  66. moonNode.Name = "Bulan";
  67. // Same as Sphere component:
  68. var moon = moonNode.CreateComponent<StaticModel>();
  69. moon.Model = CoreAssets.Models.Sphere;
  70.  
  71. moon.Material = Material.FromImage("Textures/Moon.jpg");
  72.  
  73. // Run a few actions to spin the Earth, the Moon and the clouds.
  74. earthNode.RunActions(new RepeatForever(new RotateBy(duration: 1f, deltaAngleX: 0, deltaAngleY: -4, deltaAngleZ: 0)));
  75. await TextToSpeech("Hello world from UrhoSharp!");
  76.  
  77. // More advanced samples can be found here:
  78. // https://github.com/xamarin/urho-samples/tree/master/HoloLens
  79.  
  80. Text text = new Text(Context);
  81. text.Value = ".";
  82. text.HorizontalAlignment = HorizontalAlignment.Center;
  83. text.VerticalAlignment = VerticalAlignment.Center;
  84. text.Position = new IntVector2(0, 0);
  85. text.SetColor(Color.White);
  86. text.SetFont(CoreAssets.Fonts.AnonymousPro, 30);
  87. UI.Root.AddChild(text);
  88.  
  89. //Kalau Pake Gambar
  90. Sprite crosshair = new Sprite(Context);
  91. crosshair.Texture = ResourceCache.GetTexture2D(@"Data/crosshair.png");
  92. crosshair.SetAlignment(HorizontalAlignment.Center, VerticalAlignment.Center);
  93. crosshair.Position = new IntVector2(0, 0);
  94. crosshair.SetSize(25, 25);
  95. UI.Root.AddChild(crosshair);
  96.  
  97.  
  98. }
  99.  
  100. // For HL optical stabilization (optional)
  101. public override Vector3 FocusWorldPoint => earthNode.WorldPosition;
  102.  
  103. //Handle input:
  104.  
  105. Vector3 earthPosBeforeManipulations;
  106. public override void OnGestureManipulationStarted() => earthPosBeforeManipulations = earthNode.Position;
  107. public override void OnGestureManipulationUpdated(Vector3 relativeHandPosition) =>
  108. earthNode.Position = relativeHandPosition + earthPosBeforeManipulations;
  109.  
  110. public override async void OnGestureTapped() {
  111. Ray cameraRay = RightCamera.GetScreenRay(0.5f, 0.5f);
  112.  
  113. var result = Scene.GetComponent<Octree>().RaycastSingle(cameraRay, RayQueryLevel.Triangle, 100, DrawableFlags.Geometry, 0x70000000);
  114.  
  115. if (result != null && result.Value.Node.Name == "Bumi")
  116. {
  117. //Lakukan Aksi disini
  118. await TextToSpeech("Ini Bumi");
  119. }
  120.  
  121. }
  122.  
  123. public override async void OnGestureDoubleTapped() {
  124. Ray cameraRay = RightCamera.GetScreenRay(0.5f, 0.5f);
  125.  
  126. var result = Scene.GetComponent<Octree>().RaycastSingle(cameraRay, RayQueryLevel.Triangle, 100, DrawableFlags.Geometry, 0x70000000);
  127.  
  128. if (result != null && result.Value.Node.Name == "Bulan")
  129. {
  130. //Lakukan Aksi disini
  131. await TextToSpeech("Ini Bulan");
  132. }
  133. }
  134. }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement