~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: transform_constraints.c 30590 2010-07-21 16:18:00Z blendix $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
27
25
 * ***** END GPL LICENSE BLOCK *****
28
26
 */
29
27
 
 
28
/** \file blender/editors/transform/transform_constraints.c
 
29
 *  \ingroup edtransform
 
30
 */
 
31
 
 
32
 
30
33
#include <stdlib.h>
31
34
#include <stdio.h>
32
35
#include <string.h>
38
41
#include <io.h>
39
42
#endif
40
43
 
41
 
#include "MEM_guardedalloc.h"
42
44
 
43
45
#include "DNA_object_types.h"
44
46
#include "DNA_scene_types.h"
50
52
#include "BIF_glutil.h"
51
53
 
52
54
#include "BKE_context.h"
53
 
#include "BKE_global.h"
54
 
#include "BKE_utildefines.h"
 
55
 
55
56
 
56
57
#include "ED_image.h"
57
58
#include "ED_view3d.h"
58
59
 
59
60
#include "BLI_math.h"
 
61
#include "BLI_utildefines.h"
 
62
#include "BLI_string.h"
60
63
 
61
64
//#include "blendef.h"
62
65
//
70
73
static void drawObjectConstraint(TransInfo *t);
71
74
 
72
75
/* ************************** CONSTRAINTS ************************* */
73
 
void constraintAutoValues(TransInfo *t, float vec[3])
 
