View Single Post
  #7  
Old 11-10-2008, 09:36 AM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
Hi Jeff,

Please see the following code. The car speed up when it turns. Seems still not constant speed for some curves. How can I improve it? About cubic_bezier curve, do I specify only 4 points for a curve? If the curve is complex, could I include more points?

import viz
viz.go()

viz.add('tut_ground.wrl')

ball = viz.add('ball.wrl')
ball.alpha(.5)
car = viz.add('mini.osgx')

viz.MainView.move(0,3,-60)

path = viz.add(viz.ANIMATION_PATH)
path2 = viz.add(viz.ANIMATION_PATH)

positions = [ [7,0.15,-50], [5,0.15,10], [20,0.15,-10], [140,0.15,120] ]
for x in range(0,len(positions)):
cp = viz.add(viz.CONTROL_POINT)
cp.setPosition(positions[x])
path.add(cp,x+1)
path2.add(cp,x+1)


path.constantspeed(viz.ON,4)
path2.constantspeed(viz.ON,4)


path.loop(viz.OFF)
path2.loop(viz.OFF)

path.translatemode(viz.CUBIC_BEZIER)
path.computetangents()
path2.translatemode(viz.CUBIC_BEZIER)
path2.computetangents()

path.setAutoRotate(viz.ON)
path2.setAutoRotate(viz.ON)

#Link ball and ball2 to their paths
ball.link(path)
car.link(path2)


#start playing the first animation path immediately
path.play()

#start playing the second animation path after two seconds
vizact.ontimer2(2, 1, path2.play)
Reply With Quote