diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-24 09:22:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-24 09:22:22 +0300 |
commit | 9a77f33badce2dfc24350ecc800c1c4beeb79acc (patch) | |
tree | e89db99995424571308fed09073c7d251ab2dd00 /source/blender/gpu | |
parent | 5fff3d2237a07b1495c95c74ed3e5928c7438a6b (diff) |
GPU: utility function to draw a partial circle
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_immediate_util.h | 5 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_immediate_util.c | 28 |
2 files changed, 30 insertions, 3 deletions
diff --git a/source/blender/gpu/GPU_immediate_util.h b/source/blender/gpu/GPU_immediate_util.h index 58555e287b0..9f1d9646246 100644 --- a/source/blender/gpu/GPU_immediate_util.h +++ b/source/blender/gpu/GPU_immediate_util.h @@ -48,6 +48,11 @@ void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float radiu void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments); void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments); +/* same as 'imm_draw_disk_partial_fill_2d', except it draws a wire arc. */ +void imm_draw_circle_partial_wire_2d( + uint pos, float x, float y, + float radius, int nsegments, float start, float sweep); + void imm_draw_disk_partial_fill_2d( uint pos, float x, float y, float radius_inner, float radius_outer, int nsegments, float start, float sweep); diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c index fdba7800016..93695e0fbab 100644 --- a/source/blender/gpu/intern/gpu_immediate_util.c +++ b/source/blender/gpu/intern/gpu_immediate_util.c @@ -201,9 +201,31 @@ void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float rad_x imm_draw_circle(GPU_PRIM_TRI_FAN, shdr_pos, x, y, rad_x, rad_y, nsegments); } -/** - * \note We could have `imm_draw_lined_disk_partial` but currently there is no need. - */ +static void imm_draw_circle_partial( + GPUPrimType prim_type, uint pos, float x, float y, + float rad, int nsegments, float start, float sweep) +{ + /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */ + const float angle_start = -(DEG2RADF(start)) + (float)(M_PI / 2); + const float angle_end = -(DEG2RADF(sweep) - angle_start); + nsegments += 1; + immBegin(prim_type, nsegments); + for (int i = 0; i < nsegments; ++i) { + const float angle = interpf(angle_start, angle_end, ((float)i / (float)(nsegments - 1))); + const float angle_sin = sinf(angle); + const float angle_cos = cosf(angle); + immVertex2f(pos, x + rad * angle_cos, y + rad * angle_sin); + } + immEnd(); +} + +void imm_draw_circle_partial_wire_2d( + uint pos, float x, float y, + float rad, int nsegments, float start, float sweep) +{ + imm_draw_circle_partial(GPU_PRIM_LINE_STRIP, pos, x, y, rad, nsegments, start, sweep); +} + static void imm_draw_disk_partial( GPUPrimType prim_type, uint pos, float x, float y, float rad_inner, float rad_outer, int nsegments, float start, float sweep) |