Note that there are some explanatory texts on larger screens.

plurals
  1. PO2d rotation around point
    text
    copied!<p>I'm trying to add some features into my editor that allow to the user things like dragging a selected item to a given direction although i've ran into a damn issue.</p> <p>This is my code :</p> <pre><code>//Origin double objectx = selection-&gt;getX(); double objecty = selection-&gt;getY(); //Point double pointerx = input-&gt;getMouseX(); double pointery = input-&gt;getMouseY(); //Displacement double displacementx = fabs(pointerx - objectx); double displacementy = fabs(pointery - objecty); //Angle double angle = atan2(displacementy,displacementx); //Point double pointx = displacementx * cosf(angle) + displacementy * sinf(angle); double pointy = displacementy * cosf(angle) - displacementx * sinf(angle); //Final position double fx = objectx + pointx; double fy = objecty + pointy; //Save alpha const bool alpha = graphics-&gt;getAlpha(); //Draw selection graphics-&gt;setAlpha(false); graphics-&gt;color(selection-&gt;getColor()); graphics-&gt;renderQd(selection-&gt;getBitmap(), CRect(objectx, objecty, selection-&gt;getWidth(), selection-&gt;getHeight())); //Draw pointer around selection graphics-&gt;setAlpha(true); graphics-&gt;color(editor::ssImg[0]-&gt;getColor()); graphics-&gt;renderQd(editor::ssImg[0]-&gt;getBitmap(), CRect(objectx + pointx, objecty + pointy, editor::ssImg[0]-&gt;getWidth(), editor::ssImg[0]-&gt;getHeight())); //Restore alpha graphics-&gt;setAlpha(alpha); </code></pre> <p>The exact issue is that the selection pointer doesn't follow mouse's rotation only but its actually at mouse's position(!). The wanted behaviour is a pointer locked at selection's offset but pointing to the mouse's angle.</p> <p>Anyone good at math sees anything wrong here ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload