【发布时间】:2013-06-12 17:33:56
【问题描述】:
我知道这个问题已经被问过几次了,我已经阅读了很多关于这个问题的帖子。但是我正在努力让它发挥作用。
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;
}
【问题讨论】:
-
如果不知道应用于纹理的变换,这是无法验证的。创建一个新矩阵是一种代码味道。您应该使用最初在纹理上使用的矩阵。并且不旋转鼠标位置,而是将纹理向后旋转,使其再次成为矩形。
标签: c# math graphics xna geometry