// //############################################################################# //############################################################################# // Scalar UnitQuaternion::GetAngle() { Check_Object(this); Scalar sine_of_half = Sqrt(x*x + y*y + z*z); if (Small_Enough(sine_of_half)) { return 0.0f; } SinCosPair half_angle(sine_of_half, w); Radian angle; angle = half_angle; return angle * 2.0f; }
// //############################################################################# //############################################################################# // UnitQuaternion& UnitQuaternion::Multiply( const UnitQuaternion &q, Scalar t ) { Check_Pointer(this); Check_Object(&q); // //--------------------------------------------------------- // Figure out the half the angle of rotation and scale that //--------------------------------------------------------- // Scalar sine_of_half = Sqrt(q.x*q.x + q.y*q.y + q.z*q.z); if (Small_Enough(sine_of_half)) { *this = Identity; return *this; } SinCosPair half_angle(sine_of_half, q.w); Radian angle; angle = half_angle; angle *= t; half_angle = angle; // //----------------------------------------------------------------- // Build the scaled quaternion out of the components of the old one //----------------------------------------------------------------- // w = half_angle.cosine; sine_of_half = half_angle.sine / sine_of_half; x = q.x * sine_of_half; y = q.y * sine_of_half; z = q.z * sine_of_half; Check_Object(this); return *this; }
// //########################################################################### //########################################################################### // Vector3D& Vector3D::operator=(const UnitQuaternion &q) { Check_Pointer(this); Check_Object(&q); Scalar sine_of_half = Sqrt(q.x*q.x + q.y*q.y + q.z*q.z); if (Small_Enough(sine_of_half)) { return *this = Identity; } SinCosPair half_angle(sine_of_half, q.w); Radian angle; angle = half_angle; Scalar len = angle * 2.0f / sine_of_half; x = q.x * len; y = q.y * len; z = q.z * len; return *this; }