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 System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Cnc.FileFormats;
|
||||
@@ -125,5 +126,33 @@ namespace OpenRA.Mods.Cnc.Graphics
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Rectangle AggregateBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
// Corner offsets
|
||||
var ix = new uint[] { 0, 0, 0, 0, 3, 3, 3, 3 };
|
||||
var iy = new uint[] { 1, 1, 4, 4, 1, 1, 4, 4 };
|
||||
var iz = new uint[] { 2, 5, 2, 5, 2, 5, 2, 5 };
|
||||
|
||||
// Calculate the smallest sphere that covers the model limbs
|
||||
var rSquared = 0f;
|
||||
for (var f = 0U; f < frames; f++)
|
||||
{
|
||||
var bounds = Bounds(f);
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
var x = bounds[ix[i]];
|
||||
var y = bounds[iy[i]];
|
||||
var z = bounds[iz[i]];
|
||||
rSquared = Math.Max(rSquared, x * x + y * y + z * z);
|
||||
}
|
||||
}
|
||||
|
||||
var r = (int)Math.Sqrt(rSquared) + 1;
|
||||
return Rectangle.FromLTRB(-r, -r, r, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user