Ejemplo n.º 1
0
        public void Draw(LTextureRegion region, float x, float y, float originX,
                float originY, float width, float height, float scaleX,
                float scaleY, float rotation, bool clockwise)
        {

            CheckTexture(region.GetTexture());

            float worldOriginX = x + originX;
            float worldOriginY = y + originY;
            float fx = -originX;
            float fy = -originY;
            float fx2 = width - originX;
            float fy2 = height - originY;

            if (scaleX != 1 || scaleY != 1)
            {
                fx *= scaleX;
                fy *= scaleY;
                fx2 *= scaleX;
                fy2 *= scaleY;
            }

            float p1x = fx;
            float p1y = fy;
            float p2x = fx;
            float p2y = fy2;
            float p3x = fx2;
            float p3y = fy2;
            float p4x = fx2;
            float p4y = fy;

            float x1;
            float y1;
            float x2;
            float y2;
            float x3;
            float y3;
            float x4;
            float y4;

            if (rotation != 0)
            {
                float cos = MathUtils.CosDeg(rotation);
                float sin = MathUtils.SinDeg(rotation);

                x1 = cos * p1x - sin * p1y;
                y1 = sin * p1x + cos * p1y;

                x2 = cos * p2x - sin * p2y;
                y2 = sin * p2x + cos * p2y;

                x3 = cos * p3x - sin * p3y;
                y3 = sin * p3x + cos * p3y;

                x4 = x1 + (x3 - x2);
                y4 = y3 - (y2 - y1);
            }
            else
            {
                x1 = p1x;
                y1 = p1y;

                x2 = p2x;
                y2 = p2y;

                x3 = p3x;
                y3 = p3y;

                x4 = p4x;
                y4 = p4y;
            }

            x1 += worldOriginX;
            y1 += worldOriginY;
            x2 += worldOriginX;
            y2 += worldOriginY;
            x3 += worldOriginX;
            y3 += worldOriginY;
            x4 += worldOriginX;
            y4 += worldOriginY;

            float u1, v1, u2, v2, u3, v3, u4, v4;
            if (clockwise)
            {
                u1 = region.widthRatio;
                v1 = region.heightRatio;
                u2 = region.xOff;
                v2 = region.heightRatio;
                u3 = region.xOff;
                v3 = region.yOff;
                u4 = region.widthRatio;
                v4 = region.yOff;
            }
            else
            {
                u1 = region.xOff;
                v1 = region.yOff;
                u2 = region.widthRatio;
                v2 = region.yOff;
                u3 = region.widthRatio;
                v3 = region.heightRatio;
                u4 = region.xOff;
                v4 = region.heightRatio;
            }

            vertices[idx].Position.X = x1;
            vertices[idx].Position.Y = y1;
            vertices[idx].Color = m_color;
            vertices[idx].TextureCoordinate.X = u1;
            vertices[idx].TextureCoordinate.Y = v1;

            vertices[idx + 1].Position.X = x2;
            vertices[idx + 1].Position.Y = y2;
            vertices[idx + 1].Color = m_color;
            vertices[idx + 1].TextureCoordinate.X = u2;
            vertices[idx + 1].TextureCoordinate.Y = v2;

            vertices[idx + 2].Position.X = x3;
            vertices[idx + 2].Position.Y = y3;
            vertices[idx + 2].Color = m_color;
            vertices[idx + 2].TextureCoordinate.X = u3;
            vertices[idx + 2].TextureCoordinate.Y = v3;

            vertices[idx + 3].Position.X = x4;
            vertices[idx + 3].Position.Y = y4;
            vertices[idx + 3].Color = m_color;
            vertices[idx + 3].TextureCoordinate.X = u4;
            vertices[idx + 3].TextureCoordinate.Y = v4;

            idx += 4;
        }
Ejemplo n.º 2
0
        public void Draw(LTextureRegion region, float x, float y, float width,
                float height)
        {
            CheckTexture(region.GetTexture());

            float fx2 = x + width;
            float fy2 = y + height;
            float u = region.xOff;
            float v = region.yOff;
            float u2 = region.widthRatio;
            float v2 = region.heightRatio;

            vertices[idx].Position.X = x;
            vertices[idx].Position.Y = y;
            vertices[idx].Color = m_color;
            vertices[idx].TextureCoordinate.X = u;
            vertices[idx].TextureCoordinate.Y = v;

            vertices[idx + 1].Position.X = x;
            vertices[idx + 1].Position.Y = fy2;
            vertices[idx + 1].Color = m_color;
            vertices[idx + 1].TextureCoordinate.X = u;
            vertices[idx + 1].TextureCoordinate.Y = v2;

            vertices[idx + 2].Position.X = fx2;
            vertices[idx + 2].Position.Y = fy2;
            vertices[idx + 2].Color = m_color;
            vertices[idx + 2].TextureCoordinate.X = u2;
            vertices[idx + 2].TextureCoordinate.Y = v2;

            vertices[idx + 3].Position.X = fx2;
            vertices[idx + 3].Position.Y = y;
            vertices[idx + 3].Color = m_color;
            vertices[idx + 3].TextureCoordinate.X = u2;
            vertices[idx + 3].TextureCoordinate.Y = v;

            idx += 4;
        }