76
static void constraintAutoValues(TransInfo *t, float vec[3])
74
77
{
75
78
        int mode = t->con.mode;
76
79
        if (mode & CON_APPLY)
77
80
        {
78
81
                float nval = (t->flag & T_NULL_ONE)?1.0f:0.0f;
79
82
 
80
 
                if ((mode & CON_AXIS0) == 0)
81
 
                {
 
83
                if ((mode & CON_AXIS0) == 0) {
82
84
                        vec[0] = nval;
83
85
                }
84
 
                if ((mode & CON_AXIS1) == 0)
85
 
                {
 
86
                if ((mode & CON_AXIS1) == 0) {
86
87
                        vec[1] = nval;
87
88
                }
88
 
                if ((mode & CON_AXIS2) == 0)
89
 
                {
 
89
                if ((mode & CON_AXIS2) == 0) {
90
90
                        vec[2] = nval;
91
91
                }
92
92
        }
101
101
                if (getConstraintSpaceDimension(t) == 2) {
102
102
                        int axis = mode & (CON_AXIS0|CON_AXIS1|CON_AXIS2);
103
103
                        if (axis == (CON_AXIS0|CON_AXIS1)) {
104
 
                                vec[0] = vec[0];
105
 
                                vec[1] = vec[1];
 
104
                                /* vec[0] = vec[0]; */ /* same */
 
105
                                /* vec[1] = vec[1]; */ /* same */
106
106
                                vec[2] = nval;
107
107
                        }
108
108
                        else if (axis == (CON_AXIS1|CON_AXIS2)) {
111
111
                                vec[0] = nval;
112
112
                        }
113
113
                        else if (axis == (CON_AXIS0|CON_AXIS2)) {
114
 
                                vec[0] = vec[0];
 
114
                                /* vec[0] = vec[0]; */  /* same */
115
115
                                vec[2] = vec[1];
116
116
                                vec[1] = nval;
117
117
                        }
118
118
                }
119
119
                else if (getConstraintSpaceDimension(t) == 1) {
120
120
                        if (mode & CON_AXIS0) {
121
 
                                vec[0] = vec[0];
 
121
                                /* vec[0] = vec[0]; */ /* same */
122
122
                                vec[1] = nval;
123
123
                                vec[2] = nval;
124
124
                        }
136
136
        }
137
137
}
138
138
 
139
 
static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3]) {
 
139
static void postConstraintChecks(TransInfo *t, float vec[3], float pvec[3])
 
140
{
140
141
        int i = 0;
141
142
 
142
143
        mul_m3_v3(t->con.imtx, vec);
156
157
 
157
158
        if (hasNumInput(&t->num)) {
158
159
                applyNumInput(&t->num, vec);
 
160
                removeAspectRatio(t, vec);
159
161
                constraintNumInput(t, vec);
160
162
        }
161
163
 
162
164
        /* autovalues is operator param, use that directly but not if snapping is forced */
163
 
        if (t->flag & T_AUTOVALUES && (t->tsnap.status & SNAP_FORCED) == 0)
164
 
        {
165
 
                VECCOPY(vec, t->auto_values);
 
165
        if (t->flag & T_AUTOVALUES && (t->tsnap.status & SNAP_FORCED) == 0) {
 
166
                mul_v3_m3v3(vec, t->con.imtx, t->auto_values);
166
167
                constraintAutoValues(t, vec);
 
168
                /* inverse transformation at the end */
167
169
        }
168
170
 
169
171
        if (t->con.mode & CON_AXIS0) {
179
181
        mul_m3_v3(t->con.mtx, vec);
180
182
}
181
183
 
182
 
static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3]) {
 
184
static void viewAxisCorrectCenter(TransInfo *t, float t_con_center[3])
 
185
{
 
186
        if (t->spacetype == SPACE_VIEW3D) {
 
187
                // View3D *v3d = t->sa->spacedata.first;
 
188
                const float min_dist= 1.0f; // v3d->near;
 
189
                float dir[3];
 
190
                float l;
 
191
 
 
192
                sub_v3_v3v3(dir, t_con_center, t->viewinv[3]);
 
193
                if (dot_v3v3(dir, t->viewinv[2]) < 0.0f) {
 
194
                        negate_v3(dir);
 
195
                }
 
196
                project_v3_v3v3(dir, dir, t->viewinv[2]);
 
197
 
 
198
                l= len_v3(dir);
 
199
 
 
200
                if (l < min_dist) {
 
201
                        float diff[3];
 
202
                        normalize_v3_v3(diff, t->viewinv[2]);
 
203
                        mul_v3_fl(diff, min_dist - l);
 
204
 
 
205
                        sub_v3_v3(t_con_center, diff);
 
206
                }
 
207
        }
 
208
}
 
209
 
 
210
static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3])
 
211
{
183
212
        float norm[3], vec[3], factor, angle;
 
213
        float t_con_center[3];
184
214
 
185
 
        if(in[0]==0.0f && in[1]==0.0f && in[2]==0.0f)
 
215
        if (in[0]==0.0f && in[1]==0.0f && in[2]==0.0f)
186
216
                return;
187
217
 
188
 
        angle = fabs(angle_v3v3(axis, t->viewinv[2]));
189
 
        if (angle > M_PI / 2) {
190
 
                angle = M_PI - angle;
 
218
        copy_v3_v3(t_con_center, t->con.center);
 
219
 
 
220
        /* checks for center being too close to the view center */
 
221
        viewAxisCorrectCenter(t, t_con_center);
 
222
        
 
223
        angle = fabsf(angle_v3v3(axis, t->viewinv[2]));
 
224
        if (angle > (float)M_PI / 2.0f) {
 
225
                angle = (float)M_PI - angle;
191
226
        }
192
 
        angle = 180.0f * angle / M_PI;
 
227
        angle = RAD2DEGF(angle);
193
228
 
194
229
        /* For when view is parallel to constraint... will cause NaNs otherwise
195
 
           So we take vertical motion in 3D space and apply it to the
196
 
           constraint axis. Nice for camera grab + MMB */
197
 
        if(angle < 5.0f) {
 
230
         * So we take vertical motion in 3D space and apply it to the
 
231
         * constraint axis. Nice for camera grab + MMB */
 
232
        if (angle < 5.0f) {
198
233
                project_v3_v3v3(vec, in, t->viewinv[1]);
199
234
                factor = dot_v3v3(t->viewinv[1], vec) * 2.0f;
200
235
                /* since camera distance is quite relative, use quadratic relationship. holding shift can compensate */
201
 
                if(factor<0.0f) factor*= -factor;
 
236
                if (factor<0.0f) factor*= -factor;
202
237
                else factor*= factor;
203
238
 
204
 
                VECCOPY(out, axis);
 
239
                copy_v3_v3(out, axis);
205
240
                normalize_v3(out);
206
241
                mul_v3_fl(out, -factor);        /* -factor makes move down going backwards */
207
242
        }
211
246
                float norm_center[3];
212
247
                float plane[3];
213
248
 
214
 
                getViewVector(t, t->con.center, norm_center);
 
249
                getViewVector(t, t_con_center, norm_center);
215
250
                cross_v3_v3v3(plane, norm_center, axis);
216
251
 
217
252
                project_v3_v3v3(vec, in, plane);
218
253
                sub_v3_v3v3(vec, in, vec);
219
254
                
220
 
                add_v3_v3v3(v, vec, t->con.center);
 
255
                add_v3_v3v3(v, vec, t_con_center);
221
256
                getViewVector(t, v, norm);
222
257
 
223
258
                /* give arbitrary large value if projection is impossible */
224
259
                factor = dot_v3v3(axis, norm);
225
 
                if (1 - fabs(factor) < 0.0002f) {
226
 
                        VECCOPY(out, axis);
 
260
                if (1.0f - fabsf(factor) < 0.0002f) {
 
261
                        copy_v3_v3(out, axis);
227
262
                        if (factor > 0) {
228
 
                                mul_v3_fl(out, 1000000000);
229
 
                        } else {
230
 
                                mul_v3_fl(out, -1000000000);
231
 
                        }
232
 
                } else {
233
 
                        add_v3_v3v3(v2, t->con.center, axis);
 
263
                                mul_v3_fl(out, 1000000000.0f);
 
264
                        }
 
265
                        else {
 
266
                                mul_v3_fl(out, -1000000000.0f);
 
267
                        }
 
268
                }
 
269
                else {
 
270
                        add_v3_v3v3(v2, t_con_center, axis);
234
271
                        add_v3_v3v3(v4, v, norm);
235
272
                        
236
 
                        isect_line_line_v3(t->con.center, v2, v, v4, i1, i2);
 
273
                        isect_line_line_v3(t_con_center, v2, v, v4, i1, i2);
237
274
                        
238
275
                        sub_v3_v3v3(v, i2, v);
239
276
        
240
 
                        sub_v3_v3v3(out, i1, t->con.center);
 
277
                        sub_v3_v3v3(out, i1, t_con_center);
 
278
 
 
279
                        /* possible some values become nan when
 
280
                         * viewpoint and object are both zero */
 
281
                        if (!finite(out[0])) out[0]= 0.0f;
 
282
                        if (!finite(out[1])) out[1]= 0.0f;
 
283
                        if (!finite(out[2])) out[2]= 0.0f;
241
284
                }
242
285
        }
243
286
}
244
287
 
245
 
static void planeProjection(TransInfo *t, float in[3], float out[3]) {
 
288
static void planeProjection(TransInfo *t, float in[3], float out[3])
 
289
{
246
290
        float vec[3], factor, norm[3];
247
291
 
248
292
        add_v3_v3v3(vec, in, t->con.center);
256
300
        }
257
301
        factor = dot_v3v3(vec, vec) / factor;
258
302
 
259
 
        VECCOPY(vec, norm);
 
303
        copy_v3_v3(vec, norm);
260
304
        mul_v3_fl(vec, factor);
261
305
 
262
306
        add_v3_v3v3(out, in, vec);
273
317
 
274
318
static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], float out[3], float pvec[3])
275
319
{
276
 
        VECCOPY(out, in);
 
320
        copy_v3_v3(out, in);
277
321
        if (!td && t->con.mode & CON_APPLY) {
278
322
                mul_m3_v3(t->con.pmtx, out);
279
323
 
288
332
                                float c[3];
289
333
 
290
334
                                if (t->con.mode & CON_AXIS0) {
291
 
                                        VECCOPY(c, t->con.mtx[0]);
 
335
                                        copy_v3_v3(c, t->con.mtx[0]);
292
336
                                }
293
337
                                else if (t->con.mode & CON_AXIS1) {
294
 
                                        VECCOPY(c, t->con.mtx[1]);
 
338
                                        copy_v3_v3(c, t->con.mtx[1]);
295
339
                                }
296
340
                                else if (t->con.mode & CON_AXIS2) {
297
 
                                        VECCOPY(c, t->con.mtx[2]);
 
341
                                        copy_v3_v3(c, t->con.mtx[2]);
298
342
                                }
299
343
                                axisProjection(t, c, in, out);
300
344
                        }
316
360
 
317
361
static void applyObjectConstraintVec(TransInfo *t, TransData *td, float in[3], float out[3], float pvec[3])
318
362
{
319
 
        VECCOPY(out, in);
 
363
        copy_v3_v3(out, in);
320
364
        if (t->con.mode & CON_APPLY) {
321
365
                if (!td) {
322
366
                        mul_m3_v3(t->con.pmtx, out);
329
373
                                float c[3];
330
374
 
331
375
                                if (t->con.mode & CON_AXIS0) {
332
 
                                        VECCOPY(c, t->con.mtx[0]);
 
376
                                        copy_v3_v3(c, t->con.mtx[0]);
333
377
                                }
334
378
                                else if (t->con.mode & CON_AXIS1) {
335
 
                                        VECCOPY(c, t->con.mtx[1]);
 
379
                                        copy_v3_v3(c, t->con.mtx[1]);
336
380
                                }
337
381
                                else if (t->con.mode & CON_AXIS2) {
338
 
                                        VECCOPY(c, t->con.mtx[2]);
 
382
                                        copy_v3_v3(c, t->con.mtx[2]);
339
383
                                }
340
384
                                axisProjection(t, c, in, out);
341
385
                        }
342
386
                        postConstraintChecks(t, out, pvec);
343
 
                        VECCOPY(out, pvec);
 
387
                        copy_v3_v3(out, pvec);
344
388
                }
345
389
                else {
346
390
                        int i=0;
437
481
                switch(mode) {
438
482
                case CON_AXIS0:
439
483
                case (CON_AXIS1|CON_AXIS2):
440
 
                        VECCOPY(vec, t->con.mtx[0]);
 
484
                        copy_v3_v3(vec, t->con.mtx[0]);
441
485
                        break;
442
486
                case CON_AXIS1:
443
487
                case (CON_AXIS0|CON_AXIS2):
444
 
                        VECCOPY(vec, t->con.mtx[1]);
 
488
                        copy_v3_v3(vec, t->con.mtx[1]);
445
489
                        break;
446
490
                case CON_AXIS2:
447
491
                case (CON_AXIS0|CON_AXIS1):
448
 
                        VECCOPY(vec, t->con.mtx[2]);
 
492
                        copy_v3_v3(vec, t->con.mtx[2]);
449
493
                        break;
450
494
                }
451
495
                /* don't flip axis if asked to or if num input */
484
528
                switch(mode) {
485
529
                case CON_AXIS0:
486
530
                case (CON_AXIS1|CON_AXIS2):
487
 
                        VECCOPY(vec, td->axismtx[0]);
 
531
                        copy_v3_v3(vec, td->axismtx[0]);
488
532
                        break;
489
533
                case CON_AXIS1:
490
534
                case (CON_AXIS0|CON_AXIS2):
491
 
                        VECCOPY(vec, td->axismtx[1]);
 
535
                        copy_v3_v3(vec, td->axismtx[1]);
492
536
                        break;
493
537
                case CON_AXIS2:
494
538
                case (CON_AXIS0|CON_AXIS1):
495
 
                        VECCOPY(vec, td->axismtx[2]);
 
539
                        copy_v3_v3(vec, td->axismtx[2]);
496
540
                        break;
497
541
                }
498
542
                if (angle && (mode & CON_NOFLIP) == 0 && hasNumInput(&t->num) == 0) {
505
549
 
506
550
/*--------------------- INTERNAL SETUP CALLS ------------------*/
507
551
 
508
 
void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]) {
509
 
        strncpy(t->con.text + 1, text, 48);
 
552
void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
 
553
{
 
554
        BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1);
510
555
        copy_m3_m3(t->con.mtx, space);
511
556
        t->con.mode = mode;
512
557
        getConstraintMatrix(t);
520
565
        t->redraw = 1;
521
566
}
522
567
 
523
 
void setLocalConstraint(TransInfo *t, int mode, const char text[]) {
 
568
void setLocalConstraint(TransInfo *t, int mode, const char text[])
 
569
{
524
570
        if (t->flag & T_EDIT) {
525
571
                float obmat[3][3];
526
572
                copy_m3_m4(obmat, t->scene->obedit->obmat);
532
578
                        setConstraint(t, t->data->axismtx, mode, text);
533
579
                }
534
580
                else {
535
 
                        strncpy(t->con.text + 1, text, 48);
 
581
                        BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1);
536
582
                        copy_m3_m3(t->con.mtx, t->data->axismtx);
537
583
                        t->con.mode = mode;
538
584
                        getConstraintMatrix(t);
549
595
}
550
596
 
551
597
/*
552
 
        Set the constraint according to the user defined orientation
553
 
 
554
 
        ftext is a format string passed to sprintf. It will add the name of
555
 
        the orientation where %s is (logically).
556
 
*/
557
 
void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[]) {
 
598
 * Set the constraint according to the user defined orientation
 
599
 *
 
600
 * ftext is a format string passed to BLI_snprintf. It will add the name of
 
601
 * the orientation where %s is (logically).
 
602
 */
 
603
void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[])
 
604
{
558
605
        char text[40];
559
606
 
560
607
        switch(orientation) {
561
608
        case V3D_MANIP_GLOBAL:
562
609
                {
563
 
                        float mtx[3][3];
564
 
                        sprintf(text, ftext, "global");
565
 
                        unit_m3(mtx);
 
610
                        float mtx[3][3]= MAT3_UNITY;
 
611
                        BLI_snprintf(text, sizeof(text), ftext, "global");
566
612
                        setConstraint(t, mtx, mode, text);
567
613
                }
568
614
                break;
569
615
        case V3D_MANIP_LOCAL:
570
 
                sprintf(text, ftext, "local");
 
616
                BLI_snprintf(text, sizeof(text), ftext, "local");
571
617
                setLocalConstraint(t, mode, text);
572
618
                break;
573
619
        case V3D_MANIP_NORMAL:
574
 
                sprintf(text, ftext, "normal");
 
620
                BLI_snprintf(text, sizeof(text), ftext, "normal");
575
621
                setConstraint(t, t->spacemtx, mode, text);
576
622
                break;
577
623
        case V3D_MANIP_VIEW:
578
 
                sprintf(text, ftext, "view");
 
624
                BLI_snprintf(text, sizeof(text), ftext, "view");
579
625
                setConstraint(t, t->spacemtx, mode, text);
580
626
                break;
581
627
        case V3D_MANIP_GIMBAL:
582
 
                sprintf(text, ftext, "gimbal");
 
628
                BLI_snprintf(text, sizeof(text), ftext, "gimbal");
583
629
                setConstraint(t, t->spacemtx, mode, text);
584
630
                break;
585
631
        default: /* V3D_MANIP_CUSTOM */
586
 
                sprintf(text, ftext, t->spacename);
 
632
                BLI_snprintf(text, sizeof(text), ftext, t->spacename);
587
633
                setConstraint(t, t->spacemtx, mode, text);
588
634
                break;
589
635
        }
595
641
 
596
642
/*----------------- DRAWING CONSTRAINTS -------------------*/
597
643
 
598
 
void drawConstraint(const struct bContext *C, TransInfo *t)
 
644
void drawConstraint(TransInfo *t)
599
645
{
600
646
        TransCon *tc = &(t->con);
601
647
 
610
656
 
611
657
        /* nasty exception for Z constraint in camera view */
612
658
        // TRANSFORM_FIX_ME
613
 
//      if((t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp==V3D_CAMOB)
 
659
//      if ((t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp==V3D_CAMOB)
614
660
//              return;
615
661
 
616
662
        if (tc->drawExtra) {
622
668
                        char col2[3] = {255,255,255};
623
669
                        int depth_test_enabled;
624
670
 
625
 
                        convertViewVec(t, vec, (short)(t->mval[0] - t->con.imval[0]), (short)(t->mval[1] - t->con.imval[1]));
 
671
                        convertViewVec(t, vec, (t->mval[0] - t->con.imval[0]), (t->mval[1] - t->con.imval[1]));
626
672
                        add_v3_v3(vec, tc->center);
627
673
 
628
 
                        drawLine(t, tc->center, tc->mtx[0], 'x', 0);
629
 
                        drawLine(t, tc->center, tc->mtx[1], 'y', 0);
630
 
                        drawLine(t, tc->center, tc->mtx[2], 'z', 0);
 
674
                        drawLine(t, tc->center, tc->mtx[0], 'X', 0);
 
675
                        drawLine(t, tc->center, tc->mtx[1], 'Y', 0);
 
676
                        drawLine(t, tc->center, tc->mtx[2], 'Z', 0);
631
677
 
632
678
                        glColor3ubv((GLubyte *)col2);
633
679
 
634
680
                        depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
635
 
                        if(depth_test_enabled)
 
681
                        if (depth_test_enabled)
636
682
                                glDisable(GL_DEPTH_TEST);
637
683
 
638
684
                        setlinestyle(1);
642
688
                        glEnd();
643
689
                        setlinestyle(0);
644
690
 
645
 
                        if(depth_test_enabled)
 
691
                        if (depth_test_enabled)
646
692
                                glEnable(GL_DEPTH_TEST);
647
693
                }
648
694
 
649
695
                if (tc->mode & CON_AXIS0) {
650
 
                        drawLine(t, tc->center, tc->mtx[0], 'x', DRAWLIGHT);
 
696
                        drawLine(t, tc->center, tc->mtx[0], 'X', DRAWLIGHT);
651
697
                }
652
698
                if (tc->mode & CON_AXIS1) {
653
 
                        drawLine(t, tc->center, tc->mtx[1], 'y', DRAWLIGHT);
 
699
                        drawLine(t, tc->center, tc->mtx[1], 'Y', DRAWLIGHT);
654
700
                }
655
701
                if (tc->mode & CON_AXIS2) {
656
 
                        drawLine(t, tc->center, tc->mtx[2], 'z', DRAWLIGHT);
 
702
                        drawLine(t, tc->center, tc->mtx[2], 'Z', DRAWLIGHT);
657
703
                }
658
704
        }
659
705
}
668
714
 
669
715
                UI_ThemeColor(TH_GRID);
670
716
 
671
 
                if(t->spacetype == SPACE_VIEW3D && rv3d != NULL)
672
 
                {
 
717
                if (t->spacetype == SPACE_VIEW3D && rv3d != NULL) {
673
718
                        copy_m4_m4(tmat, rv3d->viewmat);
674
719
                        invert_m4_m4(imat, tmat);
675
720
                }
676
 
                else
677
 
                {
 
721
                else {
678
722
                        unit_m4(tmat);
679
723
                        unit_m4(imat);
680
724
                }
681
725
 
682
726
                glPushMatrix();
683
727
 
684
 
                VECCOPY(center, t->center);
 
728
                copy_v3_v3(center, t->center);
685
729
 
686
 
                if((t->spacetype == SPACE_VIEW3D) && t->obedit)
687
 
                {
 
730
                if ((t->spacetype == SPACE_VIEW3D) && t->obedit) {
688
731
                        mul_m4_v3(t->obedit->obmat, center); /* because t->center is in local space */
689
732
                }
690
 
                else if(t->spacetype == SPACE_IMAGE)
691
 
                {
 
733
                else if (t->spacetype == SPACE_IMAGE) {
692
734
                        float aspx, aspy;
693
735
 
694
736
                        ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
703
745
        }
704
746
}
705
747
 
706
 
static void drawObjectConstraint(TransInfo *t) {
 
748
static void drawObjectConstraint(TransInfo *t)
 
749
{
707
750
        int i;
708
751
        TransData * td = t->data;
709
752
 
710
753
        /* Draw the first one lighter because that's the one who controls the others.
711
 
           Meaning the transformation is projected on that one and just copied on the others
712
 
           constraint space.
713
 
           In a nutshell, the object with light axis is controlled by the user and the others follow.
714
 
           Without drawing the first light, users have little clue what they are doing.
 
754
         * Meaning the transformation is projected on that one and just copied on the others
 
755
         * constraint space.
 
756
         * In a nutshell, the object with light axis is controlled by the user and the others follow.
 
757
         * Without drawing the first light, users have little clue what they are doing.
715
758
         */
716
759
        if (t->con.mode & CON_AXIS0) {
717
 
                drawLine(t, td->ob->obmat[3], td->axismtx[0], 'x', DRAWLIGHT);
 
760
                drawLine(t, td->ob->obmat[3], td->axismtx[0], 'X', DRAWLIGHT);
718
761
        }
719
762
        if (t->con.mode & CON_AXIS1) {
720
 
                drawLine(t, td->ob->obmat[3], td->axismtx[1], 'y', DRAWLIGHT);
 
763
                drawLine(t, td->ob->obmat[3], td->axismtx[1], 'Y', DRAWLIGHT);
721
764
        }
722
765
        if (t->con.mode & CON_AXIS2) {
723
 
                drawLine(t, td->ob->obmat[3], td->axismtx[2], 'z', DRAWLIGHT);
 
766
                drawLine(t, td->ob->obmat[3], td->axismtx[2], 'Z', DRAWLIGHT);
724
767
        }
725
768
 
726
769
        td++;
727
770
 
728
 
        for(i=1;i<t->total;i++,td++) {
 
771
        for (i=1;i<t->total;i++,td++) {
729
772
                if (t->con.mode & CON_AXIS0) {
730
 
                        drawLine(t, td->ob->obmat[3], td->axismtx[0], 'x', 0);
 
773
                        drawLine(t, td->ob->obmat[3], td->axismtx[0], 'X', 0);
731
774
                }
732
775
                if (t->con.mode & CON_AXIS1) {
733
 
                        drawLine(t, td->ob->obmat[3], td->axismtx[1], 'y', 0);
 
776
                        drawLine(t, td->ob->obmat[3], td->axismtx[1], 'Y', 0);
734
777
                }
735
778
                if (t->con.mode & CON_AXIS2) {
736
 
                        drawLine(t, td->ob->obmat[3], td->axismtx[2], 'z', 0);
 
779
                        drawLine(t, td->ob->obmat[3], td->axismtx[2], 'Z', 0);
737
780
                }
738
781
        }
739
782
}
740
783
 
741
784
/*--------------------- START / STOP CONSTRAINTS ---------------------- */
742
785
 
743
 
void startConstraint(TransInfo *t) {
 
786
void startConstraint(TransInfo *t)
 
787
{
744
788
        t->con.mode |= CON_APPLY;
745
789
        *t->con.text = ' ';
746
790
        t->num.idx_max = MIN2(getConstraintSpaceDimension(t) - 1, t->idx_max);
747
791
}
748
792
 
749
 
void stopConstraint(TransInfo *t) {
 
793
void stopConstraint(TransInfo *t)
 
794
{
750
795
        t->con.mode &= ~(CON_APPLY|CON_SELECT);
751
796
        *t->con.text = '\0';
752
797
        t->num.idx_max = t->idx_max;
795
840
        t->con.applyRot = applyAxisConstraintRot;
796
841
}
797
842
 
798
 
void selectConstraint(TransInfo *t) {
 
843
void selectConstraint(TransInfo *t)
 
844
{
799
845
        if (t->con.mode & CON_SELECT) {
800
846
                setNearestAxis(t);
801
847
                startConstraint(t);
823
869
        /* no correction needed... just use whichever one is lower */
824
870
        if ( abs(t->mval[0]-t->con.imval[0]) < abs(t->mval[1]-t->con.imval[1]) ) {
825
871
                t->con.mode |= CON_AXIS1;
826
 
                sprintf(t->con.text, " along Y axis");
 
872
                BLI_snprintf(t->con.text, sizeof(t->con.text), " along Y axis");
827
873
        }
828
874
        else {
829
875
                t->con.mode |= CON_AXIS0;
830
 
                sprintf(t->con.text, " along X axis");
 
876
                BLI_snprintf(t->con.text, sizeof(t->con.text), " along X axis");
831
877
        }
832
878
}
833
879
 
844
890
        mvec[2] = 0.0f;
845
891
 
846
892
        /* we need to correct axis length for the current zoomlevel of view,
847
 
           this to prevent projected values to be clipped behind the camera
848
 
           and to overflow the short integers.
849
 
           The formula used is a bit stupid, just a simplification of the substraction
850
 
           of two 2D points 30 pixels apart (that's the last factor in the formula) after
851
 
           projecting them with window_to_3d_delta and then get the length of that vector.
852
 
        */
 
893
         * this to prevent projected values to be clipped behind the camera
 
894
         * and to overflow the short integers.
 
895
         * The formula used is a bit stupid, just a simplification of the subtraction
 
896
         * of two 2D points 30 pixels apart (that's the last factor in the formula) after
 
897
         * projecting them with window_to_3d_delta and then get the length of that vector.
 
898
         */
853
899
        zfac= t->persmat[0][3]*t->center[0]+ t->persmat[1][3]*t->center[1]+ t->persmat[2][3]*t->center[2]+ t->persmat[3][3];
854
900
        zfac = len_v3(t->persinv[0]) * 2.0f/t->ar->winx * zfac * 30.0f;
855
901
 
856
902
        for (i = 0; i<3; i++) {
857
 
                VECCOPY(axis, t->con.mtx[i]);
 
903
                copy_v3_v3(axis, t->con.mtx[i]);
858
904
 
859
905
                mul_v3_fl(axis, zfac);
860
906
                /* now we can project to get window coordinate */
865
911
                axis[1] = (float)(icoord[1] - t->center2d[1]);
866
912
                axis[2] = 0.0f;
867
913
 
868
 
                 if (normalize_v3(axis) != 0.0f) {
 
914
                if (normalize_v3(axis) != 0.0f) {
869
915
                        project_v3_v3v3(proj, mvec, axis);
870
916
                        sub_v3_v3v3(axis, mvec, proj);
871
917
                        len[i] = normalize_v3(axis);
878
924
        if (len[0] <= len[1] && len[0] <= len[2]) {
879
925
                if (t->modifiers & MOD_CONSTRAINT_PLANE) {
880
926
                        t->con.mode |= (CON_AXIS1|CON_AXIS2);
881
 
                        sprintf(t->con.text, " locking %s X axis", t->spacename);
 
927
                        BLI_snprintf(t->con.text, sizeof(t->con.text), " locking %s X axis", t->spacename);
882
928
                }
883
929
                else {
884
930
                        t->con.mode |= CON_AXIS0;
885
 
                        sprintf(t->con.text, " along %s X axis", t->spacename);
 
931
                        BLI_snprintf(t->con.text, sizeof(t->con.text), " along %s X axis", t->spacename);
886
932
                }
887
933
        }
888
934
        else if (len[1] <= len[0] && len[1] <= len[2]) {
889
935
                if (t->modifiers & MOD_CONSTRAINT_PLANE) {
890
936
                        t->con.mode |= (CON_AXIS0|CON_AXIS2);
891
 
                        sprintf(t->con.text, " locking %s Y axis", t->spacename);
 
937
                        BLI_snprintf(t->con.text, sizeof(t->con.text), " locking %s Y axis", t->spacename);
892
938
                }
893
939
                else {
894
940
                        t->con.mode |= CON_AXIS1;
895
 
                        sprintf(t->con.text, " along %s Y axis", t->spacename);
 
941
                        BLI_snprintf(t->con.text, sizeof(t->con.text), " along %s Y axis", t->spacename);
896
942
                }
897
943
        }
898
944
        else if (len[2] <= len[1] && len[2] <= len[0]) {
899
945
                if (t->modifiers & MOD_CONSTRAINT_PLANE) {
900
946
                        t->con.mode |= (CON_AXIS0|CON_AXIS1);
901
 
                        sprintf(t->con.text, " locking %s Z axis", t->spacename);
 
947
                        BLI_snprintf(t->con.text, sizeof(t->con.text), " locking %s Z axis", t->spacename);
902
948
                }
903
949
                else {
904
950
                        t->con.mode |= CON_AXIS2;
905
 
                        sprintf(t->con.text, " along %s Z axis", t->spacename);
 
951
                        BLI_snprintf(t->con.text, sizeof(t->con.text), " along %s Z axis", t->spacename);
906
952
                }
907
953
        }
908
954
}
929
975
 
930
976
/*-------------- HELPER FUNCTIONS ----------------*/
931
977
 
932
 
char constraintModeToChar(TransInfo *t) {
 
978
char constraintModeToChar(TransInfo *t)
 
979
{
933
980
        if ((t->con.mode & CON_APPLY)==0) {
934
981
                return '\0';
935
982
        }
949
996
}
950
997
 
951
998
 
952
 
int isLockConstraint(TransInfo *t) {
 
999
int isLockConstraint(TransInfo *t)
 
1000
{
953
1001
        int mode = t->con.mode;
954
1002
 
955
1003
        if ( (mode & (CON_AXIS0|CON_AXIS1)) == (CON_AXIS0|CON_AXIS1))
987
1035
 
988
1036
        return n;
989
1037
/*
990
 
  Someone willing to do it criptically could do the following instead:
991
 
 
992
 
  return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2);
993
 
 
994
 
  Based on the assumptions that the axis flags are one after the other and start at 1
995
 
*/
 
1038
 * Someone willing to do it cryptically could do the following instead:
 
1039
 *
 
1040
 * return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2);
 
1041
 *
 
1042
 * Based on the assumptions that the axis flags are one after the other and start at 1
 
1043
 */
996
1044
}