[Bf-blender-cvs] [87fd594] transform-manipulators: Rotation value indicator for rotation manipulators

Julian Eisel noreply at git.blender.org
Tue Nov 8 20:37:58 CET 2016


Commit: 87fd59406b41bd262fba7a1b6dc9618f3674079e
Author: Julian Eisel
Date:   Tue Nov 8 20:03:44 2016 +0100
Branches: transform-manipulators
https://developer.blender.org/rB87fd59406b41bd262fba7a1b6dc9618f3674079e

Rotation value indicator for rotation manipulators

Adds the arc thingy that displays the current delta rotation value while rotating.
It is a different implementation than the one of the custom-manipulators branch which was based on mouse coordinates and thus didn't work correctly with snapping and precision (shift) tweaking. This new implementation is based on object matrix and fixes these issues.

Commit only adds support for rotating objects, not yet for other elements (polygons, bones, GPencil points, etc)
Also some minor cleanup of course ;)

===================================================================

M	source/blender/blenkernel/BKE_object.h
M	source/blender/blenkernel/intern/object.c
M	source/blender/editors/include/BIF_glutil.h
M	source/blender/editors/screen/glutil.c
M	source/blender/editors/space_view3d/view3d_transform_manipulators.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/manipulators/WM_manipulator_api.h
M	source/blender/windowmanager/manipulators/WM_manipulator_library.h
M	source/blender/windowmanager/manipulators/intern/manipulator_library/dial_manipulator.c
M	source/blender/windowmanager/manipulators/intern/wm_manipulator.c
M	source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h

===================================================================

diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 29e8433..211aa89 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -112,7 +112,7 @@ bool BKE_object_obdata_is_libdata(struct Object *ob);
 void BKE_object_obdata_size_init(struct Object *ob, const float scale);
 
 void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]);
-void BKE_object_rot_to_mat3(struct Object *ob, float mat[3][3], bool use_drot);
+void BKE_object_rot_to_mat3(const struct Object *ob, float mat[3][3], bool use_drot);
 void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat);
 void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
 void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index f7257b2..48392a6 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1291,7 +1291,7 @@ void BKE_object_scale_to_mat3(Object *ob, float mat[3][3])
 	size_to_mat3(mat, vec);
 }
 
-void BKE_object_rot_to_mat3(Object *ob, float mat[3][3], bool use_drot)
+void BKE_object_rot_to_mat3(const Object *ob, float r_mat[3][3], bool use_drot)
 {
 	float rmat[3][3], dmat[3][3];
 	
@@ -1323,9 +1323,9 @@ void BKE_object_rot_to_mat3(Object *ob, float mat[3][3], bool use_drot)
 	
 	/* combine these rotations */
 	if (use_drot)
-		mul_m3_m3m3(mat, dmat, rmat);
+		mul_m3_m3m3(r_mat, dmat, rmat);
 	else
-		copy_m3_m3(mat, rmat);
+		copy_m3_m3(r_mat, rmat);
 }
 
 void BKE_object_mat3_to_rot(Object *ob, float mat[3][3], bool use_compat)
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index 7045340..d3907cf 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -94,6 +94,20 @@ void imm_draw_lined_circle(unsigned pos, float x, float y, float radius, int nse
 
 /* use this version when VertexFormat has a vec3 position */
 void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float radius, int nsegments);
