Пример #1
0
        public unsafe override void Draw(Renderer r, Vertex* vertexData, ref int vertexCount)
        {
            Background layer = r.Backgrounds[0];
            float x = X - layer.HScroll;
            float y = Y - layer.VScroll;
            float x2 = X2 - layer.HScroll;
            float y2 = Y2 - layer.VScroll;

            vertexData[vertexCount].Position.X = x;
            vertexData[vertexCount].Position.Y = y;
            vertexData[vertexCount].Color = new Color4( _a * Color.R, _a * Color.G, _a * Color.B, _a * Color.A);
            vertexCount++;
            vertexData[vertexCount].Position.X = x2;
            vertexData[vertexCount].Position.Y = y2;
            vertexData[vertexCount].Color = new Color4( _a2 * Color.R, _a2 * Color.G, _a2 * Color.B, _a2 * Color.A);
            vertexCount++;
        }
Пример #2
0
        public unsafe override void Draw(Renderer r, Vertex* vertexData, ref int vertexCount)
        {
            float cx = X - r.Backgrounds[0].HScroll;
            float cy = Y - r.Backgrounds[0].VScroll;

            float bbl = cx - Radius - _thickness/2.0f - _aawidth*2.0f;
            float bbr = cx + Radius + _thickness/2.0f + _aawidth*2.0f;
            float bbt = cy - Radius - _thickness/2.0f - _aawidth*2.0f;
            float bbb = cy + Radius + _thickness/2.0f + _aawidth*2.0f;

            int subdivs = 5;

            float suby = bbt;
            float xstep = (bbr-bbl)/subdivs;
            float ystep = (bbb-bbt)/subdivs;
            float halfdiagonal = (float)Math.Sqrt(xstep*xstep+ystep*ystep)*0.5f;

            Vertex* v = &vertexData[vertexCount];

            for(int y = 0; y < subdivs; ++y)
            {
                float subx = bbl;

                for(int x = 0; x < subdivs; ++x)
                {
                    Vector2 subcenter = new Vector2(subx + xstep/2.0f - cx, suby + ystep/2.0f - cy);
                    float subdistance = subcenter.Length;

                    if(Math.Abs(subdistance-Radius) < halfdiagonal)
                    {
                        float subl = subx;
                        float subr = subx+xstep;
                        float subt = suby;
                        float subb = suby+ystep;

                        v->Position.X = v->TexCoord.X = subl;
                        v->Position.Y = v->TexCoord.Y = subt;
                        v->Position.Z = 0.0f;
                        v++;
                        v->Position.X = v->TexCoord.X = subr;
                        v->Position.Y = v->TexCoord.Y = subt;
                        v->Position.Z = 0.0f;
                        v++;
                        v->Position.X = v->TexCoord.X = subr;
                        v->Position.Y = v->TexCoord.Y = subb;
                        v->Position.Z = 0.0f;
                        v++;
                        v->Position.X = v->TexCoord.X = subl;
                        v->Position.Y = v->TexCoord.Y = subb;
                        v->Position.Z = 0.0f;
                        v++;

                        vertexCount += 4;
                    }

                    subx += xstep;
                }

                suby += ystep;
            }
        }
