View Single Post
  #6  
Old 09-22-2008, 02:26 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You could try creating another animation path with identical control points. You can delay playing the second path by two seconds. The second path would have your car linked to it. The first path would have an empty group node linked to it. The group node, which is not visible, would always have the position two seconds ahead of your car. Just get its position anytime you need to make your calculation. If however you change the speed of your car's animation path, you will need to do the same for your group nodes path, so they will always be two seconds apart.

Here is some code with a semi-transparent ball two seconds ahead of another ball. You could replace the semi-transparent ball with an empty group node that just holds the position

Code:
import viz
viz.go()

viz.add('tut_ground.wrl')

#add a ball and make semi-transparent,  this will be 2 seconds ahead of 
#ball2
ball = viz.add('ball.wrl')
ball.alpha(.2)
ball2 = viz.add('ball.wrl')

#Move the viewpoint back
viz.MainView.move(0,0,-8)

#Create the animation paths
path = viz.add(viz.ANIMATION_PATH)
path2 = viz.add(viz.ANIMATION_PATH)

#Initialize an array of control points
positions = [ [0,0,2], [2,0,0], [0,0,-2], [-2,0,0] ]

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)

#Set the initial loop mode to circular
path.loop(viz.CIRCULAR)
path2.loop(viz.CIRCULAR)

#Automatically compute tangent vectors for cubic bezier translations
path.computeTangents()
path2.computetangents()

#Automatically rotate the path
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