Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            UpdateCamera();

            if (Map.CursorPositionVisible.X < 0)
            {
                Camera.CameraHeight   = 600;
                Camera.CameraDistance = 500;
                Camera.SetTarget(new Vector3(Map.TileSize.X * Map.MapSize.X / 2, Map.CursorPosition.Z * 32, Map.TileSize.Y * Map.MapSize.Y / 2));
                Camera.Update(gameTime);
                return;
            }

            Camera.CameraHeight   = 400;
            Camera.CameraDistance = 300;
            int          X               = (int)Map.CursorPositionVisible.X;
            int          Y               = (int)Map.CursorPositionVisible.Y;
            float        Z               = Map.LayerManager.ListLayer[(int)Map.CursorPosition.Z].ArrayTerrain[X, Y].Position.Z * 32 + (Map.CursorPosition.Z * 32) + 0.3f;
            Map2D        GroundLayer     = Map.LayerManager.ListLayer[(int)Map.CursorPosition.Z].LayerGrid;
            DrawableTile ActiveTerrain   = GroundLayer.GetTile(X, Y);
            Terrain3D    ActiveTerrain3D = ActiveTerrain.Terrain3DInfo;

            Cursor = ActiveTerrain3D.CreateTile3D(0, Point.Zero,
                                                  X * Map.TileSize.X, Y * Map.TileSize.Y, Z, Map.CursorPosition.Z * 32 + 0.3f, Map.TileSize, new List <Texture2D>()
            {
                sprCursor
            }, Z, Z, Z, Z, 0)[0];

            Camera.SetTarget(new Vector3(Map.TileSize.X * Map.CursorPositionVisible.X, Map.CursorPosition.Z * 32, Map.TileSize.Y * Map.CursorPositionVisible.Y));
            Camera.Update(gameTime);

            DicDrawablePointPerColor.Clear();
            ListDrawableArrowPerColor.Clear();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to set up the renderers initial state.
        /// </summary>
        private void SetDefaultStates()
        {
            // Add shader includes if they're gone.
            if (!Graphics.Shaders.IncludeFiles.Contains("Gorgon2DShaders"))
            {
                Graphics.Shaders.IncludeFiles.Add("Gorgon2DShaders", Encoding.UTF8.GetString(Resources.BasicSprite));
            }

            // Record the initial state before set up.
            if (_initialState == null)
            {
                _initialState = new Gorgon2DStateRecall(this);
            }

            // Reset the cache values.
            _cache.Reset();

            // Set our default shaders.
            VertexShader.Current            = VertexShader.DefaultVertexShader;
            PixelShader.Current             = PixelShader.DefaultPixelShaderDiffuse;
            Graphics.Input.IndexBuffer      = DefaultIndexBuffer;
            Graphics.Input.VertexBuffers[0] = DefaultVertexBufferBinding;
            Graphics.Input.Layout           = DefaultLayout;
            Graphics.Input.PrimitiveType    = PrimitiveType.TriangleList;

            IsMultisamplingEnabled = Graphics.Rasterizer.States.IsMultisamplingEnabled;

            if (PixelShader != null)
            {
                GorgonTextureSamplerStates sampler = GorgonTextureSamplerStates.LinearFilter;
                sampler.TextureFilter = TextureFilter.Point;
                Graphics.Shaders.PixelShader.TextureSamplers[0] = sampler;
                Graphics.Shaders.PixelShader.Resources[0]       = null;
            }

            Graphics.Rasterizer.States                         = GorgonRasterizerStates.CullBackFace;
            Graphics.Output.BlendingState.States               = GorgonBlendStates.DefaultStates;
            Graphics.Output.DepthStencilState.States           = GorgonDepthStencilStates.NoDepthStencil;
            Graphics.Output.DepthStencilState.StencilReference = 0;
            Graphics.Output.SetRenderTarget(_defaultTarget.Target, _defaultTarget.DepthStencil);

            _currentTarget = _defaultTarget;

            UpdateTarget(ref _currentTarget);

            DefaultCamera.Update();

            // Get the current state.
            DefaultState = new Gorgon2DStateRecall(this);

            // By default, turn on multi sampling over a count of 1.
            if (Target.Resource.ResourceType != ResourceType.Texture2D)
            {
                return;
            }

            var target2D = (GorgonRenderTarget2D)Target.Resource;

            if ((!IsMultisamplingEnabled) &&
                ((target2D.Settings.Multisampling.Count > 1) || (target2D.Settings.Multisampling.Quality > 0)) &&
                ((Graphics.VideoDevice.SupportedFeatureLevel == DeviceFeatureLevel.SM4_1) ||
                 (Graphics.VideoDevice.SupportedFeatureLevel == DeviceFeatureLevel.SM5)))
            {
                _multiSampleEnable = true;
            }
        }