~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/transform/transform_input.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
68
68
 
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);
72
72
 
73
73
                ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor;
74
74
        }
75
75
        else {
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;
79
79
        }
80
80
 
81
81
        output[0] = ratio;
87
87
 
88
88
        /* flip scale */
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)
92
 
         {
 
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)
 
92
        {
93
93
                output[0] *= -1.0f;
94
 
         }
 
94
        }
95
95
}
96
96
 
97
97
static void InputTrackBall(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2], float output[3])
98
98
{
99
99
 
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;
103
103
        }
104
104
        else {
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]);
107
107
        }
108
108
 
109
109
        output[0] *= mi->factor;
164
164
        output[0] = dot_v3v3(t->viewinv[1], vec) * 2.0f;
165
165
}
166
166
 
167
 
void setCustomPoints(TransInfo *UNUSED(t), MouseInput *mi, int start[2], int end[2])
 
167
void setCustomPoints(TransInfo *UNUSED(t), MouseInput *mi, const int start[2], const int end[2])
168
168
{
169
169
        int *data;
170
170
 
180
180
        data[3] = end[1];
181
181
}
182
182
 
183
 
static void InputCustomRatio(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2], float output[3])
 
183
static void InputCustomRatioFlip(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2], float output[3])
184
184
{
185
185
        double length;
186
186
        double distance;
191
191
                dx = data[2] - data[0];
192
192
                dy = data[3] - data[1];
193
193
                
194
 
                length = sqrt(dx*dx + dy*dy);
 
194
                length = sqrt(dx * dx + dy * dy);
195
195
                
196
196
                if (mi->precision) {
197
197
                        /* deal with Shift key by adding motion / 10 to motion before shift press */
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];
201
201
 
202
 
                        distance = (length != 0.0f)? (mdx*dx + mdy*dy) / length: 0.0f;
 
202
                        distance = (length != 0.0) ? (mdx * dx + mdy * dy) / length : 0.0;
203
203
                }
204
204
                else {
205
205
                        int mdx, mdy;
206
206
                        mdx = mval[0] - data[2];
207
207
                        mdy = mval[1] - data[3];
208
208
 
209
 
                        distance = (length != 0.0f)? (mdx*dx + mdy*dy) / length: 0.0f;
 
209
                        distance = (length != 0.0) ? (mdx * dx + mdy * dy) / length : 0.0;
210
210
                }
211
211
 
212
 
                output[0] = (float)((length != 0.0f)? distance / length: 0.0f);
 
212
                output[0] = (length != 0.0) ? (double)(distance / length) : 0.0;
213
213
        }
214
214
}
215
215
 
 
216
static void InputCustomRatio(TransInfo *t, MouseInput *mi, const int mval[2], float output[3])
 
217
{
 
218
        InputCustomRatioFlip(t, mi, mval, output);
 
219
        output[0] = -output[0];
 
220
}
 
221
 
216
222
static void InputAngle(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2], float output[3])
217
223
{
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);
221
227
 
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);
225
231
 
226
232
        double dx3 = mval[0] - mi->imval[0];
227
233
        double dy3 = mval[1] - mi->imval[1];
229
235
        double *angle = mi->data;
230
236
 
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 */
235
242
 
236
243
        float dphi;
237
244
 
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;
240
247
 
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
255
262
                dx = dx1 - dx2;
256
263
                dy = dy1 - dy2;
257
264
 
258
 
                dphi = sqrt(dx*dx + dy*dy);
259
 
                if ( (dx1*dy2-dx2*dy1)>0.0 ) dphi= -dphi;
 
265
                dphi = sqrt(dx * dx + dy * dy);
 
266
                if ((dx1 * dy2 - dx2 * dy1) > 0.0) dphi = -dphi;
260
267
        }
261
268
 
262
269
        if (mi->precision) {
263
 
                dphi = dphi/30.0f;
 
270
                dphi = dphi / 30.0f;
264
271
        }
265
272
 
266
273
        /* if no delta angle, don't update initial position */
