Mouse position with Zoom

Mar 8, 2013 at 2:32 AM
Hi there,

I modified the example "12 - Selecting locations & objects". I applied a zoom.
However, I noticed that the click position is now incorrect.

I would like to know how I can adjust the code below so that the click position remains correct with the zoom.
var puv = {
          u:event.clientX - sheetengine.canvas.offsetLeft, 
          v:event.clientY - sheetengine.canvas.offsetTop
        };
        
        // transform coordinates to world coordinate system
        var pxy = sheetengine.transforms.inverseTransformPoint({
          u:puv.u + sheetengine.scene.center.u, 
          v:puv.v + sheetengine.scene.center.v
        });
Thanks for your help
Coordinator
Mar 8, 2013 at 7:46 AM
Edited Mar 8, 2013 at 7:47 AM
Hi,
pxy.x = (pxy.x - sheetengine.scene.center.x) / zoom + sheetengine.scene.center.x;
pxy.y = (pxy.y - sheetengine.scene.center.y) / zoom + sheetengine.scene.center.y;
Check out the source code of the "Holy yards" demo Crossyards game. It uses zoom and object selection with mouse clicks. You can read more info about how it is constructed (and also about the relevant code for mouse locations) here:
https://www.crossyards.com/developers/holy-yards
Mar 9, 2013 at 6:56 PM
Thank you so much,

it works great!