getMouseScreenPosition method

Vector3 getMouseScreenPosition(
  1. Point<num> pt
)

Get the position of the point pt in the canvas instead of the whole html document.

Returns a Vector3 conaining the coordinates x and y of the corresponding point.

Implementation

Vector3 getMouseScreenPosition(Point pt) {
  var bb = canvas.getBoundingClientRect(); // canvas bounding box

  var x = mapValue(pt.x, bb.left, bb.right, 0, camera.pixelWidth);
  var y = mapValue(pt.y, bb.top, bb.bottom, 0, camera.pixelHeight);

  return Vector3(x, y, 0);
}