Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scaling and Rotating objects in real time  (Read 1205 times)

0 Members and 1 Guest are viewing this topic.

Qluxzz

  • Guest
Scaling and Rotating objects in real time
« 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.


I imagine it's not that difficult but I just can't think of how so all help is appreciated.

Thanks in advance Qluxzz

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Scaling and Rotating objects in real time
« Reply #1 on: March 01, 2014, 06:43:57 am »
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.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Scaling and Rotating objects in real time
« Reply #2 on: March 01, 2014, 05:03:01 pm »
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 (just include the header, no need to link).
  • When releasing the mouse button, apply both scale and rotation relatively to their current values.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything