WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Multiple Viewports in Vizard, Utilizing keyboard callback (https://forum.worldviz.com/showthread.php?t=512)

shivanangel 02-21-2006 11:39 AM

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)


farshizzo 02-21-2006 12:52 PM

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)


shivanangel 02-21-2006 04:56 PM

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


All times are GMT -7. The time now is 05:32 AM.

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