<<<<<<<<<<<<<<<<<

picker(display) Filter picker(display)

NAME

picker - select (or pick) actors from graphics window

DESCRIPTION

Picker allows the selection of actors from a graphics window. Picker works with a renderer and the renderer's active camera and actors to select actors given a point in x-y screen coordinates.

Picker is implemented as follows: the screen coordinate is converted to world coordinates and, together with the active camera position, defines a ray in world space. The start and end position of the ray is determined from the clipping range of the camera. Hence picking is affected by the clipping planes of the active camera.

Once the ray is defined, for each actor that is on, pickable, and non-transparent, an intersection of the ray and the actors bounding box is performed. The geometric intersection is computed by transforming the ray into the coordinates of each actor's modeller, and then, intersecting the bounding box of the modeller. If the bounding box is hit, then the actor is added to picker's selected_actors list.

Because bounding boxes may overlap, it is possible to select more than one actor. Picker keeps track of the single actor whose bounding box center is closest to the camera (eye) position. Also, the actor's modeller, and the center of the actor bounding box in both world and modeller coordinates is maintained.

SUPERCLASS

object

INSTANCE VARIABLES

renderer name of renderer object

selection_point x-y screen coordinates

tolerance tolerance for geometric computation expressed as a fraction of the screen size (e.g., 0.025 means 2.5 of the renderer window).

MESSAGES

renderer= renderer_name set the renderer instance variable

renderer? get the renderer instance variable

selection_point=(x,y) set the selection coordinates in screen coordinates.

selection_point? get the selection coordinates.

tolerance=value set the tolerance of picking as a fraction of screen size.

tolerance? get the picking tolerance.

pick! execute picking operation. Used by picker as well as sub-classes.

picked? determine whether any actor was picked during the previous pick! operation.

selected_actors? the list of all actors whose bounding box was hit during the previous pick! operation.

actor? the actor, from the list of selected actors, whose center is closest to the eye of the viewer.

modeller? the modeller associated with the actor returned from the actor? message.

pick_coords? the x,y,z coordinates of the center of the actor picked (in world coordinates).

model_coords? the x,y,z coordinates of the center of the actor picked (in the modeller's coordinate system)

intersect:(p1(x,y,z), p2(x,y,z), tol, actor, modeller) method to perform actual intersection operation. The point coordinates p1[] and p2[] must be in modeller coordinates. tol is the tolerance in model coordinates, actor is the name of the actor, and modeller is the name of the modeller.

free! free the picker instance.

mark_picked internal message to indicate that something has been picked.

EXAMPLE

In this example three spheres are drawn (a single sphere modeller with three actors). The spheres are separated by translating them. The selection point is specified by setting the value of the vector instance p and executing the pick action (e.g., p=(250,250);pick do!;). A green cube is shown at the pick coordinates (e.g., center of actor), and a red cube indicates the actual pick location.

/* * Spheres to pick */ sphere_modeller new: asphere resolution=1 ; actor new: s1 modeller= asphere ; actor new: s2 position+(3.5,0,0) modeller= asphere ; actor new: s3 modeller= asphere position+(-3.5,0,0) ; /* * Pick markers */

cube_modeller new: acube; actor new: pick_location modeller= acube color=(1,0,0) scale=(.1,.1,.1) unpickable! ; actor new: picker_point modeller= acube color=(0,1,0) scale=(.1,.1,.1) unpickable! ;

camera new: acamera range= (-2.5,2.5) position= (1,1,1) default! on!

; renderer new: aren pref_size=(500,500) actors=[actor instances?] cameras=[camera instances?] render! ;

picker new: pick_actor renderer= aren debugon! ; vector new: p = (230,260); logic new: if; actions new: pick tick_actions=` pick_location position= [aren dpoint=p display_to_world! wpoint?]; if = [pick_actor selection_point=p pick! picked?] true: ` picker_point on! position= [pick_actor pick_coords?]; ' false: ` picker_point off!; ' ; aren render!; ' ; pick do!;

SEE ALSO

pick_points, pick_surface, display_data_geometry


Please send comments and suggestions to
consult@rpi.edu