WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   easeout wheel-rotation (https://forum.worldviz.com/showthread.php?t=4894)

white 12-10-2013 10:34 AM

easeout wheel-rotation
 
Hi,

How can I ease out a wheel-rotation depending on another action (motion of car)? I could rotate the wheel and easeout the rotation.


rim1.setCenter([1.5,0.32,0.945])
spinAction = vizact.spin(-1,0,0,270,10)
rim1.addAction(spinAction)
yield viztask.waitActionEnd(rim1,spinAction)
easeOut = vizact.spinTo(axisAngle=[1,0,0,0],speed=120, interpolate = vizact.easeOut)
rim1.addAction(easeOut)


But now I'd like the end of rotation to fit the time the cars stop. The cars have different starting positions (and therefore do not always take the same time to get to the stopping point), move to one point and ease out as well.

action1 = vizact.moveTo([-2,0,2],speed=13.89, interpolate=vizact.easeOut)

How can I link these two actions?

Thank you.
Gerda

white 01-02-2014 10:37 AM

wheel rotation
 
Hi there,

I'm still struggeling with the posted question...
Maybe it's possible to stop the two actions at the same time with the "viz.ANIMATION_END_EVENT" command ?

thanks for helping

Frank Verberne 01-03-2014 01:37 AM

I think this should fix your problem:
Code:

import viz
import viztask
import vizact

viz.go()
viz.eyeheight(0)
viz.MainView.setPosition(0,0,-4)

car1 = viz.add('box.wrl')
rim1 = viz.add('box.wrl', color = [0,0,1])
car2 = viz.add('box.wrl', color = [1,0,1])
rim2 = viz.add('box.wrl', color = [0,1,0])

action1 = vizact.spin(0,0,1,60)
action2 = vizact.moveTo([-2,0,2],speed=2.00, interpolate=vizact.easeOut)
action3 = vizact.moveTo([-2,0,2],speed=4.00, interpolate=vizact.easeOut)

def actionTime():
        rim1.addAction(action1,0)
        rim2.addAction(action1,0)
        car1.addAction(action2,0)
        car2.addAction(action3,0)
       
vizact.onkeydown(' ', actionTime)
       
def onActionEnd(e):
        if e.object is car1:
                rim1.endAction(0)
        elif e.object is car2:
                rim2.endAction(0)

viz.callback(viz.ACTION_END_EVENT,onActionEnd)

In this example, the green box (rim2) is the rim of the purple box (car2), and the blue box (rim1) is the rim of the red box (car1). The red and purple box arrive at different times at the end position, and the rotation of their rims stop accordingly. Replace the boxes with your appropriate models, and you should be good to go:)!

Erikvdb 01-06-2014 07:17 AM

Frank, that only starts/stops the spinning, it doesn't ease-in or out.

I think a more flexible solution would be to wire -in 3ds max terms- the wheel rotation to the car translation. I can't really remember how it works best exactly, but here's a quick and dirty version, based on Frank's code:

Code:

import viz
import vizact
import vizmat

viz.go()

car1 = viz.add('box.wrl')
carPos = car1.getPosition()

viz.eyeheight(0)
viz.MainView.setPosition(-5,0,-20)

action1 = vizact.moveTo([-10,0,0],speed=4.00, interpolate=vizact.easeInOut)

def actionTime():
        car1.addAction(action1,0)
       
def onUpdate():
        global carPos
        newPos = car1.getPosition()
        distance = vizmat.Distance(carPos,newPos)
        rotation = distance * viz.getFrameElapsed() * 2000
        car1.setEuler([0,0,rotation],viz.REL_LOCAL)
        carPos = newPos
       
vizact.onkeydown(' ', actionTime)
vizact.onupdate(0, onUpdate)

The 2000 number should be based on the wheel circumference, but I forgot how it relates exactly, so it's just an arbitrary multiplier.


All times are GMT -7. The time now is 06:59 PM.

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