View Single Post
Old 03-13-2009, 10:25 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
Here is a sample function that takes any sensor object and calculates the speed of it:
import viz

sensor = viz.add('testtrack_all.dls')

def CalculateSpeed(obj):
	#Get current and last position
	current_pos = obj.getPosition()
	last_pos = getattr(obj,'last_pos',None)
	if last_pos is None:
		#This is first call, so save position and set speed to 0
		obj.last_pos = current_pos
		obj.speed = 0.0
		#Compute speed using last position
		obj.speed = vizmat.Distance(current_pos,last_pos) / viz.elapsed()
		obj.last_pos = current_pos
	print obj.speed
Reply With Quote