Smoother arc rendering in OpenGL GAL

Fixes: lp:1496114
* https://bugs.launchpad.net/kicad/+bug/1496114
This commit is contained in:
Maciej Suminski 2017-03-10 11:18:15 +01:00
parent 3208d24ad4
commit 11f8e53e27
2 changed files with 12 additions and 3 deletions

View File

@ -532,12 +532,13 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
// Swap the angles, if start angle is greater than end angle // Swap the angles, if start angle is greater than end angle
SWAP( aStartAngle, >, aEndAngle ); SWAP( aStartAngle, >, aEndAngle );
const double alphaIncrement = calcAngleStep( aRadius );
Save(); Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 ); currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );
if( isStrokeEnabled ) if( isStrokeEnabled )
{ {
const double alphaIncrement = 2.0 * M_PI / CIRCLE_POINTS;
currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); currentManager->Color( strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a );
VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius ); VECTOR2D p( cos( aStartAngle ) * aRadius, sin( aStartAngle ) * aRadius );
@ -561,7 +562,6 @@ void OPENGL_GAL::DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double a
if( isFillEnabled ) if( isFillEnabled )
{ {
const double alphaIncrement = 2 * M_PI / CIRCLE_POINTS;
double alpha; double alpha;
currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a ); currentManager->Color( fillColor.r, fillColor.g, fillColor.b, fillColor.a );
currentManager->Shader( SHADER_NONE ); currentManager->Shader( SHADER_NONE );
@ -598,7 +598,7 @@ void OPENGL_GAL::DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius, d
// Swap the angles, if start angle is greater than end angle // Swap the angles, if start angle is greater than end angle
SWAP( aStartAngle, >, aEndAngle ); SWAP( aStartAngle, >, aEndAngle );
const double alphaIncrement = 2.0 * M_PI / CIRCLE_POINTS; const double alphaIncrement = calcAngleStep( aRadius );
Save(); Save();
currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 ); currentManager->Translate( aCenterPoint.x, aCenterPoint.y, 0.0 );

View File

@ -440,6 +440,15 @@ private:
*/ */
unsigned int getNewGroupNumber(); unsigned int getNewGroupNumber();
/**
* @brief Compute the angle step when drawing arcs/circles approximated with lines.
*/
double calcAngleStep( double aRadius ) const
{
// Bigger arcs need smaller alpha increment to make them look smooth
return std::min( 1e6 / aRadius, 2.0 * M_PI / CIRCLE_POINTS );
}
/** /**
* @brief Basic OpenGL initialization. * @brief Basic OpenGL initialization.
*/ */