diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs index 8bb2f07..e256a74 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs @@ -11,6 +11,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render private bool changed; private Vector3 rotation; private Vector2 origin, dimensions; + private RectangleF textureBounds; private ValueTuple[] vertices; private uint[] indices; @@ -90,6 +91,30 @@ namespace SlatedGameToolkit.Framework.Graphics.Render } } + public RectangleF TextureBounds + { + get + { + return textureBounds; + } + set + { + this.vertices[0].Item2.X = value.X; + this.vertices[0].Item2.Y = value.Y; + + this.vertices[1].Item2.X = value.X + value.Width; + this.vertices[1].Item2.Y = value.Y; + + this.vertices[2].Item2.X = value.X + value.Width; + this.vertices[2].Item2.Y = value.Y + value.Height; + + this.vertices[3].Item2.X = value.X; + this.vertices[3].Item2.Y = value.Y + value.Height; + + this.textureBounds = value; + } + } + public uint[] Elements { get {return indices; } } public Vector3 Rotation @@ -111,8 +136,8 @@ namespace SlatedGameToolkit.Framework.Graphics.Render public Color Color { get; set; } - public RectangleMesh(RectangleF textureRegion, ITexture texture, Color color) - { + + public RectangleMesh(RectangleF meshBounds, ITexture texture, Color color) { this.changed = true; this.rotation = Vector3.Zero; this.origin = Vector2.Zero; @@ -121,33 +146,22 @@ namespace SlatedGameToolkit.Framework.Graphics.Render this.Color = color; this.indices = new uint[] {0, 1, 3, 1, 2, 3}; vertices = new ValueTuple[4]; - - this.vertices[0].Item2.X = textureRegion.X; - this.vertices[0].Item2.Y = textureRegion.Y; - - this.vertices[1].Item2.X = textureRegion.X + textureRegion.Width; - this.vertices[1].Item2.Y = textureRegion.Y; - - this.vertices[2].Item2.X = textureRegion.X + textureRegion.Width; - this.vertices[2].Item2.Y = textureRegion.Y + textureRegion.Height; - - this.vertices[3].Item2.X = textureRegion.X; - this.vertices[3].Item2.Y = textureRegion.Y + textureRegion.Height; - + this.textureBounds = new RectangleF(0, 0, 1, 1); this.matRot = Matrix4x4.Identity; - - } - - public RectangleMesh(RectangleF meshBounds, RectangleF textureRegion, ITexture texture, Color color) : this(textureRegion, texture, color) { + this.TextureBounds = textureBounds; this.Bounds = meshBounds; } - public RectangleMesh(ITexture texture, Color color) : this(new Rectangle(0, 0, 1, 1), texture, color) { + public RectangleMesh(ITexture texture, Color color) : this(new RectangleF(0,0,0,0), texture, color) + { + } - - + public RectangleMesh(RectangleF meshBounds, RectangleF textureRegion, ITexture texture, Color color) : this(meshBounds, texture, color) { + this.TextureBounds = textureRegion; + } + private void CalculateVertices() { if (!changed) return;