http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: Spring model



I tried the dragforce technique and it gave very nice results.=20
=20
Thanks!=20
=20
Quoting "Peter M." <plm@snow.org>:=20
> As a recovering physicist, I can't resist replying. Have you tried just=
 =20
> introducing a "drag" force? Basically, just a force that is constant an=
d =20
> opposite of velocity. If velocity is zero, there is no drag. For more =20
> complexity/realism, make the more proportional to velocity, or velocity=
 to =20
> 1.5ish power (for air friction), or whatever.=20
> =20
> I'll try modifying the code to show what I mean:=20
> <snip>=20
> >/* apply forces */=20
> >for (int i =3D 0; i < (int)points.size(); i++) {=20
> >         point accel;=20
> =20
> // add drag=20
> point dragForce;=20
> =20
> // start out opposite to velocity=20
> dragForce.x =3D -points.at(i).veloc.x;=20
> dragForce.y =3D -points.at(i).veloc.y;=20
> =20
> double v =3D sqrt( dragForce.x * dragForce.x + dragForce.y * dragForce.=
y);=20
> =20
> if (v > DRAG_TOLERANCE)=20
> {=20
> // normalize=20
> dragForce.x /=3D v;=20
> dragForce.y /=3D v;=20
> =20
> // apply coefficient of drag=20
> const double u =3D 0.1;=20
> dragForce.x *=3D u;=20
> dragForce.y *=3D u;=20
> }=20
> =20
> >=20
> >         // acceleration=20
> >         accel.x =3D points.at(i).force.x / weight;=20
> >         accel.y =3D points.at(i).force.y / weight;=20

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/