Ejemplo n.º 1
0
        /// <summary>
        /// Function to draw the camera icon.
        /// </summary>
        public void Draw()
        {
            var     position = new Vector3(-_position.X, -_position.Y, 0);
            Vector3 iconPosition;

            Unproject(ref position, out iconPosition);      // Convert to screen space.

            // Update the position to be projected into the current camera space.
            if (Gorgon2D.Camera != this)
            {
                Vector3.Negate(ref iconPosition, out iconPosition);
                iconPosition.Z = (Gorgon2D.Camera.MaximumDepth - Gorgon2D.Camera.MinimumDepth) / Gorgon2D.Camera.MinimumDepth;
                Gorgon2D.Camera.Project(ref iconPosition, out iconPosition, false);

                // Now update that position to reflect in screen space relative to our current camera.
                // We do this without the view transform because we only want to undo the projection and
                // not the camera transformation.
                Gorgon2D.Camera.Unproject(ref iconPosition, out iconPosition);
            }

            // Project back to the default camera.
            iconPosition = Gorgon2D.DefaultCamera.Project(iconPosition);

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if ((Gorgon2D.DefaultCamera.Zoom.X != 1.0f) ||
                (Gorgon2D.DefaultCamera.Zoom.Y != 1.0f))
            {
                _cameraIcon.Scale = new Vector2(1.0f / Gorgon2D.DefaultCamera.Zoom.X,
                                                1.0f / Gorgon2D.DefaultCamera.Zoom.Y);
            }
            // ReSharper restore CompareOfFloatsByEqualityOperator

            // Highlight current camera.
            _cameraIcon.Color = Gorgon2D.Camera == this ? Color.FromArgb(204, Color.Green) : Color.FromArgb(204, Color.White);

            _cameraIcon.Position = (Vector2)iconPosition;
            _cameraIcon.Angle    = -Gorgon2D.DefaultCamera.Angle;

            // Draw the icon in our camera space, otherwise it won't look right.
            var prevCamera = Gorgon2D.Camera;

            if (prevCamera != Gorgon2D.DefaultCamera)
            {
                Gorgon2D.Camera = null;
            }

            _cameraIcon.Draw();

            if (prevCamera == Gorgon2D.DefaultCamera)
            {
                return;
            }

            Gorgon2D.Camera = prevCamera;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to render the scene and draw the Gorgon logo at the bottom-right of the screen.
        /// </summary>
        private void RenderWithLogo()
        {
            I2DCamera      camera           = _camera;
            GorgonViewport?previousViewport = _viewPort;
            Rectangle?     previousClip     = _clip;

            // Reset any view/projection/clip/viewport.
            // This will force a flush of the pipeline before drawing the logo.
            // If none of these values have changed, the the flush will be
            // peformed when we draw the logo (due to a texture switch).
            if (_camera != null)
            {
                Camera = null;
            }

            if (_viewPort != null)
            {
                Viewport = null;
            }

            if (_clip != null)
            {
                ClipRegion = null;
            }

            _logoSprite.Position = new Vector2(_currentTarget.Width, _currentTarget.Height);
            _logoSprite.Draw();

            // This flush will force the logo to appear.
            Flush();

            // Restore the active camera, viewport and clipping region.
            if (camera != null)
            {
                Camera = camera;
            }

            if (previousViewport != null)
            {
                Viewport = previousViewport;
            }

            if (previousClip != null)
            {
                ClipRegion = previousClip;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Function to render a pass.
        /// </summary>
        /// <param name="pass">Pass that is to be rendered.</param>
        protected override void OnRenderPass(GorgonEffectPass pass)
        {
            Gorgon2D.Target = _hTarget;

            // Render horizontal pass.
            _hTarget.Clear(GorgonColor.Transparent);
            _blurBuffer.Update(_xOffsets);

            // Render the scene.
            pass.RenderAction(pass);

            // Render vertical pass.
            Gorgon2D.Target = _vTarget;
            _blurBuffer.Update(_yOffsets);

            _blurSprite.Draw();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Function called when the effect is being initialized.
        /// </summary>
        /// <remarks>
        /// Use this method to set up the effect upon its creation.  For example, this method could be used to create the required shaders for the effect.
        /// </remarks>
        protected override void OnInitialize()
        {
            base.OnInitialize();

            Passes[1].PixelShader = Graphics.ImmediateContext.Shaders.CreateShader <GorgonPixelShader>("Effect.2D.DisplacementDecoder.PS", "GorgonPixelShaderDisplacementDecoder", "#GorgonInclude \"Gorgon2DShaders\"");

            _displacementBuffer = Graphics.ImmediateContext.Buffers.CreateConstantBuffer("Gorgon2DDisplacementEffect Constant Buffer",
                                                                                         new GorgonConstantBufferSettings
            {
                SizeInBytes = 16
            });
            _displacementSprite = Gorgon2D.Renderables.CreateSprite("Gorgon2DDisplacementEffect Sprite", new GorgonSpriteSettings
            {
                Size = new Vector2(1)
            });
            _displacementSprite.BlendingMode  = BlendingMode.None;
            _displacementSprite.SmoothingMode = SmoothingMode.Smooth;

            // Set the drawing for rendering the displacement map.
            Passes[1].RenderAction = pass => _displacementSprite.Draw();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Function to draw a filled rectangle.
        /// </summary>
        private void DrawFilled()
        {
            _filled.AlphaTestValues = AlphaTestValues;
            _filled.Anchor          = Anchor;
            _filled.Angle           = Angle;
            _filled.SetCornerColor(RectangleCorner.UpperLeft, _colors[0]);
            _filled.SetCornerColor(RectangleCorner.UpperRight, _colors[1]);
            _filled.SetCornerColor(RectangleCorner.LowerLeft, _colors[2]);
            _filled.SetCornerColor(RectangleCorner.LowerRight, _colors[3]);
            _filled.CullingMode    = CullingMode;
            _filled.Depth          = Depth;
            _filled.Position       = Rectangle.Location;
            _filled.Size           = Rectangle.Size;
            _filled.Texture        = Texture;
            _filled.TextureRegion  = TextureRegion;
            _filled.Blending       = Blending;
            _filled.DepthStencil   = DepthStencil;
            _filled.TextureSampler = TextureSampler;

            _filled.Draw();
        }