WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   moving at different speeds (https://forum.worldviz.com/showthread.php?t=3741)

Saz 05-10-2011 04:11 AM

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?

Saz 05-11-2011 05:15 AM

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!

Jeff 05-11-2011 12:14 PM

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)


Saz 05-17-2011 02:31 AM

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

Jeff 05-17-2011 04:22 PM

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.

Saz 05-24-2011 03:54 AM

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?

Jeff 05-31-2011 04:26 PM

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)


Saz 06-07-2011 02:08 AM

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

Saz 06-07-2011 05:02 AM

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


All times are GMT -7. The time now is 10:09 AM.

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