Ejemplo n.º 1
0
        public static Vertex[] Image(Texture texture)
        {
            if (meshCache.ContainsKey(texture))
            {
                return(meshCache[texture]);
            }

            var x          = texture.X / (float)Settings.SheetSize + Settings.SheetHalfPixel;
            var y          = texture.Y / (float)Settings.SheetSize + Settings.SheetHalfPixel;
            var w          = (texture.X + texture.Width) / (float)Settings.SheetSize - Settings.SheetHalfPixel;
            var h          = (texture.Y + texture.Height) / (float)Settings.SheetSize - Settings.SheetHalfPixel;
            var scale      = texture.Height * MasterRenderer.PixelMultiplier / 2;
            var correction = texture.Width / (float)texture.Height;
            var color      = Color.White;
            var id         = SheetManager.SheetIndex(texture.SheetID);

            Vertex[] vertices =
            {
                new Vertex(new Vector(scale * correction,  scale,  0), new Vector4(w, y, id, 0), color),
                new Vertex(new Vector(-scale * correction, -scale, 0), new Vector4(x, h, id, 0), color),
                new Vertex(new Vector(scale * correction,  -scale, 0), new Vector4(w, h, id, 0), color),
                new Vertex(new Vector(-scale * correction, scale,  0), new Vector4(x, y, id, 0), color),
                new Vertex(new Vector(-scale * correction, -scale, 0), new Vector4(x, h, id, 0), color),
                new Vertex(new Vector(scale * correction,  scale,  0), new Vector4(w, y, id, 0), color),
            };

            meshCache[texture] = vertices;

            return(vertices);
        }
Ejemplo n.º 2
0
        static Vertex[] uiPanelPiece(Texture texture, Color color, Vector offset, Vector size)
        {
            var x  = texture.X / (float)Settings.SheetSize + Settings.SheetHalfPixel;
            var y  = texture.Y / (float)Settings.SheetSize + Settings.SheetHalfPixel;
            var w  = (texture.X + size.X * texture.Width) / Settings.SheetSize - Settings.SheetHalfPixel;
            var h  = (texture.Y + size.Y * texture.Height) / Settings.SheetSize - Settings.SheetHalfPixel;
            var id = SheetManager.SheetIndex(texture.SheetID);

            Vertex[] vertices =
            {
                new Vertex(new Vector(offset.X + size.X * 2, offset.Y + size.Y * 2, 0), new Vector4(w, y, id, 0), color),
                new Vertex(new Vector(offset.X,              offset.Y,              0), new Vector4(x, h, id, 0), color),
                new Vertex(new Vector(offset.X + size.X * 2, offset.Y,              0), new Vector4(w, h, id, 0), color),
                new Vertex(new Vector(offset.X,              offset.Y + size.Y * 2, 0), new Vector4(x, y, id, 0), color),
                new Vertex(new Vector(offset.X,              offset.Y,              0), new Vector4(x, h, id, 0), color),
                new Vertex(new Vector(offset.X + size.X * 2, offset.Y + size.Y * 2, 0), new Vector4(w, y, id, 0), color),
            };

            return(vertices);
        }