Rotate Around Point Towards Mouse
I'm thinking this should be a simple problem but I'm having a lot of trouble implementing this because there are so many things involved.
I am trying to rotate objects defined by their center around a defined point besides the center to face the location of the mouse
I have the defined point in the world space and the mouse's location in the world space as well as the center of each item.
Please avoid giving answers on how to rotate towards mouse or how to rotate around a point individually - I'm trying to do bot开发者_C百科h!
If this is a fair interpretation of your question, rotating from "last frame" to "this frame",,
If you know the location of the point that you want the sprite to rotate about and you know the distance away from that point that you want the sprite to be, try this:
float radius = ?.?f; // distance from pivot point to sprite
Vector2 spritePivot = new Vector2(?, ?); //location of pivot point
Vector2 mouseToPoint = spritePivot - new Vector2(mouseState.X, mouseState.Y);
mouseToPoint.Normalize();
float spriteAngle = MathHelper.Atan2(mouseToPoint.Y, mouseToPoint.X);
mouseToPoint *= radius;
Vector2 spriteLocation = spritePivot + mouseToPoint;
later, when drawing the sprite, use spriteAngle & spriteLocation as a params in the proper overload of SpriteBatch.Draw()
Dra
精彩评论