Example #1
0
        /// <summary>
        /// Draws a reflection of a texture
        /// </summary>
        /// <param name="Texture">The texture of which a reflection should be drawn</param>
        /// <param name="rect">A SRectF struct containing the destination coordinates</param>
        /// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
        /// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
        /// <param name="space">The space between the texture and the reflection</param>
        /// <param name="height">The height of the reflection</param>
        public void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height)
        {
            if (_TextureExists(ref Texture))
            {
                if (_D3DTextures[Texture.index] == null)
                    return;

                if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f)
                    return;

                if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X)
                    return;

                if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y)
                    return;

                if (height > bounds.H)
                    height = bounds.H;

                if (_TextureExists(ref Texture))
                {
                    float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
                    float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
                    float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio;
                    float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio;

                    if (x1 < 0)
                        x1 = 0f;

                    if (x2 > Texture.width_ratio)
                        x2 = Texture.width_ratio;

                    if (y1 < 0)
                        y1 = 0f;

                    if (y2 > Texture.height_ratio)
                        y2 = Texture.height_ratio;

                    float rx1 = rect.X;
                    float rx2 = rect.X + rect.W;
                    float ry1 = rect.Y + rect.H + space;
                    float ry2 = rect.Y + rect.H + space + height;

                    if (rx1 < bounds.X)
                        rx1 = bounds.X;

                    if (rx2 > bounds.X + bounds.W)
                        rx2 = bounds.X + bounds.W;

                    if (ry1 < bounds.Y + space)
                        ry1 = bounds.Y + space;

                    if (ry2 > bounds.Y + bounds.H + space + height)
                        ry2 = bounds.Y + bounds.H + space + height;

                    //Align the pixels because Direct3D expects the pixels to be the left top corner
                    rx1 -= 0.5f;
                    ry1 -= 0.5f;
                    rx2 -= 0.5f;
                    ry2 -= 0.5f;

                    Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));
                    Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));

                    TexturedColoredVertex[] vert = new TexturedColoredVertex[4];
                    vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
                    vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb());
                    vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb());
                    vert[3] = new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
                    AddToVertexBuffer(vert, _D3DTextures[Texture.index], CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
                }
            }
        }
Example #2
0
        /// <summary>
        /// Draws a texture
        /// </summary>
        /// <param name="Texture">The texture to be drawn</param>
        /// <param name="rect">A SRectF struct containing the destination coordinates</param>
        /// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
        /// <param name="bounds">A SRectF struct containing which part of the texture should be drawn</param>
        /// <param name="mirrored">True if the texture should be mirrored</param>
        public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored)
        {
            if (_TextureExists(ref Texture))
            {
                if (_D3DTextures[Texture.index] == null)
                    return;

                //Calculate the position
                float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio;
                float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio;
                float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio;
                float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio;

                if (x1 < 0)
                    x1 = 0f;

                if (x2 > Texture.width_ratio)
                    x2 = Texture.width_ratio;

                if (y1 < 0)
                    y1 = 0f;

                if (y2 > Texture.height_ratio)
                    y2 = Texture.height_ratio;

                //Calculate the size
                float rx1 = rect.X;
                float rx2 = rect.X + rect.W;
                float ry1 = rect.Y;
                float ry2 = rect.Y + rect.H;

                if (rx1 < bounds.X)
                    rx1 = bounds.X;

                if (rx2 > bounds.X + bounds.W)
                    rx2 = bounds.X + bounds.W;

                if (ry1 < bounds.Y)
                    ry1 = bounds.Y;

                if (ry2 > bounds.Y + bounds.H)
                    ry2 = bounds.Y + bounds.H;

                //Align the pixels because Direct3D expects the pixels to be the left top corner
                rx1 -= 0.5f;
                ry1 -= 0.5f;
                rx2 -= 0.5f;
                ry2 -= 0.5f;

                if (color.A > 1)
                    color.A = 1;
                if (color.R > 1)
                    color.R = 1;
                if (color.G > 1)
                    color.G = 1;
                if (color.B > 1)
                    color.B = 1;

                Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));

                if (!mirrored)
                {
                    TexturedColoredVertex[] vert = new TexturedColoredVertex[4];
                    vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb());
                    vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
                    vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
                    vert[3] = new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb());
                    AddToVertexBuffer(vert, _D3DTextures[Texture.index], CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
                }
                else
                {
                    TexturedColoredVertex[] vert = new TexturedColoredVertex[4];
                    vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb());
                    vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb());
                    vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb());
                    vert[3] = new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y1), c.ToArgb());
                    AddToVertexBuffer(vert, _D3DTextures[Texture.index], CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
                }
            }
        }
Example #3
0
        /// <summary>
        /// Draws a texture
        /// </summary>
        /// <param name="Texture">The texture to be drawn</param>
        /// <param name="rect">A SRectF struct containing the destination coordinates</param>
        /// <param name="color">A SColorF struct containing a color which the texture will be colored in</param>
        /// <param name="begin">A Value ranging from 0 to 1 containing the beginning of the texture</param>
        /// <param name="end">A Value ranging from 0 to 1 containing the ending of the texture</param>
        public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end)
        {
            if (_TextureExists(ref Texture))
            {
                if (_D3DTextures[Texture.index] == null)
                    return;

                float x1 = 0f + begin * Texture.width_ratio;
                float x2 = Texture.width_ratio * end;
                float y1 = 0f;
                float y2 = Texture.height_ratio;

                float rx1 = rect.X + begin * rect.W;
                float rx2 = rect.X + end * rect.W;
                float ry1 = rect.Y;
                float ry2 = rect.Y + rect.H;

                //Align the pixels because Direct3D expects the pixels to be the left top corner
                rx1 -= 0.5f;
                ry1 -= 0.5f;
                rx2 -= 0.5f;
                ry2 -= 0.5f;

                Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255));

                TexturedColoredVertex[] vert = new TexturedColoredVertex[4];
                vert[0] = new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb());
                vert[1] = new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb());
                vert[2] = new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb());
                vert[3] = new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb());
                AddToVertexBuffer(vert, _D3DTextures[Texture.index], CalculateRotationMatrix(rect.Rotation, rx1, rx2, ry1, ry2));
            }
        }
Example #4
0
 /// <summary>
 /// Adds a quad a list which will be added and rendered to the vertexbuffer when calling RenderToVertexBuffer to reduce vertexbuffer calls each frame to a minimum
 /// </summary>
 /// <param name="vertices">A TexturedColoredVertex array containg 4 vertices</param>
 /// <param name="tex">The texture the vertex should be textured with</param>
 /// <param name="rotation">The vertices' rotation</param>
 private void AddToVertexBuffer(TexturedColoredVertex[] vertices, Texture tex, Matrix rotation)
 {
     //The vertexbuffer is full, so we need to flush it before we can continue
     if (_Vertices.Count >= CSettings.iVertexBufferElements)
         RenderVertexBuffer();
     _Vertices.Enqueue(vertices[0]);
     _Vertices.Enqueue(vertices[1]);
     _Vertices.Enqueue(vertices[2]);
     _Vertices.Enqueue(vertices[3]);
     _VerticesTextures.Enqueue(tex);
     _VerticesRotationMatrices.Enqueue(rotation);
 }