![]() |
|
|
|
#1
|
|||
|
|||
|
The script above works exactly as I want it to work, i.e. I had import random and import viztask at the top of my script. And as per the script above the cube should loom and then go back to its original position.
The only two things I am having difficulty with is: 1. getting the objects to loom randomly 2. adding an if statement that if there is no keyboard reaction to wafter x seconds to move onto the next object Thanks |
|
#2
|
|||
|
|||
|
I modified your script to randomly loom a new cube every iteration, and to handle the case if no reaction was registered for a certain amount of time. I also place the cube back to the original location once the reaction is entered.
Code:
import viz
import vizact
import viztask
import random
# Time limit for keyboard reaction
REACTION_TIME_LIMIT = 5.0
# Sets the speed of the rotation for all 9 cubes
ROTATE_SPEED = 50
viz.go()
viz.mouse(0)
viz.cursor(viz.OFF)
# Sets viewpoint at z meters away
viz.move(0,0,-10)
# Asks for the participant number
subject = viz.input('Enter the participant number?')
# List of cubes
cubes = []
for row in [0,2,4]:
for col in [0,-3,3]:
pos = (col,row,0)
cube = viz.add('box.wrl',cache=viz.CACHE_CLONE,pos=pos)
cube.originalPos = pos
cubes.append(cube)
# Function that will update cube rotation every frame
def RotateCubes():
increment = ROTATE_SPEED * viz.elapsed()
for cube in cubes:
cube.setAxisAngle([0, 5, 20, increment],viz.REL_PARENT)
vizact.ontimer(0,RotateCubes)
# Opens file 'response.txt' in write mode
file = open('reaction_time', 'a')
# Define a function that records reaction times in response to a looming cube
def SaveData():
#Data for getting values from wait conditions
d = viz.Data()
while True:
#Wait 2 seconds
yield viztask.waitTime(2)
# Randomly loom a cube
randomCube = random.choice(cubes)
backAndFourth = vizact.sequence([vizact.goto(0, 0, -1, 1), vizact.goto(randomCube.originalPos, 1)])
randomCube.addAction(backAndFourth)
#Wait for next frame to be drawn to screen and save display time
yield viztask.waitDraw(d)
displayTime = d.time
#Wait for keyboard reaction or timeout
waitKey = viztask.waitKeyDown(None,d)
waitTimeout = viztask.waitTime(REACTION_TIME_LIMIT)
yield viztask.waitAny([waitKey,waitTimeout],d)
if d.condition is waitKey:
reactionTime = d.time - displayTime
# Create the output string
out = str(reactionTime) + '\t''\n'
# Write the string to the output file
file.write(out)
print 'Reaction time:',reactionTime
else:
print 'Reaction timeout exceeded'
# Restore cube to original location and stop looming action
randomCube.setPosition(randomCube.originalPos)
randomCube.clearActions()
# Defines a callback for functions
viztask.schedule(SaveData())
|
|
#3
|
|||
|
|||
|
Thanks so much for your help Wizard.
The only problem is that the cubes aren't coming towards to the user they are moving to position (0, 0, -1, 1) Any thoughts? Many thanks. |
|
#4
|
|||
|
|||
|
Hi - just to say I've worked it out. Thanks for all of your help with this.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| retrieve Object names | Geoffrey | Vizard | 11 | 12-11-2009 05:26 AM |
| Can you link the position of a tracker to the orientation of an object? | michaelrepucci | Vizard | 1 | 09-19-2008 11:23 AM |
| Getting object position in screen coordinates | v-Salik | Vizard | 1 | 10-19-2007 04:41 PM |
| picking problem... | k_iwan | Vizard | 2 | 07-27-2007 08:57 PM |
| rotate to object | jargon | Vizard | 1 | 08-08-2005 01:20 PM |