I made a raycaster to intersect some object inside canvas. It works good if canvas is alone in the window browser but it doesn't get intersection if I put canvas inside some other GUI and so the position of canvas is different. I think it is a problem with mouse coordinates. How can I debug it? If I know mouse coordinates how can I understand what is the coordinate of canvas?
function getPosition(event) {
// TODO: add the border of the canvas
var x = new Number();
var y = new Number();
if (event.x != undefined && event.y != undefined) {
x = event.x;
y = event.y;
} else {
// Firefox method to get the position
x = event.clientX + document.body.scrollLeft +
document.documentElement.scrollLeft;
y = event.clientY + document.body.scrollTop +
document.documentElement.scrollTop;
}
x -= canvas.offsetLeft;
y -= canvas.offsetTop;
return {x: x, y: y};
}