I’m writing a little test project. I have an object (with a position and bounding box) at an origin, and when something happens (say a mouse click/touch on phone), I want a line to be drawn from the origin object to the point.
Using a texture, I realise I’m going to have to use the rotation here, but have no idea how to work out how much to rotate the texture by. Any help would be appreciated.
So far, I have:
Vector2 Origin
Vector2 TouchPoint
and that’s about it.
Thanks all!
Theres a simple formula for calculating an angle based on the X and Y coordinates:
You can use this angle in an overload of the
SpriteBatch.Draw()that accept an angle for the rotation.See this for reference:
http://msdn.microsoft.com/en-us/library/ff433992.aspx
You may want to convert between degrees and radians: