WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   How to pause the Vizard simulation? (https://forum.worldviz.com/showthread.php?t=2580)

4711 03-08-2010 04:36 AM

How to pause the Vizard simulation?
 
Hi guys,

I have a simple problem: I just want the whole Vizard simulation to pause for a few seconds, and afterwards continue from where it stopped right before. During that pause, no navigation through the simulation must be allowed (that is, MainView mustn't change).

So I tried:
Code:

import time
time.sleep( several seconds )

This in fact freezes the whole simulation for the stated amount of time, but meanwhile mouse input is still accepted, which is then executed right after waking from time.sleep(). That means, if the user continues moving the mouse during this pause, the whole input is recorded (instead of being ignored), and the corresponding movement just gets performed afterwards.

Of course this is not what I wanted, so I tried it another way:
Code:

viz.mouse( viz.OFF )
yield viztask.waitTime( several seconds )
viz.mouse( viz.ON )

This actually works fine (user cannot navigate and input is ignored), except one thing: The player keeps drifting through the environment - seemingly with the speed and direction of the last accepted input received before the mouse became switched off - until the viztask expires. So clearly that's useless for me, too.

Now I wonder if there is any passably simple solution for this problem?

masaki 03-08-2010 09:50 AM

you can try using viz.mouseScale() and set the scale factor for the navigation to 0 and then switch it back to 1 when you want the simulation to move again.

For example:

Code:

def goStopTask():
       
        viz.mouse.setScale(0,0)
        yield viztask.waitTime( 2)
        viz.mouse.setScale(1,1)
       
vizact.onkeydown( ' ',  viztask.schedule, goStopTask )

when you hit the space bar, the program will scale the mouse input to 0 for 2 seconds, and then back to 1.

Best,
Masaki

4711 03-09-2010 04:58 AM

Thanks, masaki, for your idea!

Unfortunatelly, it leads exactly to the same result as the mouse-on-mouse-off approach.

My code is something like this:
Code:

import viz
import viztask


def SetTrial( configuration ):
       
        # ...
       
        # Middle mouse button or spacebar picks object
        vizact.onmousedown( viz.MOUSEBUTTON_MIDDLE, pickObject )
        vizact.onkeydown( ' ', pickObject )
       
        # Loop through all trials
        for i in range( TRIALS ):

                # ...
                                                                       
                # Prepare VE
                viz.go()
                viz.mouse( viz.OFF )
                viz.MainView.eyeheight( EYEHEIGHT )
                viz.clearcolor( SKYCOLOR )
                viz.collision( viz.ON )
               
                # -------------------------------------- #

                if ( WAIT_FOR ):
                        yield viztask.waitTime( WAIT_FOR )
                else:
                        yield viztask.waitKeyDown(' ')

                # -------------------------------------- #
                       
                # Position the user
                viz.MainView.setPosition( Xc, Yc, Zc )
                viz.MainView.setEuler( Yr, Pr, Rr )

                # Enable mouse navigation
                viz.mouse( viz.ON )
                       
                # Register callback for timers
                viz.callback( viz.TIMER_EVENT,onTimer )
                viz.starttimer( 0, 0,  viz.PERPETUAL )
                viz.starttimer( 1, .05, viz.PERPETUAL )
               
                # Wait till the trial is over
                yield viztask.waitTime( DURATION )

                # Disable user's activities
                viz.mouse( viz.OFF )
                viz.killtimer(0)
                viz.killtimer(1)

                # ...


# Start Vizard
viz.go()
viz.clearcolor( viz.SKYBLUE )

# Schedule Task
viztask.schedule( SetTrial( configuration ) )

I've yet tried to define a separate function which is then called (similar to masaki's suggestion), and also placed the "yield viztask.waitTime( WAIT_FOR )" command outside the "IF" condition. But the behaviour always is the same, the player keeps drifting during the viztask.

Maybe the problem is due to the structure of my code, however, I could not find an explanation so far...

So any help would be appreciated!
:)

4711 03-18-2010 01:20 AM

Though I still have no idea how to avoid this annoying "drift effect", I could at least figure out that the player does NOT -as previously assumed- drift with the last given speed and direction input, but rather always drifts straight ahead and with always the same speed.

So maybe this effect is not due to my code, but could also be caused by a bug in the viztask module...?

Jeff 03-18-2010 04:45 PM

The code that masaki posted stops the view from moving and there is no drifting after the mouse movement is scaled back to normal. So you must have something else happening in your code.


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

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