【发布时间】:2017-03-22 08:07:01
【问题描述】:
我知道Rectangle 是轴对齐的,这很好,我只是不知道如何创建一个矩形,所以它总是包含整个精灵,而不管旋转。我一直在到处寻找答案,但在任何地方都找不到一个直接的答案。
例如:
假设原点是纹理的中间,我该怎么做呢?
编辑
稍微摆弄一下,我已经做到了这一点:
public Rectangle BoundingBox
{
get
{
var cos = Math.Cos(SpriteAngle);
var sin = Math.Cos(SpriteAngle);
var t1_opp = Width * cos;
var t1_adj = Math.Sqrt(Math.Pow(Width, 2) - Math.Pow(t1_opp, 2));
var t2_opp = Height * sin;
var t2_adj = Math.Sqrt(Math.Pow(Height, 2) - Math.Pow(t2_opp, 2));
int w = Math.Abs((int)(t1_opp + t2_opp));
int h = Math.Abs((int)(t1_adj + t2_adj));
int x = Math.Abs((int)(Position.X) - (w / 2));
int y = Math.Abs((int)(Position.Y) - (h / 2));
return new Rectangle(x, y, w, h);
}
}
【问题讨论】:
标签: rotation xna trigonometry monogame rectangles