274
281
        output[0] = *angle;
275
282
}
276
283
 
277
 
void initMouseInput(TransInfo *UNUSED(t), MouseInput *mi, int center[2], int mval[2])
 
284
void initMouseInput(TransInfo *UNUSED(t), MouseInput *mi, const int center[2], const int mval[2])
278
285
{
279
286
        mi->factor = 0;
280
287
        mi->precision = 0;
290
297
 
291
298
static void calcSpringFactor(MouseInput *mi)
292
299
{
293
 
        mi->factor = (float)sqrt(
294
 
                (
295
 
                        ((float)(mi->center[1] - mi->imval[1]))*((float)(mi->center[1] - mi->imval[1]))
296
 
                +
297
 
                        ((float)(mi->center[0] - mi->imval[0]))*((float)(mi->center[0] - mi->imval[0]))
298
 
                ) );
 
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])));
299
302
 
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 */
 
305
        }
302
306
}
303
307
 
304
308
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
305
309
{
306
 
        /* may have been allocated previously */
307
 
        /* TODO, holding R-key can cause mem leak, but this causes [#28903]
308
 
         * disable for now. */
309
 
#if 0
310
 
        if (mi->data) {
311
 
                MEM_freeN(mi->data);
312
 
                mi->data= NULL;
 
310
        /* incase we allocate a new value */
 
311
        void *mi_data_prev = mi->data;
 
312
 
 
313
        switch (mode) {
 
314
                case INPUT_VECTOR:
 
315
                        mi->apply = InputVector;
 
316
                        t->helpline = HLP_NONE;
 
317
                        break;
 
318
                case INPUT_SPRING:
 
319
                        calcSpringFactor(mi);
 
320
                        mi->apply = InputSpring;
 
321
                        t->helpline = HLP_SPRING;
 
322
                        break;
 
323
                case INPUT_SPRING_FLIP:
 
324
                        calcSpringFactor(mi);
 
325
                        mi->apply = InputSpringFlip;
 
326
                        t->helpline = HLP_SPRING;
 
327
                        break;
 
328
                case INPUT_ANGLE:
 
329
                        mi->data = MEM_callocN(sizeof(double), "angle accumulator");
 
330
                        mi->apply = InputAngle;
 
331
                        t->helpline = HLP_ANGLE;
 
332
                        break;
 
333
                case INPUT_TRACKBALL:
 
334
                        /* factor has to become setting or so */
 
335
                        mi->factor = 0.01f;
 
336
                        mi->apply = InputTrackBall;
 
337
                        t->helpline = HLP_TRACKBALL;
 
338
                        break;
 
339
                case INPUT_HORIZONTAL_RATIO:
 
340
                        mi->factor = (float)(mi->center[0] - mi->imval[0]);
 
341
                        mi->apply = InputHorizontalRatio;
 
342
                        t->helpline = HLP_HARROW;
 
343
                        break;
 
344
                case INPUT_HORIZONTAL_ABSOLUTE:
 
345
                        mi->apply = InputHorizontalAbsolute;
 
346
                        t->helpline = HLP_HARROW;
 
347
                        break;
 
348
                case INPUT_VERTICAL_RATIO:
 
349
                        mi->apply = InputVerticalRatio;
 
350
                        t->helpline = HLP_VARROW;
 
351
                        break;
 
352
                case INPUT_VERTICAL_ABSOLUTE:
 
353
                        mi->apply = InputVerticalAbsolute;
 
354
                        t->helpline = HLP_VARROW;
 
355
                        break;
 
356
                case INPUT_CUSTOM_RATIO:
 
357
                        mi->apply = InputCustomRatio;
 
358
                        t->helpline = HLP_NONE;
 
359
                        break;
 
360
                case INPUT_CUSTOM_RATIO_FLIP:
 
361
                        mi->apply = InputCustomRatioFlip;
 
362
                        t->helpline = HLP_NONE;
 
363
                        break;
 
364
                case INPUT_NONE:
 
365
                default:
 
366
                        mi->apply = NULL;
 
367
                        break;
313
368
        }
314
 
#endif
315
369
 
316
 
        switch(mode)
317
 
        {
318
 
        case INPUT_VECTOR:
319
 
                mi->apply = InputVector;
320
 
                t->helpline = HLP_NONE;
321
 
                break;
322
 
        case INPUT_SPRING:
323
 
                calcSpringFactor(mi);
324
 
                mi->apply = InputSpring;
325
 
                t->helpline = HLP_SPRING;
326
 
                break;
327
 
        case INPUT_SPRING_FLIP:
328
 
                calcSpringFactor(mi);
329
 
                mi->apply = InputSpringFlip;
330
 
                t->helpline = HLP_SPRING;
331
 
                break;
332
 
        case INPUT_ANGLE:
333
 
                mi->data = MEM_callocN(sizeof(double), "angle accumulator");
334
 
                mi->apply = InputAngle;
335
 
                t->helpline = HLP_ANGLE;
336
 
                break;
337
 
        case INPUT_TRACKBALL:
338
 
                /* factor has to become setting or so */
339
 
                mi->factor = 0.01f;
340
 
                mi->apply = InputTrackBall;
341
 
                t->helpline = HLP_TRACKBALL;
342
 
                break;
343
 
        case INPUT_HORIZONTAL_RATIO:
344
 
                mi->factor = (float)(mi->center[0] - mi->imval[0]);
345
 
                mi->apply = InputHorizontalRatio;
346
 
                t->helpline = HLP_HARROW;
347
 
                break;
348
 
        case INPUT_HORIZONTAL_ABSOLUTE:
349
 
                mi->apply = InputHorizontalAbsolute;
350
 
                t->helpline = HLP_HARROW;
351
 
                break;
352
 
        case INPUT_VERTICAL_RATIO:
353
 
                mi->apply = InputVerticalRatio;
354
 
                t->helpline = HLP_VARROW;
355
 
                break;
356
 
        case INPUT_VERTICAL_ABSOLUTE:
357
 
                mi->apply = InputVerticalAbsolute;
358
 
                t->helpline = HLP_VARROW;
359
 
                break;
360
 
        case INPUT_CUSTOM_RATIO:
361
 
                mi->apply = InputCustomRatio;
362
 
                t->helpline = HLP_NONE;
363
 
                break;
364
 
        case INPUT_NONE:
365
 
        default:
366
 
                mi->apply = NULL;
367
 
                break;
 
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);
368
374
        }
369
375
 
370
376
        /* bootstrap mouse input with initial values */
371
377
        applyMouseInput(t, mi, mi->imval, t->values);
372
378
}
373
379
 
