64
64
/* calculate ratio for shiftkey pos, and for total, and blend these for precision */
65
65
dx = (float)(mi->center[0] - mi->precision_mval[0]);
66
66
dy = (float)(mi->center[1] - mi->precision_mval[1]);
67
ratio = (float)sqrt( dx*dx + dy*dy);
67
ratio = sqrtf(dx * dx + dy * dy);
69
dx= (float)(mi->center[0] - mval[0]);
70
dy= (float)(mi->center[1] - mval[1]);
71
precise_ratio = (float)sqrt( dx*dx + dy*dy);
69
dx = (float)(mi->center[0] - mval[0]);
70
dy = (float)(mi->center[1] - mval[1]);
71
precise_ratio = (float)sqrt(dx * dx + dy * dy);
73
73
ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor;
76
76
dx = (float)(mi->center[0] - mval[0]);
77
77
dy = (float)(mi->center[1] - mval[1]);
78
ratio = (float)sqrt( dx*dx + dy*dy) / mi->factor;
78
ratio = sqrtf(dx * dx + dy * dy) / mi->factor;
89
89
/* values can become really big when zoomed in so use longs [#26598] */
90
if ((long long int)(mi->center[0] - mval[0]) * (long long int)(mi->center[0] - mi->imval[0]) +
91
(long long int)(mi->center[1] - mval[1]) * (long long int)(mi->center[1] - mi->imval[1]) < 0)
90
if ((long long int)(mi->center[0] - mval[0]) * (long long int)(mi->center[0] - mi->imval[0]) +
91
(long long int)(mi->center[1] - mval[1]) * (long long int)(mi->center[1] - mi->imval[1]) < 0)
93
93
output[0] *= -1.0f;
97
97
static void InputTrackBall(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2], float output[3])
100
100
if (mi->precision) {
101
output[0] = ( mi->imval[1] - mi->precision_mval[1] ) + ( mi->precision_mval[1] - mval[1] ) * 0.1f;
102
output[1] = ( mi->precision_mval[0] - mi->imval[0] ) + ( mval[0] - mi->precision_mval[0] ) * 0.1f;
101
output[0] = (mi->imval[1] - mi->precision_mval[1]) + (mi->precision_mval[1] - mval[1]) * 0.1f;
102
output[1] = (mi->precision_mval[0] - mi->imval[0]) + (mval[0] - mi->precision_mval[0]) * 0.1f;
105
output[0] = (float)( mi->imval[1] - mval[1] );
106
output[1] = (float)( mval[0] - mi->imval[0] );
105
output[0] = (float)(mi->imval[1] - mval[1]);
106
output[1] = (float)(mval[0] - mi->imval[0]);
109
109
output[0] *= mi->factor;
199
199
mdx = (mi->precision_mval[0] + (float)(mval[0] - mi->precision_mval[0]) / 10.0f) - data[2];
200
200
mdy = (mi->precision_mval[1] + (float)(mval[1] - mi->precision_mval[1]) / 10.0f) - data[3];
202
distance = (length != 0.0f)? (mdx*dx + mdy*dy) / length: 0.0f;
202
distance = (length != 0.0) ? (mdx * dx + mdy * dy) / length : 0.0;
206
206
mdx = mval[0] - data[2];
207
207
mdy = mval[1] - data[3];
209
distance = (length != 0.0f)? (mdx*dx + mdy*dy) / length: 0.0f;
209
distance = (length != 0.0) ? (mdx * dx + mdy * dy) / length : 0.0;
212
output[0] = (float)((length != 0.0f)? distance / length: 0.0f);
212
output[0] = (length != 0.0) ? (double)(distance / length) : 0.0;
216
static void InputCustomRatio(TransInfo *t, MouseInput *mi, const int mval[2], float output[3])
218
InputCustomRatioFlip(t, mi, mval, output);
219
output[0] = -output[0];
216
222
static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2], float output[3])
218
224
double dx2 = mval[0] - mi->center[0];
219
225
double dy2 = mval[1] - mi->center[1];
220
double B = sqrt(dx2*dx2+dy2*dy2);
226
double B = sqrt(dx2 * dx2 + dy2 * dy2);
222
228
double dx1 = mi->imval[0] - mi->center[0];
223
229
double dy1 = mi->imval[1] - mi->center[1];
224
double A = sqrt(dx1*dx1+dy1*dy1);
230
double A = sqrt(dx1 * dx1 + dy1 * dy1);
226
232
double dx3 = mval[0] - mi->imval[0];
227
233
double dy3 = mval[1] - mi->imval[1];
229
235
double *angle = mi->data;
231
237
/* use doubles here, to make sure a "1.0" (no rotation) doesnt become 9.999999e-01, which gives 0.02 for acos */
232
double deler = ((dx1*dx1+dy1*dy1)+(dx2*dx2+dy2*dy2)-(dx3*dx3+dy3*dy3))
233
/ (2.0 * ((A*B)?(A*B):1.0));
234
/* ((A*B)?(A*B):1.0) this takes care of potential divide by zero errors */
238
double deler = (((dx1 * dx1 + dy1 * dy1) +
239
(dx2 * dx2 + dy2 * dy2) -
240
(dx3 * dx3 + dy3 * dy3)) / (2.0 * ((A * B) ? (A * B) : 1.0)));
241
/* ((A * B) ? (A * B) : 1.0) this takes care of potential divide by zero errors */
238
245
dphi = saacos((float)deler);
239
if ( (dx1*dy2-dx2*dy1)>0.0 ) dphi= -dphi;
246
if ((dx1 * dy2 - dx2 * dy1) > 0.0) dphi = -dphi;
241
248
/* If the angle is zero, because of lack of precision close to the 1.0 value in acos
242
249
* approximate the angle with the opposite side of the normalized triangle
291
298
static void calcSpringFactor(MouseInput *mi)
293
mi->factor = (float)sqrt(
295
((float)(mi->center[1] - mi->imval[1]))*((float)(mi->center[1] - mi->imval[1]))
297
((float)(mi->center[0] - mi->imval[0]))*((float)(mi->center[0] - mi->imval[0]))
300
mi->factor = sqrtf(((float)(mi->center[1] - mi->imval[1])) * ((float)(mi->center[1] - mi->imval[1])) +
301
((float)(mi->center[0] - mi->imval[0])) * ((float)(mi->center[0] - mi->imval[0])));
300
if (mi->factor==0.0f)
301
mi->factor= 1.0f; /* prevent Inf */
303
if (mi->factor == 0.0f) {
304
mi->factor = 1.0f; /* prevent Inf */
304
308
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
306
/* may have been allocated previously */
307
/* TODO, holding R-key can cause mem leak, but this causes [#28903]
308
* disable for now. */
310
/* incase we allocate a new value */
311
void *mi_data_prev = mi->data;
315
mi->apply = InputVector;
316
t->helpline = HLP_NONE;
319
calcSpringFactor(mi);
320
mi->apply = InputSpring;
321
t->helpline = HLP_SPRING;
323
case INPUT_SPRING_FLIP:
324
calcSpringFactor(mi);
325
mi->apply = InputSpringFlip;
326
t->helpline = HLP_SPRING;
329
mi->data = MEM_callocN(sizeof(double), "angle accumulator");
330
mi->apply = InputAngle;
331
t->helpline = HLP_ANGLE;
333
case INPUT_TRACKBALL:
334
/* factor has to become setting or so */
336
mi->apply = InputTrackBall;
337
t->helpline = HLP_TRACKBALL;
339
case INPUT_HORIZONTAL_RATIO:
340
mi->factor = (float)(mi->center[0] - mi->imval[0]);
341
mi->apply = InputHorizontalRatio;
342
t->helpline = HLP_HARROW;
344
case INPUT_HORIZONTAL_ABSOLUTE:
345
mi->apply = InputHorizontalAbsolute;
346
t->helpline = HLP_HARROW;
348
case INPUT_VERTICAL_RATIO:
349
mi->apply = InputVerticalRatio;
350
t->helpline = HLP_VARROW;
352
case INPUT_VERTICAL_ABSOLUTE:
353
mi->apply = InputVerticalAbsolute;
354
t->helpline = HLP_VARROW;
356
case INPUT_CUSTOM_RATIO:
357
mi->apply = InputCustomRatio;
358
t->helpline = HLP_NONE;
360
case INPUT_CUSTOM_RATIO_FLIP:
361
mi->apply = InputCustomRatioFlip;
362
t->helpline = HLP_NONE;
319
mi->apply = InputVector;
320
t->helpline = HLP_NONE;
323
calcSpringFactor(mi);
324
mi->apply = InputSpring;
325
t->helpline = HLP_SPRING;
327
case INPUT_SPRING_FLIP:
328
calcSpringFactor(mi);
329
mi->apply = InputSpringFlip;
330
t->helpline = HLP_SPRING;
333
mi->data = MEM_callocN(sizeof(double), "angle accumulator");
334
mi->apply = InputAngle;
335
t->helpline = HLP_ANGLE;
337
case INPUT_TRACKBALL:
338
/* factor has to become setting or so */
340
mi->apply = InputTrackBall;
341
t->helpline = HLP_TRACKBALL;
343
case INPUT_HORIZONTAL_RATIO:
344
mi->factor = (float)(mi->center[0] - mi->imval[0]);
345
mi->apply = InputHorizontalRatio;
346
t->helpline = HLP_HARROW;
348
case INPUT_HORIZONTAL_ABSOLUTE:
349
mi->apply = InputHorizontalAbsolute;
350
t->helpline = HLP_HARROW;
352
case INPUT_VERTICAL_RATIO:
353
mi->apply = InputVerticalRatio;
354
t->helpline = HLP_VARROW;
356
case INPUT_VERTICAL_ABSOLUTE:
357
mi->apply = InputVerticalAbsolute;
358
t->helpline = HLP_VARROW;
360
case INPUT_CUSTOM_RATIO:
361
mi->apply = InputCustomRatio;
362
t->helpline = HLP_NONE;
370
/* if we've allocated new data, free the old data
371
* less hassle then checking before every alloc above */
372
if (mi_data_prev && (mi_data_prev != mi->data)) {
373
MEM_freeN(mi_data_prev);
370
376
/* bootstrap mouse input with initial values */
371
377
applyMouseInput(t, mi, mi->imval, t->values);
374
void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *, float [3]))
380
void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float values[3]))
392
398
int redraw = TREDRAW_NOTHING;
398
if (event->val == KM_PRESS) {
399
t->modifiers |= MOD_PRECISION;
400
/* shift is modifier for higher precision transform
401
* store the mouse position where the normal movement ended */
402
copy_v2_v2_int(mi->precision_mval, event->mval);
406
t->modifiers &= ~MOD_PRECISION;
409
redraw = TREDRAW_HARD;
400
switch (event->type) {
403
if (event->val == KM_PRESS) {
404
t->modifiers |= MOD_PRECISION;
405
/* shift is modifier for higher precision transform
406
* store the mouse position where the normal movement ended */
407
copy_v2_v2_int(mi->precision_mval, event->mval);
409
redraw = TREDRAW_HARD;
411
else if (event->val == KM_RELEASE) {
412
t->modifiers &= ~MOD_PRECISION;
414
redraw = TREDRAW_HARD;