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); if (Platform != Platforms.Android && Platform != Platforms.iOS) { 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; } }
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; }
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); }
/// <summary> /// Define with rendertarget and viewport. Return true if successful. /// </summary> public bool Define(RenderSurface renderTarget, Viewport viewport) { Runtime.ValidateRefCounted(this); return(View_Define(handle, (object)renderTarget == null ? IntPtr.Zero : renderTarget.Handle, (object)viewport == null ? IntPtr.Zero : viewport.Handle)); }