mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
replaced GetBoundingRectangle methods with properties
This commit is contained in:
@@ -158,7 +158,7 @@ namespace Demo.Camera
|
||||
}
|
||||
|
||||
// not all sprite batches need to be affected by the camera
|
||||
var rectangle = _camera.GetBoundingRectangle();
|
||||
var rectangle = _camera.BoundingRectangle;
|
||||
var stringBuilder = new StringBuilder();
|
||||
stringBuilder.AppendLine($"WASD: Move [{_camera.Position.X:0}, {_camera.Position.Y:0}]");
|
||||
stringBuilder.AppendLine($"EQ: Rotate [{MathHelper.ToDegrees(_camera.Rotation):0.00}]");
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace Demo.SceneGraphs
|
||||
|
||||
if (_hoveredNode != null)
|
||||
{
|
||||
var boundingRectangle = _hoveredNode.GetBoundingRectangle();
|
||||
var boundingRectangle = _hoveredNode.BoundingRectangle;
|
||||
_spriteBatch.DrawRectangle(boundingRectangle, Color.Black);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"PublishPath": "D:\\Github\\Private\\AstridAnimator\\AstridAnimator\\bin\\Debug"
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace Demo.SpriteSheetAnimations
|
||||
|
||||
private ZombieState _state;
|
||||
|
||||
public RectangleF BoundingBox => _sprite.GetBoundingRectangle();
|
||||
public RectangleF BoundingBox => _sprite.BoundingRectangle;
|
||||
|
||||
public bool IsOnGround { get; private set; }
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace MonoGame.Extended.Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Camera2D_GetBoundingRectangle_Test()
|
||||
public void Camera2D_BoundingRectangle_Test()
|
||||
{
|
||||
var graphicsDevice = TestHelper.CreateGraphicsDevice();
|
||||
var viewport = new DefaultViewportAdapter(graphicsDevice);
|
||||
@@ -47,7 +47,7 @@ namespace MonoGame.Extended.Tests
|
||||
camera.Move(new Vector2(2, 0));
|
||||
camera.Move(new Vector2(0, 3));
|
||||
|
||||
var boundingRectangle = camera.GetBoundingRectangle();
|
||||
var boundingRectangle = camera.BoundingRectangle;
|
||||
|
||||
Assert.AreEqual(2, boundingRectangle.Left, 0.01);
|
||||
Assert.AreEqual(3, boundingRectangle.Top, 0.01);
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
Position = new Vector2(400, 240)
|
||||
};
|
||||
|
||||
Assert.AreEqual(new RectangleF(375, 140, 50, 200), sprite.GetBoundingRectangle());
|
||||
Assert.AreEqual(new RectangleF(375, 140, 50, 200), sprite.BoundingRectangle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -34,7 +34,7 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
OriginNormalized = new Vector2(1.0f, 1.0f)
|
||||
};
|
||||
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 50, 200), sprite.GetBoundingRectangle());
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 50, 200), sprite.BoundingRectangle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -47,7 +47,7 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
Scale = Vector2.One * 2.0f
|
||||
};
|
||||
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 100, 400), sprite.GetBoundingRectangle());
|
||||
Assert.AreEqual(new RectangleF(-50, -200, 100, 400), sprite.BoundingRectangle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -60,7 +60,7 @@ namespace MonoGame.Extended.Tests.Sprites
|
||||
Rotation = MathHelper.ToRadians(90)
|
||||
};
|
||||
|
||||
Assert.AreEqual(new RectangleF(-100, -25, 200, 50), sprite.GetBoundingRectangle());
|
||||
Assert.AreEqual(new RectangleF(-100, -25, 200, 50), sprite.BoundingRectangle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -175,15 +175,18 @@ namespace MonoGame.Extended
|
||||
return new BoundingFrustum(projectionMatrix);
|
||||
}
|
||||
|
||||
public RectangleF GetBoundingRectangle()
|
||||
public RectangleF BoundingRectangle
|
||||
{
|
||||
var frustum = GetBoundingFrustum();
|
||||
var corners = frustum.GetCorners();
|
||||
var topLeft = corners[0];
|
||||
var bottomRight = corners[2];
|
||||
var width = bottomRight.X - topLeft.X;
|
||||
var height = bottomRight.Y - topLeft.Y;
|
||||
return new RectangleF(topLeft.X, topLeft.Y, width, height);
|
||||
get
|
||||
{
|
||||
var frustum = GetBoundingFrustum();
|
||||
var corners = frustum.GetCorners();
|
||||
var topLeft = corners[0];
|
||||
var bottomRight = corners[2];
|
||||
var width = bottomRight.X - topLeft.X;
|
||||
var height = bottomRight.Y - topLeft.Y;
|
||||
return new RectangleF(topLeft.X, topLeft.Y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public ContainmentType Contains(Point point)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MonoGame.Extended.SceneGraphs
|
||||
{
|
||||
public interface ISceneEntity
|
||||
{
|
||||
RectangleF GetBoundingRectangle();
|
||||
RectangleF BoundingRectangle { get; }
|
||||
}
|
||||
|
||||
public interface ISpriteBatchDrawable
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace MonoGame.Extended.SceneGraphs
|
||||
{
|
||||
var node = RootNode;
|
||||
|
||||
while (node != null && node.GetBoundingRectangle().Contains(x, y))
|
||||
while (node != null && node.BoundingRectangle.Contains(x, y))
|
||||
{
|
||||
var childNode = node.Children.FirstOrDefault(c => c.GetBoundingRectangle().Contains(x, y));
|
||||
var childNode = node.Children.FirstOrDefault(c => c.BoundingRectangle.Contains(x, y));
|
||||
|
||||
if(childNode != null)
|
||||
node = childNode;
|
||||
|
||||
@@ -39,23 +39,26 @@ namespace MonoGame.Extended.SceneGraphs
|
||||
public SceneEntityCollection Entities { get; }
|
||||
public object Tag { get; set; }
|
||||
|
||||
public RectangleF GetBoundingRectangle()
|
||||
public RectangleF BoundingRectangle
|
||||
{
|
||||
var rectangles = Entities
|
||||
.Select(e =>
|
||||
{
|
||||
var r = e.GetBoundingRectangle();
|
||||
r.Offset(WorldPosition);
|
||||
return r;
|
||||
})
|
||||
.Concat(Children.Select(i => i.GetBoundingRectangle()))
|
||||
.ToArray();
|
||||
var x0 = rectangles.Min(r => r.Left);
|
||||
var y0 = rectangles.Min(r => r.Top);
|
||||
var x1 = rectangles.Max(r => r.Right);
|
||||
var y1 = rectangles.Max(r => r.Bottom);
|
||||
|
||||
return new RectangleF(x0, y0, x1 - x0, y1 - y0);
|
||||
get
|
||||
{
|
||||
var rectangles = Entities
|
||||
.Select(e =>
|
||||
{
|
||||
var r = e.BoundingRectangle;
|
||||
r.Offset(WorldPosition);
|
||||
return r;
|
||||
})
|
||||
.Concat(Children.Select(i => i.BoundingRectangle))
|
||||
.ToArray();
|
||||
var x0 = rectangles.Min(r => r.Left);
|
||||
var y0 = rectangles.Min(r => r.Top);
|
||||
var x1 = rectangles.Max(r => r.Right);
|
||||
var y1 = rectangles.Max(r => r.Bottom);
|
||||
|
||||
return new RectangleF(x0, y0, x1 - x0, y1 - y0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
|
||||
@@ -125,14 +125,16 @@ namespace MonoGame.Extended.Shapes
|
||||
}
|
||||
|
||||
|
||||
public RectangleF GetBoundingRectangle()
|
||||
public RectangleF BoundingRectangle
|
||||
{
|
||||
var minX = Left;
|
||||
var minY = Top;
|
||||
var maxX = Right;
|
||||
var maxY = Bottom;
|
||||
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
get
|
||||
{
|
||||
var minX = Left;
|
||||
var minY = Top;
|
||||
var maxX = Right;
|
||||
var maxY = Bottom;
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -96,14 +96,16 @@ namespace MonoGame.Extended.Shapes
|
||||
return new PolygonF(polygon.Vertices);
|
||||
}
|
||||
|
||||
public RectangleF GetBoundingRectangle()
|
||||
public RectangleF BoundingRectangle
|
||||
{
|
||||
var minX = Left;
|
||||
var minY = Top;
|
||||
var maxX = Right;
|
||||
var maxY = Bottom;
|
||||
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
get
|
||||
{
|
||||
var minX = Left;
|
||||
var minY = Top;
|
||||
var maxX = Right;
|
||||
var maxY = Bottom;
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(Vector2 point)
|
||||
|
||||
@@ -212,10 +212,7 @@ namespace MonoGame.Extended.Shapes
|
||||
return X <= x && x < X + Width && Y <= y && y < Y + Height;
|
||||
}
|
||||
|
||||
public RectangleF GetBoundingRectangle()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public RectangleF BoundingRectangle => this;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the provided coordinates lie within the bounds of this <see cref="RectangleF"/>.
|
||||
|
||||
@@ -8,9 +8,7 @@ namespace MonoGame.Extended.Shapes
|
||||
float Top { get; }
|
||||
float Right { get; }
|
||||
float Bottom { get; }
|
||||
|
||||
RectangleF GetBoundingRectangle();
|
||||
|
||||
RectangleF BoundingRectangle { get; }
|
||||
bool Contains(float x, float y);
|
||||
bool Contains(Vector2 point);
|
||||
}
|
||||
|
||||
@@ -61,12 +61,15 @@ namespace MonoGame.Extended.Sprites
|
||||
set { Origin = new Vector2(value.X * TextureRegion.Width, value.Y * TextureRegion.Height); }
|
||||
}
|
||||
|
||||
public RectangleF GetBoundingRectangle()
|
||||
public RectangleF BoundingRectangle
|
||||
{
|
||||
var corners = GetCorners();
|
||||
var min = new Vector2(corners.Min(i => i.X), corners.Min(i => i.Y));
|
||||
var max = new Vector2(corners.Max(i => i.X), corners.Max(i => i.Y));
|
||||
return new RectangleF(min.X, min.Y, (max.X - min.X), (max.Y - min.Y));
|
||||
get
|
||||
{
|
||||
var corners = GetCorners();
|
||||
var min = new Vector2(corners.Min(i => i.X), corners.Min(i => i.Y));
|
||||
var max = new Vector2(corners.Max(i => i.X), corners.Max(i => i.Y));
|
||||
return new RectangleF(min.X, min.Y, (max.X - min.X), (max.Y - min.Y));
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2[] GetCorners()
|
||||
|
||||
Reference in New Issue
Block a user