I’m making a UI based on zooming and dragging (2d) . Basically I’m trying:
function draw() {
background(185, 175, 185);
translate(width/2, height/2);
scale(zoom);
translate(dragPos.x , dragPos.y);
for (const b of bodies) {
b.display();
b.update();
}
and I’ve tried a silly
function screenToWorld(x, y) {
let worldX = (x - dragPos.x - width/2) / zoom;
let worldY = (y - dragPos.y - height/2) / zoom;
return createVector(worldX, worldY);
}
function worldToScreen(x, y) {
let screenX = (x * zoom) + dragPos.x + width/2;
let screenY = (y * zoom) + dragPos.y + height/2;
return createVector(screenX, screenY);
}
Well, did not work… almost though
How can i keep track of the translation from transformed coordinates to mouse (screen)?
So mouse can interact with stuff based on being over or not …
The code is in progress and have a lot more going on, so I tried to isolate here the stuff about this point.
There is a running playground with the malfunctioning code here
How can I do it?