开发者

Working out point location relative to other point when rotated - C# XNA

开发者 https://www.devze.com 2023-03-21 15:47 出处:网络
I have a small rectangle, with a point at the center. I a开发者_StackOverflowlso have another point, just outside of the rectangle, 10 pixels to the left of the rectangle\'s center point when the rect

I have a small rectangle, with a point at the center. I a开发者_StackOverflowlso have another point, just outside of the rectangle, 10 pixels to the left of the rectangle's center point when the rectangle is sitting vertically, not rotated. How would i go about keeping this outside point in the same place relative to the rectangle when the rectangle is rotated about its center?

thanks


Here is an example of how to rotate one point around another point in XNA:

public Vector2 RotatePoint(Vector2 pointToRotate, Vector2 centerOfRotation, float angleOfRotation)
{
    Matrix rotationMatrix = Matrix.CreateRotationZ(angleOfRotation);
    return Vector2.Transform(pointToRotate - centerOfRotation, rotationMatrix);
}


Start the "point" at the center point of your rectangle, then translate it out to where you want it, and then rotate it from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消