PDA

View Full Version : constant speed on animation path


whj
04-21-2009, 09:16 AM
Hello, By pressing 'a', my script simply starts a car in a road. My question is how to make the car move in a constant speed. I use path.constantspeed(), but seems to me that the car will accelerate when it move along the circle. Does the way I add control point have problem?


import viz
import math
import time

viz.go()


myroad = viz.add('road4.wrl')
myroad.setPosition(0,0.1,0)
myroad.setScale(3.2,3.2,3.2)

mymini = viz.add('mini.osgx')
mymini.setPosition(-10,-10,0)

y_pos_car = 0.14
path = viz.addAnimationPath()
positions = [ [2,y_pos_car,50], [1,y_pos_car,35], [0,y_pos_car,25], [-1,y_pos_car,15],
[-1,y_pos_car,8], [-25,y_pos_car,0], [-15,y_pos_car,-8], [-10,y_pos_car,-10],
[-6,y_pos_car,-10], [-3,y_pos_car,-12], [0,y_pos_car,-18], [3,y_pos_car,-17],
[6,y_pos_car,0], [10,y_pos_car,4], [15,y_pos_car,2], [25,y_pos_car,-8],
[35,y_pos_car,-16], [50,y_pos_car,-10], [60,y_pos_car,20], [80,y_pos_car,40],
[200,y_pos_car,200] ]
for x in range(0,len(positions)):
cp = viz.add(viz.CONTROL_POINT)
cp.setPosition(positions[x])
path.add(cp,x+1)

path.loop(viz.OFF)
path.translatemode(viz.BEZIER)
path.setAutoRotate(viz.ON)
mymini.link(path)


def mytimer(num):
pass

def onkeydown(key):
if key == 'a':
path.play()
path.constantspeed(viz.ON,6.7)



viz.callback(viz.KEYBOARD_EVENT, onkeydown) #keyboard event callback
viz.callback(viz.TIMER_EVENT, mytimer) #timer event callback
viz.starttimer(0,1/60,viz.FOREVER) #timer




BTW, I cannot attach my models zip file here because it always said "Upload of file failed". What should I try?

Thanks a lot!

Jeff
04-21-2009, 11:17 AM
Constant speed will not work with the translate mode you are using. You could try using the linear mode or creating your animation in modeling software like 3ds Max.

whj
04-21-2009, 01:29 PM
Thanks anyway.