Пример #1
0
//-------------------------------------------------------------------------------
// @ IvQuat::Normalize()
//-------------------------------------------------------------------------------
// Set to unit quaternion
//-------------------------------------------------------------------------------
void
IvQuat::Normalize()
{
    float lengthsq = w*w + x*x + y*y + z*z;

    if ( ::IsZero( lengthsq ) )
    {
        Zero();
    }
    else
    {
        float factor = IvInvSqrt( lengthsq );
        w *= factor;
        x *= factor;
        y *= factor;
        z *= factor;
    }

}   // End of IvQuat::Normalize()
Пример #2
0
//Set to unit vector
void CVector3::Normalize()
{
	float lengthsq = LengthSquared();

	if(::IsZero(lengthsq))
	{
		Zero();
	}
	else
	{
		*this *= IvInvSqrt(lengthsq);
		/*
		The following is the expanded version of the above line:
		
		float factor = IvInvSqrt( lengthsq );
		x *= factor;
		y *= factor;
		z *= factor;
		*/
	}
}