I already have a
MouseMotionListener with the
mouseDragged method implemented. I can drag an object with the mouse, but it doesn't matter where I put the mouse inside the object, it will move it's origin point to the mouse.
I know that this is what the simple
x = mouseX; y = mouseY code should do, but what is the code to drag the object relative to the position of the mouse inside the shape?
I tried this, but it doesn't work when the object is in the position 0:
x = mouseX - (mouseX - x); y = mouseY - (mouseY - y);
The code doesn't work because when X and Y are 0, it is basically
x = mouseX - mouseX; y = mouseY - mouseY, that is 0 both.
What is the algorithm that is "0-pos-proof" that I can use?