Пример #3
0
        public unsafe override void Draw(Renderer r, Vertex* vertexData, ref int vertexCount)
        {
            SpriteTemplate tmp = Font.Template;

            Tilemap tilemap = r.Tilemaps[tmp.TilemapName];

            if(_text != null)
            for(int i = 0; i < _text.Length; ++i)
            {
                float x = X + _xs[i] - tmp.Offset.X;
                float y = Y - tmp.Offset.Y;
                float width = tmp.Rectangle.Width;
                float height = tmp.Rectangle.Height;

                // Calculate texcoords, with possible animation.
                int tx = tmp.Rectangle.X;
                int ty = tmp.Rectangle.Y;

                int frameOffset = Font.Template.FrameOffset;
                if(frameOffset == 0)
                    frameOffset = Font.Template.Rectangle.Width;

                tx += _indices[i] * frameOffset;

                // If the animation would take us outside the right edge of the
                // texture, start on the next row.
                while (tx + width > tilemap.Width)
                {
                    tx -= (tilemap.Width / frameOffset) * frameOffset;
                    ty += Font.Template.Rectangle.Height;
                }

                float s0 = tx * tilemap.PixelStepX;
                float t0 = ty * tilemap.PixelStepY;
                float s1 = (tx + width) * tilemap.PixelStepX;
                float t1 = (ty + height) * tilemap.PixelStepY;

                vertexData[vertexCount].Position.X = x;
                vertexData[vertexCount].Position.Y = y;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = Color;
                vertexData[vertexCount].TexCoord.X = s0;
                vertexData[vertexCount].TexCoord.Y = t0;
                vertexData[vertexCount].TexCoord.Z = 0.0f;
                vertexCount++;

                vertexData[vertexCount].Position.X = x + width;
                vertexData[vertexCount].Position.Y = y;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = Color;
                vertexData[vertexCount].TexCoord.X = s1;
                vertexData[vertexCount].TexCoord.Y = t0;
                vertexData[vertexCount].TexCoord.Z = 0.0f;
                vertexCount++;

                vertexData[vertexCount].Position.X = x+width;
                vertexData[vertexCount].Position.Y = y+height;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = Color;
                vertexData[vertexCount].TexCoord.X = s1;
                vertexData[vertexCount].TexCoord.Y = t1;
                vertexData[vertexCount].TexCoord.Z = 0.0f;
                vertexCount++;

                vertexData[vertexCount].Position.X = x;
                vertexData[vertexCount].Position.Y = y+height;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = Color;
                vertexData[vertexCount].TexCoord.X = s0;
                vertexData[vertexCount].TexCoord.Y = t1;
                vertexData[vertexCount].TexCoord.Z = 0.0f;
                vertexCount++;
            }
        }
Пример #4
0
        public unsafe override void Draw(Renderer r, Vertex* vertexData, ref int vertexCount)
        {
            Tilemap tilemap = r.Tilemaps[Template.TilemapName];

            foreach(Instance ins in _instances)
            {
                if((ins.Flags & SpriteFlags.Disable) != 0)
                    continue;

                float x = ins.X;
                float y = ins.Y;
                float width = Template.Rectangle.Width;
                float height = Template.Rectangle.Height;

                // If the object should be included in scrolling...
                if ((_flags & Drawable.Flags.NoScroll) == 0)
                {
                    // Apply offset so we're always positioned relative to the gameplay background.
                    Background bg = r.Backgrounds[0];
                    x -= (float)Math.Floor(bg.HScroll);
                    y -= (float)Math.Floor(bg.VScroll);
                }

                // Calculate texcoords, with possible animation.
                int tx = Template.Rectangle.X;
                int ty = Template.Rectangle.Y;

                int frameOffset = (Template.FrameOffset > 0 ? Template.FrameOffset : Template.Rectangle.Width);

                if(Template.VerticalAnimation)
                {
                    ty += ins.Frame * frameOffset;
                }
                else
                {
                    tx += ins.Frame * frameOffset;

                    // If the animation would take us outside the right edge of the
                    // texture, start on the next row.
                    while (tx + width > tilemap.Width)
                    {
                        tx -= (tilemap.Width / frameOffset) * frameOffset;
                        ty += Template.Rectangle.Height;
                    }
                }

                float s0 = tx * tilemap.PixelStepX;
                float t0 = ty * tilemap.PixelStepY;
                float s1 = (tx + width) * tilemap.PixelStepX;
                float t1 = (ty + height) * tilemap.PixelStepY;

                // Flip the sprite horizontally?
                if ((ins.Flags & SpriteFlags.HFlip) != 0)
                {
                    float stmp = s0;
                    s0 = s1;
                    s1 = stmp;
                }

                // Flip the sprite vertically?
                if ((ins.Flags & SpriteFlags.VFlip) != 0)
                {
                    float ttmp = t0;
                    t0 = t1;
                    t1 = ttmp;
                }

                Matrix4 m = Matrix4.CreateTranslation(x,y,0.0f);
                Matrix4 scalem = Matrix4.Scale(ins.Scale);
                Matrix4 rotm = Matrix4.Rotate(Quaternion.FromAxisAngle(Vector3.UnitZ, ins.Angle * (2.0f * (float)Math.PI) / 4096.0f));
                Matrix4.Mult(ref scalem, ref m, out m);
                Matrix4.Mult(ref rotm, ref m, out m);
                float ox = Template.Centered ? Template.Rectangle.Width/2 : Template.Offset.X;
                float oy = Template.Centered ? Template.Rectangle.Height/2 : Template.Offset.Y;
                Vector4 v00 = new Vector4(-ox, -oy, 0.0f, 1.0f);
                Vector4 v10 = new Vector4(width-ox, -oy, 0.0f, 1.0f);
                Vector4 v11 = new Vector4(width-ox, height-oy, 0.0f, 1.0f);
                Vector4 v01 = new Vector4(-ox, height-oy, 0.0f, 1.0f);

                Vector4.Transform(ref v00, ref m, out v00);
                Vector4.Transform(ref v10, ref m, out v10);
                Vector4.Transform(ref v11, ref m, out v11);
                Vector4.Transform(ref v01, ref m, out v01);

                float colorizeMode = (_flags & Drawable.Flags.Colorize) != 0 ? 1.0f : 0.0f;

                vertexData[vertexCount].Position.X = v00.X;
                vertexData[vertexCount].Position.Y = v00.Y;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = ins.Color;
                vertexData[vertexCount].TexCoord.X = s0;
                vertexData[vertexCount].TexCoord.Y = t0;
                vertexData[vertexCount].TexCoord.Z = colorizeMode;
                vertexCount++;

                vertexData[vertexCount].Position.X = v10.X;
                vertexData[vertexCount].Position.Y = v10.Y;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = ins.Color;
                vertexData[vertexCount].TexCoord.X = s1;
                vertexData[vertexCount].TexCoord.Y = t0;
                vertexData[vertexCount].TexCoord.Z = colorizeMode;
                vertexCount++;

                vertexData[vertexCount].Position.X = v11.X;
                vertexData[vertexCount].Position.Y = v11.Y;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = ins.Color;
                vertexData[vertexCount].TexCoord.X = s1;
                vertexData[vertexCount].TexCoord.Y = t1;
                vertexData[vertexCount].TexCoord.Z = colorizeMode;
                vertexCount++;

                vertexData[vertexCount].Position.X = v01.X;
                vertexData[vertexCount].Position.Y = v01.Y;
                vertexData[vertexCount].Position.Z = 0.0f;
                vertexData[vertexCount].Color = ins.Color;
                vertexData[vertexCount].TexCoord.X = s0;
                vertexData[vertexCount].TexCoord.Y = t1;
                vertexData[vertexCount].TexCoord.Z = colorizeMode;
                vertexCount++;
            }
        }
