WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-21-2006, 11:39 AM
shivanangel shivanangel is offline
Member
 
Join Date: Feb 2006
Location: New Jersey
Posts: 182
Multiple Viewports in Vizard, Utilizing keyboard callback

Hi,

I tried to create 4 viewports on the screen at once.
I have the main viewport, and then
3 viewports on the side.

I used a simple keyboard callback function to
turn the viewports on and off.

Below is the code I am using.

Everything works fine up until I press a,s, or d 4 times. After
the fourth press, Vizard will crash.

Is this just sloppy implementation on my part?

Also, the next thing I will be working on when these
viewports stop crashing is making the viewport
lock in on whatever the previous view was.

Can I simply set the
viewpoint of the window
to the main cameras view
and update it every time there
is a keyboard event (which in my
case will only make the viewports
turn on and off).

~~Thanks,

George

Code:
################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Keyboard
################################################

def mykeyboard(key):
	view = viz.add(viz.VIEWPOINT)
	if key == 'a':
		window1.visible(viz.TOGGLE) # Hide the window

	elif key == 's':
		window2.visible(viz.TOGGLE) # Hide the window

	elif key == 'd':
		window3.visible(viz.TOGGLE) # Hide the window

		
		
		
################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Objects
################################################


viz.add('outersphere.IVE')
viz.add('innersphere.IVE')
viz.add('plane.IVE')

window1 = viz.add(viz.WINDOW)
window1.position(0,1)
window2 = viz.add(viz.WINDOW)
window2.position(0,0.25)
window3 = viz.add(viz.WINDOW)
window3.position(1,0.25)



################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Callback
################################################


viz.callback(viz.KEYBOARD_EVENT,mykeyboard)
Reply With Quote
  #2  
Old 02-21-2006, 12:52 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Which version of Vizard are you using? There was a bug that would cause a crash when adding a certain amount of viewpoints, but it should be fixed in the latest version.

I've modified your script to update the viewpoint of each window when the corresponding key is pressed. The only "sloppy" thing about your script is that you are adding a new viewpoint each time a key is pressed. The the script below creates a viewpoint for each window during startup, and just modifies the existing viewpoint in the keyboard callback. Let me know if this doesn't help:
Code:
import viz
viz.go()

###############################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Keyboard
################################################

def mykeyboard(key):
	if key == 'a':
		view1.translate(mainView.get(viz.HEAD_POS))
		view1.rotatequat(mainView.get(viz.HEAD_QUAT))
	elif key == 's':
		view2.translate(mainView.get(viz.HEAD_POS))
		view2.rotatequat(mainView.get(viz.HEAD_QUAT))
	elif key == 'd':
		view3.translate(mainView.get(viz.HEAD_POS))
		view3.rotatequat(mainView.get(viz.HEAD_QUAT))
		
		
		
################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Objects
################################################

viz.add('outersphere.IVE')
viz.add('innersphere.IVE')
viz.add('plane.IVE')

window1 = viz.add(viz.WINDOW)
window1.position(0,1)
view1 = viz.add(viz.VIEWPOINT)
window1.viewpoint(view1)

window2 = viz.add(viz.WINDOW)
window2.position(0,0.25)
view2 = viz.add(viz.VIEWPOINT)
window2.viewpoint(view2)

window3 = viz.add(viz.WINDOW)
window3.position(1,0.25)
view3 = viz.add(viz.VIEWPOINT)
window3.viewpoint(view3)

mainView = viz.get(viz.MAIN_VIEWPOINT)
################################################
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Callback
################################################


viz.callback(viz.KEYBOARD_EVENT,mykeyboard)
Reply With Quote
  #3  
Old 02-21-2006, 04:56 PM
shivanangel shivanangel is offline
Member
 
Join Date: Feb 2006
Location: New Jersey
Posts: 182
Thanks a lot.

I modified it slighty and kept it from crashing again.
I believe we are using an earlier version at our school.
A few decimal places behind the one you currently offer.

That probably accounts for the error. And since I was
adding a new viewport each time, I can see how it could
compound and create some problems after the 4th instance.

Thanks again,
George
Reply With Quote
Reply


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


All times are GMT -7. The time now is 04:51 PM.


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