Rectangle mesh texture bounds can now be changed.
This commit is contained in:
parent
4b1e57ac72
commit
75f691133a
@ -11,6 +11,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render
|
||||
private bool changed;
|
||||
private Vector3 rotation;
|
||||
private Vector2 origin, dimensions;
|
||||
private RectangleF textureBounds;
|
||||
private ValueTuple<Vector3, Vector2>[] 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<Vector3, Vector2>[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;
|
||||
|
Loading…
Reference in New Issue
Block a user