WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 05-10-2011, 04:11 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
moving at different speeds

Hi,

I've got two rolling roads side by side but I want them to move at different speeds to each other as a type of comparison task, at the moment I can get them to go at the same speeds as each other but not to move independently;

Code:
import viz
#Import vizjoy module
import vizjoy  
import time
import math
import vizact
import vizinfo
import vizshape

viz.displaymode(1024, 512)
viz.go(viz.FULLSCREEN)
viz.mouse(viz.OFF)
vizact.ontimer(32,viz.quit) #runs file for 32 secs


subject = viz.input('What is the participant number?')

#define speed
MOVE_SPEEDl = 0.04459 #hard wired constant for speed gain (30mph)
MOVE_SPEEDr = 0.001

viz.clearcolor(0.5,0.5,0.5)
viz.MainView.setPosition(0,0.5,0)




#add the road texture
roadr = viz.add('roadld3.png')
roadl = viz.add('roadld3.png')
#create a texture quad1 to add the road texture to
#and place it over ground
quadr = viz.addTexQuad()
quadr.setScale(1,2,1)
quadr.setPosition(0,0.5,0)
quadr.setEuler(0,90,0)
quadr.texture(roadr)

roadr_position = 0.5
#groundr_position = 0

#create a texture quad left to add the road texture to
#and place it over ground
quadl = viz.addTexQuad()
quadl.setScale(1,2,1)
quadl.setPosition(0,-0.5,0)
quadl.setEuler(0,90,0)
quadl.texture(roadl)
roadl_position = 0

viz.link(viz.MainView, quadr)
viz.link(viz.MainView, quadl)



#add right road if getting near the end of road
def addRoadr():
	
	global roadr_position, roadl_position
	
	viewpointr_pos = viz.MainView.getPosition(quadr)
	#check to see how close the viewpoint is to the end of the road
	if roadr_position - viewpointr_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			quadrcopy = quadr.copy()
			quadrcopy.setPosition([0.75,0,roadr_position])
			quadrcopy.setEuler(0,90,0)
			roadr_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDr,viz.BODY_ORI)

addRoadr()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadr)

# add left road if getting near to the end of it
def addRoadl():
	
	global roadr_position, roadl_position
	
	viewpointl_pos = viz.MainView.getPosition(quadl)
	#check to see how close the viewpoint is to the end of the road
	if roadl_position - viewpointl_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			quadlcopy = quadl.copy()
			quadlcopy.setPosition([-0.75,0,roadl_position])
			#changing the 1st parameter to -0.5 for left quad and
			#0.5 for right quad elimates the grey space between the lines
			#one solid black road
			quadlcopy.setEuler(0,90,0)
			roadl_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDl,viz.BODY_ORI)

addRoadl()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadl)
I'm guessing that it's something to do with the viz.MainView.move command? So I tried linking it to the two objects that I want moving but no luck. Is there a easy way of achieving this that even a programming simpleton like me can understand?
Reply With Quote
  #2  
Old 05-11-2011, 05:15 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
I've tried to create another window using two different methods (from both examples in the tutorials and other forum posts) and then assign one of the quads to the left window and the other to the right window. Method one
Code:
import viz
#Import vizjoy module
import vizjoy  
import time
import math
import vizact
import vizinfo
import vizshape

viz.displaymode(1024, 768)
viz.go(viz.FULLSCREEN)
viz.mouse(viz.OFF)
vizact.ontimer(32,viz.quit) #runs file for 32 secs


subject = viz.input('What is the participant number?')

#define speed
MOVE_SPEEDl = 0.04459 #hard wired constant for speed gain (30mph)
MOVE_SPEEDr = 0.001

viz.clearcolor(0.5,0.5,0.5)
viz.MainView.setPosition(0,0.5,0)
# Create a new window in the upper left corner
UpperLeftWindow = viz.addWindow(pos=(0,1.0),size=(0.5,0.5))
UpperLeftWindow.visible(0,viz.SCREEN)
UpperLeftView = viz.addView() 
UpperLeftWindow.setView(UpperLeftView)



