WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 10-18-2007, 08:32 AM
jaclyn.bill jaclyn.bill is offline
Join Date: Oct 2007
Posts: 42
Question Timing


I've search through this and Vizard help for various timing hints but I still can't get the script to do exactly what I want.

I basically want to start the timer on a mouse click (which will also start the stimulus running) and record/ print the time an object begins to move and stops moving (in milliseconds) - printing the object's x,y,z along with these times.

Has anybody done this?

Thank you.

Reply With Quote
Old 10-18-2007, 10:24 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
Here is a sample script that waits for the left mouse button to be clicked then moves a ball while printing out the current time in milliseconds and its current position. Let me know if anything is unclear.
import viz

START_POS = [-4,2,10]
STOP_POS = [4,2,10]

ball = viz.add('ball.wrl')

def RecordTimer():
	"""Prints out current time in milliseconds followed by ball position"""
	currentTime = viz.tick()
	pos = ball.getPosition()
	print '%d %.4f %.4f %.4f'%(currentTime * 1000,pos[0],pos[1],pos[2])

import viztask

def RunSimulation():
	#Repeat simulation indefinitely
	while True:
		#Wait for left mouse button to be pressed
		yield viztask.waitMouseDown(viz.MOUSEBUTTON_LEFT)
		#Place ball in starting position
		#Start timer to record ball position
		recordTimer = vizact.onupdate(0,RecordTimer)
		#Wait for ball to finish move action
		yield viztask.runAction(ball,vizact.moveTo(STOP_POS,speed=2))
		#Stop timer
viztask.schedule( RunSimulation() )

#Disable mouse navigation
Reply With Quote
Old 10-19-2007, 03:34 AM
jaclyn.bill jaclyn.bill is offline
Join Date: Oct 2007
Posts: 42

Great, I've got it working fine now.

Thank you.

Reply With Quote

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 02:43 AM.

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