View Single Post
  #4  
Old 04-12-2016, 10:02 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,450
The following example has the crosshair fixed to the center of the screen. If were using an eye tracker the crosshair should follow the eye movements instead:

Code:
import viz
import vizact

viz.go()

GAZE_TIME_EVENT = viz.getEventID('GAZE_TIME_EVENT')

viz.clearcolor(viz.SLATE)

soccerball = viz.addChild('soccerball.osgb',pos=[-1,1.8,2])
basketball = viz.addChild('basketball.osgb',pos=[0,1.8,2])
volleyball = viz.addChild('volleyball.osgb',pos=[1,1.8,2])

crosshair = viz.addTexQuad(texture=viz.add('crosshair.png'),pos=[0,0,3],scale=[0.5]*3)
crosshair.setReferenceFrame(viz.RF_VIEW)
crosshair.disable(viz.DEPTH_TEST)
crosshair.drawOrder(10)

class GazeTime(viz.EventClass):

	def __init__(self,gazeTime=1.5):
		
		viz.EventClass.__init__(self)
		self.gazeTime = gazeTime
		self.gazeObject = None
		self.startTime = 0
		self.callback(viz.UPDATE_EVENT,self.checkGazeTime) 

	def checkGazeTime(self,e):

		node = viz.pick(pos=[0.5,0.5])
		if node != self.gazeObject:
			self.gazeObject = node
			self.startTime = viz.tick()
			print 'started looking at', self.gazeObject
			
		else:
			time = viz.tick() - self.startTime
			if time > self.gazeTime:
				viz.sendEvent(GAZE_TIME_EVENT, self.gazeObject)
				self.startTime = viz.tick()

GazeTime()

def onGazeTime(gazeObject):
	if gazeObject == soccerball:
		print 'gaze fixed on soccerball for 1.5 seconds'
	elif gazeObject == basketball:
		print 'gaze fixed on basketball for 1.5 seconds'
	elif gazeObject == volleyball:
		print 'gaze fixed on volleyball for 1.5 seconds'
	
viz.callback(GAZE_TIME_EVENT,onGazeTime)
Reply With Quote