Add IModel.AggregateBounds and ModelAnimation.ScreenBounds.
The bounds define the smallest Rectangle that covers all rotations of all frames within a model sequence.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileSystem;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
@@ -23,6 +24,9 @@ namespace OpenRA.Graphics
|
||||
float[] Size { get; }
|
||||
float[] Bounds(uint frame);
|
||||
ModelRenderData RenderData(uint section);
|
||||
|
||||
/// <summary>Returns the smallest rectangle that covers all rotations of all frames in a model</summary>
|
||||
Rectangle AggregateBounds { get; }
|
||||
}
|
||||
|
||||
public struct ModelRenderData
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
{
|
||||
@@ -33,6 +34,19 @@ namespace OpenRA.Graphics
|
||||
ShowShadow = showshadow;
|
||||
}
|
||||
|
||||
public Rectangle ScreenBounds(WPos pos, WorldRenderer wr, float scale)
|
||||
{
|
||||
var r = Model.AggregateBounds;
|
||||
var offset = OffsetFunc != null ? OffsetFunc() : WVec.Zero;
|
||||
var xy = wr.ScreenPxPosition(pos) + wr.ScreenPxOffset(offset);
|
||||
|
||||
return Rectangle.FromLTRB(
|
||||
xy.X + (int)(r.Left * scale),
|
||||
xy.Y + (int)(r.Top * scale),
|
||||
xy.X + (int)(r.Right * scale),
|
||||
xy.Y + (int)(r.Bottom * scale));
|
||||
}
|
||||
|
||||
public bool IsVisible
|
||||
{
|
||||
get
|
||||
|
||||
Reference in New Issue
Block a user