WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   speed on animation path (https://forum.worldviz.com/showthread.php?t=1695)

 whj 11-02-2008 01:48 PM

speed on animation path

Hello Jeff,

Previously you helped me out with the problem that how to get the position of an object two seconds ahead. Thanks a lot. Here is the code with slight change on your code, in which a semi-transparent ball two seconds ahead of another ball on animation path. I have a question about their speed. Why the speed of balls changes a lot along the animation path although I used path.constantspeed(viz.ON,4). How can I get a smooth constant speed? Thanks.

import viz
viz.go()

ball.alpha(.5)

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

positions = [ [2,0.15,50], [1,0.15,35], [0,0.15,25], [-4,0.15,15], [-10,0.15,8], [-25,0.15,0], [-15,0.15,-8], [-10,0.15,-10], [-6,0.15,-12], [-3,0.15,-15], [0,0.15,-18], [3,0.15,-16], [6,0.15,-8], [10,0.15,2], [15,0.15,0], [25,0.15,-12], [35,0.15,-12], [50,0.15,-12], [70,0.15,10], [90,0.15,30], [140,0.15,120] ]

for x in range(0,len(positions)):
cp.setPosition(positions[x])

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

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

path.translatemode(viz.BEZIER)
path2.translatemode(viz.BEZIER)

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

#Link ball and ball2 to their paths

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

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

 Jeff 11-03-2008 07:38 PM

thanks for the post, we'll get back to you as soon as we can on this

 Jeff 11-04-2008 12:12 PM

the constantspeed method does not work with the bezier translation mode. If you use it with one of the other modes it should be fine.

 whj 11-05-2008 09:19 PM

Seems that computeTangents() mode doesn't work too. Then how can I smoothly move a object in a specified curve with constent speed?

Thanks,

 Jeff 11-07-2008 07:02 PM

Are you using

Code:

```path.translatemode(viz.CUBIC_BEZIER) path.computetangents()```
I think this should work with constantspeed. Can you post an example with how you are using it.

 whj 11-09-2008 07:52 PM

Thanks Jeff. I didn't put path.translatemode(viz.CUBIC_BEZIER) in my code.:p Yes, cubic_bezier mode has constant speed.

BTW, it's not bad for me to specify all positions of a animation path using bezier translation mode, but it is really hard to find positions in cubic_bezier translation mode. Having a cubic-bezier curve, do you have any easy way to get its intermediate points?

Thanks,
whj

 whj 11-10-2008 09:36 AM

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()

ball.alpha(.5)

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

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.setPosition(positions[x])

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

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

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

 Jeff 11-12-2008 10:44 AM

Yes, your right. I guess the constantspeed does not work with Cubic Bezier either. Would defining more points on the curve and using the linear mode work for your situation

 whj 11-17-2008 07:41 PM