WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1  
Old 11-02-2008, 02:48 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
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()

viz.add('tut_ground.wrl')

ball = viz.add('ball.wrl')
ball.alpha(.5)
ball2 = viz.add('ball.wrl')

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

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

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 = 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.BEZIER)
path2.translatemode(viz.BEZIER)

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

#Link ball and ball2 to their paths
ball.link(path)
ball2.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
  #2  
Old 11-03-2008, 08:38 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
thanks for the post, we'll get back to you as soon as we can on this
Reply With Quote
  #3  
Old 11-04-2008, 01:12 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Reply With Quote
  #4  
Old 11-05-2008, 10:19 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
Seems that computeTangents() mode doesn't work too. Then how can I smoothly move a object in a specified curve with constent speed?

Thanks,
Reply With Quote
  #5  
Old 11-07-2008, 08:02 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Reply With Quote
  #6  
Old 11-09-2008, 08:52 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
Thanks Jeff. I didn't put path.translatemode(viz.CUBIC_BEZIER) in my code. 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
Reply With Quote
  #7  
Old 11-10-2008, 10: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
  #8  
Old 11-12-2008, 11:44 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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
Reply With Quote
  #9  
Old 11-17-2008, 08:41 PM
whj whj is offline
Member
 
Join Date: Apr 2008
Posts: 60
OK. Thanks for your help.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
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
Animation Tracks.... k_iwan Vizard 2 03-26-2007 06:52 PM
Jumpy animation Elizabeth S Vizard 1 11-08-2006 03:11 PM


All times are GMT -7. The time now is 08:00 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC