Since the objects are in some x,y,z location in the world and I'm remaining stationary and simply changing my gaze/orientation, I needed a way to determine wether or not my viewpoint was "on top of" the target. I need to be able to move the laser pointer (by moving my head) "over" one of these targets (within a specified tolerance (i.e. hotspot)) in order to trigger the next target. The problem that I'm having is sometimes the next target is triggered when the laser pointer is above and sometimes when it's below the current target (and I think that's because the laser pointer is tied to the screen--see previous post). I need to make the laser pointer visible and tied to my field of view (ideally in the center of my FOV) so that I can navigate it in a 1:1 manner over the targets in order to initiate the next target.
Code:
def __checkHeading( self ): # make into a timer that runs repeatedly
if self.targetYawPitch != [None, None]:
# Get a handle to the current head position
global CurrentLocation
#print "CurrentLocation", CurrentLocation
# update the location of the hotspot relative to the current head position
self.targetYawPitch[0] = self.findBearing( viz.get(viz.HEAD_POS), self.currentTargetPos )
self.targetYawPitch[1] = self.findPitch( viz.get(viz.HEAD_POS), self.currentTargetPos )
#self.targetYawPitch[0] = self.findBearing( CurrentLocation[0:3] , self.currentTargetPos )
#self.targetYawPitch[1] = self.findPitch( CurrentLocation[0:3], self.currentTargetPos )
# get the current pitch and yaw of the participant's head
currentYaw = viz.get(viz.HEAD_YAW)
currentPitch = viz.get(viz.HEAD_PITCH)
#currentYaw = viz.get(CurrentLocation[3])
#currentPitch = viz.get(CurrentLocation[4])
print "Target direction [yaw, pitch] =", self.targetYawPitch
print "Current gaze direction [yaw, pitch] =", [currentYaw, currentPitch]
print "\tDifference:", currentYaw-self.targetYawPitch[0],currentPitch-self.targetYawPitch[1]
print
#print "((currentYaw - self.targetYawPitch[0]) < self.hotspot) = ((%s -%s) < %s)" %(str(currentYaw), str(self.targetYawPitch[0]), str(self.hotspotTolerance))
#print "((currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance) = ((%s -%s) < %s)" %(str(currentPitch), str(self.targetYawPitch[1]), str(self.hotspotTolerance))
# Check to see if they are looking at the target
if (abs(currentYaw - self.targetYawPitch[0]) < self.hotspotTolerance) and (abs(currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance):
print "((currentYaw - self.targetYawPitch[0]) < self.hotspotTolerance) = ((%s -%s) < %s)" %(str(currentYaw), str(self.targetYawPitch[0]), str(self.hotspotTolerance))
print (abs(currentYaw - self.targetYawPitch[0]) < self.hotspotTolerance)
print "((currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance) = ((%s -%s) < %s)" %(str(currentPitch), str(self.targetYawPitch[1]), str(self.hotspotTolerance))
print (abs(currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance)
# people are looking at the target
# flag the data and go on to the next target here
print "Hit Target", self.targetNames[self.currentTarget], "at", self.targetYawPitch
self.checkHeading.stop()
self.goToNextTarget( )
WriteFlag()
def findPitch(self, ptFrom=[0,0,0], ptTo=[0,0,0]):
lenHypot = vizmat.Distance(ptFrom, ptTo)#, dimensions=3) #
lenRise = ptFrom[1] - ptTo[1] #
if (lenRise == 0):
return (0) # pitch = zero if two points are at equal height
pitch = math.asin(float(abs(lenRise)) / lenHypot ) # Determine magnitude of pitch
pitch *= [-1, 1][(lenRise <= 0)] # Determine sign of pitch
return ((pitch/math.pi) * 180)
def findBearing(self, ptFrom=[0,0,0], ptTo=[0,0,0] ):
"""Calculate the bearing (relative to North) between two points"""
# Assuming ptFrom is origin, determine ptTo quadrant
if ptFrom == ptTo:
# Points are the same, so return a bearing of zero (actually undefined?)
return 0
else:
xDiff = float(ptTo[0] - ptFrom[0])
yDiff = float(ptTo[2] - ptFrom[2])
if xDiff == 0:
# Points N-S aligned
return ( [0,180][yDiff<0] ) # Returns 0 deg or 180 deg
elif yDiff == 0:
# Points E-W aligned
return ( 90 * cmp(xDiff, 0) ) # Returns 90 deg or -90 deg
elif yDiff > 0:
# ptTo is Northward, unaligned
return ( vizmat.degrees( math.atan(abs(xDiff) / abs(yDiff)) ) * cmp(xDiff, 0) )
else:
# ptTo is Southward, unaligned
return ( (180 * cmp(xDiff, 0)) - (vizmat.degrees( math.atan(abs(xDiff) / abs(yDiff)) ) * cmp(xDiff, 0)) )
please help!!!!!!!!!!