#add the road texture
roadr = viz.add('roadld3.png')
roadl = viz.add('roadld3.png')
#create a texture quad1 to add the road texture to
#and place it over ground
quadr = viz.addTexQuad()
quadr.setScale(1,2,1)
quadr.setPosition(0,0.5,0)
quadr.setEuler(0,90,0)
quadr.texture(roadr)

roadr_position = 0.5
#groundr_position = 0

#create a texture quad left to add the road texture to
#and place it over ground
quadl = viz.addTexQuad()
quadl.setScale(1,2,1)
quadl.setPosition(0,-0.5,0)
quadl.setEuler(0,90,0)
quadl.texture(roadl)
roadl_position = 0



#add right road if getting near the end of road
def addRoadr():
	
	global roadr_position, roadl_position
	
	viewpointr_pos = viz.MainView.getPosition()
	#check to see how close the viewpoint is to the end of the road
	if roadr_position - viewpointr_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			quadrcopy = quadr.copy()
			quadrcopy.setPosition([0.75,0,roadr_position])
			quadrcopy.setEuler(0,90,0)
			roadr_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDr,viz.BODY_ORI)

addRoadr()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadr)

# add left road if getting near to the end of it


def addRoadl():
	
	global roadr_position, roadl_position
	
	viewpointl_pos = viz.MainView.getPosition()
	
	#check to see how close the viewpoint is to the end of the road
	if roadl_position - viewpointl_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			quadlcopy = quadl.copy()
			quadlcopy.setPosition([-0.75,0,roadl_position])
			#changing the 1st parameter to -0.5 for left quad and
			#0.5 for right quad elimates the grey space between the lines
			#one solid black road
			quadlcopy.setEuler(0,90,0)
			roadl_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDl,viz.BODY_ORI)

addRoadl()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadl)
However this just creates a window which merges the two qaud textures together.
Method 2:
Code:
import viz
#Import vizjoy module
import vizjoy  
import time
import math
import vizact
import vizinfo
import vizshape

viz.displaymode(1024, 768)
viz.go(viz.FULLSCREEN)
viz.mouse(viz.OFF)
vizact.ontimer(32,viz.quit) #runs file for 32 secs


subject = viz.input('What is the participant number?')

#define speed
MOVE_SPEEDl = 0.04459 #hard wired constant for speed gain (30mph)
MOVE_SPEEDr = 0.001

viz.clearcolor(0.5,0.5,0.5)

#create 2 windows

#Set main window size to half
viz.MainWindow.setSize(0.5,1)

#Add a new window to other half
window = viz.addWindow()
window.clearcolor (0.5,0.5,0.5)
window.setPosition(0.5,1)
window.setSize(0.5,1)
view = viz.addView()
view.scene(2)
window.viewpoint(view)


#add the road texture
roadr = viz.add('roadld3.png')
roadl = viz.add('roadld3.png')
#create a texture quad1 to add the road texture to
#and place it over ground
quadr = viz.addTexQuad()
quadr.setScale(1,2,1)
quadr.setPosition(0,0.5,0)
quadr.setEuler(0,90,0)
quadr.texture(roadr)

roadr_position = 0.5
#groundr_position = 0

#create a texture quad left to add the road texture to
#and place it over ground
quadl = viz.addTexQuad()
quadl.setScale(1,2,1)
quadl.setPosition(0,-0.5,0)
quadl.setEuler(0,90,0)
quadl.texture(roadl)
roadl_position = 0



#add right road if getting near the end of road
def addRoadr():
	
	global roadr_position, roadl_position
	
	viewpointr_pos = viz.MainView.getPosition()
	#check to see how close the viewpoint is to the end of the road
	if roadr_position - viewpointr_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			quadrcopy = quadr.copy()
			quadrcopy.setPosition([0.75,0,roadr_position])
			quadrcopy.setEuler(0,90,0)
			roadr_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDr,viz.BODY_ORI)

