[Bf-blender-cvs] [d1e55be96e8] blender2.8: Add gluPartialDisk replacement (imm_draw_filled_circle_partial)
Campbell Barton
noreply at git.blender.org
Mon Apr 3 07:26:52 CEST 2017
Commit: d1e55be96e89c262262d5e79fef70ef3fc12fd6c
Author: Campbell Barton
Date: Mon Apr 3 15:20:03 2017 +1000
Branches: blender2.8
https://developer.blender.org/rBd1e55be96e89c262262d5e79fef70ef3fc12fd6c
Add gluPartialDisk replacement (imm_draw_filled_circle_partial)
Needed for custom-manipulators branch but generally useful.
===================================================================
M source/blender/editors/include/BIF_glutil.h
M source/blender/editors/screen/glutil.c
===================================================================
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index ab3fd961773..53bfef7cad6 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -75,6 +75,25 @@ void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float radius, int
void imm_draw_filled_circle(unsigned pos, float x, float y, float radius, int nsegments);
/**
+ * Draw a filled arc with the given inner and outer radius.
+ * The circle is centered at \a x, \a y and drawn in the XY plane.
+ *
+ * \note Arguments are `gluPartialDisk` compatible.
+ *
+ * \param pos: The vertex attribute number for position.
+ * \param x: Horizontal center.
+ * \param y: Vertical center.
+ * \param radius_inner: The inner circle's radius.
+ * \param radius_outer: The outer circle's radius (can be zero).
+ * \param nsegments: The number of segments to use in drawing (more = smoother).
+ * \param start: Specifies the starting angle, in degrees, of the disk portion.
+ * \param sweep: Specifies the sweep angle, in degrees, of the disk portion.
+ */
+void imm_draw_filled_circle_partial(
+ unsigned pos, float x, float y,
+ float radius_inner, float radius_outer, int nsegments, float start, float sweep);
+
+/**
* Draw a lined box.
*
* \param pos The vertex attribute number for position.
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index c66268beb9f..a613537100b 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -103,6 +103,38 @@ void imm_draw_filled_circle(unsigned pos, float x, float y, float rad, int nsegm
imm_draw_circle(PRIM_TRIANGLE_FAN, pos, x, y, rad, nsegments);
}
+/**
+ * \note We could have `imm_draw_lined_circle_partial` but currently there is no need.
+ */
+static void imm_draw_circle_partial(
+ PrimitiveType prim_type, unsigned pos, float x, float y,
+ float rad_inner, float rad_outer, int nsegments, float start, float sweep)
+{
+ /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
+ const float angle_start = -(DEG2RADF(start)) + (M_PI / 2);
+ const float angle_end = -(DEG2RADF(sweep) - angle_start);
+ nsegments += 1;
+ immBegin(prim_type, nsegments * 2);
+ 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_inner * angle_cos, y + rad_inner * angle_sin);
+ immVertex2f(pos, x + rad_outer * angle_cos, y + rad_outer * angle_sin);
+ }
+ immEnd();
+}
+
+/**
+ * Replacement for gluPartialDisk, (without 'loops' argument).
+ */
+void imm_draw_filled_circle_partial(
+ unsigned pos, float x, float y,
+ float rad_inner, float rad_outer, int nsegments, float start, float sweep)
+{
+ imm_draw_circle_partial(PRIM_TRIANGLE_STRIP, pos, x, y, rad_inner, rad_outer, nsegments, start, sweep);
+}
+
void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float rad, int nsegments)
{
immBegin(PRIM_LINE_LOOP, nsegments);
More information about the Bf-blender-cvs
mailing list