Beispiel #1
0
        public void DrawOutlines(ShapeCache cache, Color color, Vector position, Vector size, float angle)
        {
            if ((iVertexBuffer + cache.Vertices.Length) > vertexBuffer.Length || (iIndexBuffer + cache.Triangles.Length) > indexBuffer.Length)
            {
                Flush();
            }

            Matrix matrix =
                Matrix.CreateScale((float)size.X, (float)size.Y, 1f)
                * Matrix.CreateRotationZ(angle)
                * Matrix.CreateTranslation((float)position.X, (float)position.Y, 0);

            uint startIndex = iVertexBuffer;

            for (int i = 0; i < cache.Vertices.Length; i++)
            {
                Vector v = cache.Vertices[i];
                vertexBuffer[iVertexBuffer++] = new VertexPositionColorTexture(Vector3.Transform(new Vector3((float)v.X, (float)v.Y, 0), matrix), color, Vector.Zero);
            }

            for (int i = 0; i < cache.OutlineIndices.Length - 1; i++)
            {
                indexBuffer[iIndexBuffer++] = (uint)cache.OutlineIndices[i] + startIndex;
                indexBuffer[iIndexBuffer++] = (uint)cache.OutlineIndices[i + 1] + startIndex;
            }

            indexBuffer[iIndexBuffer++] = (uint)cache.OutlineIndices[^ 1] + startIndex;
Beispiel #2
0
        internal void Draw(Camera camera)
        {
            var zoomMatrix  = IgnoresZoom ? Matrix.Identity : Matrix.CreateScale((float)(camera.ZoomFactor), (float)(camera.ZoomFactor), 1f);
            var worldMatrix =
                Matrix.CreateTranslation((float)(-camera.Position.X * RelativeTransition.X), (float)(-camera.Position.Y * RelativeTransition.Y), 0)
                * zoomMatrix;

            SortObjects();

            switch (DrawOrder)
            {
            case DrawOrder.Irrelevant:
                DrawEfficientlyInNoParticularOrder(ref worldMatrix);
                break;

            case DrawOrder.FirstToLast:
                DrawInOrderFromFirstToLast(ref worldMatrix);     // TODO: Halutaanko tätä vaihtoehtoa enää säilyttää, jos piirtojärjestykseen halutaan vaikuttaa, olisi layerit oikea vaihtoehto.
                break;

            default:
                break;
            }

            Effects.ForEach(e => e.Draw(worldMatrix));

            if (Grid != null)
            {
                DrawGrid(ref worldMatrix);
            }
        }
Beispiel #3
0
 public static NMatrix GetNMatrix(this FLVER.Bone b)
 {
     return(NMatrix.CreateScale(b.Scale) *
            NMatrix.CreateRotationX(b.Rotation.X) *
            NMatrix.CreateRotationZ(b.Rotation.Z) *
            NMatrix.CreateRotationY(b.Rotation.Y) *
            NMatrix.CreateTranslation(b.Translation));
 }
Beispiel #4
0
        public void Draw(Image img, Vector2 position, System.Drawing.Rectangle?sourceRectangle, System.Drawing.Color color, Vector2 scale, float angle, Vector2 origin)
        {
            Debug.Assert(beginHasBeenCalled);

            if (iTexture >= BufferSize)
            {
                Flush();
            }

            texture = img;
            float iw = img.Width;
            float ih = img.Height;

            System.Drawing.Rectangle rect = sourceRectangle.Value;

            Vector transf = new Vector(position.X - origin.X * scale.X + (float)rect.Width / 2 * scale.X, position.Y + origin.Y * scale.Y - (float)rect.Height / 2 * scale.Y);

            Matrix matrix =
                Matrix.CreateScale(scale.X * rect.Width, scale.Y * rect.Height, 1f)
                * Matrix.CreateRotationZ(angle)
                * Matrix.CreateTranslation((float)transf.X, (float)transf.Y, 0);

            Vector3[] transformedPoints = new Vector3[VerticesPerTexture];
            for (int i = 0; i < transformedPoints.Length; i++)
            {
                transformedPoints[i] = Vector3.Transform(Vertices[i], matrix);
            }

            uint startIndex = (iTexture * VerticesPerTexture);

            for (int i = 0; i < VerticesPerTexture; i++)
            {
                uint bi = (uint)((iTexture * VerticesPerTexture) + i);
                vertexBuffer[bi].Position = transformedPoints[i];
            }

            // Triangle 1
            vertexBuffer[startIndex + 0].TexCoords = new Vector2(rect.Left / iw, rect.Top / ih);
            vertexBuffer[startIndex + 0].SetColor(color);
            vertexBuffer[startIndex + 1].TexCoords = new Vector2(rect.Left / iw, rect.Bottom / ih);
            vertexBuffer[startIndex + 1].SetColor(color);
            vertexBuffer[startIndex + 2].TexCoords = new Vector2(rect.Right / iw, rect.Top / ih);
            vertexBuffer[startIndex + 2].SetColor(color);

            // Triangle 2
            vertexBuffer[startIndex + 3].TexCoords = new Vector2(rect.Left / iw, rect.Bottom / ih);
            vertexBuffer[startIndex + 3].SetColor(color);
            vertexBuffer[startIndex + 4].TexCoords = new Vector2(rect.Right / iw, rect.Bottom / ih);
            vertexBuffer[startIndex + 4].SetColor(color);
            vertexBuffer[startIndex + 5].TexCoords = new Vector2(rect.Right / iw, rect.Top / ih);
            vertexBuffer[startIndex + 5].SetColor(color);

            iTexture++;
        }
Beispiel #5
0
        public void Draw(TextureCoordinates c, Vector position, Vector size, float angle)
        {
            Debug.Assert(beginHasBeenCalled);

            if (iTexture >= BufferSize)
            {
                Flush();
            }

            Matrix matrix =
                Matrix.CreateScale((float)size.X, (float)size.Y, 1f)
                * Matrix.CreateRotationZ(angle)
                * Matrix.CreateTranslation((float)position.X, (float)position.Y, 0);

            Vector3[] transformedPoints = new Vector3[VerticesPerTexture];
            for (int i = 0; i < transformedPoints.Length; i++)
            {
                transformedPoints[i] = Vector3.Transform(Vertices[i], matrix);
            }

            uint startIndex = (iTexture * VerticesPerTexture);

            for (int i = 0; i < VerticesPerTexture; i++)
            {
                uint bi = (uint)((iTexture * VerticesPerTexture) + i);
                vertexBuffer[bi].Position = transformedPoints[i];
            }

            var color = System.Drawing.Color.FromArgb(255, 255, 255, 255);

            // Triangle 1
            vertexBuffer[startIndex + 0].TexCoords = new Vector2((float)c.TopLeft.X, (float)c.TopLeft.Y);
            vertexBuffer[startIndex + 0].SetColor(color);
            vertexBuffer[startIndex + 1].TexCoords = new Vector2((float)c.BottomLeft.X, (float)c.BottomLeft.Y);
            vertexBuffer[startIndex + 1].SetColor(color);
            vertexBuffer[startIndex + 2].TexCoords = new Vector2((float)c.TopRight.X, (float)c.TopRight.Y);
            vertexBuffer[startIndex + 2].SetColor(color);

            // Triangle 2
            vertexBuffer[startIndex + 3].TexCoords = new Vector2((float)c.BottomLeft.X, (float)c.BottomLeft.Y);
            vertexBuffer[startIndex + 3].SetColor(color);
            vertexBuffer[startIndex + 4].TexCoords = new Vector2((float)c.BottomRight.X, (float)c.BottomRight.Y);
            vertexBuffer[startIndex + 4].SetColor(color);
            vertexBuffer[startIndex + 5].TexCoords = new Vector2((float)c.TopRight.X, (float)c.TopRight.Y);
            vertexBuffer[startIndex + 5].SetColor(color);

            iTexture++;
        }
Beispiel #6
0
        internal void DrawOutlines(Camera camera, Color outlineColor, Type type)
        {
            var zoomMatrix  = IgnoresZoom ? Matrix.Identity : Matrix.CreateScale((float)(camera.ZoomFactor), (float)(camera.ZoomFactor), 1f);
            var worldMatrix =
                Matrix.CreateTranslation((float)(-camera.Position.X * RelativeTransition.X), (float)(-camera.Position.Y * RelativeTransition.Y), 0)
                * zoomMatrix;

            Graphics.ShapeBatch.Begin(ref worldMatrix, PrimitiveType.OpenGLLines);

            // TODO: Millainen tämä ratkaisu tyyppien suhteen on suorituskyvyn kannalta?
            foreach (var o in Objects.Where(type.IsInstanceOfType))
            {
                if (o.Shape.Cache.Triangles is not null)
                {
                    Graphics.ShapeBatch.DrawOutlines(o.Shape.Cache, outlineColor, o.Position, o.Size, (float)o.Angle.Radians);
                }
            }
            Graphics.ShapeBatch.End();
        }
Beispiel #7
0
        private static void Draw(IGameObject o, ref Matrix parentTransformation)
        {
            Vector drawScale = new Vector(1, 1);

            if (o.Shape.IsUnitSize)
            {
                drawScale = o.Size;
            }

            Vector position = new Vector((float)o.Position.X, (float)o.Position.Y);
            Vector scale    = new Vector((float)drawScale.X, (float)drawScale.Y);
            float  rotation = o.RotateImage ? (float)o.Angle.Radians : 0;

            if (o.IsVisible)
            {
                Matrix transformation =
                    Matrix.CreateScale((float)scale.X, (float)scale.Y, 1f)
                    * Matrix.CreateRotationZ(rotation)
                    * Matrix.CreateTranslation((float)position.X, (float)position.Y, 0f)
                    * parentTransformation;

                if (o is CustomDrawable drawable)
                {
                    drawable.Draw(parentTransformation);
                }
                else if (o.Image != null && (!o.TextureFillsShape))
                {
                    // TODO: TextureFillsShape kuntoon
                    Renderer.DrawImage(parentTransformation, o.Image, Graphics.DefaultTextureCoords, o.Position, o.Size, (float)o.Angle.Radians);
                }
                else if (o.Image != null)
                {
                    Renderer.DrawShape(o.Shape, ref transformation, ref transformation, o.Image, o.TextureWrapSize, o.Color);
                }
                else
                {
                    DrawShape(o, ref parentTransformation);
                }
            }
        }
Beispiel #8
0
        /// <inheritdoc/>
        public override void Draw(Matrix parentTransformation, Matrix transformation)
        {
            if (_indexDelta == 0)
            {
                base.Draw(parentTransformation, transformation);
                return;
            }

            int    indexDeltaInt = (int)Math.Round(_indexDelta);
            double yDelta        = _indexDelta - indexDeltaInt; // for smooth scrolling

            for (int i = -1; i <= 1; i++)
            {
                Matrix m = Matrix.CreateScale((float)TextScale.X, (float)TextScale.Y, 1)
                           * Matrix.CreateRotationZ((float)Angle.Radians)
                           * Matrix.CreateTranslation((float)Position.X, (float)(Position.Y - (i - yDelta) * TextSize.Y), 0)
                           * parentTransformation;

                int ci = AdvMod(this.SelectedIndex + indexDeltaInt + i, this.Charset.Length);
                //Renderer.DrawText( Charset[ci].ToString(), ref m, Font, TextColor );
            }
        }
Beispiel #9
0
        protected void Draw(Time gameTime)
        {
            UpdateFps(gameTime);
            GraphicsDevice.SetRenderTarget(Screen.RenderTarget);
            GraphicsDevice.Clear(Level.BackgroundColor);

            if (Level.Background.Image != null && !Level.Background.MovesWithCamera)
            {
                GraphicsDevice.BindTexture(Level.Background.Image);

                Graphics.BasicTextureShader.Use();
                Graphics.BasicTextureShader.SetUniform("world", Matrix.Identity);

                GraphicsDevice.DrawPrimitives(Rendering.PrimitiveType.OpenGlTriangles, Graphics.TextureVertices, 6, true);
            }

            // The world matrix adjusts the position and size of objects according to the camera angle.
            var worldMatrix =
                Matrix.CreateTranslation((float)-Camera.Position.X, (float)-Camera.Position.Y, 0)
                * Matrix.CreateScale((float)Camera.ZoomFactor, (float)Camera.ZoomFactor, 1f);

            // If the background should move with camera, draw it here.
            Level.Background.Draw(worldMatrix, Matrix.Identity);

            // Draw the layers containing the GameObjects
            DynamicLayers.ForEach(l => l.Draw(Camera));

            // TODO: Tätä ei tarvitsisi tehdä, jos valoja ei käytetä.
            // Yhdistetään valotekstuuri ja objektien tekstuuri.
            GraphicsDevice.DrawLights(worldMatrix);

            // Piirretään käyttöliittymäkomponentit valojen päälle
            StaticLayers.ForEach(l => l.Draw(Camera));

            // Draw on the canvas
            Graphics.Canvas.Begin(ref worldMatrix, Level);
            Paint(Graphics.Canvas);
            Graphics.Canvas.End();

            // Draw the debug information screen
            DrawDebugScreen();

            // Render the scene on screen
            Screen.Render();

            if (SaveOutput)
            {
                if (FrameCounter != 0) // Ekaa framea ei voi tallentaa?
                {
                    if (skipcounter == 0)
                    {
                        Screencap.SaveBmp(CurrentFrameStream);
                        skipcounter = FramesToSkip;
                        SavedFrameCounter++;
                    }
                    else
                    {
                        skipcounter--;
                    }
                }
            }

            if (TotalFramesToRun != 0 && FrameCounter == TotalFramesToRun)
            {
                OnExiting(this, EventArgs.Empty);
                //UnloadContent();
                Exit();
            }

            FrameCounter++;
        }