addRoadr()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadr)

# add left road if getting near to the end of it


def addRoadl():
	
	global roadr_position, roadl_position
	
	viewpointl_pos = viz.MainView.getPosition()
	
	#check to see how close the viewpoint is to the end of the road
	if roadl_position - viewpointl_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			quadlcopy = quadl.copy()
			quadlcopy.setPosition([-0.75,0,roadl_position])
			#changing the 1st parameter to -0.5 for left quad and
			#0.5 for right quad elimates the grey space between the lines
			#one solid black road
			quadlcopy.setEuler(0,90,0)
			roadl_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDl,viz.BODY_ORI)

addRoadl()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadl)
But this will only put both of the quad textures in the left hand window when I want the left quad in the left window, the right one in the right window and both of them to be able to move at independent speeds. Any help would be much appreciated as I've now started randomly crying at strangers.
Thanks!
Reply With Quote
  #3  
Old 05-11-2011, 12:14 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
The following code has two scenes that are shown side by side. The viewpoint moves at different speeds in each one:
Code:
import viz
import vizact

viz.go()

road1 = viz.addChild('tut_ground.wrl',scale=[0.02,1,1])
road2 = road1.copy(scale=[0.02,1,1],scene=2)

leftWindow = viz.MainWindow
leftWindow.setSize([0.5,1])

rightWindow = viz.addWindow(pos=[0.5,1],size=[0.5,1])
rightView = viz.addView(scene=2)
rightWindow.setView(rightView)

leftView = viz.MainView

leftView.move([0,0,-25])
rightView.move([0,0,-25])

def moveViews():
	leftView.move([0,0,.03])
	rightView.move([0,0,.1])
	
vizact.ontimer(0,moveViews)
Reply With Quote
  #4  
Old 05-17-2011, 02:31 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Hi Jeff,

many thanks for that; but when I try and load my .png file using this code, it fails to load it (similarly for .jpg files as well), also the markings on the texture I'm using need to move at a specific temporal frequency, which I've already worked out and my texture is moving on a continuous loop (agan which is already written). However when I try to assign one texture quad to one of the windows and one texture quad to another; they both end up in the left window
Reply With Quote
  #5  
Old 05-17-2011, 04:22 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
That code I posted sets the right window to scene 2. To make an object appear in that window the object also needs to be placed in scene 2.
Reply With Quote
  #6  
Old 05-24-2011, 03:54 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Hi Jeff,

yes I tried a number of ways of doing that (see below) but the best that I've succeeded in is having the two quads appear side by side in both of the viewpoints, rather than one in each,

Code:
add the road texture
#roadr = viz.add('roadld3.png',scene=viz.MainWindow)
#roadl = viz.add('roadld3.png',scene=rightView)
#roadr = viz.add('roadld3.png', parent=viz.SCREEN,SCENE=2)
#roadl = viz.add('roadld3.png',parent=viz.SCREEN,scene=1)


#create 2 windows
#Set main window size to half


leftWindow = viz.MainWindow
leftWindow.setSize([0.5,1])

#Add a new window to other half

rightWindow = viz.addWindow(pos=[0.5,1],size=[0.5,1])
rightWindow.clearcolor (0.5,0.5,0.5)

rightView = viz.addView()
rightWindow.setView(rightView)

roadr = viz.add('roadld3.png')
roadl = viz.add('roadld3.png')
#create a texture quad1 to add the road texture to
#and place it over ground
quadl = viz.addTexQuad(parent=viz.ORTHO,scene=leftWindow,texture=roadl)
quadr = viz.addTexQuad(parent=viz.ORTHO,scene=rightWindow,texture=roadr)

