View Single Post
  #4  
Old 01-08-2009, 10:00 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
this should update the speed in just the y direction every time the timer function is called

Code:
#add textbox and set position on screen
text_speed = viz.addTextbox(parent = viz.SCREEN)
text_speed.setPosition(.15, .9 ) 
text_speed.fontSize (30)

old_posY = 0
def showSpeed():
	
	global old_posY
	
	current_pos = viz.MainView.getPosition()
	current_posY = current_pos[1]
	distance = abs(current_posY - old_posY)
	
	#get speed in meters/sec
	speed = distance/viz.elapsed()
	#get speed in km/hour
	speed = speed/1000*3600
	
	old_posY = current_posY
	
	#enter speed in textbox rounded to 1 digit after decimal
	text_speed.message(str(round(speed,1)) + 'km/hour')
	
vizact.ontimer(.25, showSpeed)
Reply With Quote