[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27344] trunk/blender/source/blender/ editors/transform: [#21433] Angular rotation snap issue, final value set is not snapped - SVN 27250 and 2.50A1

Martin Poirier theeth at yahoo.com
Tue Mar 9 02:19:33 CET 2010


Revision: 27344
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27344
Author:   theeth
Date:     2010-03-09 02:19:32 +0100 (Tue, 09 Mar 2010)

Log Message:
-----------
[#21433] Angular rotation snap issue, final value set is not snapped - SVN 27250 and 2.50A1

Proper fix for this. Moving special mouse input stuff to custom callbacks (this also makes the per transform main functions a bit cleaner).

It also fixes the operator property (value) for shear and warp.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/transform/transform.c
    trunk/blender/source/blender/editors/transform/transform.h
    trunk/blender/source/blender/editors/transform/transform_input.c

Modified: trunk/blender/source/blender/editors/transform/transform.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform.c	2010-03-09 00:35:05 UTC (rev 27343)
+++ trunk/blender/source/blender/editors/transform/transform.c	2010-03-09 01:19:32 UTC (rev 27344)
@@ -2064,6 +2064,16 @@
 
 /* ************************** WARP *************************** */
 
+void postInputWarp(TransInfo *t, float values[3])
+{
+	mul_v3_fl(values, (float)(M_PI * 2));
+
+	if (t->customData) /* non-null value indicates reversed input */
+	{
+		negate_v3(values);
+	}
+}
+
 void initWarp(TransInfo *t)
 {
 	float max[3], min[3];
@@ -2073,13 +2083,14 @@
 	t->transform = Warp;
 	t->handleEvent = handleEventWarp;
 	
+	setInputPostFct(&t->mouse, postInputWarp);
 	initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
 	
 	t->idx_max = 0;
 	t->num.idx_max = 0;
 	t->snap[0] = 0.0f;
-	t->snap[1] = 5.0f;
-	t->snap[2] = 1.0f;
+	t->snap[1] = 5.0f / 180 * M_PI;
+	t->snap[2] = 1.0f / 180 * M_PI;
 	
 	t->num.increment = 1.0f;
 
@@ -2154,14 +2165,9 @@
 	mul_m4_v3(t->viewmat, cursor);
 	sub_v3_v3v3(cursor, cursor, t->viewmat[3]);
 	
-	/* amount of degrees for warp */
-	circumfac = 360.0f * t->values[0];
+	/* amount of radians for warp */
+	circumfac = t->values[0];
 	
-	if (t->customData) /* non-null value indicates reversed input */
-	{
-		circumfac *= -1;
-	}
-	
 	snapGrid(t, &circumfac);
 	applyNumInput(&t->num, &circumfac);
 	
@@ -2172,13 +2178,17 @@
 		outputNumInput(&(t->num), c);
 		
 		sprintf(str, "Warp: %s", c);
+
+		circumfac = circumfac / 180 * M_PI;
 	}
 	else {
 		/* default header print */
-		sprintf(str, "Warp: %.3f", circumfac);
+		sprintf(str, "Warp: %.3f", circumfac * 180 / M_PI);
 	}
 	
-	circumfac*= (float)(-M_PI/360.0);
+	t->values[0] = circumfac;
+
+	circumfac /= 2; /* only need 180 on each side to make 360 */
 	
 	for(i = 0; i < t->total; i++, td++) {
 		float loc[3];
@@ -2225,12 +2235,18 @@
 
 /* ************************** SHEAR *************************** */
 
+void postInputShear(TransInfo *t, float values[3])
+{
+	mul_v3_fl(values, 0.05f);
+}
+
 void initShear(TransInfo *t)
 {
 	t->mode = TFM_SHEAR;
 	t->transform = Shear;
 	t->handleEvent = handleEventShear;
 	
+	setInputPostFct(&t->mouse, postInputShear);
 	initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
 	
 	t->idx_max = 0;
@@ -2281,7 +2297,7 @@
 	copy_m3_m4(persmat, t->viewmat);
 	invert_m3_m3(persinv, persmat);
 	
-	value = 0.05f * t->values[0];
+	value = t->values[0];
 	
 	snapGrid(t, &value);
 	
@@ -2652,6 +2668,8 @@
 	else if (ratio > 1)
 		ratio = 1.0f;
 	
+	t->values[0] = ratio;
+
 	/* header print for NumInput */
 	if (hasNumInput(&t->num)) {
 		char c[20];
@@ -2696,11 +2714,19 @@
 /* ************************** ROTATION *************************** */
 
 
+void postInputRotation(TransInfo *t, float values[3])
+{
+	if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
+		t->con.applyRot(t, NULL, t->axis, values);
+	}
+}
+
 void initRotation(TransInfo *t)
 {
 	t->mode = TFM_ROTATION;
 	t->transform = Rotation;
 	
+	setInputPostFct(&t->mouse, postInputRotation);
 	initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
 	
 	t->ndof.axis = 16;
@@ -2973,7 +2999,7 @@
 	snapGrid(t, &final);
 	
 	if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
-		t->con.applyRot(t, NULL, t->axis, &final);
+		t->con.applyRot(t, NULL, t->axis, NULL);
 	} else {
 		/* reset axis if constraint is not set */
 		negate_v3_v3(t->axis, t->viewinv[2]);
@@ -3004,15 +3030,10 @@
 		sprintf(str, "Rot: %.2f%s %s", 180.0*final/M_PI, t->con.text, t->proptext);
 	}
 	
-	// fixes [#21433] but breaks, typical local axis rotation - campbell
-	// t->values[0] = final;
+	t->values[0] = final;
 
 	vec_rot_to_mat3( mat, t->axis, final);
 	
-	// TRANSFORM_FIX_ME
-//	t->values[0] = final;		// used in manipulator
-//	copy_m3_m3(t->mat, mat);	// used in manipulator
-	
 	applyRotation(t, final, t->axis);
 	
 	recalcData(t);
@@ -5521,6 +5542,7 @@
 	UI_view2d_region_to_view(v2d, t->imval[0], t->imval[0], &sval[0], &sval[1]);
 
 	/* t->values[0] stores cval[0], which is the current mouse-pointer location (in frames) */
+	// XXX Need to be able to repeat this
 	t->values[0] = cval[0];
 
 	/* handle numeric-input stuff */

Modified: trunk/blender/source/blender/editors/transform/transform.h
===================================================================
--- trunk/blender/source/blender/editors/transform/transform.h	2010-03-09 00:35:05 UTC (rev 27343)
+++ trunk/blender/source/blender/editors/transform/transform.h	2010-03-09 01:19:32 UTC (rev 27344)
@@ -234,6 +234,7 @@
 
 typedef struct MouseInput {
 	void	(*apply)(struct TransInfo *, struct MouseInput *, short [2], float [3]);
+	void	(*post)(struct TransInfo *, float [3]);
 
     short   imval[2];       	/* initial mouse position                */
 	char	precision;
@@ -632,6 +633,7 @@
 void applyMouseInput(struct TransInfo *t, struct MouseInput *mi, short mval[2], float output[3]);
 
 void setCustomPoints(TransInfo *t, MouseInput *mi, short start[2], short end[2]);
+void setInputPostFct(MouseInput *mi, void	(*post)(struct TransInfo *, float [3]));
 
 /*********************** Generics ********************************/
 

Modified: trunk/blender/source/blender/editors/transform/transform_input.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_input.c	2010-03-09 00:35:05 UTC (rev 27343)
+++ trunk/blender/source/blender/editors/transform/transform_input.c	2010-03-09 01:19:32 UTC (rev 27344)
@@ -225,6 +225,8 @@
 	double dx3 = mval[0] - mi->imval[0];
 	double dy3 = mval[1] - mi->imval[1];
 
+	double *angle = mi->data;
+
 	/* use doubles here, to make sure a "1.0" (no rotation) doesnt become 9.999999e-01, which gives 0.02 for acos */
 	double deler = ((dx1*dx1+dy1*dy1)+(dx2*dx2+dy2*dy2)-(dx3*dx3+dy3*dy3))
 		/ (2.0 * (A*B?A*B:1.0));
@@ -266,7 +268,11 @@
 		mi->imval[1] = mval[1];
 	}
 
-	output[0] += dphi;
+	*angle += dphi;
+
+	printf("angle %.3f\n", *angle);
+
+	output[0] = *angle;
 }
 
 void initMouseInput(TransInfo *t, MouseInput *mi, int center[2], short mval[2])
@@ -279,6 +285,8 @@
 
 	mi->imval[0] = mval[0];
 	mi->imval[1] = mval[1];
+
+	mi->post = NULL;
 }
 
 static void calcSpringFactor(MouseInput *mi)
@@ -314,6 +322,7 @@
 		t->helpline = HLP_SPRING;
 		break;
 	case INPUT_ANGLE:
+		mi->data = MEM_callocN(sizeof(double), "angle accumulator");
 		mi->apply = InputAngle;
 		t->helpline = HLP_ANGLE;
 		break;
@@ -354,12 +363,22 @@
 	applyMouseInput(t, mi, mi->imval, t->values);
 }
 
+void setInputPostFct(MouseInput *mi, void	(*post)(struct TransInfo *, float [3]))
+{
+	mi->post = post;
+}
+
 void applyMouseInput(TransInfo *t, MouseInput *mi, short mval[2], float output[3])
 {
 	if (mi->apply != NULL)
 	{
 		mi->apply(t, mi, mval, output);
 	}
+
+	if (mi->post)
+	{
+		mi->post(t, output);
+	}
 }
 
 int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event)





More information about the Bf-blender-cvs mailing list