나는 잠시 동안이 일을 시도했지만 많은 성공을 거두지 못했습니다. 내가하고 싶은 것은 사각형을 회전시킨 다음 회전 된 점들을 포함하는 새로운 사각형을 만드는 것입니다.Microsoft.XNA.Framework.Rectangle 회전 및 해당 회전을 기반으로 사각형 만들기?
누구나 어떻게해야 제대로 할 수 있습니까?
코드 나는이 작동하지 않습니다,하지만 예를 들어, (숫자가 내가 그것을 실제로 작동 생각하게) 정확히 잘못된거야 어디 다음과 같은 값을 가진 사각형이 있는지 확실하지 않습니다 :
을{X:865 Y:76 Width:22 Height:164}
결과는 다음과 같습니다가 회전 -1.57094443
{X:1863 Y:1740 Width:164 Height:22}
내가 뭘하는 잡아 원래 사각형의 네 점이며,이 기능을 회전 :
'앵커'피벗 점 (I이 기능은 수학적으로 소리 있는지 확실하지 않습니다), 나는이 함께 회전 된 사각형의 모서리를 결정하는 것입니다static public Vector2 RotateVectorAround(Vector2 anchor, Vector2 vector, float rotation)
{
Matrix mat = new Matrix();
mat.Translation = new Vector3(vector.X - anchor.X, vector.Y - anchor.Y, 0);
Matrix rot = new Matrix();
rot = Matrix.CreateRotationZ(rotation);
mat *= rot;
mat.Translation += new Vector3(anchor.X, anchor.Y, 0);
return new Vector2(mat.Translation.X, mat.Translation.Y);
}
:
Vector2 newTopLeft = new Vector2( Math.Min(Math.Min(topleft.X, bottomRight.X), Math.Min(bottomleft.X, topright.X)),
Math.Min(Math.Min(topleft.Y, bottomRight.Y), Math.Min(bottomleft.Y, topright.Y)));
Vector2 newBottomRight = new Vector2(
Math.Max(Math.Max(topleft.X, bottomRight.X), Math.Max(bottomleft.X, topright.X)),
Math.Max(Math.Max(topleft.Y, bottomRight.Y), Math.Max(bottomleft.Y, topright.Y)));