Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:12:14+00:00 2026-05-30T02:12:14+00:00

I’m trying to add some features into my editor that allow to the user

  • 0

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.

This is my code :

//Origin
double objectx = selection->getX();
double objecty = selection->getY();

//Point
double pointerx = input->getMouseX();
double pointery = input->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->getAlpha();

//Draw selection
graphics->setAlpha(false);
graphics->color(selection->getColor());
graphics->renderQd(selection->getBitmap(),
                   CRect(objectx,
                         objecty,
                         selection->getWidth(),
                         selection->getHeight()));

//Draw pointer around selection
graphics->setAlpha(true);
graphics->color(editor::ssImg[0]->getColor());
graphics->renderQd(editor::ssImg[0]->getBitmap(),
                   CRect(objectx + pointx,
                         objecty + pointy,
                         editor::ssImg[0]->getWidth(),
                         editor::ssImg[0]->getHeight()));

//Restore alpha
graphics->setAlpha(alpha);

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.

Anyone good at math sees anything wrong here ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:12:15+00:00Added an answer on May 30, 2026 at 2:12 am

    As I understand it, your wanted behavior presumes the existence of three points: an origin around which you’re rotating, a “mouse” to provide the direction relative to the origin, and a “selection” to provide the distance from the origin. (Somewhat confusingly, the result of your code is the “selection pointer”. I take it that “selection” means the original position of the selected object, and “selection pointer” means the position it’s been dragged to so far?)

    Your code, however, only actually refers to two of those points: (objectx, objecty), which I assume is the origin, and (pointerx, pointery), which I assume is the “mouse”. Your code never refers to the “selection”; so, naturally, the “selection” has no effect on the result of your code.

    There are a few other problems — Oli Charlesworth points out, in a comment above, that you’re wrongly dividing your angle by π/180, which means that you apply a very small rotation (which is why it looks like you end up with selection pointer = mouse; in fact, they can be up to a few degrees apart relative to the origin of rotation, but that’s not instantly noticeable) — but rather than fix those problems, I’d recommend you change your approach. Instead of generating “selection pointer” by rotating “selection” to match the angle of “mouse”, I recommend that you generate it by scaling “mouse” to match the magnitude of “selection”. The math for this is more straightforward, IMHO.

    If you do want to stick with the approach of generating “selection pointer” by rotating “selection” to match the angle of “mouse”, then you have two main things to fix. Your current code rotates “mouse” by the current angle of “mouse”. Part of the fix is to rotate “selection” instead; the other part of the fix is to rotate by the difference between the current angles of “mouse” and “selection”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.