Exemple #1
0
        public void SetTextureRegion(RectF rect, bool reset_size)
        {
            if (reset_size)
            {
                Width  = rect.Width;
                Height = rect.Height;
            }

            m_quad = new Quad(m_texture, rect, RectF.FromBox(0, 0, Width, Height));
        }
Exemple #2
0
        public Quad(Texture2D texture, RectF srcRect = default, RectF destRect = default)
        {
            this.TopLeft     = default;
            this.TopRight    = default;
            this.BottomRight = default;
            this.BottomLeft  = default;

            if (texture == null)
            {
                return;
            }

            float ax, ay, bx, by;

            float dest_x1, dest_y1, dest_x2, dest_y2;

            if (srcRect.IsEmpty)
            {
                srcRect = RectF.FromBox(0, 0, texture.Width, texture.Height);

                ax = 0;
                ay = 0;
                bx = 1;
                by = 1;
            }
            else
            {
                float inv_tex_w = 1.0f / texture.Width;
                float inv_tex_h = 1.0f / texture.Height;

                ax = srcRect.X1 * inv_tex_w;
                ay = srcRect.Y1 * inv_tex_h;
                bx = srcRect.X2 * inv_tex_w;
                by = srcRect.Y2 * inv_tex_h;
            }

            if (destRect.IsEmpty)
            {
                dest_x1 = 0;
                dest_y1 = 0;
                dest_x2 = srcRect.Width;
                dest_y2 = srcRect.Height;
            }
            else
            {
                dest_x1 = destRect.X1;
                dest_y1 = destRect.Y1;
                dest_x2 = destRect.X2;
                dest_y2 = destRect.Y2;
            }

            this.TopLeft.X   = dest_x1;
            this.TopLeft.Y   = dest_y1;
            this.TopLeft.Tx  = ax;
            this.TopLeft.Ty  = ay;
            this.TopLeft.Col = 0xFFFFFFFF;

            this.TopRight.X   = dest_x2;
            this.TopRight.Y   = dest_y1;
            this.TopRight.Tx  = bx;
            this.TopRight.Ty  = ay;
            this.TopRight.Col = 0xFFFFFFFF;

            this.BottomRight.X   = dest_x2;
            this.BottomRight.Y   = dest_y2;
            this.BottomRight.Tx  = bx;
            this.BottomRight.Ty  = by;
            this.BottomRight.Col = 0xFFFFFFFF;

            this.BottomLeft.X   = dest_x1;
            this.BottomLeft.Y   = dest_y2;
            this.BottomLeft.Tx  = ax;
            this.BottomLeft.Ty  = by;
            this.BottomLeft.Col = 0xFFFFFFFF;
        }
Exemple #3
0
 public Sprite(Texture2D texture) : this(texture, RectF.FromBox(0f, 0f, texture.Width, texture.Height))
 {
 }