WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-13-2007, 08:12 AM
Wenamun Wenamun is offline
Member
 
Join Date: Jan 2006
Location: Milwaukee Wisconsin
Posts: 11
timer counter

Is it possible to count how many times a timer has been called back (without the use of a counting variable)?

viz.elapsed() gives me the same numbers every time because it's only counting how long THIS instance has run. what about all instances?

thanks!
Reply With Quote
  #2  
Old 06-13-2007, 08:54 AM
Wenamun Wenamun is offline
Member
 
Join Date: Jan 2006
Location: Milwaukee Wisconsin
Posts: 11
i guess this is a better question:

i want to draw a line between the coordinates an object was at two seconds ago and the coordinates the object is at now. so i ran a timer to repeat every 2 seconds. the problem is obvious, and i would imagine the solution is equally so. i just can't figure it out.

the first time the function runs, i am told the variable 'oldLoc' is not defined. but if i define it in the first line of the function, it will be initialized every time the function is run and it will always be '[0,0,0]'. how can i work around this? i figure i could run a counter that assigns an arbitrary coordinate to 'oldLoc' the first time the function is run. but no matter how i do it, that counter is reset (initialized) every time the function is invoked.

hope this makes sense. thanks!

Code:
def mytimer(num):

	newLocs = []
	
	for x in range(numLights):
		
		newLoc = balls[x].get(viz.POSITION)
		newLocs.append(newLoc)
		
		viz.startlayer(viz.LINES)	
		viz.vertexcolor(1,0,1)
		viz.linewidth(1)
		
		#print 'newLocs[',x,']',newLocs[x]
		
		viz.vertex(newLoc)
		viz.vertex(0,0,0)
		
		tail = viz.endlayer()
		tails.append(tail)
			
		tail.size(0,0,0,1,viz.TIME)
		
	oldLocs = newLocs
Reply With Quote
  #3  
Old 06-13-2007, 02:35 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You need to declare the oldLocs variable as global. Your code should look like the following:
Code:
oldLocs = [ [0,0,0] for x in range(numLights) ] #Initialize to some value

def mytimer(num):
	global oldLocs 
	newLocs = []
	
	for x in range(numLights):
		
		newLoc = balls[x].get(viz.POSITION)
		newLocs.append(newLoc)
		
		viz.startlayer(viz.LINES)	
		viz.vertexcolor(1,0,1)
		viz.linewidth(1)
		
		#print 'newLocs[',x,']',newLocs[x]
		
		viz.vertex(newLoc)
		viz.vertex(0,0,0)
		
		tail = viz.endlayer()
		tails.append(tail)
			
		tail.size(0,0,0,1,viz.TIME)
		
	oldLocs = newLocs
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 07:48 AM.


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