Well for starters, i would discourage the use of free-dragging, as it will only lead to misery when you try to add collision detection.
We’re kind of reinventing the D3 wheel here, but lets put some things in perspective.
Is your window in the exact same place? What defines getMousePosition?
Why are we using the mouse position at all? Why do we not reference the element’s position, which should have an absolute measurement relative to its container? (If I grab the element on the right side, I’ll get a different position than if I grab it on the left…)
(the x/y coordinates are similar)
But now I’m trying to create a bounding box so the dragged device cant shoot off the page or dissapear (I tried to follow peters instructions, but am getting
The x and y coordinates are way off (These should be the same since the element was dragged to the same spot. It must be using the x/y coordinate system of the mouse on the page rather than the mouses position on the SVG.
I believe its set here
function getMousePosition(evt) {
var CTM = svg.getScreenCTM();
if (evt.touches) { evt = evt.touches[0]; }
return {
x: (evt.clientX - CTM.e) / CTM.a,
y: (evt.clientY - CTM.f) / CTM.d
};
}