diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 791999db..b8dfe481 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -159,71 +159,50 @@ namespace LinearAlgebra /******************************************************************** * Normalized Linear Interpolation - * @return nullvector if impossible to solve. + * @return nullvector if Lerp( start, end, t ) is nullvector. ********************************************************************/ template inline Vector2 Nlerp( const Vector2 &start, const Vector2 &end, const ScalarType &t ) { Vector2 output = Lerp( start, end, t ); ScalarType magnitudeSquared = output.Dot( output ); - if( magnitudeSquared == 0 ) + if( magnitudeSquared != 0 ) { - ScalarType half = t * 0.5f; - output = Lerp( start, end, half ); - magnitudeSquared = output.Dot( output ); - - if( magnitudeSquared == 0 ) - return output; // error: returning nullvector - - return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); - } - return output /= magnitudeSquared; + return output /= (ScalarType)::std::sqrt( magnitudeSquared ); + } + return output; // error: returning nullvector } /******************************************************************** * Normalized Linear Interpolation - * @return nullvector if impossible to solve. + * @return nullvector if Lerp( start, end, t ) is nullvector. ********************************************************************/ template inline Vector3 Nlerp( const Vector3 &start, const Vector3 &end, const ScalarType &t ) { Vector3 output = Lerp( start, end, t ); ScalarType magnitudeSquared = output.Dot( output ); - if( magnitudeSquared == 0 ) + if( magnitudeSquared != 0 ) { - ScalarType half = t * 0.5f; - output = Lerp( start, end, half ); - magnitudeSquared = output.Dot( output ); - - if( magnitudeSquared == 0 ) - return output; // error: returning nullvector - - return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); - } - return output /= magnitudeSquared; + return output /= (ScalarType)::std::sqrt( magnitudeSquared ); + } + return output; // error: returning nullvector } /******************************************************************** * Normalized Linear Interpolation - * @return nullvector if impossible to solve. + * @return nullvector if Lerp( start, end, t ) is nullvector. ********************************************************************/ template inline Vector4 Nlerp( const Vector4 &start, const Vector4 &end, const ScalarType &t ) { Vector4 output = Lerp( start, end, t ); ScalarType magnitudeSquared = output.Dot( output ); - if( magnitudeSquared == 0 ) + if( magnitudeSquared != 0 ) { - ScalarType half = t * 0.5f; - output = Lerp( start, end, half ); - magnitudeSquared = output.Dot( output ); - - if( magnitudeSquared == 0 ) - return output; // error: returning nullvector - - return Nlerp( output /= magnitudeSquared, end, half / (1.0f - half) ); - } - return output /= magnitudeSquared; + return output /= (ScalarType)::std::sqrt( magnitudeSquared ); + } + return output; // error: returning nullvector } }