Vizard 8 » Reference » Viewpoints & Windows » Windows » Picking objects off the screen
8.0

Picking objects off the screen

Several Vizard commands handle moving from the 2D screen and mouse interface to the rendered 3D world.

Picking objects in the world with the cursor

To use the 2D position of the cursor on the screen to select objects within a rendered world, use <window>.pick(). This command draws a line from the cursor's 2D location on the window into the world. By default, it will return the first 3D node you intersect.

#Create some objects.
for i in range(10):
    viz.add('wheelbarrow.ive').setPosition(i,0,0)
#Create an action to cue.
MouseOverAction = vizact.fadeTo(1,begin=0,time=1)

def picker():
    #Check if the mouse is over one of the boxes
    item = viz.MainWindow.pick()
    item.runAction(MouseOverAction)

#Start a timer to execute picker repeatedly.
vizact.ontimer(.1, picker )

Getting more information about the intersection

If you want to get more information than just the object or objects intersected, use <window>.pick( info = True ). This will return a VizIntersect object which can tell you if anything was intersected (valid), the point at which the line intersected that object (point), the normal vector of the intersect point (normal), the object (object), and the name of the sub-object that the line intersected (name).

def picker():
    #Check if the mouse is over one of the boxes
    item = viz.MainWindow.pick( info = True )
    #If there is an intersection
    if item.valid:
        #Add mouse over action
        item.object.runAction(MouseOverAction)
        #Print the point where the line intersects the object.
        print( item.point)

Cue an action when you pick an object

If you want to cue an action with an object is selected, use vizact.onpick. This action will call a command whenever the user clicks a specific object.  

#Add a node to apply an action to.
myNode = viz.add( 'logo.wrl' )
#Add the node that you'll pick.
myPicker = viz.add( 'box.wrl' )
myPicker.setPosition( 2,0,0 )
#Add an action.
quickSpin = vizact.spin( 0,1,0, 90, 3 )
#Apply the action to the node when you pick the other object.
vizact.onpick( myPicker, myNode.runAction, quickSpin )
viz.MainView.setPosition(.5,0,-5)

Picking objects that are glued to the screen

If you want to pick objects that are glued to the screen, use <window>.pick( mode = viz.SCREEN ).

See also

In this section:

Window basics

Window & world coordinates

Window command table

Other sections:

Viewpoint and window basics

Viewpoint basics

Stereo basics

Application window basics

Tutorial: Windows & views

Example scripts:

Window views