What is elasticity? How do I implement such a thing?
|
|
Checkout Robbert Penner's easing classes and examples. They are very easy to convert to C#. |
|||
|
|
|
Elasticity can be defined in two ways; either to do with physics or to do with how you move from one value to another (tweening). TweeningThis is used in games to move between two values - for example you might have a set of points that the game camera needs to move between over time. The simplest tween is a lerp (also known as a linear tween):
In order to use this function you must provide it with an initial value (for example, the camera starting position), the change required to get it to the target (where you want it to move to) and how far along that line you want it to be (a value between 0 and 1 - e.g. 0.5 would be half way to the target). The result of a lerp looks like this:
An elastic tween makes the value 'bounce' at the start, the end or both (ease in, ease out and ease in out respectively). Ease in elastic:
Ease out elastic:
Ease in out elastic:
The MCTween animation types page will let you see these as animated graphs/values. XNATweener has an elastic tween implementation. SpringsAn elastic band in physics is usually represented by a long chain of very short interconnected springs, that are connected using a revolute joint (you may limit the angle) and that have a very high dampening factor. This means that each spring:
The whole system behaves as follows:
Farseer has springs. Elastic and Inelastic CollisionsAn elastic collision is when the kinetic (movement or momentum) energy of colliding bodies remains the same after a collision (it can still be distributed differently between the bodies). This means that no energy is lost to other forms of energy (for example, sound, heat and light). Elastic collisions (or "super-elastic", where the energy is greater) only happen at the molecular level - however elastic collisions can be passable in games. An inelastic collision is when a portion of the kinetic energy is converted to other forms of energy. For example, when two billiard balls collide you hear a sound (although this does have a negligible impact on the total momentum). If a car collides with another one a lot of energy is lost to deformation and heat. At the macro-scale these types of collisions are more accurate; and will generally improve the stability of your physics simulation (they reduce the chance of a rounding error or such from introducing more energy). Wikipedia has very good articles on both elastic and inelastic collisions, Physics for Game Programmers has a free excerpt on both. |
|||||||||
|
|
I don't know what you mean exactly by "elasticity". If you mean rope simulation or grid/cloth simulation, here is how to proceed : A rope/string is simply a list of points connected together with springs :
Force applied on a point depends of forces received from the two neighbours springs :
Force applied by a spring on a point is calculated like this :
where :
Now, some code :
You can also skip simulation of some points and explicity set their position if you want them to be fixed (usually first point of rope is like this). If you want to do grid/cloth simulation, this is exactly the same thing, but instead points are arranged as a grid, and forces are received from more neighbour springs :
Here is some pseudo-code :
|
||||
|
|
|
You can check XNA Tweener library that has Elastic function among others. Its an adoption of Robbert Penner's easing framework. |
|||
|
|








