WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-15-2009, 07:40 PM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
window.pick function over sub-window

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
Reply With Quote
  #2  
Old 09-17-2009, 10:50 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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:
Code:
# 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)
Reply With Quote
  #3  
Old 09-23-2009, 06:38 AM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
I think I didn't describe the problem clearly. Imagine I created a window:

Code:
	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:

Code:
	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

Quote:
Originally Posted by farshizzo View Post
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:
Code:
# 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)
Reply With Quote
  #4  
Old 09-24-2009, 12:55 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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:
Code:
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,scene=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)
Reply With Quote
  #5  
Old 10-02-2009, 04:23 AM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
Thanks. Yes the problem was relativity to the graphics window.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Documentating function names aaThomas Vizard 5 05-15-2007 09:50 AM
Do you know how to send a value for 'pool' to the onActionEnd function? ghazanfar Vizard 1 03-22-2007 10:25 AM
timers and director function Jerry Vizard 1 06-22-2006 09:47 AM
node3d.center function tavaksai Vizard 3 08-13-2004 11:05 AM
The error window that couldn't FlyingWren Vizard 2 12-02-2003 08:23 AM


All times are GMT -7. The time now is 02:09 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC