[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18155] branches/blender2.5/blender/source /blender/editors/transform: 2.5

Martin Poirier theeth at yahoo.com
Mon Dec 29 21:37:54 CET 2008


Revision: 18155
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18155
Author:   theeth
Date:     2008-12-29 21:37:54 +0100 (Mon, 29 Dec 2008)

Log Message:
-----------
2.5

Transform house cleaning. Gattering input methods in specialized code. It's not missing much before it can be used standalone (for example, to use the mouse to specify remove doubles threshold interactively).

Note to Aligorith: Transformations using INPUT_NONE (most Time* stuff) would use a cleanup.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/transform/transform.c
    branches/blender2.5/blender/source/blender/editors/transform/transform.h
    branches/blender2.5/blender/source/blender/editors/transform/transform_generics.c

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/editors/transform/transform_input.c

Modified: branches/blender2.5/blender/source/blender/editors/transform/transform.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.c	2008-12-29 18:38:29 UTC (rev 18154)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.c	2008-12-29 20:37:54 UTC (rev 18155)
@@ -160,151 +160,6 @@
 #endif
 }
 
-
-  
-/* ************************** INPUT FROM MOUSE *************************** */
-
-float InputScaleRatio(TransInfo *t, short mval[2]) {
-	float ratio, dx, dy;
-	if(t->flag & T_SHIFT_MOD) {
-		/* calculate ratio for shiftkey pos, and for total, and blend these for precision */
-		dx = (float)(t->center2d[0] - t->shiftmval[0]);
-		dy = (float)(t->center2d[1] - t->shiftmval[1]);
-		ratio = (float)sqrt( dx*dx + dy*dy)/t->fac;
-		
-		dx= (float)(t->center2d[0] - mval[0]);
-		dy= (float)(t->center2d[1] - mval[1]);
-		ratio+= 0.1f*(float)(sqrt( dx*dx + dy*dy)/t->fac -ratio);
-	}
-	else {
-		dx = (float)(t->center2d[0] - mval[0]);
-		dy = (float)(t->center2d[1] - mval[1]);
-		ratio = (float)sqrt( dx*dx + dy*dy)/t->fac;
-	}
-	return ratio;
-}
-
-float InputHorizontalRatio(TransInfo *t, short mval[2]) {
-	float x, pad;
-
-	pad = t->ar->winx / 10;
-
-	if (t->flag & T_SHIFT_MOD) {
-		/* deal with Shift key by adding motion / 10 to motion before shift press */
-		x = t->shiftmval[0] + (float)(mval[0] - t->shiftmval[0]) / 10.0f;
-	}
-	else {
-		x = mval[0];
-	}
-	return (x - pad) / (t->ar->winx - 2 * pad);
-}
-
-float InputHorizontalAbsolute(TransInfo *t, short mval[2]) {
-	float vec[3];
-	if(t->flag & T_SHIFT_MOD) {
-		float dvec[3];
-		/* calculate the main translation and the precise one separate */
-		convertViewVec(t, dvec, (short)(mval[0] - t->shiftmval[0]), (short)(mval[1] - t->shiftmval[1]));
-		VecMulf(dvec, 0.1f);
-		convertViewVec(t, t->vec, (short)(t->shiftmval[0] - t->imval[0]), (short)(t->shiftmval[1] - t->imval[1]));
-		VecAddf(t->vec, t->vec, dvec);
-	}
-	else {
-		convertViewVec(t, t->vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
-	}
-	Projf(vec, t->vec, t->viewinv[0]);
-	return Inpf(t->viewinv[0], vec) * 2.0f;
-}
-
-float InputVerticalRatio(TransInfo *t, short mval[2]) {
-	float y, pad;
-
-	pad = t->ar->winy / 10;
-
-	if (t->flag & T_SHIFT_MOD) {
-		/* deal with Shift key by adding motion / 10 to motion before shift press */
-		y = t->shiftmval[1] + (float)(mval[1] - t->shiftmval[1]) / 10.0f;
-	}
-	else {
-		y = mval[0];
-	}
-	return (y - pad) / (t->ar->winy - 2 * pad);
-}
-
-float InputVerticalAbsolute(TransInfo *t, short mval[2]) {
-	float vec[3];
-	if(t->flag & T_SHIFT_MOD) {
-		float dvec[3];
-		/* calculate the main translation and the precise one separate */
-		convertViewVec(t, dvec, (short)(mval[0] - t->shiftmval[0]), (short)(mval[1] - t->shiftmval[1]));
-		VecMulf(dvec, 0.1f);
-		convertViewVec(t, t->vec, (short)(t->shiftmval[0] - t->imval[0]), (short)(t->shiftmval[1] - t->imval[1]));
-		VecAddf(t->vec, t->vec, dvec);
-	}
-	else {
-		convertViewVec(t, t->vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
-	}
-	Projf(vec, t->vec, t->viewinv[1]);
-	return Inpf(t->viewinv[1], vec) * 2.0f;
-}
-
-float InputDeltaAngle(TransInfo *t, short mval[2])
-{
-	double dx2 = mval[0] - t->center2d[0];
-	double dy2 = mval[1] - t->center2d[1];
-	double B = sqrt(dx2*dx2+dy2*dy2);
-
-	double dx1 = t->imval[0] - t->center2d[0];
-	double dy1 = t->imval[1] - t->center2d[1];
-	double A = sqrt(dx1*dx1+dy1*dy1);
-
-	double dx3 = mval[0] - t->imval[0];
-	double dy3 = mval[1] - t->imval[1];
-
-	/* 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));
-	/* (A*B?A*B:1.0f) this takes care of potential divide by zero errors */
-
-	float dphi;
-	
-	dphi = saacos((float)deler);
-	if( (dx1*dy2-dx2*dy1)>0.0 ) dphi= -dphi;
-
-	/* If the angle is zero, because of lack of precision close to the 1.0 value in acos
-	 * approximate the angle with the oposite side of the normalized triangle
-	 * This is a good approximation here since the smallest acos value seems to be around
-	 * 0.02 degree and lower values don't even have a 0.01% error compared to the approximation
-	 * */	
-	if (dphi == 0)
-	{
-		double dx, dy;
-		
-		dx2 /= A;
-		dy2 /= A;
-		
-		dx1 /= B;
-		dy1 /= B;
-		
-		dx = dx1 - dx2;
-		dy = dy1 - dy2;
-		
-		dphi = sqrt(dx*dx + dy*dy);
-		if( (dx1*dy2-dx2*dy1)>0.0 ) dphi= -dphi;
-	}
-	
-	if(t->flag & T_SHIFT_MOD) dphi = dphi/30.0f;
-	
-	/* if no delta angle, don't update initial position */
-	if (dphi != 0)
-	{
-		t->imval[0] = mval[0];
-		t->imval[1] = mval[1];
-	}
-	
-	return dphi;
-}
-
 /* ************************** SPACE DEPENDANT CODE **************************** */
 
 void setTransformViewMatrices(TransInfo *t)
@@ -410,12 +265,11 @@
 
 void convertVecToDisplayNum(float *vec, float *num)
 {
-	// TRANSFORM_FIX_ME
-	TransInfo *t = NULL; //BIF_GetTransInfo();
-
 	VECCOPY(num, vec);
 
 #if 0 // TRANSFORM_FIX_ME
+	TransInfo *t = BIF_GetTransInfo();
+
 	if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
 		float aspx, aspy;
 
@@ -436,12 +290,11 @@
 
 void convertDisplayNumToVec(float *num, float *vec)
 {
-	// TRANSFORM_FIX_ME
-	TransInfo *t = NULL; //BIF_GetTransInfo();
-
 	VECCOPY(vec, num);
 
 #if 0 // TRANSFORM_FIX_ME
+	TransInfo *t = BIF_GetTransInfo();
+
 	if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
 		float aspx, aspy;
 
@@ -702,12 +555,16 @@
 	
 	t->event = event;
 	
+	t->redraw |= handleMouseInput(t, &t->mouse, event);
+
 	if (event->type == MOUSEMOVE)
 	{
 		t->mval[0] = event->x - t->ar->winrct.xmin;
 		t->mval[1] = event->y - t->ar->winrct.ymin;
+		
+		applyMouseInput(t, &t->mouse, t->mval, t->values);
 	}
-
+	
 	if (event->val) {
 		switch (event->type){
 		/* enforce redraw of transform when modifiers are used */
@@ -715,14 +572,6 @@
 		case RIGHTCTRLKEY:
 			t->redraw = 1;
 			break;
-		case LEFTSHIFTKEY:
-		case RIGHTSHIFTKEY:
-			/* shift is modifier for higher resolution transform, works nice to store this mouse position */
-			t->shiftmval[0] = event->x - t->ar->winrct.xmin;
-			t->shiftmval[1] = event->y - t->ar->winrct.ymin;
-			t->flag |= T_SHIFT_MOD;
-			t->redraw = 1;
-			break;
 			
 		case SPACEKEY:
 			if ((t->spacetype==SPACE_VIEW3D) && event->alt) {
@@ -1024,11 +873,6 @@
 			if (t->options & CTX_TWEAK)
 				t->state = TRANS_CONFIRM;
 			break;
-		case LEFTSHIFTKEY:
-		case RIGHTSHIFTKEY:
-			/* shift is modifier for higher resolution transform */
-			t->flag &= ~T_SHIFT_MOD;
-			break;
 		}
 	}
 	
@@ -1114,6 +958,8 @@
 	
 	calculatePropRatio(t);
 	calculateCenter(t);
+	
+	initMouseInput(t, &t->mouse, t->center2d, t->imval);
 
 	switch (mode) {
 	case TFM_TRANSLATION:
@@ -1803,6 +1649,8 @@
 	t->transform = Warp;
 	t->handleEvent = handleEventWarp;
 	
+	initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
+
 	t->idx_max = 0;
 	t->num.idx_max = 0;
 	t->snap[0] = 0.0f;
@@ -1811,10 +1659,6 @@
 	
 	t->flag |= T_NO_CONSTRAINT;
 
-/* warp is done fully in view space */
-	calculateCenterCursor(t);
-	t->fac = (float)(t->center2d[0] - t->imval[0]);
-	
 	/* we need min/max in view space */
 	for(i = 0; i < t->total; i++) {
 		float center[3];
@@ -1885,7 +1729,7 @@
 	VecSubf(cursor, cursor, t->viewmat[3]);
 
 	/* amount of degrees for warp */
-	circumfac= 360.0f * InputHorizontalRatio(t, mval);
+	circumfac = 360.0f * t->values[0];
 	
 	if (t->customData) /* non-null value indicates reversed input */
 	{
@@ -1965,6 +1809,8 @@
 	t->transform = Shear;
 	t->handleEvent = handleEventShear;
 	
+	initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
+	
 	t->idx_max = 0;
 	t->num.idx_max = 0;
 	t->snap[0] = 0.0f;
@@ -1982,9 +1828,15 @@
 	{
 		// Use customData pointer to signal Shear direction
 		if	(t->customData == 0)
+		{
+			initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE);
 			t->customData = (void*)1;
+		}
 		else
+		{
+			initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_ABSOLUTE);
 			t->customData = 0;
+		}
 			
 		status = 1;
 	}
@@ -2005,11 +1857,7 @@
 	Mat3CpyMat4(persmat, t->viewmat);
 	Mat3Inv(persinv, persmat);
 
-	// Custom data signals shear direction
-	if (t->customData == 0)
-		value = 0.05f * InputHorizontalAbsolute(t, mval);
-	else
-		value = 0.05f * InputVerticalAbsolute(t, mval);
+	value = 0.05f * t->values[0];
 
 	snapGrid(t, &value);
 
@@ -2084,6 +1932,8 @@
 	t->mode = TFM_RESIZE;
 	t->transform = Resize;
 	
+	initMouseInputMode(t, &t->mouse, INPUT_SPRING_FLIP);
+	
 	t->flag |= T_NULL_ONE;
 	t->num.flag |= NUM_NULL_ONE;
 	t->num.flag |= NUM_AFFECT_ALL;
@@ -2097,15 +1947,6 @@
 	t->snap[0] = 0.0f;
 	t->snap[1] = 0.1f;
 	t->snap[2] = t->snap[1] * 0.1f;
-
-	t->fac = (float)sqrt(
-		(
-			((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
-		+
-			((float)(t->center2d[0] - t->imval[0]))*((float)(t->center2d[0] - t->imval[0]))
-		) );
-
-	if(t->fac==0.0f) t->fac= 1.0f;	// prevent Inf
 }
 
 static void headerResize(TransInfo *t, float vec[3], char *str) {
@@ -2295,16 +2136,13 @@
 	char str[200];
 
 	/* for manipulator, center handle, the scaling can't be done relative to center */
-	if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0) {
+	if( (t->flag & T_USES_MANIPULATOR) && t->con.mode==0)
+	{
 		ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
 	}
-	else {
-		ratio = InputScaleRatio(t, mval);
-		
-		/* flip scale, but not for manipulator center handle */
-		if	((t->center2d[0] - mval[0]) * (t->center2d[0] - t->imval[0]) + 
-			 (t->center2d[1] - mval[1]) * (t->center2d[1] - t->imval[1]) < 0)
-				ratio *= -1.0f;
+	else
+	{
+		ratio = t->values[0];
 	}
 	
 	size[0] = size[1] = size[2] = ratio;
@@ -2369,6 +2207,8 @@
 
 	t->mode = TFM_TOSPHERE;
 	t->transform = ToSphere;
+	
+	initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
 
 	t->idx_max = 0;
 	t->num.idx_max = 0;
@@ -2395,7 +2235,7 @@
 	char str[64];
 	TransData *td = t->data;
 
-	ratio = InputHorizontalRatio(t, mval);
+	ratio = t->values[0];
 
 	snapGrid(t, &ratio);
 
@@ -2457,6 +2297,8 @@
 	t->mode = TFM_ROTATION;
 	t->transform = Rotation;
 	
+	initMouseInputMode(t, &t->mouse, INPUT_ANGLE);
+	
 	t->ndof.axis = 16;
 	/* Scale down and flip input for rotation */
 	t->ndof.factor[0] = -0.2f;
@@ -2466,7 +2308,6 @@
 	t->snap[0] = 0.0f;
 	t->snap[1] = (float)((5.0/180)*M_PI);
 	t->snap[2] = t->snap[1] * 0.2f;
-	t->fac = 0;
 	
 	if (t->flag & T_2D_EDIT)
 		t->flag |= T_NO_CONSTRAINT;
@@ -2713,10 +2554,8 @@
 	VecMulf(axis, -1.0f);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list