mouse coords relative to a DOM element

06 July 2015 18:54
I need the Canvas to be smaller than the html page (80% width, 80% height), but now the objects get selected when clicking in other parts of the canvas.
I noticed m_mouse.get_coords_x(e) and m_mouse.get_coords_y(e) are returning values using the whole browser window, is there a way of making those return values using the relative space of the canvas and not the window?

I noticed a function called client_to_canvas_coords(x, y, dest), how does this work?
06 July 2015 20:43

Yes, that method should do the trick. Starting from Blend4Web v15.06 all coordinates are considered relative to the canvas. Methods get_coords_x()/get_coords_y() are exceptions to this rule because they simply return mouse/touchscreen client coordinates without any conversion (e.g. relative to browser window). So that's why you need client_to_canvas_coords() method here.
06 July 2015 20:47
Please note that the third argument to client_to_canvas_coords() is optional.
08 July 2015 14:37
Thanks, yes it works!
Please register or log in to leave a reply.