Tuesday 18 March 2014

Test

This is a test post, tralala.

Here is some test syntax highlighting for blogger:

// ----------------------------------------------------
//   round the angle to nearest x degrees
// ----------------------------------------------------
Vector3 Vector3::roundAngle ( int nearest_angle )
{
        // vector to return
        Vector3 rounded;

        // convert to radians
        float nearest_radians = RADIANS ( nearest_angle );

        // get the angle of this vector
        float angle = ( float ) atan2 ( this->y, this->x );

        // remainder between 2 angles
        float remainder = std::fmod ( angle, nearest_radians );

        // if there is a remainder, do the rounding
        if ( remainder != 0 ) {
                float new_angle = ( float ) round ( angle / nearest_radians ) * nearest_radians;

                rounded.x = ( float ) cos ( new_angle );
                rounded.y = ( float ) sin ( new_angle );
        }

        if ( fabs ( rounded.x ) < TOL ) rounded.x = 0.0f;
        if ( fabs ( rounded.y ) < TOL ) rounded.y = 0.0f;
        if ( fabs ( rounded.z ) < TOL ) rounded.z = 0.0f;

        return rounded;
}
sweet.

No comments:

Post a Comment