Rotate around a point on a mouse

I think this should be a simple problem, but I have a lot of problems implementing this, because there are so many things.

I am trying to rotate the objects defined by their center around a certain point , except for the center , to meet the mouse location p>

I have a specific point in world space and the location of the mouse in world space, as well as in the center of each element.

Please avoid answers on how to rotate in the direction of the mouse or how to rotate around a point separately - I'm trying to do both!

+4
source share
1 answer

If this is a fair interpretation of your question, rotating from the "last frame" to "this frame", enter image description here

If you know the location of the point at which you want the sprite to rotate, and you know the distance to the point at which you want the sprite, try the following:

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 a sprite, use spriteAngle and spriteLocation as parameters in the correct SpriteBatch.Draw () overload

Dra

+2
source

Source: https://habr.com/ru/post/1337744/


All Articles