开发者

How can I create wiggle animation (damped oscillations)?

I'm new to p开发者_如何学Pythonrogramming and making an app for ipad with Corona SDK.

I want to take a wiggle animation like this: http://www.youtube.com/watch?v=kXxQU0T7I2A#t=0m40s (t=40-44sec).

How can I do that? What way is easier: use physics with specific joints or use transitions? Maybe some examples?


The solution of a damped harmonic oscillator is pretty simple:

startAmplitude*sin(omega*t+startPhase)*exp(-t*dampningConstant)

I'd use this to describe the angle of the joint. From angle and length of arm you can calculate an (x,y) pair. If you have several parts in a series you can simply add the x and y values of the different steps.

This doesn't describe the physics of a coupled system of joints correctly, but might be good enough for what you need.


To simulate a damped spring you need to specify:

  • The damping force (0=no damping, 1=full damping)
  • The spring constant (0=no spring, increasing values results in a stronger spring)

Each frame, you want to keep track of the velocity of the object, and:

  1. Damp (slow) the velocity of the object
  2. Modify the velocity by adding a force pulling it back to rest
  3. Adjust the position of the object based on its velocity

In pseudo-code, this is:

velocity = velocity * (1-dampingFactor) + deviationFromRest * springConstant
position = position + velocity

You can interactively play with this on my website:
http://phrogz.net/damped-spring-oscillations-in-javascript

How can I create wiggle animation (damped oscillations)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