Reference screenToWorld()

screenToWorld()

Converts 2D screen coordinates to 3D world coordinates.

This function takes a vector and converts its coordinates from coordinates on the screen to coordinates in the currently drawn object. This can be useful for determining the mouse position relative to a 2D or 3D object.

If given, the Z component of the input coordinates is treated as "depth", or distance from the camera.

Examples

Syntax

screenToWorld(x, y, [z])

Parameters

x
Number|p5.Vector: The x coordinate in screen space. (Or a vector for all three coordinates.)
y
Number: The y coordinate in screen space.
z
Number: The z coordinate in screen space.

Returns

p5.Vector: A vector containing the 3D world space coordinates.
Notice any errors or typos? Please let us know. Please feel free to edit src/core/environment.js and open a pull request!

Related References