def move(scale = 1):
	if pause:
		return
	data = tracker.getData()
	alpha =data[3]  + ERROR		#adding 45 degrees seems to correct direction
	
	x,y,z = unitVector(math.sin(math.radians(alpha)), 0, math.cos(math.radians(alpha)))
	
	x0, y0, z0 = viz.MainView.getPosition()
	#mode can be viz.speed or viz.time. value is the arg before it
	#if mode == time, value is amount of time it takes
	#if mode == speed, value is velocity to move
	#maybe wouldn't need error if set ori_mask to viz.HEAD_ORI
	update = vizact.goto([x*strideLength*scale+x0, y0, z*strideLength*scale+z0], 2, mode = viz.SPEED, ori_mask = viz.BODY_ORI)
	
	viz.MainView.runAction(update)
def keyEvent(key):
	global rotation, objectLocations, objects, cylinder, arrow, currentTarget, targetRotations, objectFiles, objectSet
	global startPosition, startAngle, targetPosition, pptLink, height, pptLink, recordingEnabled, recordFile
	global targetLocations, targetObjects
	global PART_HEIGHT
	global testsCompleted
	global fileStartIndex, angleIndex
	global example, horse, exapmleCylinder
	global locationFinished
	
	
	#print key
	#Rotate all of the objects in the scene
#	if(key == 'r'):
#		print 'YOU PRESSED R! WHAT ARE YOU DOING?'
#		angleArray = [45,90,45]
#		newPos = rotate(angleArray[angleIndex],targetLocations)
#		for ii in range(len(newPos)):
#			arrowPosition = rotate(angleArray[angleIndex], arrowLocations)[currentTarget]
#			arrow.setPosition(arrowPosition)
#			objects[ii].setPosition(newPos[ii])
#			
#		angleIndex = (angleIndex + 1) % len(angleArray)
		
	#Change the pillars the objects are on
#	elif(key == 'm'):
#		print "inside of m"
#		fileStartIndex = (fileStartIndex + 1) % len(objects)
#		moveObjects(fileStartIndex)
			
