开发者

Rotate Around Point Towards Mouse

开发者 https://www.devze.com 2023-02-07 11:06 出处:网络
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'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",,

Rotate Around Point Towards Mouse

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

0

精彩评论

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

关注公众号