WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-08-2008, 09:00 AM
aznan aznan is offline
Member
 
Join Date: Apr 2008
Posts: 11
Prioritize Director thread

Hi!
I have some custom stereo code that runs in an eternal loop in a Director thread like so:
Code:
def updateView():
	eye = False
	IPD = 0.064
	while True:
		eye = not eye
		pos = PPT.getPosition()
		
		if eye: #right eye
			pos[0] += IPD/2
		else: #left eye
			pos[0] -= IPD/2
		
		window.update(viewpos = pos) #updates perspective
		viz.waitframe(1)

viz.director(updateView)
This produces a fine stereo effect.

I have another function, newLayout(), that removes the objects in the world and replaces them with new objects in random locations. This function is called at the push of a button.

Problems arise when newLayout() is run however, as the adding of new objects demands quite a bit of CPU time. This keeps the stereo loop from executing, which might cause the stereo to be reversed - the right-eye image gets shown to the left eye and vice versa. But this shouldn't happen since updateView() is run in its own thread, right?

Is there a way to ensure that the stereo loop will always execute?
Reply With Quote
  #2  
Old 05-08-2008, 03:28 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
What exactly are you trying to accomplish? Are you trying to manually implement field sequential stereo? It is generally not possible to do this, and you will need hardware to perform the swapping for you.

Either way, the viz.waitframe(1) command will wait for the next frame to be rendered by Vizard. So if you perform some long file loading operation then the frame will not be rendered until this is complete. So I'm not sure how increasing the priority of your thread will have any effect.
Reply With Quote
  #3  
Old 05-09-2008, 01:22 AM
aznan aznan is offline
Member
 
Join Date: Apr 2008
Posts: 11
I have this Window on World projection that is displayed on a horizontal table. This means that I have to change the direction of the stereo offset depending on the user's position relative to the table.

Simply offsetting pos[0] += IPD/2, like in the code above, is only there for you to get a hint at what I'm trying to accomplish. The acctual code used breaks down to finding a vector from pos to origo, imagine a plane with this vector as its normal vector, calculate the plane's side vector, then offset the position by IPD/2 along this side vector.

It would be great if I could do this through hardware, but viz.QUAD_BUFFER and the likes never change the direction of the offset. That's why I'm doing this manually.
Reply With Quote
  #4  
Old 05-09-2008, 02:33 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You should have a look at the vizcave module. You simply specify the physical locations of the projection corners and the users head position and it will automatically update the frustums to account for this. Either way, there is no reason to be using a director function for this. A simple timer will suffice.
Reply With Quote
  #5  
Old 05-11-2008, 08:53 AM
aznan aznan is offline
Member
 
Join Date: Apr 2008
Posts: 11
Thank you for directing me towards the cave module. I'm having some trouble with understanding quaternions for the cave's update function, though. I'm not familiar with quaternions, but a quick Google search indicates that they are used for describing a rotation, rather than a direction. How am I supposed to translate the direction of the eyes to a rotation?

Since I only keep track of one point, and not one for each eye, I assume that the user is always looking toward the center of the table. So I calculate a vector from the head's position to the table. Is it possible to somehow convert this vector into a quaternion? Or is there a better way to indicate where the user is looking? I will need this to get a proper stereo projection.

Last edited by aznan; 05-11-2008 at 08:57 AM.
Reply With Quote
  #6  
Old 05-12-2008, 09:34 AM
aznan aznan is offline
Member
 
Join Date: Apr 2008
Posts: 11
I solved it by calculating my own side vector and moving the eyes' position along this vector, I then feed left/right positions into the update function instead of a position and an orientation. This works great.
Reply With Quote
  #7  
Old 05-13-2008, 12:47 AM
aznan aznan is offline
Member
 
Join Date: Apr 2008
Posts: 11
Dammit! Okay, one final question:
I run my cave, close it, and run it again several times in a row, not touching the code between the runs. Some runs the stereo projection is good, while on others the right and left image gets swapped. This swapping is no longer affected by things that steals CPU time, like before. It seems to occur completley at random. Here is the current code I'm using:

Code:
def updateView(self):		
	pos = ppt.getPosition()
	
	# vector from head's position to the table
	invec = origo - vec.vector(pos)
	invec = vec.normalize(invec)
	
	# z vector on the imaginary plane where invec is the y vector
	upvec = [invec.data[0],math.sqrt(1-invec.data[1]*invec.data[1]),invec.data[2]]
	upvec = vec.normalize(vec.vector(upvec))
	
	# x vector on the imaginary plane where invec is the y vector
	svec = vec.normalize(vec.cross(invec, upvec))
	
	# calculate the eyes' positions by moving them along the x vector
	lpos = move(pos, svec, self.IPD/2)
	rpos = move(pos, svec, -self.IPD/2)
	
	# update viewing positions
	self.cave.update(leftPos=lpos, rightPos=rpos)
	viz.MainView.translate(pos)

def move(point, vector, distance):
	data = []
	for i in range(3):
		data.append(point[i] + vector[i]*distance)
	return data

vizact.ontimer(0,view.updateView)
Do you have any idea what might be causing this?
Reply With Quote
  #8  
Old 05-13-2008, 10:51 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
What stereo mode are you using in your script?
Reply With Quote
  #9  
Old 05-14-2008, 05:13 AM
aznan aznan is offline
Member
 
Join Date: Apr 2008
Posts: 11
Quad buffer. I currently have the users go through a simple test first to confirm whether they get the proper projection or not, so I guess I can live with it.
Reply With Quote
  #10  
Old 05-14-2008, 09:57 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Your hardware should ensure that the correct image is displayed to each eye. Your shutter glasses might not be properly synced with your graphics card. Your Vizard code looks fine, so I don't think there is anything wrong there.
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


All times are GMT -7. The time now is 08:44 PM.


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