void QuaternionFromAngle ( float * fQuaternion , float fAngle ) { fAngle = DEGTORAD ( fAngle ) ; float fMatrix [ 3 ] [ 3 ] , c = cos ( fAngle ) , s = sin ( fAngle ) ; // QuaternionRotateZ fMatrix [ 0 ] [ 0 ] = c ; fMatrix [ 0 ] [ 1 ] = s ; fMatrix [ 0 ] [ 2 ] = 0.0 ; fMatrix [ 1 ] [ 0 ] = - s ; fMatrix [ 1 ] [ 1 ] = c ; fMatrix [ 1 ] [ 2 ] = 0.0 ; fMatrix [ 2 ] [ 0 ] = 0.0 ; fMatrix [ 2 ] [ 1 ] = 0.0 ; fMatrix [ 2 ] [ 2 ] = 1.0 ; // GetQuaternionFromMatrix fQuaternion [ 0 ] = sqrt ( Max ( ( float ) 0 , 1.0f + fMatrix [ 0 ] [ 0 ] + fMatrix [ 1 ] [ 1 ] + fMatrix [ 2 ] [ 2 ] ) ) * 0.5f ; fQuaternion [ 1 ] = sqrt ( Max ( ( float ) 0 , 1.0f + fMatrix [ 0 ] [ 0 ] - fMatrix [ 1 ] [ 1 ] - fMatrix [ 2 ] [ 2 ] ) ) * 0.5f ; fQuaternion [ 2 ] = sqrt ( Max ( ( float ) 0 , 1.0f - fMatrix [ 0 ] [ 0 ] + fMatrix [ 1 ] [ 1 ] - fMatrix [ 2 ] [ 2 ] ) ) * 0.5f ; fQuaternion [ 3 ] = sqrt ( Max ( ( float ) 0 , 1.0f - fMatrix [ 0 ] [ 0 ] - fMatrix [ 1 ] [ 1 ] + fMatrix [ 2 ] [ 2 ] ) ) * 0.5f ; fQuaternion [ 1 ] = static_cast ( _copysign ( fQuaternion [ 1 ] , fMatrix [ 2 ] [ 1 ] - fMatrix [ 1 ] [ 2 ] ) ) ; fQuaternion [ 2 ] = static_cast ( _copysign ( fQuaternion [ 2 ] , fMatrix [ 0 ] [ 2 ] - fMatrix [ 2 ] [ 0 ] ) ) ; fQuaternion [ 3 ] = static_cast ( _copysign ( fQuaternion [ 3 ] , fMatrix [ 1 ] [ 0 ] - fMatrix [ 0 ] [ 1 ] ) ) ; }