[ODE] 3 beginner questions
david@csworkbench.com
david at csworkbench.com
Thu Apr 3 18:20:02 2003
Here's a process, which seems like it should work quite well, and
simulates both aerodynamic drag and rolling friction:
- When you do collision detection (so only objects touching other objects
are subject to rolling friction), for each of the 2 bodies:
+ dot the linear velocity with the contact normal
+ multiply the absolute value of that scalar by the mass
+ multiply that by the angular speed (magnitude of angular velocity)
+ use the result times a scale factor (possibly different scale factors
for different bodies, to simulate the difference between rolling on
carpet and hardwood) for the amount of torque to add
+ use the negative of the angular velocity for the direction vector
- After collision detection (or any time before the step), for every body:
+ dot the linear velocity with itself to get the square of the speed
+ if you're ambitious, project the 3d object onto the 2d plane
perpendicular to the linear velocity, and find the area of this
silhouette, and scale the previous result by this factor (don't know
the math to make this happen). Maybe a simpler algorithm to do the
same thing would be take each face individually, multiply it's area
times the dot product of its normal and the linear velocity (both
normalized), discard all negative results and sum the rest. If you
translate the linear velocity to body coordinates, much of that can
be precalculated. Only works for convex objects though. Simpler
calculations exist for geometry objects (i.e. sphere is always pi*r^2).
+ use the result times a scale factor for the amount of force to add
+ use the negative of the linear velocity as the direction vector
Just about any subset of those instructions will still give believable
results, but those are probably the most physically correct. Note that
the "find the area of the silhouette" step for air friction may be of
little use (you scale it down so much...), but for simulating water is of
paramount importance, otherwise you could paddle a boat with the thick or
the thin edge of a paddle with no difference..... probably not what you
want.
Just my thoughts,
David
> To simulate drag, are you applying a "Torque" instead of a "Force" like
> the Wiki says?
>
> http://q12.org/cgi-bin/wiki.pl?RollingFrictionOrAerodynamicDrag
>
> In my own experience, instead of damping the angular velocity (torque),
> I've found that for rolling friction, applying a *CONSTANT* force
> opposing the velocity and clamping the force so it doesn't exceed the
> current velocity works well. Here's a code snippet
>
> // get velocity and speed of body
> float* vel = dBodyGetLinearVel(body);
> F32 speed = dSqrt(vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]);
>
> // apply constant friction
> const float friction = 0.1f; // you'll need to adjust this to feel
> right
>
> float scale = -1.f;
> if (friction < speed)
> scale = -(friction / speed);
>
> float f[3];
> f[0] = vel[0] * scale;
> f[1] = vel[1] * scale;
> f[2] = vel[2] * scale;
> dBodyAddForce(body, f[0], f[1], f[2]);
>
> I don't have a theoretical basis for this, but in practice it seems to
> feel realistic.
>
> -----Original Message-----
> From: Bob Ives [mailto:bobives@jazzfree.com]
> Sent: Friday, 4 April 2003 12:06 AM
> To: ode@q12.org
> Subject: [ODE] 3 beginner questions
>
> 2. Drag. After implimenting simple drag as described in the wiki faq,
> I found that objects still take a considerable time to come to rest
> after colliding, despite increasing the drag coefficients. I thought to
> experiment with the density argument I give in dMassSetSphere, but
> surprisingly found that increasing density leads to the object slipping
> for more time before coming to rest, and vice-versa. I also found that
> with more density there was a contant interpenetration of my objects
> sphere with the ground plane. I wonder if the slip is somehow caused by
> a longer time resolving contacts between the ground and the moving body.
>
> _______________________________________________
> ODE mailing list
> ODE@q12.org
> http://q12.org/mailman/listinfo/ode