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:
- Damp (slow) the velocity of the object
- Modify the velocity by adding a force pulling it back to rest
- 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
精彩评论