+void imm_draw_filled_circle_3D(unsigned pos, float x, float y, float rad, int nsegments);
+
+/**
+ * Draw a filled arc with the given \a radius,
+ * starting at angle \a start and arcing through
+ * \a angle. The arc is centered at the origin
+ * and drawn in the XY plane.
+ *
+ * \param start The initial angle (in radians).
+ * \param angle The length of the arc (in radians).
+ * \param radius The arc radius.
+ * \param nsegments The number of segments to use in drawing the arc.
+ */
+void imm_draw_filled_arc_3D(unsigned int pos, float start, float angle, float radius, int nsegments);
 
 /**
  * Draw a filled circle with the given \a radius.
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index b64152b..0c7839c 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -203,9 +203,9 @@ void imm_draw_filled_circle(unsigned pos, float x, float y, float rad, int nsegm
 	imm_draw_circle(GL_TRIANGLE_FAN, pos, x, y, rad, nsegments);
 }
 
-void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float rad, int nsegments)
+static void imm_draw_circle_3D(GLenum prim_type, unsigned pos, float x, float y, float rad, int nsegments)
 {
-	immBegin(GL_LINE_LOOP, nsegments);
+	immBegin(prim_type, nsegments);
 	for (int i = 0; i < nsegments; ++i) {
 		float angle = 2 * M_PI * ((float)i / (float)nsegments);
 		immVertex3f(pos, x + rad * cosf(angle),
@@ -214,6 +214,35 @@ void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float rad, int nse
 	immEnd();
 }
 
+void imm_draw_lined_circle_3D(unsigned pos, float x, float y, float rad, int nsegments)
+{
+	imm_draw_circle_3D(GL_LINE_LOOP, pos, x, y, rad, nsegments);
+}
+
+void imm_draw_filled_circle_3D(unsigned pos, float x, float y, float rad, int nsegments)
+{
+	imm_draw_circle_3D(GL_TRIANGLE_FAN, pos, x, y, rad, nsegments);
+}
+
+static void imm_draw_arc_3D(GLenum prim_type, unsigned int pos, float start, float angle, float radius, int nsegments)
+{
+	immBegin(prim_type, nsegments + 1);
+
+	immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+	for (int i = 0; i < nsegments; i++) {
+		float t = (float) i / (nsegments - 1);
+		float cur = start + t * angle;
+
+		immVertex3f(pos, cosf(cur) * radius, sinf(cur) * radius, 0.0f);
+	}
+	immEnd();
+}
+
+void imm_draw_filled_arc_3D(unsigned int pos, float start, float angle, float radius, int nsegments)
+{
+	imm_draw_arc_3D(GL_TRIANGLE_FAN, pos, start, angle, radius, nsegments);
+}
+
 void imm_draw_line_box(unsigned pos, float x1, float y1, float x2, float y2)
 {
 	immBegin(GL_LINE_LOOP, 4);
diff --git a/source/blender/editors/space_view3d/view3d_transform_manipulators.c b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
index 34107b7..82e4ac6 100644
--- a/source/blender/editors/space_view3d/view3d_transform_manipulators.c
+++ b/source/blender/editors/space_view3d/view3d_transform_manipulators.c
@@ -26,6 +26,7 @@
 
 #include "BKE_action.h"
 #include "BKE_context.h"
+#include "BKE_object.h"
 
 #include "DNA_armature_types.h"
 #include "DNA_gpencil_types.h"
@@ -58,7 +59,7 @@
 /**
  * Transform axis type that can be used as index.
  */
-enum TransformAxisType {
+typedef enum eTransformAxisType {
 	/* single axes */
 	TRANSFORM_AXIS_X     = 0,
 	TRANSFORM_AXIS_Y     = 1,
@@ -69,35 +70,38 @@ enum TransformAxisType {
 	TRANSFORM_AXIS_XY    = 4,
 	TRANSFORM_AXIS_YZ    = 5,
 	TRANSFORM_AXIS_ZX    = 6,
-};
+} eTransformAxisType;
 
 /**
  * Struct for carrying data of transform manipulators as wmManipulatorGroup.customdata.
  */
 typedef struct TransformManipulatorsInfo {
-	struct TranformAxisManipulator *axes; /* Array of axes */
+	struct TransformAxisManipulator *axes; /* Array of axes */
 
 	float mat[4][4]; /* Cached loc/rot matrix */
+	float init_rot[3][3]; /* rotation matrix since last transform (to calculate rotation delta while dragging) */
 } TransformManipulatorsInfo;
 
 /* Callback types */
-typedef wmManipulator *TransformManipulatorInitFunc(struct TranformAxisManipulator *, wmManipulatorGroup *mgroup);
+typedef wmManipulator *TransformManipulatorInitFunc(struct TransformAxisManipulator *, wmManipulatorGroup *mgroup);
 typedef void TransformManipulatorUpdateFunc(
-        const bContext *, const TransformManipulatorsInfo *, const struct TranformAxisManipulator *);
+        const bContext *, const TransformManipulatorsInfo *, const struct TransformAxisManipulator *);
+typedef int TransformManipulatorHanderFunc(bContext *, const wmEvent *, wmManipulator *, const int);
 
 /**
  * Struct that allows us to store info for each transform axis manipulator in a rather generic way.
  */
