WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
  #1  
Old 09-04-2009, 07:45 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Laser Pointer Question (Again)

I'm having a new problem. My previous laser pointer worked with this code
Code:
RedDot = viz.add(viz.TEXT3D, '.', viz.SCREEN)
RedDot.translate(0.5, 0.5)
RedDot.alignment(viz.TEXT_CENTER_CENTER)
RedDot.color(1,0,0)	# Red

However, now I'm running into a new problem. Now I need the laser pointer to be tied to the viewpoint and still appear on the screen. So basically, I need to be able to use the laser pointer to navigate from object to object in space so that when the laser pointer (tied to the viewpoint) is within a certain range of a target it will trigger some function. Ideally, the laser pointer would be tied to the center of my viewpoint that way when I move my head to look at the object the laser pointer will always be in the center of my field of view.

I tried linking the object but that didn't work:
RedDot = viz.LINK_OBJECT(viz.MAIN_VIEWPOINT)

The way my program is running right now (with the laser pointer linked to the screen) is that I'm trigger some functions when the laser pointer is above some targets and I'm triggering others when the laser pointer is below some targets. I need it to be exactly on top of those objects.

Any ideas??? PLEASE help!
Reply With Quote
  #2  
Old 09-04-2009, 08:03 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
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!!!!!!!!!!
Reply With Quote
  #3  
Old 09-04-2009, 04:20 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I don't really understand your question. If you are adding the red dot to the screen, then it will automatically be tied to the viewpoint.
Reply With Quote
  #4  
Old 09-08-2009, 06:28 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Ok...well...maybe my problem is in how the program is calculating some of the bearing/yaw/pitch/distance stuff.

I'm having people navigate the red dot from point A-->B-->C-->D-->etc. The way I have the code set up is that only 2 targets (max) appear at any given time. So once the red dot gets to target A, target B appears and then once the red dot gets to B, target C appears and target A disappears. The problem that I'm having is that my results are inconsistent. Sometimes the red dot is slightly above the target and the next one gets triggered and sometimes the red dot needs to be below the target for the next one to be triggered. Oftentimes the red dot isn't even close to the target when it's triggering the next target.

Am I calculating the distance between the points incorrectly? I need it to be able to identify the current target location and compare that with my currentyawpitch. Once the red dot is within the hotspot (which right now is set to 1 degree) then I need to it to trigger the next target to appear. Am I calculating my currentyawpitch wrong? (The people are standing still and only moving their head so they aren't changing x,y,z points in the environment. They're only yawing and pitching).

Does that make more sense?
Reply With Quote
  #5  
Old 09-08-2009, 11:50 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Unhappy

I think I might have come across the problem...I need to be able to calculate what yaw and pitch I should have so that the red dot is on top of the target. In order to do that I have to calculate the appropriate yaw/pitch based on the target position and my head position. However, I think it's constantly updating the targetYawPitch (targetYawPitch[0] = yaw, targetYawPitch[1] = pitch) based on how I'm moving and thus I'm getting funky results.

For example, let's say to look at A I need targetYawPitch[0] 2.3178497724, targetYawPitch[1] -11.1697861608 (This is what is originally calculated). I need those values to remain fixed so that when my yaw and pitch get within the 1 degree hotspot I trigger the next target. However, you'll notice that I'm hitting the target at: ((currentYaw - self.targetYawPitch[0]) < self.hotspotTolerance) = ((2.63679909706 -2.89097381937) < True)
True
((currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance) = ((-4.72426462173 --5.53390520328) < True)
True
Hit Target A at [2.8909738193736922, -5.5339052032813196]

While the 2.89 is close to the original 2.31 the -5.5 is not at all close to the original -11.16. (See output below).

Similar things happen with other targets as well...sometimes I need to be far below the target to trigger the hotspot.

I have no idea how to fix this...

Going to next target
targetYawPitch [None, None]
newTarget A
currentTargetPos [0.17000000178813934, 0.99000000953674316, 4.1999998092651367]
targetYawPitch[0] 2.3178497724
targetYawPitch[1] -11.1697861608
CheckHeading
currentYaw -5.38346481323
currentPitch -10.2835168839
currentYaw -5.38346481323
currentPitch -10.2835168839
currentYaw -4.48255825043
currentPitch -11.2283706665
.
.
.
currentYaw 2.61482572556
currentPitch -3.40586543083
currentYaw 2.63679909706
currentPitch -4.72426462173
((currentYaw - self.targetYawPitch[0]) < self.hotspotTolerance) = ((2.63679909706 -2.89097381937) < True)
True
((currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance) = ((-4.72426462173 --5.53390520328) < True)
True
Hit Target A at [2.8909738193736922, -5.5339052032813196]
Going to next target
targetYawPitch [None, None]
oldTarget A
newTarget H
currentTargetPos [1.2699999809265137, 1.3799999952316284, 4.1999998092651367]
targetYawPitch[0] 18.8303756023
targetYawPitch[1] 0.32497106846
*** Reached point A
Elapsed time =11.7494435745 seconds

currentYaw 2.54890584946
currentPitch -4.94399785995
currentYaw 2.48298597336
currentPitch -5.25162506104
currentYaw 2.48298597336
currentPitch -5.25162506104
.
.
.
currentYaw 18.6773281097
currentPitch -1.09866631031
currentYaw 19.0948219299
currentPitch 0.703146457672
((currentYaw - self.targetYawPitch[0]) < self.hotspotTolerance) = ((19.0948219299 -18.7518220628) < True)
True
((currentPitch - self.targetYawPitch[1]) < self.hotspotTolerance) = ((0.703146457672 -0.285288887733) < True)
True
Hit Target H at [18.751822062820551, 0.28528888773343869]
Going to next target
targetYawPitch [None, None]
oldTarget H
newTarget I
oldOldTarget A
currentTargetPos [2.3299999237060547, 1.0349999666213989, 4.1999998092651367]
targetYawPitch[0] 31.7820902079
targetYawPitch[1] -4.17668542975
*** Reached point H
Elapsed time =14.3208748598 seconds
Reply With Quote
  #6  
Old 09-08-2009, 12:02 PM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Also, the way I have the hotspot set up is as a variable within a class:
self.hotspotTolerance = 1

So what I "want" to happen is that anytime both my current yaw AND pitch are within 1 degree of the target yaw AND pitch (which I need to be a fixed value) then I trigger the next target. But the way the code reads above--it has a < sign. I need it to be 0 < x < 1--I don't know how to set that. Otherwise the hotspots get triggered if I'm far enough away that I produce a negative yaw and pitch.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Laser Pointer Updated Elittdogg Vizard 8 04-10-2008 09:48 AM
General question and question regarding arrays dan12345 Vizard 1 01-15-2008 10:15 AM
Stereo Overlap question JMOwens Vizard 2 01-08-2008 08:54 AM
Lots of Question Karthi Vizard 4 02-20-2004 06:42 PM
Basic Joystick Navigation Question Plasma Vizard 2 01-29-2004 07:08 PM


All times are GMT -7. The time now is 06:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC