| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2009-06-23 00:09:26 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): none yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <math.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_screen_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "transform.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 12:23:56 +00:00
										 |  |  | #include "MEM_guardedalloc.h" 
 | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | /* ************************** INPUT FROM MOUSE *************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputVector(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float vec[3], dvec[3]; | 
					
						
							|  |  |  | 	if(mi->precision) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* calculate the main translation and the precise one separate */ | 
					
						
							|  |  |  | 		convertViewVec(t, dvec, (short)(mval[0] - mi->precision_mval[0]), (short)(mval[1] - mi->precision_mval[1])); | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 		mul_v3_fl(dvec, 0.1f); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		convertViewVec(t, vec, (short)(mi->precision_mval[0] - t->imval[0]), (short)(mi->precision_mval[1] - t->imval[1])); | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 		add_v3_v3v3(output, vec, dvec); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		convertViewVec(t, output, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1])); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputSpring(TransInfo *UNUSED(t), MouseInput *mi, short mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float ratio, precise_ratio, dx, dy; | 
					
						
							|  |  |  | 	if(mi->precision) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* calculate ratio for shiftkey pos, and for total, and blend these for precision */ | 
					
						
							|  |  |  | 		dx = (float)(mi->center[0] - mi->precision_mval[0]); | 
					
						
							|  |  |  | 		dy = (float)(mi->center[1] - mi->precision_mval[1]); | 
					
						
							|  |  |  | 		ratio = (float)sqrt( dx*dx + dy*dy); | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		dx= (float)(mi->center[0] - mval[0]); | 
					
						
							|  |  |  | 		dy= (float)(mi->center[1] - mval[1]); | 
					
						
							|  |  |  | 		precise_ratio = (float)sqrt( dx*dx + dy*dy); | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		dx = (float)(mi->center[0] - mval[0]); | 
					
						
							|  |  |  | 		dy = (float)(mi->center[1] - mval[1]); | 
					
						
							|  |  |  | 		ratio = (float)sqrt( dx*dx + dy*dy) / mi->factor; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	output[0] = ratio; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputSpringFlip(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	InputSpring(t, mi, mval, output); | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	/* flip scale */ | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 	if	((mi->center[0] - mval[0]) * (mi->center[0] - mi->imval[0]) + | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		 (mi->center[1] - mval[1]) * (mi->center[1] - mi->imval[1]) < 0) | 
					
						
							|  |  |  | 	 { | 
					
						
							|  |  |  | 		output[0] *= -1.0f; | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputTrackBall(TransInfo *UNUSED(t), MouseInput *mi, short mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	if(mi->precision) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		output[0] = ( mi->imval[1] - mi->precision_mval[1] ) + ( mi->precision_mval[1] - mval[1] ) * 0.1f; | 
					
						
							|  |  |  | 		output[1] = ( mi->precision_mval[0] - mi->imval[0] ) + ( mval[0] - mi->precision_mval[0] ) * 0.1f; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		output[0] = (float)( mi->imval[1] - mval[1] ); | 
					
						
							|  |  |  | 		output[1] = (float)( mval[0] - mi->imval[0] ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	output[0] *= mi->factor; | 
					
						
							|  |  |  | 	output[1] *= mi->factor; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputHorizontalRatio(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) { | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	float x, pad; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pad = t->ar->winx / 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mi->precision) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* deal with Shift key by adding motion / 10 to motion before shift press */ | 
					
						
							|  |  |  | 		x = mi->precision_mval[0] + (float)(mval[0] - mi->precision_mval[0]) / 10.0f; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		x = mval[0]; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	output[0] = (x - pad) / (t->ar->winx - 2 * pad); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputHorizontalAbsolute(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) { | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	InputVector(t, mi, mval, vec); | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	project_v3_v3v3(vec, vec, t->viewinv[0]); | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	output[0] = dot_v3v3(t->viewinv[0], vec) * 2.0f; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputVerticalRatio(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) { | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	float y, pad; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pad = t->ar->winy / 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mi->precision) { | 
					
						
							|  |  |  | 		/* deal with Shift key by adding motion / 10 to motion before shift press */ | 
					
						
							|  |  |  | 		y = mi->precision_mval[1] + (float)(mval[1] - mi->precision_mval[1]) / 10.0f; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		y = mval[0]; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	output[0] = (y - pad) / (t->ar->winy - 2 * pad); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputVerticalAbsolute(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) { | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	InputVector(t, mi, mval, vec); | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	project_v3_v3v3(vec, vec, t->viewinv[1]); | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-10 20:43:45 +00:00
										 |  |  | 	output[0] = dot_v3v3(t->viewinv[1], vec) * 2.0f; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-16 14:32:17 +00:00
										 |  |  | void setCustomPoints(TransInfo *UNUSED(t), MouseInput *mi, short start[2], short end[2]) | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	short *data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mi->data == NULL) { | 
					
						
							|  |  |  | 		mi->data = MEM_callocN(sizeof(short) * 4, "custom points"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	data = mi->data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 	data[0] = start[0]; | 
					
						
							|  |  |  | 	data[1] = start[1]; | 
					
						
							|  |  |  | 	data[2] = end[0]; | 
					
						
							|  |  |  | 	data[3] = end[1]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputCustomRatio(TransInfo *UNUSED(t), MouseInput *mi, short mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float length; | 
					
						
							|  |  |  | 	float distance; | 
					
						
							|  |  |  | 	short *data = mi->data; | 
					
						
							|  |  |  | 	short dx, dy; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	if (data) { | 
					
						
							|  |  |  | 		dx = data[2] - data[0]; | 
					
						
							|  |  |  | 		dy = data[3] - data[1]; | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 		length = (float)sqrtf(dx*dx + dy*dy); | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 		if (mi->precision) { | 
					
						
							|  |  |  | 			/* deal with Shift key by adding motion / 10 to motion before shift press */ | 
					
						
							|  |  |  | 			short mdx, mdy; | 
					
						
							|  |  |  | 			mdx = (mi->precision_mval[0] + (float)(mval[0] - mi->precision_mval[0]) / 10.0f) - data[2]; | 
					
						
							|  |  |  | 			mdy = (mi->precision_mval[1] + (float)(mval[1] - mi->precision_mval[1]) / 10.0f) - data[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-21 15:22:11 +00:00
										 |  |  | 			distance = (length != 0.0f)? (mdx*dx + mdy*dy) / length: 0.0f; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			short mdx, mdy; | 
					
						
							|  |  |  | 			mdx = mval[0] - data[2]; | 
					
						
							|  |  |  | 			mdy = mval[1] - data[3]; | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-21 15:22:11 +00:00
										 |  |  | 			distance = (length != 0.0f)? (mdx*dx + mdy*dy) / length: 0.0f; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-21 15:22:11 +00:00
										 |  |  | 		output[0] = (length != 0.0f)? distance / length: 0.0f; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-14 17:55:27 +00:00
										 |  |  | static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, short mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	double dx2 = mval[0] - mi->center[0]; | 
					
						
							|  |  |  | 	double dy2 = mval[1] - mi->center[1]; | 
					
						
							|  |  |  | 	double B = sqrt(dx2*dx2+dy2*dy2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	double dx1 = mi->imval[0] - mi->center[0]; | 
					
						
							|  |  |  | 	double dy1 = mi->imval[1] - mi->center[1]; | 
					
						
							|  |  |  | 	double A = sqrt(dx1*dx1+dy1*dy1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	double dx3 = mval[0] - mi->imval[0]; | 
					
						
							|  |  |  | 	double dy3 = mval[1] - mi->imval[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 	double *angle = mi->data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	/* 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; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	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
 | 
					
						
							| 
									
										
										
										
											2010-07-26 19:00:15 +00:00
										 |  |  | 	 * approximate the angle with the opposite side of the normalized triangle | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	 * 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 | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 	 * */ | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	if (dphi == 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		double dx, dy; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		dx2 /= A; | 
					
						
							|  |  |  | 		dy2 /= A; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		dx1 /= B; | 
					
						
							|  |  |  | 		dy1 /= B; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		dx = dx1 - dx2; | 
					
						
							|  |  |  | 		dy = dy1 - dy2; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		dphi = sqrt(dx*dx + dy*dy); | 
					
						
							|  |  |  | 		if( (dx1*dy2-dx2*dy1)>0.0 ) dphi= -dphi; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	if(mi->precision) dphi = dphi/30.0f; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	/* if no delta angle, don't update initial position */ | 
					
						
							|  |  |  | 	if (dphi != 0) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		mi->imval[0] = mval[0]; | 
					
						
							|  |  |  | 		mi->imval[1] = mval[1]; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 	*angle += dphi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	output[0] = *angle; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-16 14:32:17 +00:00
										 |  |  | void initMouseInput(TransInfo *UNUSED(t), MouseInput *mi, int center[2], short mval[2]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mi->factor = 0; | 
					
						
							|  |  |  | 	mi->precision = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mi->center[0] = center[0]; | 
					
						
							|  |  |  | 	mi->center[1] = center[1]; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	mi->imval[0] = mval[0]; | 
					
						
							|  |  |  | 	mi->imval[1] = mval[1]; | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mi->post = NULL; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void calcSpringFactor(MouseInput *mi) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	mi->factor = (float)sqrt( | 
					
						
							|  |  |  | 		( | 
					
						
							|  |  |  | 			((float)(mi->center[1] - mi->imval[1]))*((float)(mi->center[1] - mi->imval[1])) | 
					
						
							|  |  |  | 		+ | 
					
						
							|  |  |  | 			((float)(mi->center[0] - mi->imval[0]))*((float)(mi->center[0] - mi->imval[0])) | 
					
						
							|  |  |  | 		) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mi->factor==0.0f) | 
					
						
							|  |  |  | 		mi->factor= 1.0f; /* prevent Inf */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	switch(mode) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case INPUT_VECTOR: | 
					
						
							|  |  |  | 		mi->apply = InputVector; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_NONE; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_SPRING: | 
					
						
							|  |  |  | 		calcSpringFactor(mi); | 
					
						
							|  |  |  | 		mi->apply = InputSpring; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_SPRING; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_SPRING_FLIP: | 
					
						
							|  |  |  | 		calcSpringFactor(mi); | 
					
						
							|  |  |  | 		mi->apply = InputSpringFlip; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_SPRING; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_ANGLE: | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 		mi->data = MEM_callocN(sizeof(double), "angle accumulator"); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		mi->apply = InputAngle; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_ANGLE; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_TRACKBALL: | 
					
						
							|  |  |  | 		/* factor has to become setting or so */ | 
					
						
							| 
									
										
										
										
											2009-07-09 19:49:04 +00:00
										 |  |  | 		mi->factor = 0.01f; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		mi->apply = InputTrackBall; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_TRACKBALL; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_HORIZONTAL_RATIO: | 
					
						
							|  |  |  | 		mi->factor = (float)(mi->center[0] - mi->imval[0]); | 
					
						
							|  |  |  | 		mi->apply = InputHorizontalRatio; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_HARROW; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_HORIZONTAL_ABSOLUTE: | 
					
						
							|  |  |  | 		mi->apply = InputHorizontalAbsolute; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_HARROW; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_VERTICAL_RATIO: | 
					
						
							|  |  |  | 		mi->apply = InputVerticalRatio; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_VARROW; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case INPUT_VERTICAL_ABSOLUTE: | 
					
						
							|  |  |  | 		mi->apply = InputVerticalAbsolute; | 
					
						
							| 
									
										
										
										
											2009-04-30 11:47:35 +00:00
										 |  |  | 		t->helpline = HLP_VARROW; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 	case INPUT_CUSTOM_RATIO: | 
					
						
							|  |  |  | 		mi->apply = InputCustomRatio; | 
					
						
							|  |  |  | 		t->helpline = HLP_NONE; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	case INPUT_NONE: | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		mi->apply = NULL; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* bootstrap mouse input with initial values */ | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	applyMouseInput(t, mi, mi->imval, t->values); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | void setInputPostFct(MouseInput *mi, void	(*post)(struct TransInfo *, float [3])) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	mi->post = post; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | void applyMouseInput(TransInfo *t, MouseInput *mi, short mval[2], float output[3]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (mi->apply != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		mi->apply(t, mi, mval, output); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (mi->post) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		mi->post(t, output); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int handleMouseInput(TransInfo *t, MouseInput *mi, wmEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-03 21:01:41 +00:00
										 |  |  | 	int redraw = TREDRAW_NOTHING; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	switch (event->type) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case LEFTSHIFTKEY: | 
					
						
							|  |  |  | 	case RIGHTSHIFTKEY: | 
					
						
							| 
									
										
										
										
											2009-07-29 11:53:37 +00:00
										 |  |  | 		if (event->val==KM_PRESS) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-01-03 22:15:59 +00:00
										 |  |  | 			t->modifiers |= MOD_PRECISION; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 			/* shift is modifier for higher precision transform
 | 
					
						
							|  |  |  | 			 * store the mouse position where the normal movement ended */ | 
					
						
							|  |  |  | 			mi->precision_mval[0] = event->x - t->ar->winrct.xmin; | 
					
						
							|  |  |  | 			mi->precision_mval[1] = event->y - t->ar->winrct.ymin; | 
					
						
							|  |  |  | 			mi->precision = 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-01-03 22:15:59 +00:00
										 |  |  | 			t->modifiers &= ~MOD_PRECISION; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 			mi->precision = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-02-03 21:01:41 +00:00
										 |  |  | 		redraw = TREDRAW_HARD; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	return redraw; | 
					
						
							|  |  |  | } |