diff options
author | David <hlorus> | 2020-01-17 19:03:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-01-17 19:07:13 +0300 |
commit | f417787ee116f25889f853a98319d4e351edb3b5 (patch) | |
tree | 36acb9162cedbd360f7e1ba5b38b9bc16f251ef4 /source/blender/editors/gizmo_library | |
parent | 3ef32cb90a1f23d3ea7ceb468be411b1a914c246 (diff) |
Gizmo: draw dial arc only over one rotation to avoid artifacts
There were some visual artifacts when the spin gizmo had a rotation
greater than 360 degrees.
Avoids this by drawing the arc over the span of one rotation only
and adjusting the background color based on the rotation count.
Diffstat (limited to 'source/blender/editors/gizmo_library')
-rw-r--r-- | source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c index 25a066ae36b..6dc81e26bf1 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/dial3d_gizmo.c @@ -235,7 +235,7 @@ static void dial_ghostarc_draw_incremental_angle(const float incremental_angle, } static void dial_ghostarc_draw(const float angle_ofs, - const float angle_delta, + float angle_delta, const float arc_inner_factor, const float color[4]) { @@ -244,21 +244,36 @@ static void dial_ghostarc_draw(const float angle_ofs, uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + /* Avoid artifacts by drawing the main arc over the span of one rotation only. */ + const float pi2 = (float)(M_PI * 2.0); + int rotation_count = (int)floorf(fabsf(angle_delta) / pi2); + angle_delta = fmod(angle_delta, pi2); + + /* Calculate the remaining angle that can be filled with the background color. */ + const float angle_background = angle_delta >= 0 ? (pi2 - angle_delta) : -(pi2 + angle_delta); + + float color_background[4] = {0}; if (arc_inner_factor != 0.0) { - float color_dark[4] = {0}; - color_dark[3] = color[3] / 2; - immUniformColor4fv(color_dark); - imm_draw_disk_partial_fill_2d(pos, - 0, - 0, - arc_inner_factor, - width_inner, - DIAL_RESOLUTION, - RAD2DEGF(angle_ofs), - RAD2DEGF(M_PI * 2)); + color_background[3] = color[3] / 2.0f; } - immUniformColor4fv(color); + if (rotation_count != 0) { + /* Calculate the background color to visualize the rotation count. */ + copy_v4_v4(color_background, color); + color_background[3] = color[3] * rotation_count; + } + + immUniformColor4fv(color_background); + imm_draw_disk_partial_fill_2d(pos, + 0, + 0, + arc_inner_factor, + width_inner, + DIAL_RESOLUTION, + RAD2DEGF(angle_ofs + angle_delta), + RAD2DEGF(angle_background)); + + immUniformColor4f(UNPACK3(color), color[3] * (rotation_count + 1)); imm_draw_disk_partial_fill_2d(pos, 0, 0, |