WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-13-2009, 11: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:
Code:
import viz
viz.go()

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
	else:
		#Compute speed using last position
		obj.speed = vizmat.Distance(current_pos,last_pos) / viz.elapsed()
		obj.last_pos = current_pos
		
	print obj.speed
	
vizact.ontimer(0,CalculateSpeed,sensor)
Reply With Quote
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Vizard Sensor Plugin farshizzo Plug-in development 25 08-01-2019 01:24 AM
speed on animation path whj Vizard 8 11-17-2008 08:41 PM
wiimote and sensor bar masaki Vizard 1 03-06-2008 04:07 PM
Multiple Copies of same sensor plugin RedSpikeyThing Plug-in development 2 02-12-2008 03:10 PM
using sensor data in Physics1.py Eunice Vizard 4 01-03-2006 06:18 AM


All times are GMT -7. The time now is 01:09 PM.


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