18.9 An Application Layer 863
// Create axis and angle for the rotation.
Vector3f kAxis = kVec0.Cross(kVec1);
float fDot = kVec0.Dot(kVec1);
float fAngle;
if (kAxis.Normalize() > Mathf::ZERO_TOLERANCE)
{
fAngle = Mathf::ACos(kVec0.Dot(kVec1));
}
else // Vectors are parallel.
{
if (fDot < 0.0f)
{
// rotated pi radians
fInvLength = Mathf::InvSqrt(fX0 * fX0 + fY0 * fY0);
kAxis.X() = fY0 * fInvLength;
kAxis.Y() = -fX0 * fInvLength;
kAxis.Z() = 0.0f;
fAngle = Mathf::PI;
}
else
{
// rotation by zero radians
kAxis = Vector3f::UNIT_X;
fAngle = 0.0f;
}
}
Vector3f kWorldAxis =
kAxis.X()*m_spkCamera->GetDVector() +
kAxis.Y()*m_spkCamera->GetUVector() +
kAxis.Z()*m_spkCamera->GetRVector();
Matrix3f kTrackRotate(kWorldAxis,fAngle);
const Spatial* pkParent = m_spkMotionObject->GetParent(); ...