示例#1
0
        public override void Start()
        {
            Art.Load();

            var graphics = AtomicNET.GetSubsystem<Graphics>();
            float width = graphics.Width;
            float height = graphics.Height;

            ScreenSize = new Vector2(width, height);
            ScreenBounds = new IntRect(0, 0, (int)ScreenSize.X, (int)ScreenSize.Y);

            var renderer = AtomicNET.GetSubsystem<Renderer>();
            var viewport = renderer.GetViewport(0);

            renderer.HDRRendering = true;

            var renderpath = viewport.GetRenderPath().Clone();
            renderpath.Append(AtomicNET.Cache.GetResource<XMLFile>("RenderPath/BloomHDR.xml"));
            renderpath.Append(AtomicNET.Cache.GetResource<XMLFile>("RenderPath/Blur.xml"));
            viewport.SetRenderPath(renderpath);

            Scene = new Scene();
            Scene.CreateComponent<Octree>();

            var camera = Scene.CreateChild("Camera").CreateComponent<Camera>();
            camera.Node.Position = new Vector3(width / 2.0f, height / 2.0f, 0.0f);
            camera.Orthographic = true;
            camera.OrthoSize = height;

            viewport.Scene = Scene;
            viewport.Camera = camera;

            CustomRenderer.Initialize();

            ParticleManager = new ParticleManager<ParticleState>(1024 * 20, ParticleState.UpdateParticle);

            #if ATOMIC_DESKTOP
            const int maxGridPoints = 1600;
            #else
            const int maxGridPoints = 400;
            #endif

            float amt = (float)Math.Sqrt(ScreenBounds.Width * ScreenBounds.Height / maxGridPoints);
            Vector2 gridSpacing = new Vector2(amt, amt);

            IntRect expandedBounds = ScreenBounds;
            expandedBounds.Inflate((int)gridSpacing.X, (int)gridSpacing.Y);
            Grid = new Grid(expandedBounds, gridSpacing);

            EntityManager.Add(PlayerShip.Instance);

            SubscribeToEvent("Update", HandleUpdate);
            SubscribeToEvent("RenderPathEvent", HandleRenderPathEvent);
        }
示例#2
0
        public Grid(IntRect size, Vector2 spacing)
        {
            var springList = new List<Spring>();

            int numColumns = (int)(size.Width / spacing.X) + 1;
            int numRows = (int)(size.Height / spacing.Y) + 1;
            points = new PointMass[numColumns, numRows];

            // these fixed points will be used to anchor the grid to fixed positions on the screen
            PointMass[,] fixedPoints = new PointMass[numColumns, numRows];

            // create the point masses
            int column = 0, row = 0;
            for (float y = size.Top; y <= size.Bottom; y += spacing.Y)
            {
                for (float x = size.Left; x <= size.Right; x += spacing.X)
                {
                    points[column, row] = new PointMass(new Vector3(x, y, 0), 1);
                    fixedPoints[column, row] = new PointMass(new Vector3(x, y, 0), 0);
                    column++;
                }
                row++;
                column = 0;
            }

            // link the point masses with springs
            for (int y = 0; y < numRows; y++)
                for (int x = 0; x < numColumns; x++)
                {
                    if (x == 0 || y == 0 || x == numColumns - 1 || y == numRows - 1)    // anchor the border of the grid
                        springList.Add(new Spring(fixedPoints[x, y], points[x, y], 0.1f, 0.1f));
                    else if (x % 3 == 0 && y % 3 == 0)                                  // loosely anchor 1/9th of the point masses
                        springList.Add(new Spring(fixedPoints[x, y], points[x, y], 0.002f, 0.02f));

                    const float stiffness = 0.28f;
                    const float damping = 0.06f;

                    if (x > 0)
                        springList.Add(new Spring(points[x - 1, y], points[x, y], stiffness, damping));
                    if (y > 0)
                        springList.Add(new Spring(points[x, y - 1], points[x, y], stiffness, damping));
                }

            springs = springList.ToArray();
        }
        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);
        }