protected override void Start() { // 3D scene with Octree Scene = new Scene(Context); Octree = Scene.CreateComponent <Octree>(); RootNode = Scene.CreateChild("RootNode"); RootNode.Position = new Vector3(x: 0, y: 0, z: 8); LightNode = Scene.CreateChild("DirectionalLight"); LightNode.SetDirection(new Vector3(0.5f, 0.0f, 0.8f)); Light = LightNode.CreateComponent <Light>(); Light.LightType = LightType.Directional; Light.CastShadows = true; Light.ShadowBias = new BiasParameters(0.00025f, 0.5f); Light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f); Light.SpecularIntensity = 0.5f; Light.Color = new Color(1.2f, 1.2f, 1.2f); // Camera CameraNode = Scene.CreateChild(name: "Camera"); Camera = CameraNode.CreateComponent <Camera>(); // Viewport Viewport = new Viewport(Context, Scene, Camera, null); Renderer.SetViewport(0, Viewport); Viewport.SetClearColor(Color.White); Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2); // Subscribe to Esc key: Input.SubscribeToKeyDown(args => { if (args.Key == Key.Esc) { Exit(); } }); }
void CreateScene() { scene = new Scene(); scene.CreateComponent<Octree>(); // Camera var 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; var cache = ResourceCache; // Get sprite Sprite2D sprite = cache.GetSprite2D("2D/Nut.png"); if (sprite == null) return; var nutNode = scene.CreateChild(); nutNode.Position = new Vector3(0f,0f,0f); StaticSprite2D staticSprite = nutNode.CreateComponent<StaticSprite2D>(); // Set sprite staticSprite.Sprite = sprite; Renderer.SetViewport(0, Viewport = new Viewport(Context, scene, cameraNode.GetComponent<Camera>(), null)); }
async void CreateScene() { scene = new Scene(); scene.CreateComponent<Octree>(); var physics = scene.CreateComponent<PhysicsWorld>(); physics.SetGravity(new Vector3(0, 0, 0)); // Camera var cameraNode = scene.CreateChild(); cameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f)); cameraNode.CreateComponent<Camera>(); Viewport = new Viewport(Context, scene, cameraNode.GetComponent<Camera>(), null); RenderPath effectRenderPath = Viewport.RenderPath.Clone(); var fxaaRp = ResourceCache.GetXmlFile(Assets.PostProcess.FXAA3); effectRenderPath.Append(fxaaRp); Viewport.RenderPath = effectRenderPath; Renderer.SetViewport(0, Viewport); var zoneNode = scene.CreateChild(); var zone = zoneNode.CreateComponent<Zone>(); zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f)); zone.AmbientColor = new Color(1f, 1f, 1f); // UI coinsText = new Text(); coinsText.HorizontalAlignment = HorizontalAlignment.Right; coinsText.SetFont(ResourceCache.GetFont(Assets.Fonts.Font), Graphics.Width / 20); UI.Root.AddChild(coinsText); Input.SetMouseVisible(true, false); // Background var background = new Background(); scene.AddComponent(background); background.Start(); // Lights: var lightNode = scene.CreateChild(); lightNode.Position = new Vector3(0, -5, -40); lightNode.AddComponent(new Light { Range = 120, Brightness = 0.8f }); // Game logic cycle bool firstCycle = true; while (true) { var startMenu = scene.CreateComponent<StartMenu>(); await startMenu.ShowStartMenu(!firstCycle); //wait for "start" startMenu.Remove(); await StartGame(); firstCycle = false; } }
protected override void Start() { // 3D scene with Octree Scene = new Scene(Context); Octree = Scene.CreateComponent <Octree>(); Zone = Scene.CreateComponent <Zone>(); Zone.AmbientColor = new Color(0.6f, 0.6f, 0.6f); RootNode = Scene.CreateChild("RootNode"); RootNode.Position = new Vector3(x: 0, y: -2, z: 8); // Camera CameraNode = Scene.CreateChild(name: "Camera"); CameraNode.Rotation = new Quaternion(Pitch = 0, 0, 0); Camera = CameraNode.CreateComponent <Camera>(); // Light LightNode = CameraNode.CreateChild(); LightNode.Position = new Vector3(-5, 10, 0); Light = LightNode.CreateComponent <Light>(); Light.Range = 100; Light.Brightness = 0.5f; Light.LightType = LightType.Point; // Viewport Viewport = new Viewport(Context, Scene, Camera, null); Renderer.SetViewport(0, Viewport); Viewport.SetClearColor(new Color(0.88f, 0.88f, 0.88f)); if (Platform.IsMobile()) { Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA2); } else if (Platform != Platforms.UWP && Platform != Platforms.SharpReality) { ResourceCache.AutoReloadResources = true; Renderer.HDRRendering = true; Viewport.RenderPath.Append(CoreAssets.PostProcess.BloomHDR); Viewport.RenderPath.Append(CoreAssets.PostProcess.FXAA3); } #if DESKTOP Input.SubscribeToMouseWheel(args => CameraNode.Translate(-Vector3.UnitZ * 1f * args.Wheel * -1)); Input.SetMouseVisible(true, true); Input.SubscribeToKeyDown(args => { if (args.Key == Key.Esc) { Exit(); } }); #endif }
async void CreateScene() { scene = new Scene(); scene.CreateComponent<Octree>(); var physics = scene.CreateComponent<PhysicsWorld>(); physics.SetGravity(new Vector3(0, 0, 0)); // Camera var cameraNode = scene.CreateChild(); cameraNode.Position = (new Vector3(0.0f, 0.0f, -10.0f)); cameraNode.CreateComponent<Camera>(); Renderer.SetViewport(0, Viewport = new Viewport(Context, scene, cameraNode.GetComponent<Camera>(), null)); // UI coinsText = new Text(); coinsText.HorizontalAlignment = HorizontalAlignment.Right; coinsText.SetFont(ResourceCache.GetFont(Assets.Fonts.Font), Graphics.Width / 20); UI.Root.AddChild(coinsText); Input.SetMouseVisible(true, false); // Background var background = new Background(); scene.AddComponent(background); background.Start(); // Lights: var lightNode1 = scene.CreateChild(); lightNode1.Position = new Vector3(0, -5, -40); lightNode1.AddComponent(new Light { Range = 120, Brightness = 1.5f }); var lightNode2 = scene.CreateChild(); lightNode2.Position = new Vector3(10, 15, -12); lightNode2.AddComponent(new Light { Range = 30.0f, Brightness = 1.5f }); // Game logic cycle while (true) { var startMenu = scene.CreateComponent<StartMenu>(); await startMenu.ShowStartMenu(); //wait for "start" startMenu.Remove(); await StartGame(); } }
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; }
async void CreateScene () { Input.SubscribeToTouchEnd(OnTouched); var cache = ResourceCache; scene = new Scene (); octree = scene.CreateComponent<Octree> (); plotNode = scene.CreateChild(); var baseNode = plotNode.CreateChild().CreateChild(); var plane = baseNode.CreateComponent<StaticModel>(); plane.Model = ResourceCache.GetModel("Models/Plane.mdl"); var cameraNode = scene.CreateChild ("camera"); camera = cameraNode.CreateComponent<Camera>(); cameraNode.Position = new Vector3(10, 15, 10) / 1.75f; cameraNode.Rotation = new Quaternion(-0.121f, 0.878f, -0.305f, -0.35f); Node lightNode = cameraNode.CreateChild(name: "light"); var light = lightNode.CreateComponent<Light>(); light.LightType = LightType.Point; light.Range = 100; light.Brightness = 1.3f; int size = 3; baseNode.Scale = new Vector3(size * 1.5f, 1, size * 1.5f); bars = new List<Bar>(size * size); 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, size / 2f - j); var box = new Bar(new Color(RandomHelper.NextRandom(), RandomHelper.NextRandom(), RandomHelper.NextRandom(), 0.9f)); boxNode.AddComponent(box); box.SetValueWithAnimation((Math.Abs(i) + Math.Abs(j) + 1) / 2f); bars.Add(box); } } SelectedBar = bars.First(); SelectedBar.Select(); await plotNode.RunActionsAsync(new EaseBackOut(new RotateBy(2f, 0, 360, 0))); movementsEnabled = true; }
async void CreateScene() { // UI text var helloText = new Text(Context); helloText.Value = "Hello World from UrhoSharp"; helloText.HorizontalAlignment = HorizontalAlignment.Center; helloText.VerticalAlignment = VerticalAlignment.Top; helloText.SetColor(new Color(r: 0f, g: 1f, b: 1f)); helloText.SetFont(font: ResourceCache.GetFont("Fonts/Font.ttf"), size: 30); UI.Root.AddChild(helloText); // 3D scene with Octree var scene = new Scene(Context); scene.CreateComponent<Octree>(); // Box Node boxNode = scene.CreateChild(name: "Box node"); boxNode.Position = new Vector3(x: 0, y: 0, z: 5); boxNode.SetScale(0f); boxNode.Rotation = new Quaternion(x: 60, y: 0, z: 30); StaticModel boxModel = boxNode.CreateComponent<StaticModel>(); boxModel.Model = ResourceCache.GetModel("Models/Box.mdl"); boxModel.SetMaterial(ResourceCache.GetMaterial("Materials/BoxMaterial.xml")); // Light Node lightNode = scene.CreateChild(name: "light"); var light = lightNode.CreateComponent<Light>(); light.Range = 10; light.Brightness = 1.5f; // Camera Node cameraNode = scene.CreateChild(name: "camera"); Camera camera = cameraNode.CreateComponent<Camera>(); // Viewport Renderer.SetViewport(0, new Viewport(Context, scene, camera, null)); // Do actions await boxNode.RunActionsAsync(new EaseBounceOut(new ScaleTo(duration: 1f, scale: 1))); await boxNode.RunActionsAsync(new RepeatForever( new RotateBy(duration: 1, deltaAngleX: 90, deltaAngleY: 0, deltaAngleZ: 0))); }
async void CreateScene() { // UI text helloText = new Text() { Value = "Hello World from MySample", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; helloText.SetColor(new Color(0f, 1f, 1f)); helloText.SetFont( font: ResourceCache.GetFont("Fonts/BlueHighway.ttf"), size: 30); UI.Root.AddChild(helloText); // Create a top-level scene, must add the Octree // to visualize any 3D content. var scene = new Scene(); scene.CreateComponent<Octree>(); // Box Node boxNode = scene.CreateChild(); boxNode.Position = new Vector3(0, 0, 5); boxNode.Rotation = new Quaternion(60, 0, 30); boxNode.SetScale(0f); StaticModel modelObject = boxNode.CreateComponent<StaticModel>(); modelObject.Model = ResourceCache.GetModel("Models/Box.mdl"); // Light Node lightNode = scene.CreateChild(name: "light"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); lightNode.CreateComponent<Light>(); // Camera Node cameraNode = scene.CreateChild(name: "camera"); Camera camera = cameraNode.CreateComponent<Camera>(); // Viewport Renderer.SetViewport(0, new Viewport(scene, camera, null)); // Perform some actions await boxNode.RunActionsAsync( new EaseBounceOut(new ScaleTo(duration: 1f, scale: 1))); await boxNode.RunActionsAsync( new RepeatForever(new RotateBy(duration: 1, deltaAngleX: 90, deltaAngleY: 0, deltaAngleZ: 0))); }
protected override void Start() { // UI text var helloText = new Text(Context); helloText.Value = "UrhoSharp face detection"; helloText.HorizontalAlignment = Urho.Gui.HorizontalAlignment.Center; helloText.VerticalAlignment = Urho.Gui.VerticalAlignment.Top; helloText.SetColor(new Color(r: 0f, g: 0f, b: 1f)); helloText.SetFont(font: CoreAssets.Fonts.AnonymousPro, size: 30); UI.Root.AddChild(helloText); // 3D scene with Octree scene = new Scene(Context); scene.CreateComponent<Octree>(); // Mask maskNode = scene.CreateChild(); maskNode.Position = new Vector3(x: 1, y: 0, z: 5); maskNode.Scale = new Vector3(1, 1, 1) / 3f; var leftEye = maskNode.CreateChild(); var leftEyeModel = leftEye.CreateComponent<Urho.Shapes.Sphere>(); var rightEye = maskNode.CreateChild(); var rightEyeModel = rightEye.CreateComponent<Urho.Shapes.Sphere>(); leftEye.Position = new Vector3(-0.6f, 0, 0); rightEye.Position = new Vector3(0.6f, 0, 0); leftEye.RunActions(new TintTo(1f, Randoms.Next(), Randoms.Next(), Randoms.Next())); rightEye.RunActions(new TintTo(1f, Randoms.Next(), Randoms.Next(), Randoms.Next())); // Light Node lightNode = scene.CreateChild(); lightNode.Position = new Vector3(-2, 0, 0); var light = lightNode.CreateComponent<Light>(); light.Range = 20; light.Brightness = 1f; // Camera Node cameraNode = scene.CreateChild(); camera = cameraNode.CreateComponent<Camera>(); // Viewport var vp = new Viewport(Context, scene, camera, null); Renderer.SetViewport(0, vp); vp.SetClearColor(Color.White); }
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); }