![]() |
|
#1
|
|||
|
|||
|
constant speed on animation path
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?
Code:
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! Last edited by whj; 04-21-2009 at 10:23 AM. |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems with interaction of vizact.turn and animation path | Enlil | Vizard | 3 | 11-24-2008 05:23 PM |
| speed on animation path | whj | Vizard | 8 | 11-17-2008 08:41 PM |
| real time collision on animation path | whj | Vizard | 10 | 10-06-2008 05:38 PM |
| Animation Path | djdesmangles | Vizard | 2 | 06-11-2007 04:37 PM |
| Animation Path | djdesmangles | Vizard | 0 | 06-06-2007 12:03 PM |