#	#Show the target to walk toward
#	elif(key == 't'):
#		global targetLocations, arrow
#		currentTarget = (currentTarget + 1) % len(targetLocations)
#		targetPosition = rotate(rotation, targetLocations)[currentTarget]
#		targetRotation = targetRotations[currentTarget] + rotation
#		cylinder.setPosition(targetPosition)
#		arrowX = targetPosition[0] + 0.3 * math.cos(math.radians(targetRotation + rotation))
#		arrowZ = targetPosition[2] + 0.3 * math.sin(math.radians(targetRotation + rotation))
#		#arrow.setPosition(arrowX, arrow.getPosition()[1], arrowZ)
#		arrow.setPosition([-9.873720169067383, 0.5, 3.1146695613861084])
#		cylinder.setEuler(targetRotations[currentTarget] + rotation)
#		cylinder.visible(viz.ON)
#		arrow.visible(viz.ON)
#	

	#hide the objects
	if(key == 'h'):
		for x in range (len(objects)):
			objects[x].visible(viz.OFF)
			
	#show the objects
	elif(key == 's'):
		for x in range (len(objects)):
			objects[x].visible(viz.ON)
			
	#switch the set of objects
	elif(key == 'o'):
		print"inside of o"
		changeObjects()
	
	#when a condition is done, push the almighty button
	elif(key == 'a'):
		changeConditions()

	#update the state
	elif(key == ' '):
		global  currentState, targetToFace, targetObjects, turnAngle
		
		debug = False
		if debug:
			print "current view angle: ", view.getEuler()[0] + ERROR
			print currentState
		#Show the next target to walk toward
		if(currentState == 0):
			currentState = 1
			if(recordingEnabled):
				recordFile.write('Target: %d\n' % currentTarget)
			changeState(currentState)
		#Hide the scene and let the participant turn
		elif(currentState == 1):
			targetToFace = -1
			currentState = 3
			#print 'Object Index: %d, Total Objects: %d' % (targetToFace, len(targetObjects[currentTarget]))
			changeState(currentState)
		#Show the arrow to reorient the participant
		elif(currentState == 2):
			global startTime
			timeDifference = time.clock() - startTime
			currentPosition = view.getPosition()
			movedTurned = False
			if startPosition != currentPosition:
				print "WARNING! STARTPOSITION IS NOT CURRENTPOSITION"
				movedTurned = True
				print startPosition
				print view.getPosition()
			#calculate the angle turned and the angle desired
			objectPosition = rotate(rotation, masterObjectLocations)
			objectNumber = targetObjects[currentTarget][targetToFace]
			destX = objectPosition[targetObjects[currentTarget][targetToFace]][0] - startPosition[0]
			destY = objectPosition[targetObjects[currentTarget][targetToFace]][2] - startPosition[2]
			mag = math.sqrt(destX*destX + destY*destY)
			normX = destX / mag
			normY = destY / mag
			startY = math.cos(math.radians(startAngle))
			startX = math.sin(math.radians(startAngle))
			endY = math.cos(math.radians(view.getEuler()[0] + ERROR))
			endX = math.sin(math.radians(view.getEuler()[0] + ERROR))
			dotNeeded = normX * startX + normY * startY
			dotTurned = startX * endX + startY * endY
			angleNeeded = math.degrees(math.acos(dotNeeded))
			angleTurned = math.degrees(math.acos(dotTurned))
			
			#print 'StartX: %f, StartY: %f, DestX: %f, DestY: %f, EndX: %f, EndY: %f' % (startX, startY, destX, destY, endX, endY)
			print 'Angle Needed: %f, Angle Turned: %f' % (angleNeeded, angleTurned)
			
			#not used as of 8/7/2013. Used to show file reader where to get info
			#see mod360.py for a way to use number of commas instead
			delim1 = '$'
			delim2 = '^'
			
			if(recordingEnabled):
				recordFile.write('%d,%s,%f,%f,%f,%f,%f,%f,%s%f%s, %s%f%s, %s\n' % (objectNumber,
				objectAddresses[currentCondition][(fileStartIndex + targetObjects[currentTarget][targetToFace]) % len(objectFiles[objectSet])],
				startPosition[0],startPosition[1],startPosition[2],startAngle,angleTurned,angleNeeded,delim1,timeDifference,delim1,delim2,abs(angleNeeded - angleTurned),delim2,movedTurned))
			
			currentState = 3
			if(targetToFace + 1 >= len(targetObjects[currentTarget])):
				currentTarget = (currentTarget + 1) % len(targetObjects)
				locationFinished = True
			changeState(currentState)
		#Hide everything again and let the participant turn toward the new target
		elif(currentState == 3):
			if locationFinished:
				currentState = 0
				locationFinished = False
				changeState(currentState)
				
			targetToFace = targetToFace + 1
			if debug:
				print "here is target to face: ",targetToFace
			testsCompleted += 1
			#print 'here is testscompleted: %d' %testsCompleted
			#print 'here is len of amount of targets: %d' % len(targetObjects[currentTarget])
			#if not finished with round
			if(targetToFace < len(targetObjects[currentTarget])):
				currentState = 2
				if debug:
					print 'Object Index: %d, Total Objects: %d' % (targetToFace, len(targetObjects[currentTarget]))
			#move on to next rotation
			else:
				print "move onto next location!"
				currentState = 0
				
			changeState(currentState)
			
	elif key == 'p':
		global pause
		pause = not pause
		
	elif key == 'd':
		pos = view.getPosition()
		update = vizact.goto([pos[0], pos[1] -1, pos[2]], 2, mode = viz.SPEED, ori_mask = viz.BODY_ORI)
		viz.MainView.runAction(update)
		
	elif key == 'e':
		example = not example
		if example:
			keyEvent('h')
			horse.visible(viz.ON)
			exapmleCylinder.visible(viz.ON)
		else:
			keyEvent('s')
			horse.visible(viz.OFF)
			exapmleCylinder.visible(viz.OFF)
			
	#if trial was messed up, redo that trial afterwards by pressing the number corresponding to that trial
	elif key == '1' or key == '2' or key == '3' or key == '3' or key == '4' or key == '5' or key == '0':
		redoTrial(int(key))
		
	else:
		print view.getPosition()
				#Save hit speed
				self.hitSpeed = speed
				self.hit()
				
			self.__inRegion[stick] = True
		else:
			self.__inRegion[stick] = False

#Create action for drum hitting
DrumHitAction = vizact.sequence(vizact.move(0,-1,0,0.05),vizact.move(0,1,0,0.05))

#Create class for animation cymbal hit
CymbalHitAnimation = CymbalHit(CymbalModel)

#Create action to open hihat
OpenHiHat = vizact.goto(0,0,0,0.5)

#Create action to close hihat
CloseHiHat = vizact.goto(0,0.04,0,0.5)

#List of drums
DrumList = []

#Create tom drum
TomDrum = Drum('sounds/tom.wav',DrumHitAction)
TomDrum.setPos(0.18,0.82,0.24)
DrumTomModel.parent(TomDrum.model)
DrumList.append(TomDrum)

#Create snare drum
SnareDrum = Drum('sounds/snare2.wav',DrumHitAction)
Example #4
0
def AnimateView(orientation):
    offset = distance * np.tan(np.radians(orientation))
    action = vizact.goto([offset, height, distance], SPEED, MODE)
    view.runAction(action)