SFML community forums
Help => General => Topic started by: Qluxzz on March 01, 2014, 06:15:03 am
-
Hi there, I'm working on a level editor and have gotten stuck. I know how to drag and drop the objects, but not how to scale them or rotate the objects according to the users mouse input.
For example I have a video of another persons level editor.
http://www.youtube.com/watch?v=E1KGlngYJ9E (http://www.youtube.com/watch?v=E1KGlngYJ9E)
I imagine it's not that difficult but I just can't think of how so all help is appreciated.
Thanks in advance Qluxzz
-
Video isn't loading for me. But if I think I know what you are talking about. For scaling - it depends on the distance from the initial mouse button press to the current mouse position. For rotation - you need to use atan2 to calculate the rotation from the initial button press to the current mouse position. ;)
-
I would do it as follows:
- When pressing the mouse button, compute the vector v from the object's center to the mouse position.
- As long as the mouse button is held down, check the position every frame. Compute another vector w from the center to the new mouse position. Then, the scale factor is length(w) / length(v) and the rotation is signedAngle(v, w) -- these functions already exist in Thor.Vectors (http://www.bromeon.ch/libraries/thor/v2.0/doc/_vector_algebra2_d_8hpp.html) (just include the header, no need to link).
- When releasing the mouse button, apply both scale and rotation relatively to their current values.