-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvr_experiment_clean.py
389 lines (330 loc) · 12.4 KB
/
vr_experiment_clean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
'''
Created by David Way & Emer Mooney
This experiment is used to investigate the effect that crossing a physical boundary can have on memory recall.
In research previously undertaken utilising virtual environments a decline in memory has been noted while moving between new locations.
Group A does not walk through boundary/door
Group B walks through boundary/door
'''
import viz
import vizshape
import vizact
import random
import vizinput
import vizcam
import viztask
import vizproximity
import viztracker
import vizfx.postprocess
import vizinfo
import vizshape
import vr_utils
#Variables
scale = 14
walls = roof = divider = door = None
bag1 = bag2 = None
stationOne = stationTwo = stationOneSensor = stationTwoSensor = doorStation = doorStationSensor = None
viewTracker = mouseTracker = None
taskA = []
firstPickObject = secondPickObject = None
shapes = []
timerCount = 0
#Strings
startingInstructions = """Please read these instructions: \nControls: W = Move Forward, S = Move Back, D = Move Right, \nA = Move Left, Left Mouse to select objects. \n\nIn the next section you will be given 10 seconds to read and memorise a task. \nPlease ask the the tester if you have any questions before continuing.\n\nPress the spacebar to continue when ready."""
selectPhaseInstructionsGroupA = """Select the RED CUBE, this will put it in your bag. \nThen move to the desk behind you. \nSwap the shape in your bag with the GREEN SPHERE by clicking it with the mouse."""
selectPhaseInstructionsGroupB = """Select the RED CUBE, this will put it in your bag. \nThen move to the desk in the room behind you. \nSwap the shape in your bag with the GREEN SPHERE by clicking it with the mouse."""
#Set up vizard
vr_utils.init(viz, viztracker)
# Setup keyboard/mouse tracker
viewTracker = vr_utils.enableNavigation(viewTracker, mouseTracker, viz, viztracker)
bag1 = vr_utils.makeBag(viewTracker, 1)
bag2 = vr_utils.makeBag(viewTracker, 2)
#Build the scene
vr_utils.buildScene(walls, roof, scale)
#Add the shapes to the scene
shapes = vr_utils.makeShapes1(viz, vizshape)
def exitStationOne(e):
global bag1
#print bag1.getDst().name #returns the bag from the link (bag1)
bag1.postTrans([0,-0.5,0])
def exitStationTwo(e):
global bag2
bag2.postTrans([0,-0.5,0])
def enterStationOne(e):
global bag1
bag1.postTrans([0,0.5,0])
def enterStationTwo(e):
global bag2
bag2.postTrans([0,0.5,0])
def addSensors():
global stationOne, stationTwo, stationOneSensor, stationTwoSensor, doorStation, doorStationSensor
stationOne = viz.addChild('plant.osgb',pos=[0, 0, 10],scale=[1, 1, 1])
stationOne.disable(viz.PICKING)
stationOne.disable(viz.RENDERING)
stationOneSensor = vizproximity.Sensor(vizproximity.Box([3,4,3],center=[0,1.5,1]),source=stationOne)
doorStation = viz.addChild('plant.osgb',pos=[0, 0, 0],scale=[1,1,1])
doorStation.disable(viz.PICKING)
doorStation.disable(viz.RENDERING)
#doorStationSensor = vizproximity.Sensor(vizproximity.Box([3,4,3],center=[0,1.5,1]),source=doorStation)
doorStationSensor = vizproximity.Sensor(vizproximity.Box([2.5,2.5,3.5]),source=viz.Matrix.translate(0,1.75,0))
stationTwo = viz.addChild('plant.osgb',pos=[0, 0, -12],scale=[1, 1, 1])
stationTwo.disable(viz.PICKING)
stationTwo.disable(viz.RENDERING)
stationTwoSensor = vizproximity.Sensor(vizproximity.Box([3,4,3],center=[0,1.5,1]),source=stationTwo)
target = vizproximity.Target(viz.MainView)
#Create proximity manager
manager = vizproximity.Manager()
#Add destination sensors to manager
manager.addSensor(stationOneSensor)
manager.addSensor(stationTwoSensor)
manager.addSensor(doorStationSensor)
manager.onExit(stationOneSensor, exitStationOne)
manager.onExit(stationTwoSensor, exitStationTwo)
manager.onEnter(stationOneSensor, enterStationOne)
manager.onEnter(stationTwoSensor, enterStationTwo)
#Add viewpoint target to manager
manager.addTarget(target)
#Toggle debug shapes with keypress
vizact.onkeydown('t',manager.setDebug,viz.TOGGLE)
#Create proximty sensors/hit boxes
##addSensors(stationOne, stationTwo, stationOneSensor, stationTwoSensor, doorStation, doorStationSensor)
addSensors()
#Result class
class Result:
def __init__(self, correctAnswers):
self.correctAnswers = correctAnswers
def __str__(self):
return self.correctAnswers
def getParticipantInfo():
global divider, door, scale
#Add an InfoPanel with a title bar
participantInfo = vizinfo.InfoPanel('',title='Participant Information', align=viz.ALIGN_CENTER, icon=False)
participantInfo.getPanel().fontSize(40)
#Add name and ID fields
textbox_first = participantInfo.addLabelItem('First Name',viz.addTextbox())
textbox_last = participantInfo.addLabelItem('Last Name',viz.addTextbox())
textbox_group = participantInfo.addLabelItem('Group (A/B)',viz.addTextbox())
participantInfo.addSeparator(padding=(20,20))
#Add gender and age fields
radiobutton_male = participantInfo.addLabelItem('Male',viz.addRadioButton(0))
radiobutton_female = participantInfo.addLabelItem('Female',viz.addRadioButton(0))
textbox_age = participantInfo.addLabelItem('Age',viz.addTextbox())
#droplist_age = participantInfo.addLabelItem('Age',viz.addDropList())
#ageList = ['18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33', '34', '35', '36', '37', '38', '39', '40+']
#droplist_age.addItems(ageList)
participantInfo.addSeparator(padding=(20,20))
#Add submit button aligned to the right and wait until it's pressed
submitButton = participantInfo.addItem(viz.addButtonLabel('Submit'),align=viz.ALIGN_RIGHT_CENTER)
yield viztask.waitButtonUp(submitButton)
#Collect participant data
data = viz.Data()
data.lastName = textbox_last.get()
data.firstName = textbox_first.get()
data.group = textbox_group.get().lower()
data.ageGroup = textbox_age.get()
#data.ageGroup = ageList[droplist_age.getSelection()]
if radiobutton_male.get() == viz.DOWN:
data.gender = 'male'
else:
data.gender = 'female'
#if the person is a menber of the group B
if (data.group == 'b'):
#load the diving wall and door, hide them
divider = viz.addChild('models/new/divider_large_2.osgb')
divider.setScale(scale, scale, scale)
divider.setPosition([0,0,20])
divider.disable(viz.PICKING)
door = viz.addChild('models/new/door_large.osgb')
door.setCenter([-0.05, 0, 0])
door.setScale(scale, scale, scale)
door.setPosition([0,0,20])
door.disable(viz.PICKING)
divider.setPosition([0,0,0])
door.setPosition([-0.65,0,0])
participantInfo.remove()
# Return participant data
viztask.returnValue(data)
def pickObject():
global firstPickObject
while True:
yield viztask.waitMouseDown(viz.MOUSEBUTTON_LEFT)
#Check if the mouse is over one of the shapes
item = viz.MainWindow.pick( info = True )
#If there is an intersection
if item.valid:
#Add mouse over action
bag1Position = bag1.getDst().getPosition()
aboveBag1 = [bag1Position[0], bag1Position[1]+0.6, bag1Position[2]]
inThaBag1up = vizact.moveTo(aboveBag1,speed=5)
inThaBag1down = vizact.moveTo(bag1.getDst().getPosition(),speed=5)
item.object.addAction(inThaBag1up)
item.object.addAction(inThaBag1down)
firstPickObject = item.object
print firstPickObject.getPosition();
yield viztask.waitTime(0.6)
firstPickObject.visible((viz.OFF))
#Print the point where the line intersects the object.
taskA.append(item.object.name)
viz.callback(viz.MOUSEDOWN_EVENT, 0)
print taskA
#print taskA[0].getPosition()
#print taskA[0].size
#print taskA[0].colour
print "picked"
return
def swapObject():
global firstPickObject, bag2 , secondPickOject
while True:
yield viztask.waitMouseDown(viz.MOUSEBUTTON_LEFT)
#Check if the mouse is over one of the shapes
item = viz.MainWindow.pick( info = True )
#If there is an intersection
if item.valid:
#Add mouse over action
bag2Position = bag2.getDst().getPosition()
firstPickObject.visible(viz.ON)
firstPickObject.setPosition(bag2Position)
aboveBag2 = [bag2Position[0], bag2Position[1]+0.6, bag2Position[2]]
outtaThaBag2up = vizact.moveTo(aboveBag2,speed=5)
outtaThaBag2down = vizact.moveTo(item.object.getPosition(),speed=5)
firstPickObject.addAction(outtaThaBag2up)
firstPickObject.addAction(outtaThaBag2down)
inThaBag2up = vizact.moveTo(aboveBag2,speed=5)
inThaBag2down = vizact.moveTo(bag2.getDst().getPosition(),speed=5)
item.object.addAction(inThaBag2up)
item.object.addAction(inThaBag2down)
secondPickOject = item.object
yield viztask.waitTime(0.6)
firstPickObject.visible(viz.ON)
secondPickOject.visible((viz.OFF))
#Print the point where the line intersects the object.
taskA.append(item.object.name)
viz.callback(viz.MOUSEDOWN_EVENT, 0)
print taskA
print "swapped"
return
def selectPhase(participant):
global divider, door, bag1, bag2, vizact
panel = vr_utils.displayOnCenterPanel("")
#Add vizinfo panel to display instructions
if (participant.group == 'a'):
panel.setText(selectPhaseInstructionsGroupA)
else:
panel.setText(selectPhaseInstructionsGroupB)
panel.visible(viz.ON)
#count the user in
yield viztask.waitTime(11)
panel.visible(viz.OFF)
yield pickObject()
vizact.ontimer(1,dostuff)
print "Done with waiting for mouse"
if (participant.group == 'b'):
##open the door
#divider.collideNone()
yield vizproximity.waitEnter(doorStationSensor)
spinToYaw90 = vizact.spinTo(euler=[90,0,0], speed=50)
door.addAction( spinToYaw90 )
#lowerBag = vizact.move(0,-1,0,3)
#bag1.addAction(lowerBag)
#bag1.postTrans([0,-0.5,0])
doorAngle = 0;
door.disable(viz.INTERSECTION)
#door.collideNone()
##door.addAction( vizact.spin(0,1,0,90) )
#while (doorAngle < 90):
#door.setEuler([doorAngle,0,0])
#doorAngle +=0.01
#else :
#yield vizproximity.waitEnter(doorStationSensor)
#bag1.postTrans([0,-0.5,0])
#wait until they reach the test table
yield vizproximity.waitEnter(stationTwoSensor)
print "at station 2"
return
def swapPhase(participant):
print "waiting to click item"
#loopin
#yield swapClick()
#wait until the user selects a shape
yield swapObject()
print "Done with waiting for mouse"
if (participant.group == 'a'):
panel = vr_utils.displayOnCenterPanel("Great! Now just move back to the original desk.")
else:
panel = vr_utils.displayOnCenterPanel("Great! Now just move back to the original desk in the other room.")
panel.visible(viz.ON)
yield viztask.waitTime(4)
panel.visible(viz.OFF)
for s in shapes:
s.visible(viz.OFF)
firstPickObject.visible(viz.ON)
vr_utils.makeShapes2(viz, vizshape)
if (participant.group == 'b'):
##open the door
#divider.collideNone()
yield vizproximity.waitEnter(doorStationSensor)
doorAngle = 0;
door.addAction( vizact.spin(0,1,0,90) )
#door.collideNone()
while (doorAngle < 90):
#door.setEuler([doorAngle,0,0])
doorAngle +=0.01
#wait untl ther reach the test table
yield vizproximity.waitEnter(stationOneSensor)
return
def dostuff():
global timerCount
timerCount = timerCount + 1
print timerCount
def testPhase(participant):
panel = vr_utils.displayOnCenterPanel("")
panel.setText("Click on the shape you currently have in your backpack.")
panel.visible(viz.ON)
#count the user in
yield viztask.waitTime(4)
panel.visible(viz.OFF)
yield pickObject()
print "Done with waiting for mouse"
#result = Result("1")
result = getResults()
#save the results to a document
viztask.returnValue(result)
def getResults():
results = []
if taskA[0] == 'BOX_RED':
results.append("Correct")
else:
results.append("Incorrect")
if taskA[1] == 'SPHERE_GREEN':
results.append("Correct")
else:
results.append("Incorrect")
if taskA[2] == taskA[1]:
results.append("Correct")
else:
results.append("Incorrect")
return results
def runExperiment():
global divider, door, scale
#tool.setUpdateFunction(updateGrabber)
#Collect and store participant information
participant = yield getParticipantInfo()
panel = vr_utils.displayOnCenterPanel(startingInstructions)
print "divider"
print divider
#Wait for spacebar to begin experiment
yield viztask.waitKeyDown(' ')
vr_utils.removeCenterPanel(panel)
print "select phase"
#Start the select phase/phase one
yield selectPhase(participant)
print "swap phase"
#wait for participant to move to testing station
yield swapPhase(participant)
print "result phase"
#begin the test phase, store the results, results saved
result = yield testPhase(participant)
print result
vr_utils.saveResults(participant, result, timerCount)
print 'Experiment Complete.'
panel = vr_utils.displayOnCenterPanel("Experiment complete!")
viztask.schedule(runExperiment)