[ODE] Balancing act

Nate W coding at natew.com
Mon Aug 11 23:03:01 2003


On Mon, 11 Aug 2003, Stephen Moorhouse wrote:

> As the capsule topples from outside forces, say a shove in one
> direction, i grab its new and slightly different orientation each
> frame. I'd like to get the capsule to balance itself upright by
> applying some torque to fire it in the right direction. The trouble is
> i can't work out which direction the torque should be in.

I'm making this up as I go along, so no promises:

Just before the simulation starts, take your global 'up' vector and
multiply it by the capsule's initial orientation matrix (I'm assuming that
this is the orientation you want the capsule to maintain).  Call the
result your 'reference vector.'

Each frame, take your global up vector and multiply it by the capsule's
current orientation matrix.  Call the result your 'present vector.'

The cross product of the reference and present vectors will give you a
third vector, which is perpendicular to both and whose length depends on
the angle between them.  It's definitely in the right direction to be used
for the angle about which to apply your torque, and I have a hunch that
you could even use the magnitude as well.  Try multiplying that vector by
a scalar (possibly a negative number) and apply it as a torque, and see
what happens.

-- 

Nate Waddoups
Redmond WA USA
http://www.natew.com