-typedef struct TranformAxisManipulator {
+typedef struct TransformAxisManipulator {
 	/* -- initialized using static array -- */
 
-	enum TransformAxisType axis_type;
+	eTransformAxisType type;
 	int transform_type; /* View3d->twtype */
 
 	/* per-manipulator callbacks for initializing/updating data */
 	TransformManipulatorInitFunc   (*init);
 	TransformManipulatorUpdateFunc (*refresh);
 	TransformManipulatorUpdateFunc (*draw_prepare);
+	TransformManipulatorHanderFunc (*handler);
 
 	const char *name;
 	int constraint[3]; /* {x, y, z} */
@@ -112,20 +116,26 @@ typedef struct TranformAxisManipulator {
 
 	/* The manipulator that represents this axis */
 	wmManipulator *manipulator;
-} TranformAxisManipulator;
+} TransformAxisManipulator;
 
 
 /* -------------------------------------------------------------------- */
 /* Manipulator init/update callbacks */
 
-static wmManipulator *manipulator_arrow_init(TranformAxisManipulator *axis, wmManipulatorGroup *mgroup)
+static wmManipulator *manipulator_arrow_init(TransformAxisManipulator *axis, wmManipulatorGroup *mgroup)
 {
 	return WM_arrow_manipulator_new(mgroup, axis->name, axis->manipulator_style);
 }
 
-static wmManipulator *manipulator_dial_init(TranformAxisManipulator *axis, wmManipulatorGroup *mgroup)
+static wmManipulator *manipulator_dial_init(TransformAxisManipulator *axis, wmManipulatorGroup *mgroup)
 {
-	return WM_dial_manipulator_new(mgroup, axis->name, axis->manipulator_style);
+	wmManipulator *manipulator = WM_dial_manipulator_new(mgroup, axis->name, axis->manipulator_style);
+
+	if (axis->transform_type == V3D_MANIP_ROTATE) { /* could also be separate callback */
+		WM_manipulator_set_flag(manipulator, WM_MANIPULATOR_DRAW_ACTIVE, true);
+	}
+
+	return manipulator;
 }
 
 /**
@@ -133,7 +143,7 @@ static wmManipulator *manipulator_dial_init(TranformAxisManipulator *axis, wmMan
  * Needed to adjust line drawing for combined manipulator axis types.
  */
 static void manipulator_line_range(
-        const TranformAxisManipulator *axis, const View3D *v3d,
+        const TransformAxisManipulator *axis, const View3D *v3d,
         float *r_start, float *r_len)
 {
 	const float ofs = 0.2f;
@@ -160,7 +170,7 @@ static void manipulator_line_range(
 	*r_len -= *r_start;
 }
 
-static void manipulator_arrow_update_line_range(const View3D *v3d, const TranformAxisManipulator *axis)
+static void manipulator_arrow_update_line_range(const View3D *v3d, const TransformAxisManipulator *axis)
 {
 	float start[3] = {0.0f};
 	float len;
@@ -171,110 +181,238 @@ static void manipulator_arrow_update_line_range(const View3D *v3d, const Tranfor
 }
 
 static void manipulator_arrow_refresh(
-        const bContext *C, const TransformManipulatorsInfo *UNUSED(info), const TranformAxisManipulator *axis)
+        const bContext *C, const TransformManipulatorsInfo *UNUSED(info), const TransformAxisManipulator *axis)
 {
 	manipulator_arrow_update_line_range(CTX_wm_view3d(C), axis);
 }
 
 static void manipulator_dial_refresh(
-        const bContext *UNUSED(C), const TransformManipulatorsInfo *info, const TranformAxisManipulator *axis)
+        const bContext *UNUSED(C), const TransformManipulatorsInfo *info, const TransformAxisManipulator *axis)
 {
-	WM_dial_manipulator_set_up_vector(axis->manipulator, info->mat[axis->axis_type]);
+	WM_dial_manipulator_set_up_vector(axis->manipulator, info->mat[axis->type]);
 }
 
 static void manipulator_arro

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list