Optimize VECTOR2::Rotation for 0, 90, 180 and -90 degrees by avoiding time consumming calculations.
This commit is contained in:
parent
c1f0ab91a2
commit
5da341d1fc
|
@ -358,6 +358,19 @@ VECTOR2<T>& VECTOR2<T>::operator-=( const T& aScalar )
|
|||
template <class T>
|
||||
VECTOR2<T> VECTOR2<T>::Rotate( double aAngle ) const
|
||||
{
|
||||
// fast calculation of some rotations, very frequently found
|
||||
if( aAngle == 0.0 )
|
||||
return VECTOR2<T> ( T( x ), T( y ) );
|
||||
|
||||
if( aAngle == 90.0 )
|
||||
return VECTOR2<T> ( T( -y ), T( x ) );
|
||||
|
||||
if( aAngle == -90.0 )
|
||||
return VECTOR2<T> ( T( y ), T( -x ) );
|
||||
|
||||
if( aAngle == 180.0 || aAngle == -180.0 )
|
||||
return VECTOR2<T> ( T( -x ), T( -y ) );
|
||||
|
||||
double sa = sin( aAngle );
|
||||
double ca = cos( aAngle );
|
||||
|
||||
|
|
Loading…
Reference in New Issue