| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											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 ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  | /** \file blender/editors/transform/transform_input.c
 | 
					
						
							|  |  |  |  *  \ingroup edtransform | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | #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 *************************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputVector(TransInfo *t, MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 	convertViewVec(t, output, mval[0] - mi->imval[0], mval[1] - mi->imval[1]); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputSpring(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 	double dx, dy; | 
					
						
							|  |  |  | 	float ratio; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 15:52:47 +11:00
										 |  |  | 	dx = ((double)mi->center[0] - mval[0]); | 
					
						
							|  |  |  | 	dy = ((double)mi->center[1] - mval[1]); | 
					
						
							|  |  |  | 	ratio = hypot(dx, dy) / (double)mi->factor; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	output[0] = ratio; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputSpringFlip(TransInfo *t, MouseInput *mi, const double 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 */ | 
					
						
							| 
									
										
										
										
											2011-03-24 12:17:24 +00:00
										 |  |  | 	/* values can become really big when zoomed in so use longs [#26598] */ | 
					
						
							| 
									
										
										
										
											2015-12-02 15:52:47 +11:00
										 |  |  | 	if ((int64_t)((int)mi->center[0] - mval[0]) * (int64_t)((int)mi->center[0] - mi->imval[0]) + | 
					
						
							|  |  |  | 	    (int64_t)((int)mi->center[1] - mval[1]) * (int64_t)((int)mi->center[1] - mi->imval[1]) < 0) | 
					
						
							| 
									
										
										
										
											2012-05-20 21:23:26 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		output[0] *= -1.0f; | 
					
						
							| 
									
										
										
										
											2012-05-20 21:23:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputSpringDelta(TransInfo *t, MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2014-06-03 22:02:02 +06:00
										 |  |  | { | 
					
						
							|  |  |  | 	InputSpring(t, mi, mval, output); | 
					
						
							|  |  |  | 	output[0] -= 1.0f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputTrackBall(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 	output[0] = (float)(mi->imval[1] - mval[1]); | 
					
						
							|  |  |  | 	output[1] = (float)(mval[0] - mi->imval[0]); | 
					
						
							| 
									
										
										
										
											2015-10-27 21:46:22 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 	output[0] *= mi->factor; | 
					
						
							|  |  |  | 	output[1] *= mi->factor; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputHorizontalRatio(TransInfo *t, MouseInput *UNUSED(mi), const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2011-09-28 05:53:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-29 15:03:49 +11:00
										 |  |  | 	const int winx = t->ar ? t->ar->winx : 1; | 
					
						
							|  |  |  | 	const double pad = winx / 10; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 15:03:49 +11:00
										 |  |  | 	output[0] = (mval[0] - pad) / (winx - 2 * pad); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputHorizontalAbsolute(TransInfo *t, MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2011-09-28 05:53:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputVerticalRatio(TransInfo *t, MouseInput *UNUSED(mi), const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2011-09-28 05:53:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-29 15:03:49 +11:00
										 |  |  | 	const int winy = t->ar ? t->ar->winy : 1; | 
					
						
							|  |  |  | 	const double pad = winy / 10; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 15:03:49 +11:00
										 |  |  | 	output[0] = (mval[1] - pad) / (winy - 2 * pad); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputVerticalAbsolute(TransInfo *t, MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2011-09-28 05:53:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 02:22:23 +00:00
										 |  |  | void setCustomPoints(TransInfo *UNUSED(t), MouseInput *mi, const int mval_start[2], const int mval_end[2]) | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-12 16:47:36 +00:00
										 |  |  | 	int *data; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 15:06:42 +00:00
										 |  |  | 	mi->data = MEM_reallocN(mi->data, sizeof(int) * 4); | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	data = mi->data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-19 02:22:23 +00:00
										 |  |  | 	data[0] = mval_start[0]; | 
					
						
							|  |  |  | 	data[1] = mval_start[1]; | 
					
						
							|  |  |  | 	data[2] = mval_end[0]; | 
					
						
							|  |  |  | 	data[3] = mval_end[1]; | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputCustomRatioFlip(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-03 13:16:32 +00:00
										 |  |  | 	double length; | 
					
						
							|  |  |  | 	double distance; | 
					
						
							|  |  |  | 	double dx, dy; | 
					
						
							| 
									
										
										
										
											2014-04-27 00:22:49 +10:00
										 |  |  | 	const int *data = mi->data; | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	if (data) { | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 		int mdx, mdy; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 		dx = data[2] - data[0]; | 
					
						
							|  |  |  | 		dy = data[3] - data[1]; | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-14 17:27:50 +10:00
										 |  |  | 		length = hypot(dx, dy); | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 		mdx = mval[0] - data[2]; | 
					
						
							|  |  |  | 		mdy = mval[1] - data[3]; | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 		distance = (length != 0.0) ? (mdx * dx + mdy * dy) / length : 0.0; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-22 21:16:59 +00:00
										 |  |  | 		output[0] = (length != 0.0) ? (double)(distance / length) : 0.0; | 
					
						
							| 
									
										
										
										
											2009-11-18 17:14:56 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-09-21 00:48:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputCustomRatio(TransInfo *t, MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2013-01-31 22:18:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	InputCustomRatioFlip(t, mi, mval, output); | 
					
						
							|  |  |  | 	output[0] = -output[0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | struct InputAngle_Data { | 
					
						
							|  |  |  | 	double angle; | 
					
						
							|  |  |  | 	double mval_prev[2]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 	struct InputAngle_Data *data = mi->data; | 
					
						
							| 
									
										
										
										
											2015-12-02 15:52:47 +11:00
										 |  |  | 	double dx2 = mval[0] - (double)mi->center[0]; | 
					
						
							|  |  |  | 	double dy2 = mval[1] - (double)mi->center[1]; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 	double B = sqrt(dx2 * dx2 + dy2 * dy2); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 15:52:47 +11:00
										 |  |  | 	double dx1 = data->mval_prev[0] - (double)mi->center[0]; | 
					
						
							|  |  |  | 	double dy1 = data->mval_prev[1] - (double)mi->center[1]; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 	double A = sqrt(dx1 * dx1 + dy1 * dy1); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 	double dx3 = mval[0] - data->mval_prev[0]; | 
					
						
							|  |  |  | 	double dy3 = mval[1] - data->mval_prev[1]; | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-25 13:19:21 +12:00
										 |  |  | 	/* use doubles here, to make sure a "1.0" (no rotation) doesn't become 9.999999e-01, which gives 0.02 for acos */ | 
					
						
							| 
									
										
										
										
											2012-05-09 09:24:15 +00:00
										 |  |  | 	double deler = (((dx1 * dx1 + dy1 * dy1) + | 
					
						
							|  |  |  | 	                 (dx2 * dx2 + dy2 * dy2) - | 
					
						
							|  |  |  | 	                 (dx3 * dx3 + dy3 * dy3)) / (2.0 * ((A * B) ? (A * B) : 1.0))); | 
					
						
							| 
									
										
										
										
											2013-02-02 04:58:03 +00:00
										 |  |  | 	/* ((A * B) ? (A * B) : 1.0) this takes care of potential divide by zero errors */ | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	float dphi; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	dphi = saacos((float)deler); | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 	if ((dx1 * dy2 - dx2 * dy1) > 0.0) dphi = -dphi; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* 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 | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	if (dphi == 0) { | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 		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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		dphi = sqrt(dx * dx + dy * dy); | 
					
						
							|  |  |  | 		if ((dx1 * dy2 - dx2 * dy1) > 0.0) dphi = -dphi; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-02 15:52:47 +11:00
										 |  |  | 	data->angle += ((double)dphi) * (mi->precision ? (double)mi->precision_factor : 1.0); | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 	data->mval_prev[0] = mval[0]; | 
					
						
							|  |  |  | 	data->mval_prev[1] = mval[1]; | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 	output[0] = data->angle; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | static void InputAngleSpring(TransInfo *t, MouseInput *mi, const double mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2013-10-13 01:09:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float toutput[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	InputAngle(t, mi, mval, output); | 
					
						
							|  |  |  | 	InputSpring(t, mi, mval, toutput); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	output[1] = toutput[0]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-12 03:42:06 +00:00
										 |  |  | void initMouseInput(TransInfo *UNUSED(t), MouseInput *mi, const float center[2], const int 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) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-09 09:24:15 +00:00
										 |  |  | 	mi->factor = sqrtf(((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) { | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		mi->factor = 1.0f; /* prevent Inf */ | 
					
						
							| 
									
										
										
										
											2012-05-09 09:24:15 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-02-11 02:06:19 +00:00
										 |  |  | 	/* incase we allocate a new value */ | 
					
						
							|  |  |  | 	void *mi_data_prev = mi->data; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 	mi->use_virtual_mval = true; | 
					
						
							|  |  |  | 	mi->precision_factor = 1.0f / 10.0f; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	switch (mode) { | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		case INPUT_VECTOR: | 
					
						
							|  |  |  | 			mi->apply = InputVector; | 
					
						
							|  |  |  | 			t->helpline = HLP_NONE; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_SPRING: | 
					
						
							|  |  |  | 			calcSpringFactor(mi); | 
					
						
							|  |  |  | 			mi->apply = InputSpring; | 
					
						
							|  |  |  | 			t->helpline = HLP_SPRING; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_SPRING_FLIP: | 
					
						
							|  |  |  | 			calcSpringFactor(mi); | 
					
						
							|  |  |  | 			mi->apply = InputSpringFlip; | 
					
						
							|  |  |  | 			t->helpline = HLP_SPRING; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2014-06-03 22:02:02 +06:00
										 |  |  | 		case INPUT_SPRING_DELTA: | 
					
						
							|  |  |  | 			calcSpringFactor(mi); | 
					
						
							|  |  |  | 			mi->apply = InputSpringDelta; | 
					
						
							|  |  |  | 			t->helpline = HLP_SPRING; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		case INPUT_ANGLE: | 
					
						
							| 
									
										
										
										
											2013-10-13 01:09:23 +00:00
										 |  |  | 		case INPUT_ANGLE_SPRING: | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			struct InputAngle_Data *data; | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 			mi->use_virtual_mval = false; | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 			mi->precision_factor = 1.0f / 30.0f; | 
					
						
							|  |  |  | 			data = MEM_callocN(sizeof(struct InputAngle_Data), "angle accumulator"); | 
					
						
							|  |  |  | 			data->mval_prev[0] = mi->imval[0]; | 
					
						
							|  |  |  | 			data->mval_prev[1] = mi->imval[1]; | 
					
						
							|  |  |  | 			mi->data = data; | 
					
						
							|  |  |  | 			if (mode == INPUT_ANGLE) { | 
					
						
							|  |  |  | 				mi->apply = InputAngle; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2015-12-17 19:45:29 +11:00
										 |  |  | 				calcSpringFactor(mi); | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 				mi->apply = InputAngleSpring; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-10-13 01:09:23 +00:00
										 |  |  | 			t->helpline = HLP_ANGLE; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2015-11-12 22:58:35 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		case INPUT_TRACKBALL: | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 			mi->precision_factor = 1.0f / 30.0f; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 			/* factor has to become setting or so */ | 
					
						
							|  |  |  | 			mi->factor = 0.01f; | 
					
						
							|  |  |  | 			mi->apply = InputTrackBall; | 
					
						
							|  |  |  | 			t->helpline = HLP_TRACKBALL; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_HORIZONTAL_RATIO: | 
					
						
							|  |  |  | 			mi->factor = (float)(mi->center[0] - mi->imval[0]); | 
					
						
							|  |  |  | 			mi->apply = InputHorizontalRatio; | 
					
						
							|  |  |  | 			t->helpline = HLP_HARROW; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_HORIZONTAL_ABSOLUTE: | 
					
						
							|  |  |  | 			mi->apply = InputHorizontalAbsolute; | 
					
						
							|  |  |  | 			t->helpline = HLP_HARROW; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_VERTICAL_RATIO: | 
					
						
							|  |  |  | 			mi->apply = InputVerticalRatio; | 
					
						
							|  |  |  | 			t->helpline = HLP_VARROW; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_VERTICAL_ABSOLUTE: | 
					
						
							|  |  |  | 			mi->apply = InputVerticalAbsolute; | 
					
						
							|  |  |  | 			t->helpline = HLP_VARROW; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case INPUT_CUSTOM_RATIO: | 
					
						
							|  |  |  | 			mi->apply = InputCustomRatio; | 
					
						
							|  |  |  | 			t->helpline = HLP_NONE; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2013-01-31 22:18:37 +00:00
										 |  |  | 		case INPUT_CUSTOM_RATIO_FLIP: | 
					
						
							|  |  |  | 			mi->apply = InputCustomRatioFlip; | 
					
						
							|  |  |  | 			t->helpline = HLP_NONE; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		case INPUT_NONE: | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			mi->apply = NULL; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-11 02:06:19 +00:00
										 |  |  | 	/* if we've allocated new data, free the old data
 | 
					
						
							|  |  |  | 	 * less hassle then checking before every alloc above */ | 
					
						
							|  |  |  | 	if (mi_data_prev && (mi_data_prev != mi->data)) { | 
					
						
							|  |  |  | 		MEM_freeN(mi_data_prev); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-14 08:02:06 +00:00
										 |  |  | void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float values[3])) | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	mi->post = post; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-20 07:40:05 +00:00
										 |  |  | void applyMouseInput(TransInfo *t, MouseInput *mi, const int mval[2], float output[3]) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 	double mval_db[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mi->use_virtual_mval) { | 
					
						
							|  |  |  | 		/* update accumulator */ | 
					
						
							|  |  |  | 		double mval_delta[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mval_delta[0] = (mval[0] - mi->imval[0]) - mi->virtual_mval.prev[0]; | 
					
						
							|  |  |  | 		mval_delta[1] = (mval[1] - mi->imval[1]) - mi->virtual_mval.prev[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mi->virtual_mval.prev[0] += mval_delta[0]; | 
					
						
							|  |  |  | 		mi->virtual_mval.prev[1] += mval_delta[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (mi->precision) { | 
					
						
							| 
									
										
										
										
											2015-12-02 15:52:47 +11:00
										 |  |  | 			mval_delta[0] *= (double)mi->precision_factor; | 
					
						
							|  |  |  | 			mval_delta[1] *= (double)mi->precision_factor; | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mi->virtual_mval.accum[0] += mval_delta[0]; | 
					
						
							|  |  |  | 		mi->virtual_mval.accum[1] += mval_delta[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mval_db[0] = mi->imval[0] + mi->virtual_mval.accum[0]; | 
					
						
							|  |  |  | 		mval_db[1] = mi->imval[1] + mi->virtual_mval.accum[1]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		mval_db[0] = mval[0]; | 
					
						
							|  |  |  | 		mval_db[1] = mval[1]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 	if (mi->apply != NULL) { | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 		mi->apply(t, mi, mval_db, output); | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 	if (mi->post) { | 
					
						
							| 
									
										
										
										
											2010-03-09 01:19:32 +00:00
										 |  |  | 		mi->post(t, output); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-23 06:48:36 +00:00
										 |  |  | eRedrawFlag handleMouseInput(TransInfo *t, MouseInput *mi, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-23 06:48:36 +00:00
										 |  |  | 	eRedrawFlag redraw = TREDRAW_NOTHING; | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	switch (event->type) { | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 		case LEFTSHIFTKEY: | 
					
						
							|  |  |  | 		case RIGHTSHIFTKEY: | 
					
						
							|  |  |  | 			if (event->val == KM_PRESS) { | 
					
						
							|  |  |  | 				t->modifiers |= MOD_PRECISION; | 
					
						
							| 
									
										
										
										
											2015-10-30 17:31:07 +11:00
										 |  |  | 				/* shift is modifier for higher precision transforn */ | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 				mi->precision = 1; | 
					
						
							| 
									
										
										
										
											2012-12-13 07:32:31 +00:00
										 |  |  | 				redraw = TREDRAW_HARD; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-12-14 04:38:52 +00:00
										 |  |  | 			else if (event->val == KM_RELEASE) { | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 				t->modifiers &= ~MOD_PRECISION; | 
					
						
							|  |  |  | 				mi->precision = 0; | 
					
						
							| 
									
										
										
										
											2012-12-13 07:32:31 +00:00
										 |  |  | 				redraw = TREDRAW_HARD; | 
					
						
							| 
									
										
										
										
											2012-06-10 22:13:17 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-09 01:52:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-29 20:37:54 +00:00
										 |  |  | 	return redraw; | 
					
						
							|  |  |  | } |