void SetupViewport() { var renderer = GetSubsystem <Renderer>(); var graphics = GetSubsystem <Graphics>(); renderer.NumViewports = 2; // Set up the front camera viewport Viewport viewport = new Viewport(scene, CameraNode.GetComponent <Camera>()); renderer.SetViewport(0, viewport); // Clone the default render path so that we do not interfere with the other viewport, then add // bloom and FXAA post process effects to the front viewport. Render path commands can be tagged // for example with the effect name to allow easy toggling on and off. We start with the effects // disabled. var cache = GetSubsystem <ResourceCache>(); RenderPath effectRenderPath = viewport.GetRenderPath().Clone(); effectRenderPath.Append(cache.Get <XMLFile>("PostProcess/Bloom.xml")); effectRenderPath.Append(cache.Get <XMLFile>("PostProcess/FXAA2.xml")); // Make the bloom mixing parameter more pronounced effectRenderPath.SetShaderParameter("BloomMix", new Vector2(0.9f, 0.6f)); effectRenderPath.SetEnabled("Bloom", false); effectRenderPath.SetEnabled("FXAA2", false); viewport.SetRenderPath(effectRenderPath); // Set up the rear camera viewport on top of the front view ("rear view mirror") // The viewport index must be greater in that case, otherwise the view would be left behind IntRect rect = new IntRect(graphics.Width * 2 / 3, 32, graphics.Width - 32, graphics.Height / 3); Viewport rearViewport = new Viewport(scene, rearCameraNode.GetComponent <Camera>(), rect); renderer.SetViewport(1, rearViewport); }
void CreateScene() { if (_scene == null) { _scene = new Scene(); } _scene.CreateComponent <Octree>(); var physics = _scene.CreateComponent <PhysicsWorld>(); physics.SetGravity(WorldGravity); var cameraNode = _scene.CreateChild(); cameraNode.Position = CameraPosition; cameraNode.Rotate(CameraRotation); cameraNode.CreateComponent <Camera>(); var Viewport = new Viewport(Context, _scene, cameraNode.GetComponent <Camera>(), null); if (Application.Platform != Platforms.Android && Application.Platform != Platforms.iOS) { RenderPath effectRenderPath = Viewport.RenderPath.Clone(); var fxaaRp = Application.ResourceCache.GetXmlFile(Assets.PostProcess.FXAA3); effectRenderPath.Append(fxaaRp); Viewport.RenderPath = effectRenderPath; } Application.Renderer.SetViewport(0, Viewport); var zoneNode = _scene.CreateChild(); var zone = zoneNode.CreateComponent <Zone>(); zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); zone.AmbientColor = new Color(1f, 1f, 1f); _trackNode = _scene.CreateChild(); _trackNode.Scale = TrackSize; _trackNode.Position = TrackPosition; var track = _trackNode.CreateComponent <AnimatedModel>(); track.Model = Application.ResourceCache.GetModel(Assets.Models.Plane); track.Material = Application.ResourceCache.GetMaterial(Assets.Materials.Grass); _lightNode = _scene.CreateChild(); _lightNode.Position = LightPosition; _lightNode.Rotation = LightRotation; _lightNode.AddComponent(new Light { Range = 1200, Brightness = 0.8f }); _scoreLabel = new Text(); _scoreLabel.HorizontalAlignment = HorizontalAlignment.Right; _scoreLabel.VerticalAlignment = VerticalAlignment.Top; _scoreLabel.SetFont(Application.ResourceCache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 20); _scoreLabel.Value = 0.ToString(); Application.UI.Root.AddChild(_scoreLabel); }
private 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(); // Luci var lightNode = scene.CreateChild(); lightNode.Position = new Vector3(0, -5, -40); lightNode.AddComponent(new Light { Range = 120, Brightness = 0.8f }); // ciclo della logica di gioco bool firstCycle = true; while (true) { var startMenu = scene.CreateComponent <StartMenu>(); await startMenu.ShowStartMenu(!firstCycle); //wait for "start" startMenu.Remove(); await StartGame(); firstCycle = false; } }
public void CreateScence() { Scene scene = new Scene(); scene.CreateComponent <Octree>(); //camera var cameraNode = scene.CreateChild(); cameraNode.Position = (new Vector3(0.0f, 0.0f, -8.0f)); cameraNode.SetDirection(new Vector3(0.1f, 0f, 900f)); /*string filepath = "D:\\dir.txt"; * var dir = cameraNode.Direction; * if (!File.Exists(filepath)) * { * File.Create(filepath).Dispose(); * File.WriteAllText(filepath, "X:" + dir.X.ToString() + "Y:" + dir.Y.ToString() + "Z:" + dir.Z.ToString() + "\n"); * } * else * { * File.AppendAllText(filepath, "X:" + dir.X.ToString() + "Y:" + dir.Y.ToString() + "Z:" + dir.Z.ToString() + "\n"); * }*/ 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); //zone construct- 构造分区 var zoneNode = scene.CreateChild(); var zone = zoneNode.CreateComponent <Zone>(); zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f)); zone.AmbientColor = new Color(1, 1, 1); //生成背景 var backgroud = new Backgroud(); scene.AddComponent(backgroud); backgroud.Start(); //生成house var house = new House(); scene.AddComponent(house); house.Start(); //生成Apple var apple = new Apple(); scene.AddComponent(apple); apple.Start(); }
protected override void OnShow(Node node, Asset asset) { oldRp = App.Viewport.RenderPath.Clone(); RenderPath customRp = oldRp.Clone(); customRp.Append(ResourceCache.GetXmlFile(asset.RelativePathToAsset)); App.Viewport.RenderPath = customRp; var model = node.CreateComponent <StaticModel>(); model.Model = ResourceCache.GetModel("Models/TeaPot.mdl"); model.SetMaterial(ResourceCache.GetMaterial("Materials/DefaulPreviewerMaterial.xml")); node.SetScale(5f); node.Rotation = new Quaternion(20, 150, 20); }
public override void Start() { // We get the variables we are going to use in this example Renderer renderer = GetSubsystem <Renderer>(); graphics = GetSubsystem <Graphics>(); viewport = renderer.GetViewport(0); // We create a new Scene scene = new Scene(); // The Octree should be added to the root scene node (mandatory?) TODO: answer this scene.CreateComponent <Octree>(); // We pass the scene we just created to be displayed in the viewport viewport.Scene = scene; // We create a new camera on the scene, called "Camera". Tip: you can think of a camera as a glorified projection matrix // - Scene.CreateChild(string name) returns a new Node with that name. // - Node.CreateComponent<ComponentType>() returns a component attached to that Node camera = scene.CreateChild("Camera").CreateComponent <Camera>(); // We can access the Node any component is attached to using Component.Node camera.Node.Position = new Vector3(0.5f, 0.5f, 0.0f); // Remember, 'camera' is a Camera component, so we access it directly here camera.Orthographic = true; camera.OrthoSize = 1.5f; // We pass our newly created camera to the viewport so it's used to display our scene viewport.Camera = camera; // We create an XML from string so this code is fully self-contained XMLFile xml = new XMLFile(); xml.FromString("<renderpath><command type=\"sendevent\"/></renderpath>"); // We create a new RenderPath. A Viewport comes by default with some events, and you can use viewport.GetRenderPath().Clone() // to clone the default RenderPath and Append instructions to it instead (see AtomicBlaster for examples on how to do effects) RenderPath renderpath = new RenderPath(); renderpath.Append(xml); // We replace the viewport's default renderpath by the one we just created viewport.SetRenderPath(renderpath); // We subscribe to the RenderPathEvent. Here we pass an anonymous function that just absorbs the argument and calls Render() SubscribeToEvent <RenderPathEvent>(e => { Render(); }); // Here we setup our shaders, we are using the BasicVColUnlitAlpha "technique" and selecting DIFFMAP and VERTEXCOLOR // DIFFMAP is the diffuse texture and VERTEXCOLOR is a color each vertex holds that is used to 'tint' the surface // See this link: github.com/AtomicGameEngine/AtomicGameEngine/tree/master/Resources/CoreData/Techniques ShaderVariation pixelShader = graphics.GetShader(ShaderType.PS, "Basic", "DIFFMAP VERTEXCOLOR"); ShaderVariation vertexShader = graphics.GetShader(ShaderType.VS, "Basic", "DIFFMAP VERTEXCOLOR"); graphics.SetShaders(vertexShader, pixelShader); // This vertex shader parameter just applies no transformation (Identity Matrix means no transformation) so the vertices // display in world coordinates what allow us to use the camera properly. NOTE: Identity Matrix is also called Unit Matrix graphics.SetShaderParameter(ShaderParams.VSP_MODEL, Matrix3x4.IDENTITY); // We set the pixel shader diffuse color to be white. You can change this to 'tint' the texture similar to vertex colors // but this applies to the whole material and in this example vertex colors will also affect it graphics.SetShaderParameter(ShaderParams.PSP_MATDIFFCOLOR, Color.White); // We set cull mode to NONE so our geometry won't be culled (ignored), for this example we don't really need any culling graphics.SetCullMode(CullMode.CULL_NONE); // We create a texture from literal data so this code is fully self-contained, you can safely skip the lines below. // In your real projects you're most likely going to load textures from the disk using Texture.Load Image image = new Image(); image.SetSize(16, 16, 3); Color z = Color.White; Color M = Color.Blue; Color k = Color.Black; Color[] imageData = { k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, z, z, z, z, z, z, z, z, z, z, z, z, z, M, k, k, z, z, z, z, z, z, M, M, z, z, z, z, z, z, k, k, z, z, z, z, z, z, M, M, z, z, z, z, z, z, k, k, z, z, z, z, z, M, z, z, M, z, z, z, z, z, k, k, z, z, z, z, z, M, z, z, M, z, z, z, z, z, k, k, z, z, z, z, M, z, z, z, z, M, z, z, z, z, k, k, z, z, z, z, M, z, z, z, z, M, z, z, z, z, k, k, z, z, z, M, z, z, z, z, z, z, M, z, z, z, k, k, z, z, z, M, z, z, z, z, z, z, M, z, z, z, k, k, z, z, M, M, M, M, M, M, M, M, M, M, z, z, k, k, z, z, M, z, z, z, z, z, z, z, z, M, z, z, k, k, z, M, z, z, z, z, z, z, z, z, z, z, M, z, k, k, z, M, z, z, z, z, z, z, z, z, z, z, M, z, k, k, z, z, z, z, z, z, z, z, z, z, z, z, z, z, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, k, }; for (int pixel = 0; pixel < imageData.Length; pixel++) { image.SetPixel(pixel % 16, 15 - pixel / 16, imageData[pixel]); } texture = new Texture2D(); texture.SetData(image); // We call this function that creates the quad geometry CreateQuad(); }
public void CreateMenu() { if (_scene == null) { _scene = new Scene(); } _scene.CreateComponent <Octree>(); var physics = _scene.CreateComponent <PhysicsWorld>(); physics.SetGravity(new Vector3(0, 0, 0)); var cameraNode = _scene.CreateChild(); cameraNode.Position = (new Vector3(0.0f, 0f, -500.0f)); cameraNode.Rotate(new Quaternion(10, 0, 0)); cameraNode.CreateComponent <Camera>(); var Viewport = new Viewport(Context, _scene, cameraNode.GetComponent <Camera>(), null); if (Application.Platform != Platforms.Android && Application.Platform != Platforms.iOS) { RenderPath effectRenderPath = Viewport.RenderPath.Clone(); var fxaaRp = Application.ResourceCache.GetXmlFile(Assets.PostProcess.FXAA3); effectRenderPath.Append(fxaaRp); Viewport.RenderPath = effectRenderPath; } Application.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); var plannerNode = _scene.CreateChild(); plannerNode.Position = new Vector3(0, -50, 0); plannerNode.Scale = new Vector3(10, 10, 10); var planner = plannerNode.CreateComponent <StaticModel>(); planner.Model = Application.ResourceCache.GetModel(Assets.Models.VerBot); planner.Material = Application.ResourceCache.GetMaterial(Assets.Materials.VerBot); planner.SetMaterial(Application.ResourceCache.GetMaterial(Assets.Materials.VerBot)); var movement = new RepeatForever(new RotateBy(1, 0, 5, 0)); plannerNode.RunActionsAsync(movement); // Lights: var _lightNode = _scene.CreateChild(); _lightNode.Position = new Vector3(0.0f, 0f, -5.0f); var light = _lightNode.CreateComponent <Light>(); light.Range = 1200; light.Brightness = 2; if (ResultString != "") { Text ResultText = new Text(); ResultText.HorizontalAlignment = HorizontalAlignment.Center; ResultText.VerticalAlignment = VerticalAlignment.Center; ResultText.Value = ResultString; ResultText.SetFont(Application.ResourceCache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 20); Application.UI.Root.AddChild(ResultText); } Text WelcomeText = new Text(); WelcomeText.HorizontalAlignment = HorizontalAlignment.Center; WelcomeText.VerticalAlignment = VerticalAlignment.Center; WelcomeText.Position = new IntVector2(WelcomeText.Position.X, 150); WelcomeText.Value = WelcomeString; WelcomeText.SetFont(Application.ResourceCache.GetFont(Assets.Fonts.Font), Application.Graphics.Width / 20); Application.UI.Root.AddChild(WelcomeText); }