[ODE] Re: Angle Rotation
Matthew D. Hancher
mdh at email.arc.nasa.gov
Sat Jun 12 14:08:38 MST 2004
Quoth Alexander Bussman <buxman at telia.com>:
> dQuaternion q;
> dGeomGetQuaternion(obj->GetGeom(), q);
> dReal newAngle = obj->GetAngle()+angle; // <---- something like that
> dQFromAxisAndAngle(q, ax, ay, az, newAngle);
It would appear that what you are trying to do here is rotate the Geom
relative to its current position, instead of just setting its absolute
orientation. Adding angles, like you suggest above, only works if
the two rotations (in this case, the one you are trying to apply and
the implied one that puts the Geom in the orientation it's in now) are
both rotations about the same axis. In general this isn't going to be
The tool you want is quaternion multiplication; ODE supports it through
the function dQMultiply0(result, q1, q2), which sets result = q1 * q2.
The order of multiplication (which quaternion is q1 and which is q2)
depends on whether your axis of rotation is measured in the global
coordinate system or the current local coordinate system of the Geom.
I'll assume it's the former. In that case you want something like:
dQuaternion q, q1, q2;
dQFromAxisAndAngle(q1, ax, ay, az, angle);
dQMultiply0(q, q1, q2);
Hopefully something along those lines will do the trick for you.
If you're more familiar with rotation matrices than with quaternions,
note that the way you combine rotations by multiplication is the same
in the two cases.
NASA Ames Research Center
Official: mdh at email.arc.nasa.gov
Personal: mdh at media.mit.edu
More information about the ODE