#1
|
|||
|
|||
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) |
#2
|
|||
|
|||
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) 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) Thanks! |
#3
|
|||
|
|||
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) |
#4
|
|||
|
|||
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 |
#5
|
|||
|
|||
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.
|
#6
|
|||
|
|||
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 |
#7
|
|||
|
|||
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) |
#8
|
|||
|
|||
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 |
#9
|
|||
|
|||
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) Thanks |
Thread Tools | |
Display Modes | Rate This Thread |
|
|
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 |