Ejemplo n.º 1
0
        private void DrawTexture(IGameObject o, ref Matrix parentTransformation)
        {
            Vector2 position = new Vector2((float)o.Position.X, (float)o.Position.Y);
            Vector2 scale    = new Vector2((float)o.Size.X, (float)o.Size.Y);
            float   rotation = o.RotateImage ? (float)o.Angle.Radians : 0;

            if (o.IsVisible)
            {
                if (o.TextureWrapSize == Vector.Diagonal)
                {
                    Graphics.ImageBatch.Draw(defaultCoords, position, scale, rotation);
                }
                else
                {
                    float wx     = (float)(Math.Sign(o.TextureWrapSize.X));
                    float wy     = (float)(Math.Sign(o.TextureWrapSize.Y));
                    float left   = (float)(-wx / 2 + 0.5);
                    float right  = (float)(wx / 2 + 0.5);
                    float top    = (float)(-wy / 2 + 0.5);
                    float bottom = (float)(wy / 2 + 0.5);

                    TextureCoordinates customCoords = new TextureCoordinates()
                    {
                        TopLeft     = new Vector2(left, top),
                        TopRight    = new Vector2(right, top),
                        BottomLeft  = new Vector2(left, bottom),
                        BottomRight = new Vector2(right, bottom),
                    };

                    if (o.TextureWrapSize.X == wx && o.TextureWrapSize.Y == wy)
                    {
                        // Draw only once
                        Graphics.ImageBatch.Draw(customCoords, position, scale, rotation);
                        return;
                    }

                    float topLeftX = -(float)(o.TextureWrapSize.X - 1) / 2;
                    float topLeftY = -(float)(o.TextureWrapSize.Y - 1) / 2;

                    Vector2 newScale = new Vector2(
                        scale.X / (wx * (float)o.TextureWrapSize.X),
                        scale.Y / (wy * (float)o.TextureWrapSize.Y));

                    for (int y = 0; y < o.TextureWrapSize.Y; y++)
                    {
                        for (int x = 0; x < o.TextureWrapSize.X; x++)
                        {
                            Vector2 newPosition = position + new Vector2((topLeftX + x) * newScale.X, (topLeftY + y) * newScale.Y);
                            Graphics.ImageBatch.Draw(customCoords, newPosition, newScale, rotation);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Draw(TextureCoordinates c, Vector2 position, Vector2 size, float angle)
        {
            Debug.Assert(beginHasBeenCalled);

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

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

            Vector3[] transformedPoints = new Vector3[VerticesPerTexture];
            Vector3.Transform(Vertices, ref matrix, transformedPoints);

            int startIndex = (iTexture * VerticesPerTexture);

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

            // Triangle 1
            vertexBuffer[startIndex + 0].TextureCoordinate = c.TopLeft;
            vertexBuffer[startIndex + 1].TextureCoordinate = c.BottomLeft;
            vertexBuffer[startIndex + 2].TextureCoordinate = c.TopRight;

            // Triangle 2
            vertexBuffer[startIndex + 3].TextureCoordinate = c.BottomLeft;
            vertexBuffer[startIndex + 4].TextureCoordinate = c.BottomRight;
            vertexBuffer[startIndex + 5].TextureCoordinate = c.TopRight;

            iTexture++;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Piirtää kuvan
 /// </summary>
 /// <param name="parentTransformation"></param>
 /// <param name="texture"></param>
 /// <param name="tex"></param>
 /// <param name="position"></param>
 /// <param name="size"></param>
 /// <param name="angle"></param>
 public static void DrawImage(Matrix parentTransformation, Image texture, TextureCoordinates tex, Vector position, Vector size, float angle)
 {
     Graphics.CustomBatch.AddImage(parentTransformation, texture, tex, position, size, angle);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Piirtää kuvan
 /// </summary>
 /// <param name="matrix">Transformaatiomatriisi</param>
 /// <param name="texture">Tekstuuri</param>
 /// <param name="texCoords">Tekstuurikoordinaatit alueesta joka piirretään. Voit käyttää suoraan <c>new TextureCoordinates()</c> jos koko kuva piirretään.</param>
 /// <param name="position">Sijainti</param>
 /// <param name="size">Koko</param>
 /// <param name="angle">Kulma</param>
 /// <param name="shader">Piirtoon käytettävä shader</param>
 public static void DrawImage(Matrix matrix, Image texture, TextureCoordinates texCoords, Vector position, Vector size, float angle, IShader shader)
 {
     Graphics.CustomBatch.AddShader(matrix, shader, texture, texCoords, position, size, angle);
 }