#quadr = viz.addTexQuad()
#quadr = viz.add(viz.TEXQUAD,viz.SCENE,2)
quadr.setScale(1,2,1)
quadr.setPosition(0,0.5,0,)
quadr.setEuler(0,90,0)
#quadr.texture(roadr)

roadr_position = 0.5
#groundr_position = 0

#create a texture quad left to add the road texture to
#and place it over ground

#quadl = viz.addTexQuad()
quadl.setScale(1,2,1)
quadl.setPosition(0,-0.5,0,)
quadl.setEuler(0,90,0)
#quadl.texture(roadl)
roadl_position = 0.5
Do you know whereabouts I am going wrong?
Reply With Quote
  #7  
Old 05-31-2011, 04:26 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
The following code adds texture quads to each window and textures them. Is this what you are looking for?
Code:
import viz
import vizact

viz.go()

texture = viz.addTexture('ball.jpg')
road = viz.addTexQuad()
road.texture(texture)
road.visible(0)

for i in range(1,100):
	road.clone(pos=[0,0,i],euler=[0,90,0])
	road.clone(pos=[0,0,i],euler=[0,90,0],scene=2)

leftWindow = viz.MainWindow
leftWindow.setSize([0.5,1])

rightWindow = viz.addWindow(pos=[0.5,1],size=[0.5,1])
rightView = viz.addView(scene=2)
rightWindow.setView(rightView)

leftView = viz.MainView

def moveViews():
	leftView.move([0,0,.03])
	rightView.move([0,0,.1])
	
vizact.ontimer(0,moveViews)
Reply With Quote
  #8  
Old 06-07-2011, 02:08 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Hi Jeff,

thanks for that; yes, that's the idea but it's a follow on from another experiment so it has to have an identical set up as before, ie the surface and position of the road, the temporal frequency of the lines, plus the road needs to continue indefinitely to the end of the experiment.

All the other parts are already coded (although I may need to call upon your expertise for additional parts of the experiment - sorry!) so it's just really a case of assigning a left quad to the left window and right quad to the right window using the code that I already have.

Is this possible or do I need to change the code so that it is similar to what you have written?

Thanks
Reply With Quote
  #9  
Old 06-07-2011, 05:02 AM
Saz Saz is offline
Member
 
Join Date: Nov 2008
Posts: 36
Hi Jeff,

Further to my last post I've done a bit of experimenting with the code and the problem appears with this part of the coding that makes the road infinite

Code:
def addRoadr():
	
	global roadr_position, roadl_position
	
	viewpointr_pos = viz.MainView.getPosition()
	rightView.setPosition(viewpointr_pos)
	#check to see how close the viewpoint is to the end of the road
	if roadr_position - viewpointr_pos[2] < 50:
		
		
		
		#add 50 meters of road
		for i in range(1,50):
			#quadrcopy = quadr.copy(scene=2)#makes left hand quad appear in both windows
			quadrcopy = quadr.copy()#makes the 2 quads appear in each window
			quadrcopy.setPosition([0.75,0,roadr_position])
			quadrcopy.setEuler(0,90,0)
			roadr_position +=1
			
	viz.MainView.move(0,0,MOVE_SPEEDr,viz.HEAD_ORI)

addRoadr()
#call a timer every frame to check if road needs to be added
vizact.ontimer(0, addRoadr)
As well as repeating the road it also seems to copy the quad into both of the scenes, so I'm guessing that it's the quadr.copy command that's the issue, any ideas on how I can still keep the infinite road but just have the quad in one scene?
Thanks
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
rotate around moving axis moneim230 Vizard 1 07-14-2010 09:04 AM
Stop moving after few seconds?? Chrissy2009 Vizard 8 05-10-2009 02:47 PM
Moving avatars lips with sound dan12345 Vizard 5 01-29-2008 07:32 PM
Moving view with object Xliben Vizard 2 07-25-2005 05:36 PM
moving viewpoint vs. translating Head_pos bailenson Vizard 5 02-01-2005 01:51 PM


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


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