module:extras/raypick

Back to documentation index.

module:extras/raypick()

The extras/raypick.js module. To import all symbols in this module, either of the following can be used:

import * from "extras/raypick.js";
// -- or --
import * as CustomModuleName from "extras/raypick.js";

Methods

(static) module:extras/raypick.raypick(x, y, projView, viewport, objects)

Finds the three-dimensional shape object and world-space coordinates corresponding to the given two-dimensional (X and Y) coordinates.

Parameters

Return Value

An object with the following properties:

Examples

The following example shows how a hypothetical scene graph could implement picking objects based on the position of the mouse cursor.

var mousePos = scene.getMousePosInPixels();
var viewport = [0, 0, scene.getWidth(), scene.getHeight()];
var projview = scene.getProjectionViewMatrix();
var o = raypick(mousePos.cx, mousePos.cy, projview, viewport, objects);
if(o.index >= 0) {
pickedShape = objects[o.index];
} else {
pickedShape = null;
}

Back to documentation index.