View Single Post
  #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