374
 
void setInputPostFct(MouseInput *mi, void       (*post)(struct TransInfo *, float [3]))
 
380
void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float values[3]))
375
381
{
376
382
        mi->post = post;
377
383
}
391
397
{
392
398
        int redraw = TREDRAW_NOTHING;
393
399
 
394
 
        switch (event->type)
395
 
        {
396
 
        case LEFTSHIFTKEY:
397
 
        case RIGHTSHIFTKEY:
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);
403
 
                        mi->precision = 1;
404
 
                }
405
 
                else {
406
 
                        t->modifiers &= ~MOD_PRECISION;
407
 
                        mi->precision = 0;
408
 
                }
409
 
                redraw = TREDRAW_HARD;
410
 
                break;
 
400
        switch (event->type) {
 
401
                case LEFTSHIFTKEY:
 
402
                case RIGHTSHIFTKEY:
 
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);
 
408
                                mi->precision = 1;
 
409
                                redraw = TREDRAW_HARD;
 
410
                        }
 
411
                        else if (event->val == KM_RELEASE) {
 
412
                                t->modifiers &= ~MOD_PRECISION;
 
413
                                mi->precision = 0;
 
414
                                redraw = TREDRAW_HARD;
 
415
                        }
 
416
                        break;
411
417
        }
412
418
 
413
419
        return redraw;