View Single Post
  #1  
Old 03-16-2015, 10:13 AM
vserchi vserchi is offline
Member
 
Join Date: Sep 2013
Posts: 7
update sequence animation speed

Hi, I am trying to interactively update the speed of certain objects animations (sequences of animation) in my virtual reality. At the change of the variable "speed" I need that the speed of translation of my objects accordingly changes too. In the following code there is a a very simplified example of what I am trying to do.

Code:
import viz
import vizact

viz.fov(60)
viz.go()

#Add the ground plane
ground = viz.addChild('ground.osgb')

#Move the viewpoint back
viz.MainView.move([0,0,-7])

ball = viz.add('beachball.osgb')
ball.setPosition(0,1,0)

ball1 = viz.add('beachball.osgb')
ball1.setPosition(0,0,0)

myAction1 = vizact.moveTo([ball.getPosition()[0], -1,  ball.getPosition()[1]],speed=1) # Definition of the animation of the road (custom function that manages its resume defined from line 364 to line 439
myAction2 = vizact.moveTo([ball.getPosition()[0], ball.getPosition()[1], ball.getPosition()[2]],[ball.getPosition()[0], 4, ball.getPosition()[1]],speed=1)
myAnimation = vizact.sequence(myAction1, myAction2, viz.FOREVER)

myAction3 = vizact.moveTo([ball1.getPosition()[0], -1,  ball1.getPosition()[1]],speed=1) # Definition of the animation of the road (custom function that manages its resume defined from line 364 to line 439
myAction4 = vizact.moveTo([ball1.getPosition()[0], ball1.getPosition()[1], ball1.getPosition()[2]],[ball1.getPosition()[0], 4, ball1.getPosition()[1]],speed=1)
myAnimation1 = vizact.sequence(myAction3, myAction4, viz.FOREVER)

ball.addAction(myAnimation)
ball1.addAction(myAnimation1)

def changeSpeed(pos):
	print str(pos), viz.Vector(ball.getVelocity())
	ball.setVelocity([0, pos, 0]) 
	ball1.setVelocity([0, pos, 0]) 

####	ball.setSpeed(pos) 
####	ball1.setSpeed(pos) 

slider = viz.addSlider()
slider.setPosition([.5,.5,0])

#Setup callbacks for slider events
vizact.onslider(slider, changeSpeed)
I really appreciate any help you may give me.
Valeria
Reply With Quote