PDA

View Full Version : window.pick function over sub-window


omidbrb
09-15-2009, 07:40 PM
Hi,

I have a function that examines all the pixels of the MainWindow using the window.pick function. The problem is that when I use a sub-window instead of MainWindow, I get strange results. Specially, the window.pick command returns "no object" over the portion of the MainWindow that hasn't been occupied by the sub-window. My question is, does the window.pick function works with sub-windows?

Best,
Omid

farshizzo
09-17-2009, 10:50 AM
The window.pick function only works for that window. You will have to call the pick function for the specific window you are interested in. You can use the viz.window.select command to get the current sub-window located at the specified screen position. I just noticed that this command is currently undocumented, so here is some example code showing how to use it:# Get the sub-window located at the current mouse position
window = viz.window.select()

# Get the window located at the center of the screen
window = viz.window.select([0.5,0.5])

# Get the window located at pixel location (100,100)
window = viz.window.select([100,100],mode=viz.WINDOW_PIXELS)

omidbrb
09-23-2009, 06:38 AM
I think I didn't describe the problem clearly. Imagine I created a window:


UpperRightWindow = viz.addWindow()
UpperRightWindow.position (0.6, 1.0)
UpperRightWindow.size(0.4, 0.4)
UpperRightWindow.visible(0,viz.SCREEN)

RightEye = viz.add(viz.VIEWPOINT)
RightEye.eyeheight(0)
rightLink = viz.link(avatar.getBone('Bip01 Head'),RightEye)

UpperRightWindow.viewpoint(RightEye)
UpperRightWindow.clip(0.00001, 50000)


Then I want to determine what object lies at any pixel:


xres = 200
yres = 200
size = (xres, yres)

for x in xrange(xres):
for y in xrange(yres):
xNorm = x/(xres*1.0)
yNorm = 1-y/(yres*1.0)
intersect = UpperRightWindow.pick(True, viz.WORLD, pos = [xNorm, yNorm])
if intersect.valid == True:
print "pixel " + str(x) + "," + str(y) + "," + intersect.name + "," + str(intersect.point)
else:
print "no object at " + str(x) + "," + str(y)


This function works correctly with viz.MainWindow but not with the new UpperRightWindow.

Am I doing anything wrong?

Best,
Omid

The window.pick function only works for that window. You will have to call the pick function for the specific window you are interested in. You can use the viz.window.select command to get the current sub-window located at the specified screen position. I just noticed that this command is currently undocumented, so here is some example code showing how to use it:# Get the sub-window located at the current mouse position
window = viz.window.select()

# Get the window located at the center of the screen
window = viz.window.select([0.5,0.5])

# Get the window located at pixel location (100,100)
window = viz.window.select([100,100],mode=viz.WINDOW_PIXELS)

farshizzo
09-24-2009, 12:55 PM
Are the coordinates you are passing to the pick function relative to the lower-left corner of the sub-window, or the lower-left corner of the graphics window? The pick function expects coordinates that are relative to the lower-left corner of the graphics window. Here is a simple script showing that picking does work with sub-windows:import viz
viz.go()

viz.mouse(0)
viz.clearcolor(viz.GRAY)

#Add sub-windows
window = viz.addWindow(view=viz.addView(scene=2),pos=(0.8,1 ))
window = viz.addWindow(view=viz.addView(scene=3),pos=(0,1))
window = viz.addWindow(view=viz.addView(scene=4),pos=(0,0.2 ))
window = viz.addWindow(view=viz.addView(scene=5),pos=(0.8,0 .2))

#Add quad to each window
viz.addTexQuad(pos=(0,1.8,2),color=viz.WHITE,scene =1)
viz.addTexQuad(pos=(0,1.8,2),color=viz.RED,scene=2 )
viz.addTexQuad(pos=(0,1.8,2),color=viz.GREEN,scene =3)
viz.addTexQuad(pos=(0,1.8,2),color=viz.BLUE,scene= 4)
viz.addTexQuad(pos=(0,1.8,2),color=viz.YELLOW,scen e=5)

def dopick():
win = viz.window.select()
if win:
node = win.pick()
if node:
node.runAction(vizact.sizeTo(size=[2,2,1],time=0.1))
node.addAction(vizact.sizeTo(size=[1,1,1],time=0.1))
vizact.onmousedown(viz.MOUSEBUTTON_LEFT,dopick)

omidbrb
10-02-2009, 04:23 AM
Thanks. Yes the problem was relativity to the graphics window.