Пример #5
0
        public unsafe override void Draw(Renderer r, Vertex* vertexData, ref int vertexCount)
        {
            if(_dirty)
            {
                _dirty = false;

                int xi = (int)X;
                int yi = (int)Y;
                int wi = (int)Width;
                int hi = (int)Height;
                int x0 = xi;
                int x1 = xi + 16;
                int x2 = xi + wi - 16;
                int x3 = xi + wi;
                int y0 = yi;
                int y1 = yi + 16;
                int y2 = yi + hi - 16;
                int y3 = yi + hi;

                SetQuad(1, x1, y0, x2, y1, 80, 325, 80, 325);
                SetQuad(3, x0, y1, x1, y2, 80, 325, 80, 325);
                SetQuad(4, x1, y1, x2, y2, 80, 325, 80, 325);
                SetQuad(5, x2, y1, x3, y2, 80, 325, 80, 325);
                SetQuad(7, x1, y2, x2, y3, 80, 325, 80, 325);

                if((_corners & Corners.TopLeft) != 0) SetQuad(0, x0, y0, x1, y1, 64, 320, 80, 336); else SetQuad(0, x0, y0, x1, y1, 80, 325, 80, 325);
                if((_corners & Corners.TopRight) != 0) SetQuad(2, x2, y0, x3, y1, 80, 320, 96, 336); else SetQuad(2, x2, y0, x3, y1, 80, 325, 80, 325);
                if((_corners & Corners.BottomLeft) != 0) SetQuad(6, x0, y2, x1, y3, 96, 320, 112, 336); else SetQuad(6, x0, y2, x1, y3, 80, 325, 80, 325);
                if((_corners & Corners.BottomRight) != 0) SetQuad(8, x2, y2, x3, y3, 112, 320, 128, 336); else SetQuad(8, x2, y2, x3, y3, 80, 325, 80, 325);
            }

            for(int i = 0; i < 9*4; ++i)
                vertexData[vertexCount++] = _verts[i];
        }