|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [gameprogrammer] Re: Spring model
At 04:53 PM 2004-04-01, straver@apollo.nu wrote:
>I'm playing with a spring model but I have run into a trouble.=20
>The trouble is that I want a dampning effect on the springs so=20
>they don't go all crazy but I don't want any damping effect on=20
>the gravity movement for example.=20
>=20
>I can't think of any way to seperate them.=20
As a recovering physicist, I can't resist replying. Have you tried just
introducing a "drag" force? Basically, just a force that is constant and
opposite of velocity. If velocity is zero, there is no drag. For more
complexity/realism, make the more proportional to velocity, or velocity to
1.5ish power (for air friction), or whatever.
I'll try modifying the code to show what I mean:
<snip>
>/* apply forces */
>for (int i = 0; i < (int)points.size(); i++) {
> point accel;
// add drag
point dragForce;
// start out opposite to velocity
dragForce.x = -points.at(i).veloc.x;
dragForce.y = -points.at(i).veloc.y;
double v = sqrt( dragForce.x * dragForce.x + dragForce.y * dragForce.y);
if (v > DRAG_TOLERANCE)
{
// normalize
dragForce.x /= v;
dragForce.y /= v;
// apply coefficient of drag
const double u = 0.1;
dragForce.x *= u;
dragForce.y *= u;
}
>
> // acceleration
> accel.x = points.at(i).force.x / weight;
> accel.y = points.at(i).force.y / weight;
<snip>
Peter Mikelsons
plm@snow.org
http://plm.snow.org/
Snowbound
|
|