WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-01-2006, 02:50 PM
paulpars paulpars is offline
Member
 
Join Date: May 2006
Location: Kingston, Ontario
Posts: 14
multiple timers

i have two timers, one that listens for certain keyboard input, and another that makes a person walk around in my world. I want the first one to be always on, but is there a way to make the second one start after a certain elapsed time, say 5 seconds or so? here's what my timer function looks like:

Code:
def mytimer(num):
	if num == 0:
		brake = 0
		if viz.iskeydown(viz.KEY_TAB):
			brake = 1
		if viz.iskeydown(viz.KEY_UP) and brake != 1:
			view.move(0,0,MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
			car2.translate(0,0,MOVE_SPEED*viz.elapsed(),viz.RELATIVE)
		elif viz.iskeydown(viz.KEY_DOWN):
			view.move(0,0,-MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
			car2.translate(0,0,-MOVE_SPEED*viz.elapsed(),viz.RELATIVE)
		if viz.iskeydown(viz.KEY_RIGHT):
			view.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD)
		elif viz.iskeydown(viz.KEY_LEFT):
			view.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD)
		updatecar()
	# puts the walker on the screen	
	if num == 1:
		walker.visible(viz.ON)
		global walkerX, walkerY, walkerZ, walkerAngle
		walker.rotate(0,1,0,90)
		# calculate components of motion w.r.t X and Z axis
		walkerZ = walkerZ - 0.00002 * math.sin(math.radians(walkerAngle))
		walkerX = walkerX + 0.00002 * math.cos(math.radians(walkerAngle))
		# move the walker
		walker.translate(walkerX,walkerY,walkerZ,viz.RELATIVE)

		

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.01,viz.FOREVER)
viz.starttimer(1,0,viz.PERPETUAL)
Reply With Quote
  #2  
Old 06-02-2006, 07:55 AM
halley halley is offline
Member
 
Join Date: Oct 2005
Posts: 27
A timer starts whenever you call viz.starttimer(), so your goal is to decide when it's appropriate to make that call.

Something like this sketch (this is not tested code):

Code:
timer_one = False

def mytimer(num):
	if num == 0:
		if not timer_one and viz.get(viz.FRAME_TIMESTAMP) > 5.0:
			timer_one = True
			viz.starttimer(1, 0, viz.PERPETUAL)
		# do other timer-zero stuff
	if num == 1:
		# do other timer-one stuff

viz.callback(viz.TIMER_EVENT, mytimer)
viz.starttimer(0, 0.01, viz.FOREVER)
__________________
--
[ e d h a l l e y ]
I'm just a user, not a representative of WorldViz. Hope I've been helpful.
Reply With Quote
  #3  
Old 06-02-2006, 10:12 AM
paulpars paulpars is offline
Member
 
Join Date: May 2006
Location: Kingston, Ontario
Posts: 14
error

when I try to run that I get this error:


if not timer_one and viz.get(viz.FRAME_TIMESTAMP) > 5.0:
AttributeError: 'module' object has no attribute 'FRAME_TIMESTAMP'
Reply With Quote
  #4  
Old 06-02-2006, 10:43 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
You can also use the Python time module.

Code:
import time

#Gives number of seconds since program start
print time.clock()
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #5  
Old 06-02-2006, 11:12 AM
paulpars paulpars is offline
Member
 
Join Date: May 2006
Location: Kingston, Ontario
Posts: 14
ok that seems to work fine, thanks!
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


All times are GMT -7. The time now is 10:59 AM.


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