나는이 질문을 몇 번 전에 물어 봤고 이것에 관한 여러 게시물을 읽었습니다. 그러나 나는 이것이 작동하도록 고심하고있다.회전 된 사각형 안에 점이 있는지 확인
bool isClicked()
{
Vector2 origLoc = Location;
Matrix rotationMatrix = Matrix.CreateRotationZ(-Rotation);
Location = new Vector2(0 -(Texture.Width/2), 0 - (Texture.Height/2));
Vector2 rotatedPoint = new Vector2(Game1.mouseState.X, Game1.mouseState.Y);
rotatedPoint = Vector2.Transform(rotatedPoint, rotationMatrix);
if (Game1.mouseState.LeftButton == ButtonState.Pressed &&
rotatedPoint.X > Location.X &&
rotatedPoint.X < Location.X + Texture.Width &&
rotatedPoint.Y > Location.Y &&
rotatedPoint.Y < Location.Y + Texture.Height)
{
Location = origLoc;
return true;
}
Location = origLoc;
return false;
}
이것은 텍스처에 적용된 변환을 알지 못하면 확인할 수 없습니다. 새로운 매트릭스를 만드는 것은 코드 냄새입니다. 원래 텍스처에 사용 된 행렬을 사용해야합니다. 그리고 마우스 위치를 회전시키지 말고 텍스처를 다시 회전시켜 다시 사각형으로 만듭니다. –