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

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/constraint.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:
69
69
#include "BKE_constraint.h"
70
70
#include "BKE_displist.h"
71
71
#include "BKE_deform.h"
72
 
#include "BKE_DerivedMesh.h"    /* for geometry targets */
 
72
#include "BKE_DerivedMesh.h"    /* for geometry targets */
73
73
#include "BKE_cdderivedmesh.h" /* for geometry targets */
74
74
#include "BKE_object.h"
75
75
#include "BKE_ipo.h"
82
82
#include "BKE_tessmesh.h"
83
83
#include "BKE_tracking.h"
84
84
#include "BKE_movieclip.h"
85
 
#include "BKE_tracking.h"
86
 
#include "BKE_movieclip.h"
87
85
 
88
86
#ifdef WITH_PYTHON
89
 
#include "BPY_extern.h"
90
 
#endif
91
 
 
92
 
#ifndef M_PI
93
 
#define M_PI            3.14159265358979323846
94
 
#endif
95
 
 
96
 
 
 
87
#  include "BPY_extern.h"
 
88
#endif
97
89
 
98
90
/* ************************ Constraints - General Utilities *************************** */
99
91
/* These functions here don't act on any specific constraints, and are therefore should/will
104
96
/* -------------- Naming -------------- */
105
97
 
106
98
/* Find the first available, non-duplicate name for a given constraint */
107
 
void unique_constraint_name (bConstraint *con, ListBase *list)
 
99
void BKE_unique_constraint_name(bConstraint *con, ListBase *list)
108
100
{
109
101
        BLI_uniquename(list, con, "Const", '.', offsetof(bConstraint, name), sizeof(con->name));
110
102
}
113
105
 
114
106
/* package an object/bone for use in constraint evaluation */
115
107
/* This function MEM_calloc's a bConstraintOb struct, that will need to be freed after evaluation */
116
 
bConstraintOb *constraints_make_evalob (Scene *scene, Object *ob, void *subdata, short datatype)
 
108
bConstraintOb *BKE_constraints_make_evalob(Scene *scene, Object *ob, void *subdata, short datatype)
117
109
{
118
110
        bConstraintOb *cob;
119
111
        
120
112
        /* create regardless of whether we have any data! */
121
 
        cob= MEM_callocN(sizeof(bConstraintOb), "bConstraintOb");
 
113
        cob = MEM_callocN(sizeof(bConstraintOb), "bConstraintOb");
122
114
        
123
115
        /* for system time, part of deglobalization, code nicer later with local time (ton) */
124
 
        cob->scene= scene;
 
116
        cob->scene = scene;
125
117
        
126
118
        /* based on type of available data */
127
119
        switch (datatype) {
139
131
                        
140
132
                        copy_m4_m4(cob->startmat, cob->matrix);
141
133
                }
142
 
                        break;
 
134
                break;
143
135
                case CONSTRAINT_OBTYPE_BONE:
144
136
                {
145
137
                        /* only set if we have valid bone, otherwise default */
150
142
                                
151
143
                                if (cob->pchan->rotmode > 0) {
152
144
                                        /* should be some type of Euler order */
153
 
                                        cob->rotOrder= cob->pchan->rotmode; 
 
145
                                        cob->rotOrder = cob->pchan->rotmode;
154
146
                                }
155
147
                                else {
156
148
                                        /* Quats, so eulers should just use default order */
157
 
                                        cob->rotOrder= EULER_ORDER_DEFAULT;
 
149
                                        cob->rotOrder = EULER_ORDER_DEFAULT;
158
150
                                }
159
151
                                
160
152
                                /* matrix in world-space */
165
157
                                
166
158
                        copy_m4_m4(cob->startmat, cob->matrix);
167
159
                }
168
 
                        break;
 
160
                break;
169
161
                        
170
162
                default: /* other types not yet handled */
171
163
                        unit_m4(cob->matrix);
177
169
}
178
170
 
179
171
/* cleanup after constraint evaluation */
180
 
void constraints_clear_evalob (bConstraintOb *cob)
 
172
void BKE_constraints_clear_evalob(bConstraintOb *cob)
181
173
{
182
174
        float delta[4][4], imat[4][4];
183
175
        
202
194
                                invert_m4_m4(cob->ob->constinv, delta);
203
195
                        }
204
196
                }
205
 
                        break;
 
197
                break;
206
198
                case CONSTRAINT_OBTYPE_BONE:
207
199
                {
208
200
                        /* cob->ob or cob->pchan might not exist */
214
206
                                invert_m4_m4(cob->pchan->constinv, delta);
215
207
                        }
216
208
                }
217
 
                        break;
 
209
                break;
218
210
        }
219
211
        
220
212
        /* free tempolary struct */
223
215
 
224
216
/* -------------- Space-Conversion API -------------- */
225
217
 
226
 
#if 0 /* XXX Old code, does the same as one in armature.c, will remove it later. */
227
 
static void constraint_pchan_diff_mat(bPoseChannel *pchan, float diff_mat[4][4])
228
 
{
229
 
        if (pchan->parent) {
230
 
                float offs_bone[4][4];
231
 
 
232
 
                /* construct offs_bone the same way it is done in armature.c */
233
 
                copy_m4_m3(offs_bone, pchan->bone->bone_mat);
234
 
                copy_v3_v3(offs_bone[3], pchan->bone->head);
235
 
                offs_bone[3][1] += pchan->bone->parent->length;
236
 
 
237
 
                if (pchan->bone->flag & BONE_HINGE) {
238
 
                        /* pose_mat = par_pose-space_location * chan_mat */
239
 
                        float tmat[4][4];
240
 
 
241
 
                        /* the rotation of the parent restposition */
242
 
                        copy_m4_m4(tmat, pchan->bone->parent->arm_mat);
243
 
 
244
 
                        /* the location of actual parent transform */
245
 
                        copy_v3_v3(tmat[3], offs_bone[3]);
246
 
                        zero_v3(offs_bone[3]);
247
 
                        mul_m4_v3(pchan->parent->pose_mat, tmat[3]);
248
 
 
249
 
                        mult_m4_m4m4(diff_mat, tmat, offs_bone);
250
 
                }
251
 
                else {
252
 
                        /* pose_mat = par_pose_mat * bone_mat * chan_mat */
253
 
                        if (pchan->bone->flag & BONE_NO_SCALE) {
254
 
                                float tmat[4][4];
255
 
                                copy_m4_m4(tmat, pchan->parent->pose_mat);
256
 
                                normalize_m4(tmat);
257
 
                                mult_m4_m4m4(diff_mat, tmat, offs_bone);
258
 
                        }
259
 
                        else {
260
 
                                mult_m4_m4m4(diff_mat, pchan->parent->pose_mat, offs_bone);
261
 
                        }
262
 
                }
263
 
        }
264
 
        else {
265
 
                /* pose_mat = chan_mat * arm_mat */
266
 
                copy_m4_m4(diff_mat, pchan->bone->arm_mat);
267
 
        }
268
 
}
269
 
#endif
270
 
 
271
218
/* This function is responsible for the correct transformations/conversions 
272
219
 * of a matrix from one space to another for constraint evaluation.
273
220
 * For now, this is only implemented for Objects and PoseChannels.
274
221
 */
275
 
void constraint_mat_convertspace (Object *ob, bPoseChannel *pchan, float mat[][4], short from, short to)
 
222
void BKE_constraint_mat_convertspace(Object *ob, bPoseChannel *pchan, float mat[4][4], short from, short to)
276
223
{
277
224
        float diff_mat[4][4];
278
225
        float imat[4][4];
279
226
        
280
227
        /* prevent crashes in these unlikely events  */
281
 
        if (ob==NULL || mat==NULL) return;
 
228
        if (ob == NULL || mat == NULL) return;
282
229
        /* optimize trick - check if need to do anything */
283
230
        if (from == to) return;
284
231
        
295
242
                                /* use pose-space as stepping stone for other spaces... */
296
243
                                if (ELEM(to, CONSTRAINT_SPACE_LOCAL, CONSTRAINT_SPACE_PARLOCAL)) {
297
244
                                        /* call self with slightly different values */
298
 
                                        constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
 
245
                                        BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
299
246
                                }
300
247
                        }
301
 
                                break;
302
 
                        case CONSTRAINT_SPACE_POSE:     /* ---------- FROM POSESPACE ---------- */
 
248
                        break;
 
249
                        case CONSTRAINT_SPACE_POSE: /* ---------- FROM POSESPACE ---------- */
303
250
                        {
304
251
                                /* pose to world */
305
252
                                if (to == CONSTRAINT_SPACE_WORLD) {
308
255
                                /* pose to local */
309
256
                                else if (to == CONSTRAINT_SPACE_LOCAL) {
310
257
                                        if (pchan->bone) {
311
 
                                                armature_mat_pose_to_bone(pchan, mat, mat);
312
 
#if 0  /* XXX Old code, will remove it later. */
313
 
                                                constraint_pchan_diff_mat(pchan, diff_mat);
314
 
 
315
 
                                                invert_m4_m4(imat, diff_mat);
316
 
                                                mult_m4_m4m4(mat, imat, mat);
317
 
 
318
 
                                                /* override with local location */
319
 
                                                if ((pchan->parent) && (pchan->bone->flag & BONE_NO_LOCAL_LOCATION)) {
320
 
                                                        armature_mat_pose_to_bone_ex(ob, pchan, pchan->pose_mat, tempmat);
321
 
                                                        copy_v3_v3(mat[3], tempmat[3]);
322
 
                                                }
323
 
#endif
 
258
                                                BKE_armature_mat_pose_to_bone(pchan, mat, mat);
324
259
                                        }
325
260
                                }
326
261
                                /* pose to local with parent */
331
266
                                        }
332
267
                                }
333
268
                        }
334
 
                                break;
 
269
                        break;
335
270
                        case CONSTRAINT_SPACE_LOCAL: /* ------------ FROM LOCALSPACE --------- */
336
271
                        {
337
272
                                /* local to pose - do inverse procedure that was done for pose to local */
338
273
                                if (pchan->bone) {
339
274
                                        /* we need the posespace_matrix = local_matrix + (parent_posespace_matrix + restpos) */
340
 
                                        armature_mat_bone_to_pose(pchan, mat, mat);
341
 
#if 0
342
 
                                        constraint_pchan_diff_mat(pchan, diff_mat);
343
 
 
344
 
                                        mult_m4_m4m4(mat, diff_mat, mat);
345
 
#endif
 
275
                                        BKE_armature_mat_bone_to_pose(pchan, mat, mat);
346
276
                                }
347
277
                                
348
278
                                /* use pose-space as stepping stone for other spaces */
349
279
                                if (ELEM(to, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL)) {
350
280
                                        /* call self with slightly different values */
351
 
                                        constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
352
 
                                }                               
 
281
                                        BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
 
282
                                }
353
283
                        }
354
 
                                break;
 
284
                        break;
355
285
                        case CONSTRAINT_SPACE_PARLOCAL: /* -------------- FROM LOCAL WITH PARENT ---------- */
356
286
                        {
357
287
                                /* local + parent to pose */
358
 
                                if (pchan->bone) {                                      
 
288
                                if (pchan->bone) {
359
289
                                        copy_m4_m4(diff_mat, pchan->bone->arm_mat);
360
290
                                        mult_m4_m4m4(mat, mat, diff_mat);
361
291
                                }
363
293
                                /* use pose-space as stepping stone for other spaces */
364
294
                                if (ELEM(to, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL)) {
365
295
                                        /* call self with slightly different values */
366
 
                                        constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
 
296
                                        BKE_constraint_mat_convertspace(ob, pchan, mat, CONSTRAINT_SPACE_POSE, to);
367
297
                                }
368
298
                        }
369
 
                                break;
 
299
                        break;
370
300
                }
371
301
        }
372
302
        else {
373
303
                /* objects */
374
 
                if (from==CONSTRAINT_SPACE_WORLD && to==CONSTRAINT_SPACE_LOCAL) {
 
304
                if (from == CONSTRAINT_SPACE_WORLD && to == CONSTRAINT_SPACE_LOCAL) {
375
305
                        /* check if object has a parent */
376
306
                        if (ob->parent) {
377
307
                                /* 'subtract' parent's effects from owner */
383
313
                                /* Local space in this case will have to be defined as local to the owner's 
384
314
                                 * transform-property-rotated axes. So subtract this rotation component.
385
315
                                 */
386
 
                                object_to_mat4(ob, diff_mat);
 
316
                                BKE_object_to_mat4(ob, diff_mat);
387
317
                                normalize_m4(diff_mat);
388
318
                                zero_v3(diff_mat[3]);
389
319
                                
391
321
                                mult_m4_m4m4(mat, imat, mat);
392
322
                        }
393
323
                }
394
 
                else if (from==CONSTRAINT_SPACE_LOCAL && to==CONSTRAINT_SPACE_WORLD) {
 
324
                else if (from == CONSTRAINT_SPACE_LOCAL && to == CONSTRAINT_SPACE_WORLD) {
395
325
                        /* check that object has a parent - otherwise this won't work */
396
326
                        if (ob->parent) {
397
327
                                /* 'add' parent's effect back to owner */
402
332
                                /* Local space in this case will have to be defined as local to the owner's 
403
333
                                 * transform-property-rotated axes. So add back this rotation component.
404
334
                                 */
405
 
                                object_to_mat4(ob, diff_mat);
 
335
                                BKE_object_to_mat4(ob, diff_mat);
406
336
                                normalize_m4(diff_mat);
407
337
                                zero_v3(diff_mat[3]);
408
338
                                
415
345
/* ------------ General Target Matrix Tools ---------- */
416
346
 
417
347
/* function that sets the given matrix based on given vertex group in mesh */
418
 
static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat[][4])
 
348
static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[4][4])
419
349
{
420
350
        DerivedMesh *dm = NULL;
421
 
        Mesh *me= ob->data;
422
 
        BMEditMesh *em = me->edit_btmesh;
 
351
        BMEditMesh *em = BMEdit_FromObject(ob);
423
352
        float vec[3] = {0.0f, 0.0f, 0.0f};
424
353
        float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3];
425
354
        float imat[3][3], tmat[3][3];
426
 
        const int defgroup= defgroup_name_index(ob, substring);
 
355
        const int defgroup = defgroup_name_index(ob, substring);
427
356
        short freeDM = 0;
428
357
        
429
358
        /* initialize target matrix using target matrix */
435
364
        /* get DerivedMesh */
436
365
        if (em) {
437
366
                /* target is in editmode, so get a special derived mesh */
438
 
                dm = CDDM_from_BMEditMesh(em, ob->data, FALSE, FALSE);
439
 
                freeDM= 1;
 
367
                dm = CDDM_from_editbmesh(em, FALSE, FALSE);
 
368
                freeDM = 1;
440
369
        }
441
370
        else {
442
371
                /* when not in EditMode, use the 'final' derived mesh, depsgraph
454
383
                
455
384
                /* check that dvert is a valid pointers (just in case) */
456
385
                if (dvert) {
457
 
                        MDeformVert *dv= dvert;
 
386
                        MDeformVert *dv = dvert;
458
387
                        /* get the average of all verts with that are in the vertex-group */
459
388
                        for (i = 0; i < numVerts; i++, dv++) {
460
 
                                MDeformWeight *dw= defvert_find_index(dv, defgroup);
 
389
                                MDeformWeight *dw = defvert_find_index(dv, defgroup);
461
390
                                if (dw && dw->weight != 0.0f) {
462
391
                                        dm->getVertCo(dm, i, co);
463
392
                                        dm->getVertNo(dm, i, nor);
512
441
}
513
442
 
514
443
/* function that sets the given matrix based on given vertex group in lattice */
515
 
static void contarget_get_lattice_mat (Object *ob, const char *substring, float mat[][4])
 
444
static void contarget_get_lattice_mat(Object *ob, const char *substring, float mat[4][4])
516
445
{
517
 
        Lattice *lt= (Lattice *)ob->data;
 
446
        Lattice *lt = (Lattice *)ob->data;
518
447
        
519
 
        DispList *dl = find_displist(&ob->disp, DL_VERTS);
520
 
        float *co = dl?dl->verts:NULL;
 
448
        DispList *dl = BKE_displist_find(&ob->disp, DL_VERTS);
 
449
        float *co = dl ? dl->verts : NULL;
521
450
        BPoint *bp = lt->def;
522
451
        
523
452
        MDeformVert *dv = lt->dvert;
524
 
        int tot_verts= lt->pntsu*lt->pntsv*lt->pntsw;
525
 
        float vec[3]= {0.0f, 0.0f, 0.0f}, tvec[3];
526
 
        int grouped=0;
 
453
        int tot_verts = lt->pntsu * lt->pntsv * lt->pntsw;
 
454
        float vec[3] = {0.0f, 0.0f, 0.0f}, tvec[3];
 
455
        int grouped = 0;
527
456
        int i, n;
528
 
        const int defgroup= defgroup_name_index(ob, substring);
 
457
        const int defgroup = defgroup_name_index(ob, substring);
529
458
        
530
459
        /* initialize target matrix using target matrix */
531
460
        copy_m4_m4(mat, ob->obmat);
537
466
        /* 1. Loop through control-points checking if in nominated vertex-group.
538
467
         * 2. If it is, add it to vec to find the average point.
539
468
         */
540
 
        for (i=0; i < tot_verts; i++, dv++) {
541
 
                for (n= 0; n < dv->totweight; n++) {
542
 
                        MDeformWeight *dw= defvert_find_index(dv, defgroup);
 
469
        for (i = 0; i < tot_verts; i++, dv++) {
 
470
                for (n = 0; n < dv->totweight; n++) {
 
471
                        MDeformWeight *dw = defvert_find_index(dv, defgroup);
543
472
                        if (dw && dw->weight > 0.0f) {
544
473
                                /* copy coordinates of point to temporary vector, then add to find average */
545
474
                                memcpy(tvec, co ? co : bp->vec, 3 * sizeof(float));
551
480
                
552
481
                /* advance pointer to coordinate data */
553
482
                if (co) co += 3;
554
 
                else    bp++;
 
483
                else bp++;
555
484
        }
556
485
        
557
486
        /* find average location, then multiply by ob->obmat to find world-space location */
565
494
 
566
495
/* generic function to get the appropriate matrix for most target cases */
567
496
/* The cases where the target can be object data have not been implemented */
568
 
static void constraint_target_to_mat4 (Object *ob, const char *substring, float mat[][4], short from, short to, float headtail)
 
497
static void constraint_target_to_mat4(Object *ob, const char *substring, float mat[4][4], short from, short to, float headtail)
569
498
{
570
499
        /*      Case OBJECT */
571
500
        if (!strlen(substring)) {
572
501
                copy_m4_m4(mat, ob->obmat);
573
 
                constraint_mat_convertspace(ob, NULL, mat, from, to);
 
502
                BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
574
503
        }
575
 
        /*      Case VERTEXGROUP */
 
504
        /*  Case VERTEXGROUP */
576
505
        /* Current method just takes the average location of all the points in the
577
506
         * VertexGroup, and uses that as the location value of the targets. Where 
578
507
         * possible, the orientation will also be calculated, by calculating an
583
512
         */
584
513
        else if (ob->type == OB_MESH) {
585
514
                contarget_get_mesh_mat(ob, substring, mat);
586
 
                constraint_mat_convertspace(ob, NULL, mat, from, to);
 
515
                BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
587
516
        }
588
517
        else if (ob->type == OB_LATTICE) {
589
518
                contarget_get_lattice_mat(ob, substring, mat);
590
 
                constraint_mat_convertspace(ob, NULL, mat, from, to);
 
519
                BKE_constraint_mat_convertspace(ob, NULL, mat, from, to);
591
520
        }
592
521
        /*      Case BONE */
593
522
        else {
594
523
                bPoseChannel *pchan;
595
524
                
596
 
                pchan = get_pose_channel(ob->pose, substring);
 
525
                pchan = BKE_pose_channel_find_name(ob->pose, substring);
597
526
                if (pchan) {
598
527
                        /* Multiply the PoseSpace accumulation/final matrix for this
599
528
                         * PoseChannel by the Armature Object's Matrix to get a worldspace
607
536
                                float tempmat[4][4], loc[3];
608
537
                                
609
538
                                /* interpolate along length of bone */
610
 
                                interp_v3_v3v3(loc, pchan->pose_head, pchan->pose_tail, headtail);      
 
539
                                interp_v3_v3v3(loc, pchan->pose_head, pchan->pose_tail, headtail);
611
540
                                
612
541
                                /* use interpolated distance for subtarget */
613
 
                                copy_m4_m4(tempmat, pchan->pose_mat);   
 
542
                                copy_m4_m4(tempmat, pchan->pose_mat);
614
543
                                copy_v3_v3(tempmat[3], loc);
615
544
                                
616
545
                                mult_m4_m4m4(mat, ob->obmat, tempmat);
617
546
                        }
618
 
                } 
 
547
                }
619
548
                else
620
549
                        copy_m4_m4(mat, ob->obmat);
621
550
                        
622
551
                /* convert matrix space as required */
623
 
                constraint_mat_convertspace(ob, pchan, mat, from, to);
 
552
                BKE_constraint_mat_convertspace(ob, pchan, mat, from, to);
624
553
        }
625
554
}
626
555
 
631
560
 */
632
561
 
633
562
/* Template for type-info data:
634
 
 *      - make a copy of this when creating new constraints, and just change the functions
635
 
 *        pointed to as necessary
636
 
 *      - although the naming of functions doesn't matter, it would help for code
637
 
 *        readability, to follow the same naming convention as is presented here
638
 
 *      - any functions that a constraint doesn't need to define, don't define
639
 
 *        for such cases, just use NULL 
640
 
 *      - these should be defined after all the functions have been defined, so that
641
 
 *        forward-definitions/prototypes don't need to be used!
 
563
 *  - make a copy of this when creating new constraints, and just change the functions
 
564
 *    pointed to as necessary
 
565
 *  - although the naming of functions doesn't matter, it would help for code
 
566
 *    readability, to follow the same naming convention as is presented here
 
567
 *  - any functions that a constraint doesn't need to define, don't define
 
568
 *    for such cases, just use NULL 
 
569
 *  - these should be defined after all the functions have been defined, so that
 
570
 *    forward-definitions/prototypes don't need to be used!
642
571
 *      - keep this copy #if-def'd so that future constraints can get based off this
643
572
 */
644
573
#if 0
648
577
        "ConstrName", /* name */
649
578
        "bConstrNameConstraint", /* struct name */
650
579
        constrname_free, /* free data */
651
 
        constrname_relink, /* relink data */
652
580
        constrname_id_looper, /* id looper */
653
581
        constrname_copy, /* copy data */
654
582
        constrname_new_data, /* new data */
662
590
/* This function should be used for the get_target_matrix member of all 
663
591
 * constraints that are not picky about what happens to their target matrix.
664
592
 */
665
 
static void default_get_tarmat (bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime))
 
593
static void default_get_tarmat(bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime))
666
594
{
667
595
        if (VALID_CONS_TARGET(ct))
668
596
                constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail);
678
606
// TODO: cope with getting rotation order...
679
607
#define SINGLETARGET_GET_TARS(con, datatar, datasubtarget, ct, list) \
680
608
        { \
681
 
                ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
 
609
                ct = MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
682
610
                 \
683
 
                ct->tar= datatar; \
 
611
                ct->tar = datatar; \
684
612
                BLI_strncpy(ct->subtarget, datasubtarget, sizeof(ct->subtarget)); \
685
 
                ct->space= con->tarspace; \
686
 
                ct->flag= CONSTRAINT_TAR_TEMP; \
 
613
                ct->space = con->tarspace; \
 
614
                ct->flag = CONSTRAINT_TAR_TEMP; \
687
615
                 \
688
616
                if (ct->tar) { \
689
 
                        if ((ct->tar->type==OB_ARMATURE) && (ct->subtarget[0])) { \
690
 
                                bPoseChannel *pchan= get_pose_channel(ct->tar->pose, ct->subtarget); \
 
617
                        if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) { \
 
618
                                bPoseChannel *pchan = BKE_pose_channel_find_name(ct->tar->pose, ct->subtarget); \
691
619
                                ct->type = CONSTRAINT_OBTYPE_BONE; \
692
 
                                ct->rotOrder= (pchan) ? (pchan->rotmode) : EULER_ORDER_DEFAULT; \
693
 
                        }\
 
620
                                ct->rotOrder = (pchan) ? (pchan->rotmode) : EULER_ORDER_DEFAULT; \
 
621
                        } \
694
622
                        else if (OB_TYPE_SUPPORT_VGROUP(ct->tar->type) && (ct->subtarget[0])) { \
695
623
                                ct->type = CONSTRAINT_OBTYPE_VERT; \
696
624
                                ct->rotOrder = EULER_ORDER_DEFAULT; \
697
625
                        } \
698
 
                        else {\
 
626
                        else { \
699
627
                                ct->type = CONSTRAINT_OBTYPE_OBJECT; \
700
 
                                ct->rotOrder= ct->tar->rotmode; \
 
628
                                ct->rotOrder = ct->tar->rotmode; \
701
629
                        } \
702
630
                } \
703
631
                 \
704
632
                BLI_addtail(list, ct); \
705
 
        }
 
633
        } (void)0
706
634
        
707
635
/* This following macro should be used for all standard single-target *_get_tars functions 
708
636
 * to save typing and reduce maintenance woes. It does not do the subtarget related operations
712
640
// TODO: cope with getting rotation order...
713
641
#define SINGLETARGETNS_GET_TARS(con, datatar, ct, list) \
714
642
        { \
715
 
                ct= MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
 
643
                ct = MEM_callocN(sizeof(bConstraintTarget), "tempConstraintTarget"); \
716
644
                 \
717
 
                ct->tar= datatar; \
718
 
                ct->space= con->tarspace; \
719
 
                ct->flag= CONSTRAINT_TAR_TEMP; \
 
645
                ct->tar = datatar; \
 
646
                ct->space = con->tarspace; \
 
647
                ct->flag = CONSTRAINT_TAR_TEMP; \
720
648
                 \
721
649
                if (ct->tar) ct->type = CONSTRAINT_OBTYPE_OBJECT; \
722
650
                 \
723
651
                BLI_addtail(list, ct); \
724
 
        }
 
652
        } (void)0
725
653
 
726
654
/* This following macro should be used for all standard single-target *_flush_tars functions
727
655
 * to save typing and reduce maintenance woes.
734
662
                if (ct) { \
735
663
                        bConstraintTarget *ctn = ct->next; \
736
664
                        if (nocopy == 0) { \
737
 
                                datatar= ct->tar; \
 
665
                                datatar = ct->tar; \
738
666
                                BLI_strncpy(datasubtarget, ct->subtarget, sizeof(datasubtarget)); \
739
 
                                con->tarspace= (char)ct->space; \
 
667
                                con->tarspace = (char)ct->space; \
740
668
                        } \
741
669
                         \
742
670
                        BLI_freelinkN(list, ct); \
743
 
                        ct= ctn; \
 
671
                        ct = ctn; \
744
672
                } \
745
 
        }
 
673
        } (void)0
746
674
        
747
675
/* This following macro should be used for all standard single-target *_flush_tars functions
748
676
 * to save typing and reduce maintenance woes. It does not do the subtarget related operations.
755
683
                if (ct) { \
756
684
                        bConstraintTarget *ctn = ct->next; \
757
685
                        if (nocopy == 0) { \
758
 
                                datatar= ct->tar; \
759
 
                                con->tarspace= (char)ct->space; \
 
686
                                datatar = ct->tar; \
 
687
                                con->tarspace = (char)ct->space; \
760
688
                        } \
761
689
                         \
762
690
                        BLI_freelinkN(list, ct); \
763
 
                        ct= ctn; \
 
691
                        ct = ctn; \
764
692
                } \
765
 
        }
 
693
        } (void)0
766
694
 
767
695
/* --------- ChildOf Constraint ------------ */
768
696
 
769
 
static void childof_new_data (void *cdata)
 
697
static void childof_new_data(void *cdata)
770
698
{
771
 
        bChildOfConstraint *data= (bChildOfConstraint *)cdata;
 
699
        bChildOfConstraint *data = (bChildOfConstraint *)cdata;
772
700
        
773
701
        data->flag = (CHILDOF_LOCX | CHILDOF_LOCY | CHILDOF_LOCZ |
774
 
                                        CHILDOF_ROTX |CHILDOF_ROTY | CHILDOF_ROTZ |
775
 
                                        CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ);
 
702
                      CHILDOF_ROTX | CHILDOF_ROTY | CHILDOF_ROTZ |
 
703
                      CHILDOF_SIZEX | CHILDOF_SIZEY | CHILDOF_SIZEZ);
776
704
        unit_m4(data->invmat);
777
705
}
778
706
 
779
 
static void childof_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
707
static void childof_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
780
708
{
781
 
        bChildOfConstraint *data= con->data;
 
709
        bChildOfConstraint *data = con->data;
782
710
        
783
711
        /* target only */
784
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
712
        func(con, (ID **)&data->tar, FALSE, userdata);
785
713
}
786
714
 
787
 
static int childof_get_tars (bConstraint *con, ListBase *list)
 
715
static int childof_get_tars(bConstraint *con, ListBase *list)
788
716
{
789
717
        if (con && list) {
790
 
                bChildOfConstraint *data= con->data;
 
718
                bChildOfConstraint *data = con->data;
791
719
                bConstraintTarget *ct;
792
720
                
793
721
                /* standard target-getting macro for single-target constraints */
794
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
722
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
795
723
                
796
724
                return 1;
797
725
        }
799
727
        return 0;
800
728
}
801
729
 
802
 
static void childof_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
730
static void childof_flush_tars(bConstraint *con, ListBase *list, short nocopy)
803
731
{
804
732
        if (con && list) {
805
 
                bChildOfConstraint *data= con->data;
806
 
                bConstraintTarget *ct= list->first;
 
733
                bChildOfConstraint *data = con->data;
 
734
                bConstraintTarget *ct = list->first;
807
735
                
808
736
                /* the following macro is used for all standard single-target constraints */
809
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
737
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
810
738
        }
811
739
}
812
740
 
813
 
static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
741
static void childof_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
814
742
{
815
 
        bChildOfConstraint *data= con->data;
816
 
        bConstraintTarget *ct= targets->first;
 
743
        bChildOfConstraint *data = con->data;
 
744
        bConstraintTarget *ct = targets->first;
817
745
 
818
746
        /* only evaluate if there is a target */
819
747
        if (VALID_CONS_TARGET(ct)) {
823
751
                if (data->flag == CHILDOF_ALL) {
824
752
                        
825
753
                        /* multiply target (parent matrix) by offset (parent inverse) to get 
826
 
                         * the effect of the parent that will be exherted on the owner
 
754
                         * the effect of the parent that will be exerted on the owner
827
755
                         */
828
756
                        mult_m4_m4m4(parmat, ct->matrix, data->invmat);
829
757
                        
830
758
                        /* now multiply the parent matrix by the owner matrix to get the 
831
 
                         * the effect of this constraint (i.e.  owner is 'parented' to parent)
 
759
                         * the effect of this constraint (i.e. owner is 'parented' to parent)
832
760
                         */
833
761
                        mult_m4_m4m4(cob->matrix, parmat, cob->matrix);
834
762
                }
850
778
                        mat4_to_size(sizo, invmat);
851
779
                        
852
780
                        /* disable channels not enabled */
853
 
                        if (!(data->flag & CHILDOF_LOCX)) loc[0]= loco[0]= 0.0f;
854
 
                        if (!(data->flag & CHILDOF_LOCY)) loc[1]= loco[1]= 0.0f;
855
 
                        if (!(data->flag & CHILDOF_LOCZ)) loc[2]= loco[2]= 0.0f;
856
 
                        if (!(data->flag & CHILDOF_ROTX)) eul[0]= eulo[0]= 0.0f;
857
 
                        if (!(data->flag & CHILDOF_ROTY)) eul[1]= eulo[1]= 0.0f;
858
 
                        if (!(data->flag & CHILDOF_ROTZ)) eul[2]= eulo[2]= 0.0f;
859
 
                        if (!(data->flag & CHILDOF_SIZEX)) size[0]= sizo[0]= 1.0f;
860
 
                        if (!(data->flag & CHILDOF_SIZEY)) size[1]= sizo[1]= 1.0f;
861
 
                        if (!(data->flag & CHILDOF_SIZEZ)) size[2]= sizo[2]= 1.0f;
 
781
                        if (!(data->flag & CHILDOF_LOCX)) loc[0] = loco[0] = 0.0f;
 
782
                        if (!(data->flag & CHILDOF_LOCY)) loc[1] = loco[1] = 0.0f;
 
783
                        if (!(data->flag & CHILDOF_LOCZ)) loc[2] = loco[2] = 0.0f;
 
784
                        if (!(data->flag & CHILDOF_ROTX)) eul[0] = eulo[0] = 0.0f;
 
785
                        if (!(data->flag & CHILDOF_ROTY)) eul[1] = eulo[1] = 0.0f;
 
786
                        if (!(data->flag & CHILDOF_ROTZ)) eul[2] = eulo[2] = 0.0f;
 
787
                        if (!(data->flag & CHILDOF_SIZEX)) size[0] = sizo[0] = 1.0f;
 
788
                        if (!(data->flag & CHILDOF_SIZEY)) size[1] = sizo[1] = 1.0f;
 
789
                        if (!(data->flag & CHILDOF_SIZEZ)) size[2] = sizo[2] = 1.0f;
862
790
                        
863
791
                        /* make new target mat and offset mat */
864
792
                        loc_eulO_size_to_mat4(ct->matrix, loc, eul, size, ct->rotOrder);
865
793
                        loc_eulO_size_to_mat4(invmat, loco, eulo, sizo, cob->rotOrder);
866
794
                        
867
795
                        /* multiply target (parent matrix) by offset (parent inverse) to get 
868
 
                         * the effect of the parent that will be exherted on the owner
 
796
                         * the effect of the parent that will be exerted on the owner
869
797
                         */
870
798
                        mult_m4_m4m4(parmat, ct->matrix, invmat);
871
799
                        
874
802
                         */
875
803
                        copy_m4_m4(tempmat, cob->matrix);
876
804
                        mult_m4_m4m4(cob->matrix, parmat, tempmat);
877
 
 
 
805
                        
878
806
                        /* without this, changes to scale and rotation can change location
879
807
                         * of a parentless bone or a disconnected bone. Even though its set
880
808
                         * to zero above. */
881
 
                        if (!(data->flag & CHILDOF_LOCX)) cob->matrix[3][0]= tempmat[3][0];
882
 
                        if (!(data->flag & CHILDOF_LOCY)) cob->matrix[3][1]= tempmat[3][1];
883
 
                        if (!(data->flag & CHILDOF_LOCZ)) cob->matrix[3][2]= tempmat[3][2];     
 
809
                        if (!(data->flag & CHILDOF_LOCX)) cob->matrix[3][0] = tempmat[3][0];
 
810
                        if (!(data->flag & CHILDOF_LOCY)) cob->matrix[3][1] = tempmat[3][1];
 
811
                        if (!(data->flag & CHILDOF_LOCZ)) cob->matrix[3][2] = tempmat[3][2];
884
812
                }
885
813
        }
886
814
}
892
820
        "ChildOf", /* name */
893
821
        "bChildOfConstraint", /* struct name */
894
822
        NULL, /* free data */
895
 
        NULL, /* relink data */
896
823
        childof_id_looper, /* id looper */
897
824
        NULL, /* copy data */
898
825
        childof_new_data, /* new data */
904
831
 
905
832
/* -------- TrackTo Constraint ------- */
906
833
 
907
 
static void trackto_new_data (void *cdata)
 
834
static void trackto_new_data(void *cdata)
908
835
{
909
 
        bTrackToConstraint *data= (bTrackToConstraint *)cdata;
 
836
        bTrackToConstraint *data = (bTrackToConstraint *)cdata;
910
837
        
911
838
        data->reserved1 = TRACK_Y;
912
839
        data->reserved2 = UP_Z;
913
840
}       
914
841
 
915
 
static void trackto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
842
static void trackto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
916
843
{
917
 
        bTrackToConstraint *data= con->data;
 
844
        bTrackToConstraint *data = con->data;
918
845
        
919
846
        /* target only */
920
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
847
        func(con, (ID **)&data->tar, FALSE, userdata);
921
848
}
922
849
 
923
 
static int trackto_get_tars (bConstraint *con, ListBase *list)
 
850
static int trackto_get_tars(bConstraint *con, ListBase *list)
924
851
{
925
852
        if (con && list) {
926
 
                bTrackToConstraint *data= con->data;
 
853
                bTrackToConstraint *data = con->data;
927
854
                bConstraintTarget *ct;
928
855
                
929
856
                /* standard target-getting macro for single-target constraints */
930
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
857
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
931
858
                
932
859
                return 1;
933
860
        }
935
862
        return 0;
936
863
}
937
864
 
938
 
static void trackto_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
865
static void trackto_flush_tars(bConstraint *con, ListBase *list, short nocopy)
939
866
{
940
867
        if (con && list) {
941
 
                bTrackToConstraint *data= con->data;
942
 
                bConstraintTarget *ct= list->first;
 
868
                bTrackToConstraint *data = con->data;
 
869
                bConstraintTarget *ct = list->first;
943
870
                
944
871
                /* the following macro is used for all standard single-target constraints */
945
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
872
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
946
873
        }
947
874
}
948
875
 
949
876
 
950
 
static int basis_cross (int n, int m)
 
877
static int basis_cross(int n, int m)
951
878
{
952
 
        switch (n-m) {
 
879
        switch (n - m) {
953
880
                case 1: 
954
881
                case -2:
955
882
                        return 1;
963
890
        }
964
891
}
965
892
 
966
 
static void vectomat (float *vec, float *target_up, short axis, short upflag, short flags, float m[][3])
 
893
static void vectomat(const float vec[3], const float target_up[3], short axis, short upflag, short flags, float m[3][3])
967
894
{
968
895
        float n[3];
969
896
        float u[3]; /* vector specifying the up axis */
981
908
        else negate_v3(n);
982
909
 
983
910
        /* n specifies the transformation of the track axis */
984
 
        if (flags & TARGET_Z_UP) { 
 
911
        if (flags & TARGET_Z_UP) {
985
912
                /* target Z axis is the global up axis */
986
913
                copy_v3_v3(u, target_up);
987
914
        }
988
 
        else { 
 
915
        else {
989
916
                /* world Z axis is the global up axis */
990
917
                u[0] = 0;
991
918
                u[1] = 0;
1027
954
}
1028
955
 
1029
956
 
1030
 
static void trackto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
957
static void trackto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
1031
958
{
1032
 
        bTrackToConstraint *data= con->data;
1033
 
        bConstraintTarget *ct= targets->first;
 
959
        bTrackToConstraint *data = con->data;
 
960
        bConstraintTarget *ct = targets->first;
1034
961
        
1035
962
        if (VALID_CONS_TARGET(ct)) {
1036
963
                float size[3], vec[3];
1037
964
                float totmat[3][3];
1038
 
                float tmat[4][4];
1039
965
                
1040
966
                /* Get size property, since ob->size is only the object's own relative size, not its global one */
1041
967
                mat4_to_size(size, cob->matrix);
1042
968
                
1043
 
                /* Clear the object's rotation */       
1044
 
                cob->matrix[0][0]=size[0];
1045
 
                cob->matrix[0][1]=0;
1046
 
                cob->matrix[0][2]=0;
1047
 
                cob->matrix[1][0]=0;
1048
 
                cob->matrix[1][1]=size[1];
1049
 
                cob->matrix[1][2]=0;
1050
 
                cob->matrix[2][0]=0;
1051
 
                cob->matrix[2][1]=0;
1052
 
                cob->matrix[2][2]=size[2];
 
969
                /* Clear the object's rotation */
 
970
                cob->matrix[0][0] = size[0];
 
971
                cob->matrix[0][1] = 0;
 
972
                cob->matrix[0][2] = 0;
 
973
                cob->matrix[1][0] = 0;
 
974
                cob->matrix[1][1] = size[1];
 
975
                cob->matrix[1][2] = 0;
 
976
                cob->matrix[2][0] = 0;
 
977
                cob->matrix[2][1] = 0;
 
978
                cob->matrix[2][2] = size[2];
1053
979
                
1054
980
                /* targetmat[2] instead of ownermat[2] is passed to vectomat
1055
981
                 * for backwards compatibility it seems... (Aligorith)
1056
982
                 */
1057
983
                sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]);
1058
984
                vectomat(vec, ct->matrix[2], 
1059
 
                                (short)data->reserved1, (short)data->reserved2, 
1060
 
                                data->flags, totmat);
1061
 
                
1062
 
                copy_m4_m4(tmat, cob->matrix);
1063
 
                mul_m4_m3m4(cob->matrix, totmat, tmat);
 
985
                         (short)data->reserved1, (short)data->reserved2,
 
986
                         data->flags, totmat);
 
987
 
 
988
                mul_m4_m3m4(cob->matrix, totmat, cob->matrix);
1064
989
        }
1065
990
}
1066
991
 
1070
995
        "TrackTo", /* name */
1071
996
        "bTrackToConstraint", /* struct name */
1072
997
        NULL, /* free data */
1073
 
        NULL, /* relink data */
1074
998
        trackto_id_looper, /* id looper */
1075
999
        NULL, /* copy data */
1076
1000
        trackto_new_data, /* new data */
1082
1006
 
1083
1007
/* --------- Inverse-Kinemetics --------- */
1084
1008
 
1085
 
static void kinematic_new_data (void *cdata)
 
1009
static void kinematic_new_data(void *cdata)
1086
1010
{
1087
 
        bKinematicConstraint *data= (bKinematicConstraint *)cdata;
 
1011
        bKinematicConstraint *data = (bKinematicConstraint *)cdata;
1088
1012
        
1089
 
        data->weight= 1.0f;
1090
 
        data->orientweight= 1.0f;
 
1013
        data->weight = 1.0f;
 
1014
        data->orientweight = 1.0f;
1091
1015
        data->iterations = 500;
1092
 
        data->dist= 1.0f;
1093
 
        data->flag= CONSTRAINT_IK_TIP|CONSTRAINT_IK_STRETCH|CONSTRAINT_IK_POS;
 
1016
        data->dist = 1.0f;
 
1017
        data->flag = CONSTRAINT_IK_TIP | CONSTRAINT_IK_STRETCH | CONSTRAINT_IK_POS;
1094
1018
}
1095
1019
 
1096
 
static void kinematic_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1020
static void kinematic_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
1097
1021
{
1098
 
        bKinematicConstraint *data= con->data;
 
1022
        bKinematicConstraint *data = con->data;
1099
1023
        
1100
1024
        /* chain target */
1101
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
1025
        func(con, (ID **)&data->tar, FALSE, userdata);
1102
1026
        
1103
1027
        /* poletarget */
1104
 
        func(con, (ID**)&data->poletar, FALSE, userdata);
 
1028
        func(con, (ID **)&data->poletar, FALSE, userdata);
1105
1029
}
1106
1030
 
1107
 
static int kinematic_get_tars (bConstraint *con, ListBase *list)
 
1031
static int kinematic_get_tars(bConstraint *con, ListBase *list)
1108
1032
{
1109
1033
        if (con && list) {
1110
 
                bKinematicConstraint *data= con->data;
 
1034
                bKinematicConstraint *data = con->data;
1111
1035
                bConstraintTarget *ct;
1112
1036
                
1113
1037
                /* standard target-getting macro for single-target constraints is used twice here */
1114
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
1115
 
                SINGLETARGET_GET_TARS(con, data->poletar, data->polesubtarget, ct, list)
 
1038
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
 
1039
                SINGLETARGET_GET_TARS(con, data->poletar, data->polesubtarget, ct, list);
1116
1040
                
1117
1041
                return 2;
1118
1042
        }
1120
1044
        return 0;
1121
1045
}
1122
1046
 
1123
 
static void kinematic_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
1047
static void kinematic_flush_tars(bConstraint *con, ListBase *list, short nocopy)
1124
1048
{
1125
1049
        if (con && list) {
1126
 
                bKinematicConstraint *data= con->data;
1127
 
                bConstraintTarget *ct= list->first;
 
1050
                bKinematicConstraint *data = con->data;
 
1051
                bConstraintTarget *ct = list->first;
1128
1052
                
1129
1053
                /* the following macro is used for all standard single-target constraints */
1130
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
1131
 
                SINGLETARGET_FLUSH_TARS(con, data->poletar, data->polesubtarget, ct, list, nocopy)
 
1054
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
 
1055
                SINGLETARGET_FLUSH_TARS(con, data->poletar, data->polesubtarget, ct, list, nocopy);
1132
1056
        }
1133
1057
}
1134
1058
 
1135
 
static void kinematic_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
1059
static void kinematic_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
1136
1060
{
1137
 
        bKinematicConstraint *data= con->data;
 
1061
        bKinematicConstraint *data = con->data;
1138
1062
        
1139
1063
        if (VALID_CONS_TARGET(ct)) 
1140
1064
                constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->headtail);
1141
1065
        else if (ct) {
1142
1066
                if (data->flag & CONSTRAINT_IK_AUTO) {
1143
 
                        Object *ob= cob->ob;
 
1067
                        Object *ob = cob->ob;
1144
1068
                        
1145
1069
                        if (ob == NULL) {
1146
1070
                                unit_m4(ct->matrix);
1164
1088
        "IK", /* name */
1165
1089
        "bKinematicConstraint", /* struct name */
1166
1090
        NULL, /* free data */
1167
 
        NULL, /* relink data */
1168
1091
        kinematic_id_looper, /* id looper */
1169
1092
        NULL, /* copy data */
1170
1093
        kinematic_new_data, /* new data */
1176
1099
 
1177
1100
/* -------- Follow-Path Constraint ---------- */
1178
1101
 
1179
 
static void followpath_new_data (void *cdata)
 
1102
static void followpath_new_data(void *cdata)
1180
1103
{
1181
 
        bFollowPathConstraint *data= (bFollowPathConstraint *)cdata;
 
1104
        bFollowPathConstraint *data = (bFollowPathConstraint *)cdata;
1182
1105
        
1183
1106
        data->trackflag = TRACK_Y;
1184
1107
        data->upflag = UP_Z;
1186
1109
        data->followflag = 0;
1187
1110
}
1188
1111
 
1189
 
static void followpath_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1112
static void followpath_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
1190
1113
{
1191
 
        bFollowPathConstraint *data= con->data;
 
1114
        bFollowPathConstraint *data = con->data;
1192
1115
        
1193
1116
        /* target only */
1194
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
1117
        func(con, (ID **)&data->tar, FALSE, userdata);
1195
1118
}
1196
1119
 
1197
 
static int followpath_get_tars (bConstraint *con, ListBase *list)
 
1120
static int followpath_get_tars(bConstraint *con, ListBase *list)
1198
1121
{
1199
1122
        if (con && list) {
1200
 
                bFollowPathConstraint *data= con->data;
 
1123
                bFollowPathConstraint *data = con->data;
1201
1124
                bConstraintTarget *ct;
1202
1125
                
1203
1126
                /* standard target-getting macro for single-target constraints without subtargets */
1204
 
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list)
 
1127
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list);
1205
1128
                
1206
1129
                return 1;
1207
1130
        }
1209
1132
        return 0;
1210
1133
}
1211
1134
 
1212
 
static void followpath_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
1135
static void followpath_flush_tars(bConstraint *con, ListBase *list, short nocopy)
1213
1136
{
1214
1137
        if (con && list) {
1215
 
                bFollowPathConstraint *data= con->data;
1216
 
                bConstraintTarget *ct= list->first;
 
1138
                bFollowPathConstraint *data = con->data;
 
1139
                bConstraintTarget *ct = list->first;
1217
1140
                
1218
1141
                /* the following macro is used for all standard single-target constraints */
1219
 
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy)
 
1142
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy);
1220
1143
        }
1221
1144
}
1222
1145
 
1223
 
static void followpath_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
1146
static void followpath_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
1224
1147
{
1225
 
        bFollowPathConstraint *data= con->data;
 
1148
        bFollowPathConstraint *data = con->data;
1226
1149
        
1227
1150
        if (VALID_CONS_TARGET(ct)) {
1228
 
                Curve *cu= ct->tar->data;
 
1151
                Curve *cu = ct->tar->data;
1229
1152
                float vec[4], dir[3], radius;
1230
 
                float totmat[4][4]= MAT4_UNITY;
 
1153
                float totmat[4][4] = MAT4_UNITY;
1231
1154
                float curvetime;
1232
1155
 
1233
1156
                unit_m4(ct->matrix);
1237
1160
                 */
1238
1161
                
1239
1162
                /* only happens on reload file, but violates depsgraph still... fix! */
1240
 
                if (cu->path==NULL || cu->path->data==NULL)
1241
 
                        makeDispListCurveTypes(cob->scene, ct->tar, 0);
 
1163
                if (cu->path == NULL || cu->path->data == NULL)
 
1164
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
1242
1165
                
1243
1166
                if (cu->path && cu->path->data) {
1244
1167
                        float quat[4];
1245
1168
                        if ((data->followflag & FOLLOWPATH_STATIC) == 0) {
1246
1169
                                /* animated position along curve depending on time */
1247
1170
                                Nurb *nu = cu->nurb.first;
1248
 
                                curvetime= cu->ctime - data->offset;
 
1171
                                curvetime = cu->ctime - data->offset;
1249
1172
                                
1250
1173
                                /* ctime is now a proper var setting of Curve which gets set by Animato like any other var that's animated,
1251
1174
                                 * but this will only work if it actually is animated... 
1269
1192
                        }
1270
1193
                        else {
1271
1194
                                /* fixed position along curve */
1272
 
                                curvetime= data->offset_fac;
 
1195
                                curvetime = data->offset_fac;
1273
1196
                        }
1274
1197
                        
1275
 
                        if ( where_on_path(ct->tar, curvetime, vec, dir, (data->followflag & FOLLOWPATH_FOLLOW) ? quat : NULL, &radius, NULL) ) { /* quat_pt is quat or NULL*/
 
1198
                        if (where_on_path(ct->tar, curvetime, vec, dir, (data->followflag & FOLLOWPATH_FOLLOW) ? quat : NULL, &radius, NULL) ) {  /* quat_pt is quat or NULL*/
1276
1199
                                if (data->followflag & FOLLOWPATH_FOLLOW) {
1277
1200
#if 0
1278
1201
                                        float x1, q[4];
1279
1202
                                        vec_to_quat(quat, dir, (short)data->trackflag, (short)data->upflag);
1280
1203
                                        
1281
1204
                                        normalize_v3(dir);
1282
 
                                        q[0]= (float)cos(0.5*vec[3]);
1283
 
                                        x1= (float)sin(0.5*vec[3]);
1284
 
                                        q[1]= -x1*dir[0];
1285
 
                                        q[2]= -x1*dir[1];
1286
 
                                        q[3]= -x1*dir[2];
 
1205
                                        q[0] = (float)cos(0.5 * vec[3]);
 
1206
                                        x1 = (float)sin(0.5 * vec[3]);
 
1207
                                        q[1] = -x1 * dir[0];
 
1208
                                        q[2] = -x1 * dir[1];
 
1209
                                        q[3] = -x1 * dir[2];
1287
1210
                                        mul_qt_qtqt(quat, q, quat);
1288
1211
#else
1289
1212
                                        quat_apply_track(quat, data->trackflag, data->upflag);
1309
1232
                unit_m4(ct->matrix);
1310
1233
}
1311
1234
 
1312
 
static void followpath_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
1235
static void followpath_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
1313
1236
{
1314
 
        bConstraintTarget *ct= targets->first;
 
1237
        bConstraintTarget *ct = targets->first;
1315
1238
        
1316
1239
        /* only evaluate if there is a target */
1317
1240
        if (VALID_CONS_TARGET(ct)) {
1318
1241
                float obmat[4][4];
1319
1242
                float size[3];
1320
 
                bFollowPathConstraint *data= con->data;
 
1243
                bFollowPathConstraint *data = con->data;
1321
1244
                
1322
1245
                /* get Object transform (loc/rot/size) to determine transformation from path */
1323
 
                // TODO: this used to be local at one point, but is probably more useful as-is
 
1246
                /* TODO: this used to be local at one point, but is probably more useful as-is */
1324
1247
                copy_m4_m4(obmat, cob->matrix);
1325
1248
                
1326
1249
                /* get scaling of object before applying constraint */
1330
1253
                mul_serie_m4(cob->matrix, ct->matrix, obmat, NULL, NULL, NULL, NULL, NULL, NULL);
1331
1254
                
1332
1255
                /* un-apply scaling caused by path */
1333
 
                if ((data->followflag & FOLLOWPATH_RADIUS)==0) { /* XXX - assume that scale correction means that radius will have some scale error in it - Campbell */
 
1256
                if ((data->followflag & FOLLOWPATH_RADIUS) == 0) { /* XXX - assume that scale correction means that radius will have some scale error in it - Campbell */
1334
1257
                        float obsize[3];
1335
1258
                        
1336
 
                        mat4_to_size( obsize,cob->matrix);
 
1259
                        mat4_to_size(obsize, cob->matrix);
1337
1260
                        if (obsize[0])
1338
1261
                                mul_v3_fl(cob->matrix[0], size[0] / obsize[0]);
1339
1262
                        if (obsize[1])
1350
1273
        "Follow Path", /* name */
1351
1274
        "bFollowPathConstraint", /* struct name */
1352
1275
        NULL, /* free data */
1353
 
        NULL, /* relink data */
1354
1276
        followpath_id_looper, /* id looper */
1355
1277
        NULL, /* copy data */
1356
1278
        followpath_new_data, /* new data */
1363
1285
/* --------- Limit Location --------- */
1364
1286
 
1365
1287
 
1366
 
static void loclimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
 
1288
static void loclimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
1367
1289
{
1368
1290
        bLocLimitConstraint *data = con->data;
1369
1291
        
1399
1321
        "Limit Location", /* name */
1400
1322
        "bLocLimitConstraint", /* struct name */
1401
1323
        NULL, /* free data */
1402
 
        NULL, /* relink data */
1403
1324
        NULL, /* id looper */
1404
1325
        NULL, /* copy data */
1405
1326
        NULL, /* new data */
1411
1332
 
1412
1333
/* -------- Limit Rotation --------- */
1413
1334
 
1414
 
static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
 
1335
static void rotlimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
1415
1336
{
1416
1337
        bRotLimitConstraint *data = con->data;
1417
1338
        float loc[3];
1457
1378
        "Limit Rotation", /* name */
1458
1379
        "bRotLimitConstraint", /* struct name */
1459
1380
        NULL, /* free data */
1460
 
        NULL, /* relink data */
1461
1381
        NULL, /* id looper */
1462
1382
        NULL, /* copy data */
1463
1383
        NULL, /* new data */
1467
1387
        rotlimit_evaluate /* evaluate */
1468
1388
};
1469
1389
 
1470
 
/* --------- Limit Scaling --------- */
1471
 
 
1472
 
 
1473
 
static void sizelimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
 
1390
/* --------- Limit Scale --------- */
 
1391
 
 
1392
 
 
1393
static void sizelimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
1474
1394
{
1475
1395
        bSizeLimitConstraint *data = con->data;
1476
1396
        float obsize[3], size[3];
1477
1397
        
1478
 
        mat4_to_size( size,cob->matrix);
1479
 
        mat4_to_size( obsize,cob->matrix);
 
1398
        mat4_to_size(size, cob->matrix);
 
1399
        mat4_to_size(obsize, cob->matrix);
1480
1400
        
1481
1401
        if (data->flag & LIMIT_XMIN) {
1482
1402
                if (size[0] < data->xmin) 
1483
 
                        size[0] = data->xmin;   
 
1403
                        size[0] = data->xmin;
1484
1404
        }
1485
1405
        if (data->flag & LIMIT_XMAX) {
1486
1406
                if (size[0] > data->xmax) 
1488
1408
        }
1489
1409
        if (data->flag & LIMIT_YMIN) {
1490
1410
                if (size[1] < data->ymin) 
1491
 
                        size[1] = data->ymin;   
 
1411
                        size[1] = data->ymin;
1492
1412
        }
1493
1413
        if (data->flag & LIMIT_YMAX) {
1494
1414
                if (size[1] > data->ymax) 
1496
1416
        }
1497
1417
        if (data->flag & LIMIT_ZMIN) {
1498
1418
                if (size[2] < data->zmin) 
1499
 
                        size[2] = data->zmin;   
 
1419
                        size[2] = data->zmin;
1500
1420
        }
1501
1421
        if (data->flag & LIMIT_ZMAX) {
1502
1422
                if (size[2] > data->zmax) 
1504
1424
        }
1505
1425
        
1506
1426
        if (obsize[0]) 
1507
 
                mul_v3_fl(cob->matrix[0], size[0]/obsize[0]);
 
1427
                mul_v3_fl(cob->matrix[0], size[0] / obsize[0]);
1508
1428
        if (obsize[1]) 
1509
 
                mul_v3_fl(cob->matrix[1], size[1]/obsize[1]);
 
1429
                mul_v3_fl(cob->matrix[1], size[1] / obsize[1]);
1510
1430
        if (obsize[2]) 
1511
 
                mul_v3_fl(cob->matrix[2], size[2]/obsize[2]);
 
1431
                mul_v3_fl(cob->matrix[2], size[2] / obsize[2]);
1512
1432
}
1513
1433
 
1514
1434
static bConstraintTypeInfo CTI_SIZELIMIT = {
1515
1435
        CONSTRAINT_TYPE_SIZELIMIT, /* type */
1516
1436
        sizeof(bSizeLimitConstraint), /* size */
1517
 
        "Limit Scaling", /* name */
 
1437
        "Limit Scale", /* name */
1518
1438
        "bSizeLimitConstraint", /* struct name */
1519
1439
        NULL, /* free data */
1520
 
        NULL, /* relink data */
1521
1440
        NULL, /* id looper */
1522
1441
        NULL, /* copy data */
1523
1442
        NULL, /* new data */
1529
1448
 
1530
1449
/* ----------- Copy Location ------------- */
1531
1450
 
1532
 
static void loclike_new_data (void *cdata)
 
1451
static void loclike_new_data(void *cdata)
1533
1452
{
1534
 
        bLocateLikeConstraint *data= (bLocateLikeConstraint *)cdata;
 
1453
        bLocateLikeConstraint *data = (bLocateLikeConstraint *)cdata;
1535
1454
        
1536
 
        data->flag = LOCLIKE_X|LOCLIKE_Y|LOCLIKE_Z;
 
1455
        data->flag = LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z;
1537
1456
}
1538
1457
 
1539
 
static void loclike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1458
static void loclike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
1540
1459
{
1541
 
        bLocateLikeConstraint *data= con->data;
 
1460
        bLocateLikeConstraint *data = con->data;
1542
1461
        
1543
1462
        /* target only */
1544
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
1463
        func(con, (ID **)&data->tar, FALSE, userdata);
1545
1464
}
1546
1465
 
1547
 
static int loclike_get_tars (bConstraint *con, ListBase *list)
 
1466
static int loclike_get_tars(bConstraint *con, ListBase *list)
1548
1467
{
1549
1468
        if (con && list) {
1550
 
                bLocateLikeConstraint *data= con->data;
 
1469
                bLocateLikeConstraint *data = con->data;
1551
1470
                bConstraintTarget *ct;
1552
1471
                
1553
1472
                /* standard target-getting macro for single-target constraints */
1554
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
1473
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
1555
1474
                
1556
1475
                return 1;
1557
1476
        }
1559
1478
        return 0;
1560
1479
}
1561
1480
 
1562
 
static void loclike_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
1481
static void loclike_flush_tars(bConstraint *con, ListBase *list, short nocopy)
1563
1482
{
1564
1483
        if (con && list) {
1565
 
                bLocateLikeConstraint *data= con->data;
1566
 
                bConstraintTarget *ct= list->first;
 
1484
                bLocateLikeConstraint *data = con->data;
 
1485
                bConstraintTarget *ct = list->first;
1567
1486
                
1568
1487
                /* the following macro is used for all standard single-target constraints */
1569
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
1488
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
1570
1489
        }
1571
1490
}
1572
1491
 
1573
 
static void loclike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
1492
static void loclike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
1574
1493
{
1575
 
        bLocateLikeConstraint *data= con->data;
1576
 
        bConstraintTarget *ct= targets->first;
 
1494
        bLocateLikeConstraint *data = con->data;
 
1495
        bConstraintTarget *ct = targets->first;
1577
1496
        
1578
1497
        if (VALID_CONS_TARGET(ct)) {
1579
1498
                float offset[3] = {0.0f, 0.0f, 0.0f};
1608
1527
        "Copy Location", /* name */
1609
1528
        "bLocateLikeConstraint", /* struct name */
1610
1529
        NULL, /* free data */
1611
 
        NULL, /* relink data */
1612
1530
        loclike_id_looper, /* id looper */
1613
1531
        NULL, /* copy data */
1614
1532
        loclike_new_data, /* new data */
1620
1538
 
1621
1539
/* ----------- Copy Rotation ------------- */
1622
1540
 
1623
 
static void rotlike_new_data (void *cdata)
 
1541
static void rotlike_new_data(void *cdata)
1624
1542
{
1625
 
        bRotateLikeConstraint *data= (bRotateLikeConstraint *)cdata;
 
1543
        bRotateLikeConstraint *data = (bRotateLikeConstraint *)cdata;
1626
1544
        
1627
 
        data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
 
1545
        data->flag = ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z;
1628
1546
}
1629
1547
 
1630
 
static void rotlike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1548
static void rotlike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
1631
1549
{
1632
 
        bChildOfConstraint *data= con->data;
 
1550
        bRotateLikeConstraint *data = con->data;
1633
1551
        
1634
1552
        /* target only */
1635
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
1553
        func(con, (ID **)&data->tar, FALSE, userdata);
1636
1554
}
1637
1555
 
1638
 
static int rotlike_get_tars (bConstraint *con, ListBase *list)
 
1556
static int rotlike_get_tars(bConstraint *con, ListBase *list)
1639
1557
{
1640
1558
        if (con && list) {
1641
 
                bRotateLikeConstraint *data= con->data;
 
1559
                bRotateLikeConstraint *data = con->data;
1642
1560
                bConstraintTarget *ct;
1643
1561
                
1644
1562
                /* standard target-getting macro for single-target constraints */
1645
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
1563
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
1646
1564
                
1647
1565
                return 1;
1648
1566
        }
1650
1568
        return 0;
1651
1569
}
1652
1570
 
1653
 
static void rotlike_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
1571
static void rotlike_flush_tars(bConstraint *con, ListBase *list, short nocopy)
1654
1572
{
1655
1573
        if (con && list) {
1656
 
                bRotateLikeConstraint *data= con->data;
1657
 
                bConstraintTarget *ct= list->first;
 
1574
                bRotateLikeConstraint *data = con->data;
 
1575
                bConstraintTarget *ct = list->first;
1658
1576
                
1659
1577
                /* the following macro is used for all standard single-target constraints */
1660
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
1578
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
1661
1579
        }
1662
1580
}
1663
1581
 
1664
 
static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
1582
static void rotlike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
1665
1583
{
1666
 
        bRotateLikeConstraint *data= con->data;
1667
 
        bConstraintTarget *ct= targets->first;
 
1584
        bRotateLikeConstraint *data = con->data;
 
1585
        bConstraintTarget *ct = targets->first;
1668
1586
        
1669
1587
        if (VALID_CONS_TARGET(ct)) {
1670
 
                float   loc[3];
1671
 
                float   eul[3], obeul[3];
1672
 
                float   size[3];
 
1588
                float loc[3];
 
1589
                float eul[3], obeul[3];
 
1590
                float size[3];
1673
1591
                
1674
1592
                copy_v3_v3(loc, cob->matrix[3]);
1675
1593
                mat4_to_size(size, cob->matrix);
1679
1597
                /* we must get compatible eulers from the beginning because some of them can be modified below (see bug #21875) */
1680
1598
                mat4_to_compatible_eulO(eul, obeul, cob->rotOrder, ct->matrix);
1681
1599
                
1682
 
                if ((data->flag & ROTLIKE_X)==0)
 
1600
                if ((data->flag & ROTLIKE_X) == 0)
1683
1601
                        eul[0] = obeul[0];
1684
1602
                else {
1685
1603
                        if (data->flag & ROTLIKE_OFFSET)
1689
1607
                                eul[0] *= -1;
1690
1608
                }
1691
1609
                
1692
 
                if ((data->flag & ROTLIKE_Y)==0)
 
1610
                if ((data->flag & ROTLIKE_Y) == 0)
1693
1611
                        eul[1] = obeul[1];
1694
1612
                else {
1695
1613
                        if (data->flag & ROTLIKE_OFFSET)
1699
1617
                                eul[1] *= -1;
1700
1618
                }
1701
1619
                
1702
 
                if ((data->flag & ROTLIKE_Z)==0)
 
1620
                if ((data->flag & ROTLIKE_Z) == 0)
1703
1621
                        eul[2] = obeul[2];
1704
1622
                else {
1705
1623
                        if (data->flag & ROTLIKE_OFFSET)
1721
1639
        "Copy Rotation", /* name */
1722
1640
        "bRotateLikeConstraint", /* struct name */
1723
1641
        NULL, /* free data */
1724
 
        NULL, /* relink data */
1725
1642
        rotlike_id_looper, /* id looper */
1726
1643
        NULL, /* copy data */
1727
1644
        rotlike_new_data, /* new data */
1731
1648
        rotlike_evaluate /* evaluate */
1732
1649
};
1733
1650
 
1734
 
/* ---------- Copy Scaling ---------- */
 
1651
/* ---------- Copy Scale ---------- */
1735
1652
 
1736
 
static void sizelike_new_data (void *cdata)
 
1653
static void sizelike_new_data(void *cdata)
1737
1654
{
1738
 
        bSizeLikeConstraint *data= (bSizeLikeConstraint *)cdata;
 
1655
        bSizeLikeConstraint *data = (bSizeLikeConstraint *)cdata;
1739
1656
        
1740
 
        data->flag = SIZELIKE_X|SIZELIKE_Y|SIZELIKE_Z;
 
1657
        data->flag = SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z;
1741
1658
}
1742
1659
 
1743
 
static void sizelike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1660
static void sizelike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
1744
1661
{
1745
 
        bSizeLikeConstraint *data= con->data;
 
1662
        bSizeLikeConstraint *data = con->data;
1746
1663
        
1747
1664
        /* target only */
1748
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
1665
        func(con, (ID **)&data->tar, FALSE, userdata);
1749
1666
}
1750
1667
 
1751
 
static int sizelike_get_tars (bConstraint *con, ListBase *list)
 
1668
static int sizelike_get_tars(bConstraint *con, ListBase *list)
1752
1669
{
1753
1670
        if (con && list) {
1754
 
                bSizeLikeConstraint *data= con->data;
 
1671
                bSizeLikeConstraint *data = con->data;
1755
1672
                bConstraintTarget *ct;
1756
1673
                
1757
1674
                /* standard target-getting macro for single-target constraints */
1758
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
1675
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
1759
1676
                
1760
1677
                return 1;
1761
1678
        }
1763
1680
        return 0;
1764
1681
}
1765
1682
 
1766
 
static void sizelike_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
1683
static void sizelike_flush_tars(bConstraint *con, ListBase *list, short nocopy)
1767
1684
{
1768
1685
        if (con && list) {
1769
 
                bSizeLikeConstraint *data= con->data;
1770
 
                bConstraintTarget *ct= list->first;
 
1686
                bSizeLikeConstraint *data = con->data;
 
1687
                bConstraintTarget *ct = list->first;
1771
1688
                
1772
1689
                /* the following macro is used for all standard single-target constraints */
1773
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
1690
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
1774
1691
        }
1775
1692
}
1776
1693
 
1777
 
static void sizelike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
1694
static void sizelike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
1778
1695
{
1779
 
        bSizeLikeConstraint *data= con->data;
1780
 
        bConstraintTarget *ct= targets->first;
 
1696
        bSizeLikeConstraint *data = con->data;
 
1697
        bConstraintTarget *ct = targets->first;
1781
1698
        
1782
1699
        if (VALID_CONS_TARGET(ct)) {
1783
1700
                float obsize[3], size[3];
1818
1735
        "Copy Scale", /* name */
1819
1736
        "bSizeLikeConstraint", /* struct name */
1820
1737
        NULL, /* free data */
1821
 
        NULL, /* relink data */
1822
1738
        sizelike_id_looper, /* id looper */
1823
1739
        NULL, /* copy data */
1824
1740
        sizelike_new_data, /* new data */
1830
1746
 
1831
1747
/* ----------- Copy Transforms ------------- */
1832
1748
 
1833
 
static void translike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1749
static void translike_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
1834
1750
{
1835
 
        bTransLikeConstraint *data= con->data;
 
1751
        bTransLikeConstraint *data = con->data;
1836
1752
        
1837
1753
        /* target only */
1838
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
1754
        func(con, (ID **)&data->tar, FALSE, userdata);
1839
1755
}
1840
1756
 
1841
 
static int translike_get_tars (bConstraint *con, ListBase *list)
 
1757
static int translike_get_tars(bConstraint *con, ListBase *list)
1842
1758
{
1843
1759
        if (con && list) {
1844
 
                bTransLikeConstraint *data= con->data;
 
1760
                bTransLikeConstraint *data = con->data;
1845
1761
                bConstraintTarget *ct;
1846
1762
                
1847
1763
                /* standard target-getting macro for single-target constraints */
1848
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
1764
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
1849
1765
                
1850
1766
                return 1;
1851
1767
        }
1853
1769
        return 0;
1854
1770
}
1855
1771
 
1856
 
static void translike_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
1772
static void translike_flush_tars(bConstraint *con, ListBase *list, short nocopy)
1857
1773
{
1858
1774
        if (con && list) {
1859
 
                bTransLikeConstraint *data= con->data;
1860
 
                bConstraintTarget *ct= list->first;
 
1775
                bTransLikeConstraint *data = con->data;
 
1776
                bConstraintTarget *ct = list->first;
1861
1777
                
1862
1778
                /* the following macro is used for all standard single-target constraints */
1863
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
1779
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
1864
1780
        }
1865
1781
}
1866
1782
 
1867
 
static void translike_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
 
1783
static void translike_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
1868
1784
{
1869
 
        bConstraintTarget *ct= targets->first;
 
1785
        bConstraintTarget *ct = targets->first;
1870
1786
        
1871
1787
        if (VALID_CONS_TARGET(ct)) {
1872
1788
                /* just copy the entire transform matrix of the target */
1880
1796
        "Copy Transforms", /* name */
1881
1797
        "bTransLikeConstraint", /* struct name */
1882
1798
        NULL, /* free data */
1883
 
        NULL, /* relink data */
1884
1799
        translike_id_looper, /* id looper */
1885
1800
        NULL, /* copy data */
1886
1801
        NULL, /* new data */
1892
1807
 
1893
1808
/* ---------- Maintain Volume ---------- */
1894
1809
 
1895
 
static void samevolume_new_data (void *cdata)
 
1810
static void samevolume_new_data(void *cdata)
1896
1811
{
1897
 
        bSameVolumeConstraint *data= (bSameVolumeConstraint *)cdata;
 
1812
        bSameVolumeConstraint *data = (bSameVolumeConstraint *)cdata;
1898
1813
 
1899
1814
        data->flag = SAMEVOL_Y;
1900
1815
        data->volume = 1.0f;
1901
1816
}
1902
1817
 
1903
 
static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
 
1818
static void samevolume_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
1904
1819
{
1905
 
        bSameVolumeConstraint *data= con->data;
 
1820
        bSameVolumeConstraint *data = con->data;
1906
1821
 
1907
1822
        float volume = data->volume;
1908
1823
        float fac = 1.0f;
1937
1852
        "Maintain Volume", /* name */
1938
1853
        "bSameVolumeConstraint", /* struct name */
1939
1854
        NULL, /* free data */
1940
 
        NULL, /* relink data */
1941
1855
        NULL, /* id looper */
1942
1856
        NULL, /* copy data */
1943
1857
        samevolume_new_data, /* new data */
1949
1863
 
1950
1864
/* ----------- Python Constraint -------------- */
1951
1865
 
1952
 
static void pycon_free (bConstraint *con)
 
1866
static void pycon_free(bConstraint *con)
1953
1867
{
1954
 
        bPythonConstraint *data= con->data;
 
1868
        bPythonConstraint *data = con->data;
1955
1869
        
1956
1870
        /* id-properties */
1957
1871
        IDP_FreeProperty(data->prop);
1961
1875
        BLI_freelistN(&data->targets);
1962
1876
}       
1963
1877
 
1964
 
static void pycon_relink (bConstraint *con)
1965
 
{
1966
 
        bPythonConstraint *data= con->data;
1967
 
        
1968
 
        ID_NEW(data->text);
1969
 
}
1970
 
 
1971
 
static void pycon_copy (bConstraint *con, bConstraint *srccon)
 
1878
static void pycon_copy(bConstraint *con, bConstraint *srccon)
1972
1879
{
1973
1880
        bPythonConstraint *pycon = (bPythonConstraint *)con->data;
1974
1881
        bPythonConstraint *opycon = (bPythonConstraint *)srccon->data;
1977
1884
        BLI_duplicatelist(&pycon->targets, &opycon->targets);
1978
1885
}
1979
1886
 
1980
 
static void pycon_new_data (void *cdata)
 
1887
static void pycon_new_data(void *cdata)
1981
1888
{
1982
 
        bPythonConstraint *data= (bPythonConstraint *)cdata;
 
1889
        bPythonConstraint *data = (bPythonConstraint *)cdata;
1983
1890
        
1984
1891
        /* everything should be set correctly by calloc, except for the prop->type constant.*/
1985
1892
        data->prop = MEM_callocN(sizeof(IDProperty), "PyConstraintProps");
1986
1893
        data->prop->type = IDP_GROUP;
1987
1894
}
1988
1895
 
1989
 
static int pycon_get_tars (bConstraint *con, ListBase *list)
 
1896
static int pycon_get_tars(bConstraint *con, ListBase *list)
1990
1897
{
1991
1898
        if (con && list) {
1992
 
                bPythonConstraint *data= con->data;
 
1899
                bPythonConstraint *data = con->data;
1993
1900
                
1994
1901
                list->first = data->targets.first;
1995
1902
                list->last = data->targets.last;
2000
1907
        return 0;
2001
1908
}
2002
1909
 
2003
 
static void pycon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
1910
static void pycon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
2004
1911
{
2005
 
        bPythonConstraint *data= con->data;
 
1912
        bPythonConstraint *data = con->data;
2006
1913
        bConstraintTarget *ct;
2007
1914
        
2008
1915
        /* targets */
2009
 
        for (ct= data->targets.first; ct; ct= ct->next)
2010
 
                func(con, (ID**)&ct->tar, FALSE, userdata);
 
1916
        for (ct = data->targets.first; ct; ct = ct->next)
 
1917
                func(con, (ID **)&ct->tar, FALSE, userdata);
2011
1918
                
2012
1919
        /* script */
2013
 
        func(con, (ID**)&data->text, TRUE, userdata);
 
1920
        func(con, (ID **)&data->text, TRUE, userdata);
2014
1921
}
2015
1922
 
2016
1923
/* Whether this approach is maintained remains to be seen (aligorith) */
2017
 
static void pycon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
1924
static void pycon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
2018
1925
{
2019
1926
#ifdef WITH_PYTHON
2020
 
        bPythonConstraint *data= con->data;
 
1927
        bPythonConstraint *data = con->data;
2021
1928
#endif
2022
1929
 
2023
1930
        if (VALID_CONS_TARGET(ct)) {
2024
1931
                /* special exception for curves - depsgraph issues */
2025
1932
                if (ct->tar->type == OB_CURVE) {
2026
 
                        Curve *cu= ct->tar->data;
 
1933
                        Curve *cu = ct->tar->data;
2027
1934
                        
2028
1935
                        /* this check is to make sure curve objects get updated on file load correctly.*/
2029
 
                        if (cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */
2030
 
                                makeDispListCurveTypes(cob->scene, ct->tar, 0);                         
 
1936
                        if (cu->path == NULL || cu->path->data == NULL) /* only happens on reload file, but violates depsgraph still... fix! */
 
1937
                                BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
2031
1938
                }
2032
1939
                
2033
1940
                /* firstly calculate the matrix the normal way, then let the py-function override
2045
1952
                unit_m4(ct->matrix);
2046
1953
}
2047
1954
 
2048
 
static void pycon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
1955
static void pycon_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
2049
1956
{
2050
1957
#ifndef WITH_PYTHON
2051
1958
        (void)con; (void)cob; (void)targets; /* unused */
2052
1959
        return;
2053
1960
#else
2054
 
        bPythonConstraint *data= con->data;
 
1961
        bPythonConstraint *data = con->data;
2055
1962
        
2056
1963
        /* only evaluate in python if we're allowed to do so */
2057
 
        if ((G.f & G_SCRIPT_AUTOEXEC)==0)  return;
 
1964
        if ((G.f & G_SCRIPT_AUTOEXEC) == 0) return;
2058
1965
        
2059
1966
/* currently removed, until I this can be re-implemented for multiple targets */
2060
1967
#if 0
2076
1983
        "Script", /* name */
2077
1984
        "bPythonConstraint", /* struct name */
2078
1985
        pycon_free, /* free data */
2079
 
        pycon_relink, /* relink data */
2080
1986
        pycon_id_looper, /* id looper */
2081
1987
        pycon_copy, /* copy data */
2082
1988
        pycon_new_data, /* new data */
2088
1994
 
2089
1995
/* -------- Action Constraint ----------- */
2090
1996
 
2091
 
static void actcon_relink (bConstraint *con)
2092
 
{
2093
 
        bActionConstraint *data= con->data;
2094
 
        ID_NEW(data->act);
2095
 
}
2096
 
 
2097
 
static void actcon_new_data (void *cdata)
2098
 
{
2099
 
        bActionConstraint *data= (bActionConstraint *)cdata;
 
1997
static void actcon_new_data(void *cdata)
 
1998
{
 
1999
        bActionConstraint *data = (bActionConstraint *)cdata;
2100
2000
        
2101
2001
        /* set type to 20 (Loc X), as 0 is Rot X for backwards compatibility */
2102
2002
        data->type = 20;
2103
2003
}
2104
2004
 
2105
 
static void actcon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2005
static void actcon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
2106
2006
{
2107
 
        bActionConstraint *data= con->data;
 
2007
        bActionConstraint *data = con->data;
2108
2008
        
2109
2009
        /* target */
2110
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
2010
        func(con, (ID **)&data->tar, FALSE, userdata);
2111
2011
        
2112
2012
        /* action */
2113
 
        func(con, (ID**)&data->act, TRUE, userdata);
 
2013
        func(con, (ID **)&data->act, TRUE, userdata);
2114
2014
}
2115
2015
 
2116
 
static int actcon_get_tars (bConstraint *con, ListBase *list)
 
2016
static int actcon_get_tars(bConstraint *con, ListBase *list)
2117
2017
{
2118
2018
        if (con && list) {
2119
 
                bActionConstraint *data= con->data;
 
2019
                bActionConstraint *data = con->data;
2120
2020
                bConstraintTarget *ct;
2121
2021
                
2122
2022
                /* standard target-getting macro for single-target constraints */
2123
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
2023
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
2124
2024
                
2125
2025
                return 1;
2126
2026
        }
2128
2028
        return 0;
2129
2029
}
2130
2030
 
2131
 
static void actcon_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2031
static void actcon_flush_tars(bConstraint *con, ListBase *list, short nocopy)
2132
2032
{
2133
2033
        if (con && list) {
2134
 
                bActionConstraint *data= con->data;
2135
 
                bConstraintTarget *ct= list->first;
 
2034
                bActionConstraint *data = con->data;
 
2035
                bConstraintTarget *ct = list->first;
2136
2036
                
2137
2037
                /* the following macro is used for all standard single-target constraints */
2138
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
2038
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
2139
2039
        }
2140
2040
}
2141
2041
 
2142
 
static void actcon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
2042
static void actcon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
2143
2043
{
2144
2044
        bActionConstraint *data = con->data;
2145
2045
        
2157
2057
                /* determine where in transform range target is */
2158
2058
                /* data->type is mapped as follows for backwards compatibility:
2159
2059
                 *      00,01,02        - rotation (it used to be like this)
2160
 
                 *      10,11,12        - scaling
 
2060
                 *  10,11,12    - scaling
2161
2061
                 *      20,21,22        - location
2162
2062
                 */
2163
2063
                if (data->type < 10) {
2164
2064
                        /* extract rotation (is in whatever space target should be in) */
2165
2065
                        mat4_to_eul(vec, tempmat);
2166
2066
                        mul_v3_fl(vec, RAD2DEGF(1.0f)); /* rad -> deg */
2167
 
                        axis= data->type;
 
2067
                        axis = data->type;
2168
2068
                }
2169
2069
                else if (data->type < 20) {
2170
2070
                        /* extract scaling (is in whatever space target should be in) */
2171
2071
                        mat4_to_size(vec, tempmat);
2172
 
                        axis= data->type - 10;
 
2072
                        axis = data->type - 10;
2173
2073
                }
2174
2074
                else {
2175
2075
                        /* extract location */
2176
2076
                        copy_v3_v3(vec, tempmat[3]);
2177
 
                        axis= data->type - 20;
 
2077
                        axis = data->type - 20;
2178
2078
                }
2179
2079
                
2180
2080
                /* Target defines the animation */
2181
 
                s = (vec[axis]-data->min) / (data->max-data->min);
 
2081
                s = (vec[axis] - data->min) / (data->max - data->min);
2182
2082
                CLAMP(s, 0, 1);
2183
 
                t = (s * (data->end-data->start)) + data->start;
 
2083
                t = (s * (data->end - data->start)) + data->start;
2184
2084
                
2185
2085
                if (G.debug & G_DEBUG)
2186
 
                        printf("do Action Constraint %s - Ob %s Pchan %s\n", con->name, cob->ob->id.name+2, (cob->pchan)?cob->pchan->name:NULL);
 
2086
                        printf("do Action Constraint %s - Ob %s Pchan %s\n", con->name, cob->ob->id.name + 2, (cob->pchan) ? cob->pchan->name : NULL);
2187
2087
                
2188
2088
                /* Get the appropriate information from the action */
2189
 
                if (cob->type == CONSTRAINT_OBTYPE_BONE) {
 
2089
                if (cob->type == CONSTRAINT_OBTYPE_OBJECT || (data->flag & ACTCON_BONE_USE_OBJECT_ACTION)) {
 
2090
                        Object workob;
 
2091
                        
 
2092
                        /* evaluate using workob */
 
2093
                        /* FIXME: we don't have any consistent standards on limiting effects on object... */
 
2094
                        what_does_obaction(cob->ob, &workob, NULL, data->act, NULL, t);
 
2095
                        BKE_object_to_mat4(&workob, ct->matrix);
 
2096
                }
 
2097
                else if (cob->type == CONSTRAINT_OBTYPE_BONE) {
2190
2098
                        Object workob;
2191
2099
                        bPose *pose;
2192
2100
                        bPoseChannel *pchan, *tchan;
2199
2107
                         */
2200
2108
                        pchan = cob->pchan;
2201
2109
                        
2202
 
                        tchan= verify_pose_channel(pose, pchan->name);
2203
 
                        tchan->rotmode= pchan->rotmode;
 
2110
                        tchan = BKE_pose_channel_verify(pose, pchan->name);
 
2111
                        tchan->rotmode = pchan->rotmode;
2204
2112
                        
2205
2113
                        /* evaluate action using workob (it will only set the PoseChannel in question) */
2206
2114
                        what_does_obaction(cob->ob, &workob, pose, data->act, pchan->name, t);
2207
2115
                        
2208
2116
                        /* convert animation to matrices for use here */
2209
 
                        pchan_calc_mat(tchan);
 
2117
                        BKE_pchan_calc_mat(tchan);
2210
2118
                        copy_m4_m4(ct->matrix, tchan->chan_mat);
2211
2119
                        
2212
2120
                        /* Clean up */
2213
 
                        free_pose(pose);
2214
 
                }
2215
 
                else if (cob->type == CONSTRAINT_OBTYPE_OBJECT) {
2216
 
                        Object workob;
2217
 
                        
2218
 
                        /* evaluate using workob */
2219
 
                        // FIXME: we don't have any consistent standards on limiting effects on object...
2220
 
                        what_does_obaction(cob->ob, &workob, NULL, data->act, NULL, t);
2221
 
                        object_to_mat4(&workob, ct->matrix);
 
2121
                        BKE_pose_free(pose);
2222
2122
                }
2223
2123
                else {
2224
2124
                        /* behavior undefined... */
2227
2127
        }
2228
2128
}
2229
2129
 
2230
 
static void actcon_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
 
2130
static void actcon_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
2231
2131
{
2232
 
        bConstraintTarget *ct= targets->first;
 
2132
        bConstraintTarget *ct = targets->first;
2233
2133
        
2234
2134
        if (VALID_CONS_TARGET(ct)) {
2235
2135
                float temp[4][4];
2248
2148
        "Action", /* name */
2249
2149
        "bActionConstraint", /* struct name */
2250
2150
        NULL, /* free data */
2251
 
        actcon_relink, /* relink data */
2252
2151
        actcon_id_looper, /* id looper */
2253
2152
        NULL, /* copy data */
2254
2153
        actcon_new_data, /* new data */
2260
2159
 
2261
2160
/* --------- Locked Track ---------- */
2262
2161
 
2263
 
static void locktrack_new_data (void *cdata)
 
2162
static void locktrack_new_data(void *cdata)
2264
2163
{
2265
 
        bLockTrackConstraint *data= (bLockTrackConstraint *)cdata;
 
2164
        bLockTrackConstraint *data = (bLockTrackConstraint *)cdata;
2266
2165
        
2267
2166
        data->trackflag = TRACK_Y;
2268
2167
        data->lockflag = LOCK_Z;
2269
2168
}       
2270
2169
 
2271
 
static void locktrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2170
static void locktrack_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
2272
2171
{
2273
 
        bLockTrackConstraint *data= con->data;
 
2172
        bLockTrackConstraint *data = con->data;
2274
2173
        
2275
2174
        /* target only */
2276
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
2175
        func(con, (ID **)&data->tar, FALSE, userdata);
2277
2176
}
2278
2177
 
2279
 
static int locktrack_get_tars (bConstraint *con, ListBase *list)
 
2178
static int locktrack_get_tars(bConstraint *con, ListBase *list)
2280
2179
{
2281
2180
        if (con && list) {
2282
 
                bLockTrackConstraint *data= con->data;
 
2181
                bLockTrackConstraint *data = con->data;
2283
2182
                bConstraintTarget *ct;
2284
2183
                
2285
2184
                /* the following macro is used for all standard single-target constraints */
2286
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
2185
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
2287
2186
                
2288
2187
                return 1;
2289
2188
        }
2291
2190
        return 0;
2292
2191
}
2293
2192
 
2294
 
static void locktrack_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2193
static void locktrack_flush_tars(bConstraint *con, ListBase *list, short nocopy)
2295
2194
{
2296
2195
        if (con && list) {
2297
 
                bLockTrackConstraint *data= con->data;
2298
 
                bConstraintTarget *ct= list->first;
 
2196
                bLockTrackConstraint *data = con->data;
 
2197
                bConstraintTarget *ct = list->first;
2299
2198
                
2300
2199
                /* the following macro is used for all standard single-target constraints */
2301
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
2200
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
2302
2201
        }
2303
2202
}
2304
2203
 
2305
 
static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
2204
static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
2306
2205
{
2307
 
        bLockTrackConstraint *data= con->data;
2308
 
        bConstraintTarget *ct= targets->first;
 
2206
        bLockTrackConstraint *data = con->data;
 
2207
        bConstraintTarget *ct = targets->first;
2309
2208
        
2310
2209
        if (VALID_CONS_TARGET(ct)) {
2311
 
                float vec[3],vec2[3];
 
2210
                float vec[3], vec2[3];
2312
2211
                float totmat[3][3];
2313
2212
                float tmpmat[3][3];
2314
2213
                float invmat[3][3];
2315
 
                float tmat[4][4];
2316
2214
                float mdet;
2317
2215
                
2318
2216
                /* Vector object -> target */
2319
2217
                sub_v3_v3v3(vec, ct->matrix[3], cob->matrix[3]);
2320
2218
                switch (data->lockflag) {
2321
 
                case LOCK_X: /* LOCK X */
2322
 
                {
2323
 
                        switch (data->trackflag) {
2324
 
                                case TRACK_Y: /* LOCK X TRACK Y */
2325
 
                                {
2326
 
                                        /* Projection of Vector on the plane */
2327
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[0]);
2328
 
                                        sub_v3_v3v3(totmat[1], vec, vec2);
2329
 
                                        normalize_v3(totmat[1]);
2330
 
                                        
2331
 
                                        /* the x axis is fixed */
2332
 
                                        normalize_v3_v3(totmat[0], cob->matrix[0]);
2333
 
                                        
2334
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2335
 
                                        cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2336
 
                                }
2337
 
                                        break;
2338
 
                                case TRACK_Z: /* LOCK X TRACK Z */
2339
 
                                {
2340
 
                                        /* Projection of Vector on the plane */
2341
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[0]);
2342
 
                                        sub_v3_v3v3(totmat[2], vec, vec2);
2343
 
                                        normalize_v3(totmat[2]);
2344
 
                                        
2345
 
                                        /* the x axis is fixed */
2346
 
                                        normalize_v3_v3(totmat[0], cob->matrix[0]);
2347
 
                                        
2348
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2349
 
                                        cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2350
 
                                }
2351
 
                                        break;
2352
 
                                case TRACK_nY: /* LOCK X TRACK -Y */
2353
 
                                {
2354
 
                                        /* Projection of Vector on the plane */
2355
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[0]);
2356
 
                                        sub_v3_v3v3(totmat[1], vec, vec2);
2357
 
                                        normalize_v3(totmat[1]);
2358
 
                                        negate_v3(totmat[1]);
2359
 
                                        
2360
 
                                        /* the x axis is fixed */
2361
 
                                        normalize_v3_v3(totmat[0], cob->matrix[0]);
2362
 
                                        
2363
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2364
 
                                        cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2365
 
                                }
2366
 
                                        break;
2367
 
                                case TRACK_nZ: /* LOCK X TRACK -Z */
2368
 
                                {
2369
 
                                        /* Projection of Vector on the plane */
2370
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[0]);
2371
 
                                        sub_v3_v3v3(totmat[2], vec, vec2);
2372
 
                                        normalize_v3(totmat[2]);
2373
 
                                        negate_v3(totmat[2]);
2374
 
                                                
2375
 
                                        /* the x axis is fixed */
2376
 
                                        normalize_v3_v3(totmat[0], cob->matrix[0]);
2377
 
                                                
2378
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2379
 
                                        cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2380
 
                                }
2381
 
                                        break;
2382
 
                                default:
2383
 
                                {
2384
 
                                        unit_m3(totmat);
2385
 
                                }
2386
 
                                        break;
 
2219
                        case LOCK_X: /* LOCK X */
 
2220
                        {
 
2221
                                switch (data->trackflag) {
 
2222
                                        case TRACK_Y: /* LOCK X TRACK Y */
 
2223
                                        {
 
2224
                                                /* Projection of Vector on the plane */
 
2225
                                                project_v3_v3v3(vec2, vec, cob->matrix[0]);
 
2226
                                                sub_v3_v3v3(totmat[1], vec, vec2);
 
2227
                                                normalize_v3(totmat[1]);
 
2228
                                        
 
2229
                                                /* the x axis is fixed */
 
2230
                                                normalize_v3_v3(totmat[0], cob->matrix[0]);
 
2231
                                        
 
2232
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2233
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
 
2234
                                        }
 
2235
                                        break;
 
2236
                                        case TRACK_Z: /* LOCK X TRACK Z */
 
2237
                                        {
 
2238
                                                /* Projection of Vector on the plane */
 
2239
                                                project_v3_v3v3(vec2, vec, cob->matrix[0]);
 
2240
                                                sub_v3_v3v3(totmat[2], vec, vec2);
 
2241
                                                normalize_v3(totmat[2]);
 
2242
                                        
 
2243
                                                /* the x axis is fixed */
 
2244
                                                normalize_v3_v3(totmat[0], cob->matrix[0]);
 
2245
                                        
 
2246
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2247
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
 
2248
                                        }
 
2249
                                        break;
 
2250
                                        case TRACK_nY: /* LOCK X TRACK -Y */
 
2251
                                        {
 
2252
                                                /* Projection of Vector on the plane */
 
2253
                                                project_v3_v3v3(vec2, vec, cob->matrix[0]);
 
2254
                                                sub_v3_v3v3(totmat[1], vec, vec2);
 
2255
                                                normalize_v3(totmat[1]);
 
2256
                                                negate_v3(totmat[1]);
 
2257
                                        
 
2258
                                                /* the x axis is fixed */
 
2259
                                                normalize_v3_v3(totmat[0], cob->matrix[0]);
 
2260
                                        
 
2261
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2262
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
 
2263
                                        }
 
2264
                                        break;
 
2265
                                        case TRACK_nZ: /* LOCK X TRACK -Z */
 
2266
                                        {
 
2267
                                                /* Projection of Vector on the plane */
 
2268
                                                project_v3_v3v3(vec2, vec, cob->matrix[0]);
 
2269
                                                sub_v3_v3v3(totmat[2], vec, vec2);
 
2270
                                                normalize_v3(totmat[2]);
 
2271
                                                negate_v3(totmat[2]);
 
2272
                                                
 
2273
                                                /* the x axis is fixed */
 
2274
                                                normalize_v3_v3(totmat[0], cob->matrix[0]);
 
2275
                                                
 
2276
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2277
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
 
2278
                                        }
 
2279
                                        break;
 
2280
                                        default:
 
2281
                                        {
 
2282
                                                unit_m3(totmat);
 
2283
                                        }
 
2284
                                        break;
 
2285
                                }
2387
2286
                        }
2388
 
                }
2389
2287
                        break;
2390
 
                case LOCK_Y: /* LOCK Y */
2391
 
                {
2392
 
                        switch (data->trackflag) {
2393
 
                                case TRACK_X: /* LOCK Y TRACK X */
2394
 
                                {
2395
 
                                        /* Projection of Vector on the plane */
2396
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[1]);
2397
 
                                        sub_v3_v3v3(totmat[0], vec, vec2);
2398
 
                                        normalize_v3(totmat[0]);
 
2288
                        case LOCK_Y: /* LOCK Y */
 
2289
                        {
 
2290
                                switch (data->trackflag) {
 
2291
                                        case TRACK_X: /* LOCK Y TRACK X */
 
2292
                                        {
 
2293
                                                /* Projection of Vector on the plane */
 
2294
                                                project_v3_v3v3(vec2, vec, cob->matrix[1]);
 
2295
                                                sub_v3_v3v3(totmat[0], vec, vec2);
 
2296
                                                normalize_v3(totmat[0]);
2399
2297
                                        
2400
 
                                        /* the y axis is fixed */
2401
 
                                        normalize_v3_v3(totmat[1], cob->matrix[1]);
 
2298
                                                /* the y axis is fixed */
 
2299
                                                normalize_v3_v3(totmat[1], cob->matrix[1]);
2402
2300
 
2403
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2404
 
                                        cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2405
 
                                }
2406
 
                                        break;
2407
 
                                case TRACK_Z: /* LOCK Y TRACK Z */
2408
 
                                {
2409
 
                                        /* Projection of Vector on the plane */
2410
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[1]);
2411
 
                                        sub_v3_v3v3(totmat[2], vec, vec2);
2412
 
                                        normalize_v3(totmat[2]);
2413
 
                                        
2414
 
                                        /* the y axis is fixed */
2415
 
                                        normalize_v3_v3(totmat[1], cob->matrix[1]);
2416
 
                                        
2417
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2418
 
                                        cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2419
 
                                }
2420
 
                                        break;
2421
 
                                case TRACK_nX: /* LOCK Y TRACK -X */
2422
 
                                {
2423
 
                                        /* Projection of Vector on the plane */
2424
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[1]);
2425
 
                                        sub_v3_v3v3(totmat[0], vec, vec2);
2426
 
                                        normalize_v3(totmat[0]);
2427
 
                                        negate_v3(totmat[0]);
2428
 
                                        
2429
 
                                        /* the y axis is fixed */
2430
 
                                        normalize_v3_v3(totmat[1], cob->matrix[1]);
2431
 
                                        
2432
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2433
 
                                        cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2434
 
                                }
2435
 
                                        break;
2436
 
                                case TRACK_nZ: /* LOCK Y TRACK -Z */
2437
 
                                {
2438
 
                                        /* Projection of Vector on the plane */
2439
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[1]);
2440
 
                                        sub_v3_v3v3(totmat[2], vec, vec2);
2441
 
                                        normalize_v3(totmat[2]);
2442
 
                                        negate_v3(totmat[2]);
2443
 
                                        
2444
 
                                        /* the y axis is fixed */
2445
 
                                        normalize_v3_v3(totmat[1], cob->matrix[1]);
2446
 
                                        
2447
 
                                        /* the z axis gets mapped onto a third orthogonal vector */
2448
 
                                        cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2449
 
                                }
2450
 
                                        break;
2451
 
                                default:
2452
 
                                {
2453
 
                                        unit_m3(totmat);
2454
 
                                }
2455
 
                                        break;
2456
 
                        }
2457
 
                }
2458
 
                        break;
2459
 
                case LOCK_Z: /* LOCK Z */
2460
 
                {
2461
 
                        switch (data->trackflag) {
2462
 
                                case TRACK_X: /* LOCK Z TRACK X */
2463
 
                                {
2464
 
                                        /* Projection of Vector on the plane */
2465
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[2]);
2466
 
                                        sub_v3_v3v3(totmat[0], vec, vec2);
2467
 
                                        normalize_v3(totmat[0]);
2468
 
                                        
2469
 
                                        /* the z axis is fixed */
2470
 
                                        normalize_v3_v3(totmat[2], cob->matrix[2]);
2471
 
                                        
2472
 
                                        /* the x axis gets mapped onto a third orthogonal vector */
2473
 
                                        cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2474
 
                                }
2475
 
                                        break;
2476
 
                                case TRACK_Y: /* LOCK Z TRACK Y */
2477
 
                                {
2478
 
                                        /* Projection of Vector on the plane */
2479
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[2]);
2480
 
                                        sub_v3_v3v3(totmat[1], vec, vec2);
2481
 
                                        normalize_v3(totmat[1]);
2482
 
                                        
2483
 
                                        /* the z axis is fixed */
2484
 
                                        normalize_v3_v3(totmat[2], cob->matrix[2]);
2485
 
                                                
2486
 
                                        /* the x axis gets mapped onto a third orthogonal vector */
2487
 
                                        cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2488
 
                                }
2489
 
                                        break;
2490
 
                                case TRACK_nX: /* LOCK Z TRACK -X */
2491
 
                                {
2492
 
                                        /* Projection of Vector on the plane */
2493
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[2]);
2494
 
                                        sub_v3_v3v3(totmat[0], vec, vec2);
2495
 
                                        normalize_v3(totmat[0]);
2496
 
                                        negate_v3(totmat[0]);
2497
 
                                        
2498
 
                                        /* the z axis is fixed */
2499
 
                                        normalize_v3_v3(totmat[2], cob->matrix[2]);
2500
 
                                        
2501
 
                                        /* the x axis gets mapped onto a third orthogonal vector */
2502
 
                                        cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2503
 
                                }
2504
 
                                        break;
2505
 
                                case TRACK_nY: /* LOCK Z TRACK -Y */
2506
 
                                {
2507
 
                                        /* Projection of Vector on the plane */
2508
 
                                        project_v3_v3v3(vec2, vec, cob->matrix[2]);
2509
 
                                        sub_v3_v3v3(totmat[1], vec, vec2);
2510
 
                                        normalize_v3(totmat[1]);
2511
 
                                        negate_v3(totmat[1]);
2512
 
                                        
2513
 
                                        /* the z axis is fixed */
2514
 
                                        normalize_v3_v3(totmat[2], cob->matrix[2]);
2515
 
                                                
2516
 
                                        /* the x axis gets mapped onto a third orthogonal vector */
2517
 
                                        cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2518
 
                                }
2519
 
                                        break;
2520
 
                                default:
2521
 
                                {
2522
 
                                        unit_m3(totmat);
2523
 
                                }
2524
 
                                        break;
2525
 
                        }
2526
 
                }
2527
 
                        break;
2528
 
                default:
2529
 
                {
2530
 
                        unit_m3(totmat);
2531
 
                }
 
2301
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2302
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
 
2303
                                        }
 
2304
                                        break;
 
2305
                                        case TRACK_Z: /* LOCK Y TRACK Z */
 
2306
                                        {
 
2307
                                                /* Projection of Vector on the plane */
 
2308
                                                project_v3_v3v3(vec2, vec, cob->matrix[1]);
 
2309
                                                sub_v3_v3v3(totmat[2], vec, vec2);
 
2310
                                                normalize_v3(totmat[2]);
 
2311
                                        
 
2312
                                                /* the y axis is fixed */
 
2313
                                                normalize_v3_v3(totmat[1], cob->matrix[1]);
 
2314
                                        
 
2315
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2316
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
 
2317
                                        }
 
2318
                                        break;
 
2319
                                        case TRACK_nX: /* LOCK Y TRACK -X */
 
2320
                                        {
 
2321
                                                /* Projection of Vector on the plane */
 
2322
                                                project_v3_v3v3(vec2, vec, cob->matrix[1]);
 
2323
                                                sub_v3_v3v3(totmat[0], vec, vec2);
 
2324
                                                normalize_v3(totmat[0]);
 
2325
                                                negate_v3(totmat[0]);
 
2326
                                        
 
2327
                                                /* the y axis is fixed */
 
2328
                                                normalize_v3_v3(totmat[1], cob->matrix[1]);
 
2329
                                        
 
2330
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2331
                                                cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
 
2332
                                        }
 
2333
                                        break;
 
2334
                                        case TRACK_nZ: /* LOCK Y TRACK -Z */
 
2335
                                        {
 
2336
                                                /* Projection of Vector on the plane */
 
2337
                                                project_v3_v3v3(vec2, vec, cob->matrix[1]);
 
2338
                                                sub_v3_v3v3(totmat[2], vec, vec2);
 
2339
                                                normalize_v3(totmat[2]);
 
2340
                                                negate_v3(totmat[2]);
 
2341
                                        
 
2342
                                                /* the y axis is fixed */
 
2343
                                                normalize_v3_v3(totmat[1], cob->matrix[1]);
 
2344
                                        
 
2345
                                                /* the z axis gets mapped onto a third orthogonal vector */
 
2346
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
 
2347
                                        }
 
2348
                                        break;
 
2349
                                        default:
 
2350
                                        {
 
2351
                                                unit_m3(totmat);
 
2352
                                        }
 
2353
                                        break;
 
2354
                                }
 
2355
                        }
 
2356
                        break;
 
2357
                        case LOCK_Z: /* LOCK Z */
 
2358
                        {
 
2359
                                switch (data->trackflag) {
 
2360
                                        case TRACK_X: /* LOCK Z TRACK X */
 
2361
                                        {
 
2362
                                                /* Projection of Vector on the plane */
 
2363
                                                project_v3_v3v3(vec2, vec, cob->matrix[2]);
 
2364
                                                sub_v3_v3v3(totmat[0], vec, vec2);
 
2365
                                                normalize_v3(totmat[0]);
 
2366
                                        
 
2367
                                                /* the z axis is fixed */
 
2368
                                                normalize_v3_v3(totmat[2], cob->matrix[2]);
 
2369
                                        
 
2370
                                                /* the x axis gets mapped onto a third orthogonal vector */
 
2371
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
 
2372
                                        }
 
2373
                                        break;
 
2374
                                        case TRACK_Y: /* LOCK Z TRACK Y */
 
2375
                                        {
 
2376
                                                /* Projection of Vector on the plane */
 
2377
                                                project_v3_v3v3(vec2, vec, cob->matrix[2]);
 
2378
                                                sub_v3_v3v3(totmat[1], vec, vec2);
 
2379
                                                normalize_v3(totmat[1]);
 
2380
                                        
 
2381
                                                /* the z axis is fixed */
 
2382
                                                normalize_v3_v3(totmat[2], cob->matrix[2]);
 
2383
                                                
 
2384
                                                /* the x axis gets mapped onto a third orthogonal vector */
 
2385
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
 
2386
                                        }
 
2387
                                        break;
 
2388
                                        case TRACK_nX: /* LOCK Z TRACK -X */
 
2389
                                        {
 
2390
                                                /* Projection of Vector on the plane */
 
2391
                                                project_v3_v3v3(vec2, vec, cob->matrix[2]);
 
2392
                                                sub_v3_v3v3(totmat[0], vec, vec2);
 
2393
                                                normalize_v3(totmat[0]);
 
2394
                                                negate_v3(totmat[0]);
 
2395
                                        
 
2396
                                                /* the z axis is fixed */
 
2397
                                                normalize_v3_v3(totmat[2], cob->matrix[2]);
 
2398
                                        
 
2399
                                                /* the x axis gets mapped onto a third orthogonal vector */
 
2400
                                                cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
 
2401
                                        }
 
2402
                                        break;
 
2403
                                        case TRACK_nY: /* LOCK Z TRACK -Y */
 
2404
                                        {
 
2405
                                                /* Projection of Vector on the plane */
 
2406
                                                project_v3_v3v3(vec2, vec, cob->matrix[2]);
 
2407
                                                sub_v3_v3v3(totmat[1], vec, vec2);
 
2408
                                                normalize_v3(totmat[1]);
 
2409
                                                negate_v3(totmat[1]);
 
2410
                                        
 
2411
                                                /* the z axis is fixed */
 
2412
                                                normalize_v3_v3(totmat[2], cob->matrix[2]);
 
2413
                                                
 
2414
                                                /* the x axis gets mapped onto a third orthogonal vector */
 
2415
                                                cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
 
2416
                                        }
 
2417
                                        break;
 
2418
                                        default:
 
2419
                                        {
 
2420
                                                unit_m3(totmat);
 
2421
                                        }
 
2422
                                        break;
 
2423
                                }
 
2424
                        }
 
2425
                        break;
 
2426
                        default:
 
2427
                        {
 
2428
                                unit_m3(totmat);
 
2429
                        }
2532
2430
                        break;
2533
2431
                }
2534
2432
                /* Block to keep matrix heading */
2536
2434
                normalize_m3(tmpmat);
2537
2435
                invert_m3_m3(invmat, tmpmat);
2538
2436
                mul_m3_m3m3(tmpmat, totmat, invmat);
2539
 
                totmat[0][0] = tmpmat[0][0];totmat[0][1] = tmpmat[0][1];totmat[0][2] = tmpmat[0][2];
2540
 
                totmat[1][0] = tmpmat[1][0];totmat[1][1] = tmpmat[1][1];totmat[1][2] = tmpmat[1][2];
2541
 
                totmat[2][0] = tmpmat[2][0];totmat[2][1] = tmpmat[2][1];totmat[2][2] = tmpmat[2][2];
2542
 
                
2543
 
                copy_m4_m4(tmat, cob->matrix);
2544
 
                
2545
 
                mdet = determinant_m3(  totmat[0][0],totmat[0][1],totmat[0][2],
2546
 
                                                totmat[1][0],totmat[1][1],totmat[1][2],
2547
 
                                                totmat[2][0],totmat[2][1],totmat[2][2]);
2548
 
                if (mdet==0) {
 
2437
                totmat[0][0] = tmpmat[0][0]; totmat[0][1] = tmpmat[0][1]; totmat[0][2] = tmpmat[0][2];
 
2438
                totmat[1][0] = tmpmat[1][0]; totmat[1][1] = tmpmat[1][1]; totmat[1][2] = tmpmat[1][2];
 
2439
                totmat[2][0] = tmpmat[2][0]; totmat[2][1] = tmpmat[2][1]; totmat[2][2] = tmpmat[2][2];
 
2440
                
 
2441
                mdet = determinant_m3(totmat[0][0], totmat[0][1], totmat[0][2],
 
2442
                                      totmat[1][0], totmat[1][1], totmat[1][2],
 
2443
                                      totmat[2][0], totmat[2][1], totmat[2][2]);
 
2444
                if (mdet == 0) {
2549
2445
                        unit_m3(totmat);
2550
2446
                }
2551
2447
                
2552
2448
                /* apply out transformaton to the object */
2553
 
                mul_m4_m3m4(cob->matrix, totmat, tmat);
 
2449
                mul_m4_m3m4(cob->matrix, totmat, cob->matrix);
2554
2450
        }
2555
2451
}
2556
2452
 
2560
2456
        "Locked Track", /* name */
2561
2457
        "bLockTrackConstraint", /* struct name */
2562
2458
        NULL, /* free data */
2563
 
        NULL, /* relink data */
2564
2459
        locktrack_id_looper, /* id looper */
2565
2460
        NULL, /* copy data */
2566
2461
        locktrack_new_data, /* new data */
2572
2467
 
2573
2468
/* ---------- Limit Distance Constraint ----------- */
2574
2469
 
2575
 
static void distlimit_new_data (void *cdata)
 
2470
static void distlimit_new_data(void *cdata)
2576
2471
{
2577
 
        bDistLimitConstraint *data= (bDistLimitConstraint *)cdata;
 
2472
        bDistLimitConstraint *data = (bDistLimitConstraint *)cdata;
2578
2473
        
2579
 
        data->dist= 0.0f;
 
2474
        data->dist = 0.0f;
2580
2475
}
2581
2476
 
2582
 
static void distlimit_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2477
static void distlimit_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
2583
2478
{
2584
 
        bDistLimitConstraint *data= con->data;
 
2479
        bDistLimitConstraint *data = con->data;
2585
2480
        
2586
2481
        /* target only */
2587
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
2482
        func(con, (ID **)&data->tar, FALSE, userdata);
2588
2483
}
2589
2484
 
2590
 
static int distlimit_get_tars (bConstraint *con, ListBase *list)
 
2485
static int distlimit_get_tars(bConstraint *con, ListBase *list)
2591
2486
{
2592
2487
        if (con && list) {
2593
 
                bDistLimitConstraint *data= con->data;
 
2488
                bDistLimitConstraint *data = con->data;
2594
2489
                bConstraintTarget *ct;
2595
2490
                
2596
2491
                /* standard target-getting macro for single-target constraints */
2597
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
2492
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
2598
2493
                
2599
2494
                return 1;
2600
2495
        }
2602
2497
        return 0;
2603
2498
}
2604
2499
 
2605
 
static void distlimit_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2500
static void distlimit_flush_tars(bConstraint *con, ListBase *list, short nocopy)
2606
2501
{
2607
2502
        if (con && list) {
2608
 
                bDistLimitConstraint *data= con->data;
2609
 
                bConstraintTarget *ct= list->first;
 
2503
                bDistLimitConstraint *data = con->data;
 
2504
                bConstraintTarget *ct = list->first;
2610
2505
                
2611
2506
                /* the following macro is used for all standard single-target constraints */
2612
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
2507
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
2613
2508
        }
2614
2509
}
2615
2510
 
2616
 
static void distlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
2511
static void distlimit_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
2617
2512
{
2618
 
        bDistLimitConstraint *data= con->data;
2619
 
        bConstraintTarget *ct= targets->first;
 
2513
        bDistLimitConstraint *data = con->data;
 
2514
        bConstraintTarget *ct = targets->first;
2620
2515
        
2621
2516
        /* only evaluate if there is a target */
2622
2517
        if (VALID_CONS_TARGET(ct)) {
2623
 
                float dvec[3], dist=0.0f, sfac=1.0f;
2624
 
                short clamp_surf= 0;
 
2518
                float dvec[3], dist = 0.0f, sfac = 1.0f;
 
2519
                short clamp_surf = 0;
2625
2520
                
2626
2521
                /* calculate our current distance from the target */
2627
 
                dist= len_v3v3(cob->matrix[3], ct->matrix[3]);
 
2522
                dist = len_v3v3(cob->matrix[3], ct->matrix[3]);
2628
2523
                
2629
2524
                /* set distance (flag is only set when user demands it) */
2630
2525
                if (data->dist == 0)
2631
 
                        data->dist= dist;
 
2526
                        data->dist = dist;
2632
2527
                
2633
2528
                /* check if we're which way to clamp from, and calculate interpolation factor (if needed) */
2634
2529
                if (data->mode == LIMITDIST_OUTSIDE) {
2635
2530
                        /* if inside, then move to surface */
2636
2531
                        if (dist <= data->dist) {
2637
 
                                clamp_surf= 1;
2638
 
                                if (dist != 0.0f) sfac= data->dist / dist;
 
2532
                                clamp_surf = 1;
 
2533
                                if (dist != 0.0f) sfac = data->dist / dist;
2639
2534
                        }
2640
2535
                        /* if soft-distance is enabled, start fading once owner is dist+softdist from the target */
2641
2536
                        else if (data->flag & LIMITDIST_USESOFT) {
2647
2542
                else if (data->mode == LIMITDIST_INSIDE) {
2648
2543
                        /* if outside, then move to surface */
2649
2544
                        if (dist >= data->dist) {
2650
 
                                clamp_surf= 1;
2651
 
                                if (dist != 0.0f) sfac= data->dist / dist;
 
2545
                                clamp_surf = 1;
 
2546
                                if (dist != 0.0f) sfac = data->dist / dist;
2652
2547
                        }
2653
2548
                        /* if soft-distance is enabled, start fading once owner is dist-soft from the target */
2654
2549
                        else if (data->flag & LIMITDIST_USESOFT) {
2655
 
                                // FIXME: there's a problem with "jumping" when this kicks in
 
2550
                                /* FIXME: there's a problem with "jumping" when this kicks in */
2656
2551
                                if (dist >= (data->dist - data->soft)) {
2657
 
                                        sfac = (float)( data->soft*(1.0f - expf(-(dist - data->dist)/data->soft)) + data->dist );
 
2552
                                        sfac = (float)(data->soft * (1.0f - expf(-(dist - data->dist) / data->soft)) + data->dist);
2658
2553
                                        if (dist != 0.0f) sfac /= dist;
2659
2554
                                        
2660
 
                                        clamp_surf= 1;
 
2555
                                        clamp_surf = 1;
2661
2556
                                }
2662
2557
                        }
2663
2558
                }
2664
2559
                else {
2665
 
                        if (IS_EQF(dist, data->dist)==0) {
2666
 
                                clamp_surf= 1;
2667
 
                                if (dist != 0.0f) sfac= data->dist / dist;
 
2560
                        if (IS_EQF(dist, data->dist) == 0) {
 
2561
                                clamp_surf = 1;
 
2562
                                if (dist != 0.0f) sfac = data->dist / dist;
2668
2563
                        }
2669
2564
                }
2670
2565
                
2685
2580
        "Limit Distance", /* name */
2686
2581
        "bDistLimitConstraint", /* struct name */
2687
2582
        NULL, /* free data */
2688
 
        NULL, /* relink data */
2689
2583
        distlimit_id_looper, /* id looper */
2690
2584
        NULL, /* copy data */
2691
2585
        distlimit_new_data, /* new data */
2697
2591
 
2698
2592
/* ---------- Stretch To ------------ */
2699
2593
 
2700
 
static void stretchto_new_data (void *cdata)
 
2594
static void stretchto_new_data(void *cdata)
2701
2595
{
2702
 
        bStretchToConstraint *data= (bStretchToConstraint *)cdata;
 
2596
        bStretchToConstraint *data = (bStretchToConstraint *)cdata;
2703
2597
        
2704
2598
        data->volmode = 0;
2705
2599
        data->plane = 0;
2707
2601
        data->bulge = 1.0;
2708
2602
}
2709
2603
 
2710
 
static void stretchto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2604
static void stretchto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
2711
2605
{
2712
 
        bStretchToConstraint *data= con->data;
 
2606
        bStretchToConstraint *data = con->data;
2713
2607
        
2714
2608
        /* target only */
2715
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
2609
        func(con, (ID **)&data->tar, FALSE, userdata);
2716
2610
}
2717
2611
 
2718
 
static int stretchto_get_tars (bConstraint *con, ListBase *list)
 
2612
static int stretchto_get_tars(bConstraint *con, ListBase *list)
2719
2613
{
2720
2614
        if (con && list) {
2721
 
                bStretchToConstraint *data= con->data;
 
2615
                bStretchToConstraint *data = con->data;
2722
2616
                bConstraintTarget *ct;
2723
2617
                
2724
2618
                /* standard target-getting macro for single-target constraints */
2725
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
2619
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
2726
2620
                
2727
2621
                return 1;
2728
2622
        }
2730
2624
        return 0;
2731
2625
}
2732
2626
 
2733
 
static void stretchto_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2627
static void stretchto_flush_tars(bConstraint *con, ListBase *list, short nocopy)
2734
2628
{
2735
2629
        if (con && list) {
2736
 
                bStretchToConstraint *data= con->data;
2737
 
                bConstraintTarget *ct= list->first;
 
2630
                bStretchToConstraint *data = con->data;
 
2631
                bConstraintTarget *ct = list->first;
2738
2632
                
2739
2633
                /* the following macro is used for all standard single-target constraints */
2740
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
2634
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
2741
2635
        }
2742
2636
}
2743
2637
 
2744
 
static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
2638
static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
2745
2639
{
2746
 
        bStretchToConstraint *data= con->data;
2747
 
        bConstraintTarget *ct= targets->first;
 
2640
        bStretchToConstraint *data = con->data;
 
2641
        bConstraintTarget *ct = targets->first;
2748
2642
        
2749
2643
        /* only evaluate if there is a target */
2750
2644
        if (VALID_CONS_TARGET(ct)) {
2751
2645
                float size[3], scale[3], vec[3], xx[3], zz[3], orth[3];
2752
2646
                float totmat[3][3];
2753
 
                float tmat[4][4];
2754
2647
                float dist;
2755
2648
                
2756
2649
                /* store scaling before destroying obmat */
2780
2673
                if (data->bulge == 0)
2781
2674
                        data->bulge = 1.0;
2782
2675
                
2783
 
                scale[1] = dist/data->orglength;
 
2676
                scale[1] = dist / data->orglength;
2784
2677
                switch (data->volmode) {
2785
 
                /* volume preserving scaling */
2786
 
                case VOLUME_XZ :
2787
 
                        scale[0] = 1.0f - (float)sqrt(data->bulge) + (float)sqrt(data->bulge*(data->orglength/dist));
2788
 
                        scale[2] = scale[0];
2789
 
                        break;
2790
 
                case VOLUME_X:
2791
 
                        scale[0] = 1.0f + data->bulge * (data->orglength /dist - 1);
2792
 
                        scale[2] = 1.0;
2793
 
                        break;
2794
 
                case VOLUME_Z:
2795
 
                        scale[0] = 1.0;
2796
 
                        scale[2] = 1.0f + data->bulge * (data->orglength /dist - 1);
2797
 
                        break;
 
2678
                        /* volume preserving scaling */
 
2679
                        case VOLUME_XZ:
 
2680
                                scale[0] = 1.0f - (float)sqrt(data->bulge) + (float)sqrt(data->bulge * (data->orglength / dist));
 
2681
                                scale[2] = scale[0];
 
2682
                                break;
 
2683
                        case VOLUME_X:
 
2684
                                scale[0] = 1.0f + data->bulge * (data->orglength / dist - 1);
 
2685
                                scale[2] = 1.0;
 
2686
                                break;
 
2687
                        case VOLUME_Z:
 
2688
                                scale[0] = 1.0;
 
2689
                                scale[2] = 1.0f + data->bulge * (data->orglength / dist - 1);
 
2690
                                break;
2798
2691
                        /* don't care for volume */
2799
 
                case NO_VOLUME:
2800
 
                        scale[0] = 1.0;
2801
 
                        scale[2] = 1.0;
2802
 
                        break;
2803
 
                default: /* should not happen, but in case*/
2804
 
                        return;    
 
2692
                        case NO_VOLUME:
 
2693
                                scale[0] = 1.0;
 
2694
                                scale[2] = 1.0;
 
2695
                                break;
 
2696
                        default: /* should not happen, but in case*/
 
2697
                                return;
2805
2698
                } /* switch (data->volmode) */
2806
 
 
 
2699
                
2807
2700
                /* Clear the object's rotation and scale */
2808
 
                cob->matrix[0][0]=size[0]*scale[0];
2809
 
                cob->matrix[0][1]=0;
2810
 
                cob->matrix[0][2]=0;
2811
 
                cob->matrix[1][0]=0;
2812
 
                cob->matrix[1][1]=size[1]*scale[1];
2813
 
                cob->matrix[1][2]=0;
2814
 
                cob->matrix[2][0]=0;
2815
 
                cob->matrix[2][1]=0;
2816
 
                cob->matrix[2][2]=size[2]*scale[2];
 
2701
                cob->matrix[0][0] = size[0] * scale[0];
 
2702
                cob->matrix[0][1] = 0;
 
2703
                cob->matrix[0][2] = 0;
 
2704
                cob->matrix[1][0] = 0;
 
2705
                cob->matrix[1][1] = size[1] * scale[1];
 
2706
                cob->matrix[1][2] = 0;
 
2707
                cob->matrix[2][0] = 0;
 
2708
                cob->matrix[2][1] = 0;
 
2709
                cob->matrix[2][2] = size[2] * scale[2];
2817
2710
                
2818
2711
                sub_v3_v3v3(vec, cob->matrix[3], ct->matrix[3]);
2819
2712
                normalize_v3(vec);
2821
2714
                /* new Y aligns  object target connection*/
2822
2715
                negate_v3_v3(totmat[1], vec);
2823
2716
                switch (data->plane) {
2824
 
                case PLANE_X:
2825
 
                        /* build new Z vector */
2826
 
                        /* othogonal to "new Y" "old X! plane */
2827
 
                        cross_v3_v3v3(orth, vec, xx);
2828
 
                        normalize_v3(orth);
2829
 
                        
2830
 
                        /* new Z*/
2831
 
                        copy_v3_v3(totmat[2], orth);
2832
 
                        
2833
 
                        /* we decided to keep X plane*/
2834
 
                        cross_v3_v3v3(xx, orth, vec);
2835
 
                        normalize_v3_v3(totmat[0], xx);
2836
 
                        break;
2837
 
                case PLANE_Z:
2838
 
                        /* build new X vector */
2839
 
                        /* othogonal to "new Y" "old Z! plane */
2840
 
                        cross_v3_v3v3(orth, vec, zz);
2841
 
                        normalize_v3(orth);
2842
 
                        
2843
 
                        /* new X */
2844
 
                        negate_v3_v3(totmat[0], orth);
2845
 
                        
2846
 
                        /* we decided to keep Z */
2847
 
                        cross_v3_v3v3(zz, orth, vec);
2848
 
                        normalize_v3_v3(totmat[2], zz);
2849
 
                        break;
 
2717
                        case PLANE_X:
 
2718
                                /* build new Z vector */
 
2719
                                /* othogonal to "new Y" "old X! plane */
 
2720
                                cross_v3_v3v3(orth, vec, xx);
 
2721
                                normalize_v3(orth);
 
2722
                                
 
2723
                                /* new Z*/
 
2724
                                copy_v3_v3(totmat[2], orth);
 
2725
                                
 
2726
                                /* we decided to keep X plane*/
 
2727
                                cross_v3_v3v3(xx, orth, vec);
 
2728
                                normalize_v3_v3(totmat[0], xx);
 
2729
                                break;
 
2730
                        case PLANE_Z:
 
2731
                                /* build new X vector */
 
2732
                                /* othogonal to "new Y" "old Z! plane */
 
2733
                                cross_v3_v3v3(orth, vec, zz);
 
2734
                                normalize_v3(orth);
 
2735
                                
 
2736
                                /* new X */
 
2737
                                negate_v3_v3(totmat[0], orth);
 
2738
                                
 
2739
                                /* we decided to keep Z */
 
2740
                                cross_v3_v3v3(zz, orth, vec);
 
2741
                                normalize_v3_v3(totmat[2], zz);
 
2742
                                break;
2850
2743
                } /* switch (data->plane) */
2851
2744
                
2852
 
                copy_m4_m4(tmat, cob->matrix);
2853
 
                mul_m4_m3m4(cob->matrix, totmat, tmat);
 
2745
                mul_m4_m3m4(cob->matrix, totmat, cob->matrix);
2854
2746
        }
2855
2747
}
2856
2748
 
2860
2752
        "Stretch To", /* name */
2861
2753
        "bStretchToConstraint", /* struct name */
2862
2754
        NULL, /* free data */
2863
 
        NULL, /* relink data */
2864
2755
        stretchto_id_looper, /* id looper */
2865
2756
        NULL, /* copy data */
2866
2757
        stretchto_new_data, /* new data */
2872
2763
 
2873
2764
/* ---------- Floor ------------ */
2874
2765
 
2875
 
static void minmax_new_data (void *cdata)
 
2766
static void minmax_new_data(void *cdata)
2876
2767
{
2877
 
        bMinMaxConstraint *data= (bMinMaxConstraint *)cdata;
 
2768
        bMinMaxConstraint *data = (bMinMaxConstraint *)cdata;
2878
2769
        
2879
2770
        data->minmaxflag = TRACK_Z;
2880
2771
        data->offset = 0.0f;
2882
2773
        data->flag = 0;
2883
2774
}
2884
2775
 
2885
 
static void minmax_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2776
static void minmax_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
2886
2777
{
2887
 
        bMinMaxConstraint *data= con->data;
 
2778
        bMinMaxConstraint *data = con->data;
2888
2779
        
2889
2780
        /* target only */
2890
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
2781
        func(con, (ID **)&data->tar, FALSE, userdata);
2891
2782
}
2892
2783
 
2893
 
static int minmax_get_tars (bConstraint *con, ListBase *list)
 
2784
static int minmax_get_tars(bConstraint *con, ListBase *list)
2894
2785
{
2895
2786
        if (con && list) {
2896
 
                bMinMaxConstraint *data= con->data;
 
2787
                bMinMaxConstraint *data = con->data;
2897
2788
                bConstraintTarget *ct;
2898
2789
                
2899
2790
                /* standard target-getting macro for single-target constraints */
2900
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
2791
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
2901
2792
                
2902
2793
                return 1;
2903
2794
        }
2905
2796
        return 0;
2906
2797
}
2907
2798
 
2908
 
static void minmax_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2799
static void minmax_flush_tars(bConstraint *con, ListBase *list, short nocopy)
2909
2800
{
2910
2801
        if (con && list) {
2911
 
                bMinMaxConstraint *data= con->data;
2912
 
                bConstraintTarget *ct= list->first;
 
2802
                bMinMaxConstraint *data = con->data;
 
2803
                bConstraintTarget *ct = list->first;
2913
2804
                
2914
2805
                /* the following macro is used for all standard single-target constraints */
2915
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
2806
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
2916
2807
        }
2917
2808
}
2918
2809
 
2919
 
static void minmax_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
2810
static void minmax_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
2920
2811
{
2921
 
        bMinMaxConstraint *data= con->data;
2922
 
        bConstraintTarget *ct= targets->first;
 
2812
        bMinMaxConstraint *data = con->data;
 
2813
        bConstraintTarget *ct = targets->first;
2923
2814
        
2924
2815
        /* only evaluate if there is a target */
2925
2816
        if (VALID_CONS_TARGET(ct)) {
2939
2830
                }
2940
2831
                
2941
2832
                switch (data->minmaxflag) {
2942
 
                case TRACK_Z:
2943
 
                        val1 = tarmat[3][2];
2944
 
                        val2 = obmat[3][2]-data->offset;
2945
 
                        index = 2;
2946
 
                        break;
2947
 
                case TRACK_Y:
2948
 
                        val1 = tarmat[3][1];
2949
 
                        val2 = obmat[3][1]-data->offset;
2950
 
                        index = 1;
2951
 
                        break;
2952
 
                case TRACK_X:
2953
 
                        val1 = tarmat[3][0];
2954
 
                        val2 = obmat[3][0]-data->offset;
2955
 
                        index = 0;
2956
 
                        break;
2957
 
                case TRACK_nZ:
2958
 
                        val2 = tarmat[3][2];
2959
 
                        val1 = obmat[3][2]-data->offset;
2960
 
                        index = 2;
2961
 
                        break;
2962
 
                case TRACK_nY:
2963
 
                        val2 = tarmat[3][1];
2964
 
                        val1 = obmat[3][1]-data->offset;
2965
 
                        index = 1;
2966
 
                        break;
2967
 
                case TRACK_nX:
2968
 
                        val2 = tarmat[3][0];
2969
 
                        val1 = obmat[3][0]-data->offset;
2970
 
                        index = 0;
2971
 
                        break;
2972
 
                default:
2973
 
                        return;
 
2833
                        case TRACK_Z:
 
2834
                                val1 = tarmat[3][2];
 
2835
                                val2 = obmat[3][2] - data->offset;
 
2836
                                index = 2;
 
2837
                                break;
 
2838
                        case TRACK_Y:
 
2839
                                val1 = tarmat[3][1];
 
2840
                                val2 = obmat[3][1] - data->offset;
 
2841
                                index = 1;
 
2842
                                break;
 
2843
                        case TRACK_X:
 
2844
                                val1 = tarmat[3][0];
 
2845
                                val2 = obmat[3][0] - data->offset;
 
2846
                                index = 0;
 
2847
                                break;
 
2848
                        case TRACK_nZ:
 
2849
                                val2 = tarmat[3][2];
 
2850
                                val1 = obmat[3][2] - data->offset;
 
2851
                                index = 2;
 
2852
                                break;
 
2853
                        case TRACK_nY:
 
2854
                                val2 = tarmat[3][1];
 
2855
                                val1 = obmat[3][1] - data->offset;
 
2856
                                index = 1;
 
2857
                                break;
 
2858
                        case TRACK_nX:
 
2859
                                val2 = tarmat[3][0];
 
2860
                                val1 = obmat[3][0] - data->offset;
 
2861
                                index = 0;
 
2862
                                break;
 
2863
                        default:
 
2864
                                return;
2974
2865
                }
2975
2866
                
2976
2867
                if (val1 > val2) {
2978
2869
                        if (data->flag & MINMAX_STICKY) {
2979
2870
                                if (data->flag & MINMAX_STUCK) {
2980
2871
                                        copy_v3_v3(obmat[3], data->cache);
2981
 
                                } 
 
2872
                                }
2982
2873
                                else {
2983
2874
                                        copy_v3_v3(data->cache, obmat[3]);
2984
2875
                                        data->flag |= MINMAX_STUCK;
2988
2879
                                /* get out of localspace */
2989
2880
                                mult_m4_m4m4(tmat, ct->matrix, obmat);
2990
2881
                                copy_m4_m4(cob->matrix, tmat);
2991
 
                        } 
2992
 
                        else {                  
 
2882
                        }
 
2883
                        else {
2993
2884
                                copy_v3_v3(cob->matrix[3], obmat[3]);
2994
2885
                        }
2995
 
                } 
 
2886
                }
2996
2887
                else {
2997
2888
                        data->flag &= ~MINMAX_STUCK;
2998
2889
                }
3005
2896
        "Floor", /* name */
3006
2897
        "bMinMaxConstraint", /* struct name */
3007
2898
        NULL, /* free data */
3008
 
        NULL, /* relink data */
3009
2899
        minmax_id_looper, /* id looper */
3010
2900
        NULL, /* copy data */
3011
2901
        minmax_new_data, /* new data */
3017
2907
 
3018
2908
/* ------- RigidBody Joint ---------- */
3019
2909
 
3020
 
static void rbj_new_data (void *cdata)
 
2910
static void rbj_new_data(void *cdata)
3021
2911
{
3022
 
        bRigidBodyJointConstraint *data= (bRigidBodyJointConstraint *)cdata;
 
2912
        bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint *)cdata;
3023
2913
        
3024
 
        // removed code which set target of this constraint  
3025
 
        data->type=1;
 
2914
        /* removed code which set target of this constraint */
 
2915
        data->type = 1;
3026
2916
}
3027
2917
 
3028
 
static void rbj_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2918
static void rbj_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
3029
2919
{
3030
 
        bRigidBodyJointConstraint *data= con->data;
 
2920
        bRigidBodyJointConstraint *data = con->data;
3031
2921
        
3032
2922
        /* target only */
3033
 
        func(con, (ID**)&data->tar, FALSE, userdata);
3034
 
        func(con, (ID**)&data->child, FALSE, userdata);
 
2923
        func(con, (ID **)&data->tar, FALSE, userdata);
 
2924
        func(con, (ID **)&data->child, FALSE, userdata);
3035
2925
}
3036
2926
 
3037
 
static int rbj_get_tars (bConstraint *con, ListBase *list)
 
2927
static int rbj_get_tars(bConstraint *con, ListBase *list)
3038
2928
{
3039
2929
        if (con && list) {
3040
 
                bRigidBodyJointConstraint *data= con->data;
 
2930
                bRigidBodyJointConstraint *data = con->data;
3041
2931
                bConstraintTarget *ct;
3042
2932
                
3043
2933
                /* standard target-getting macro for single-target constraints without subtargets */
3044
 
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list)
 
2934
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list);
3045
2935
                
3046
2936
                return 1;
3047
2937
        }
3049
2939
        return 0;
3050
2940
}
3051
2941
 
3052
 
static void rbj_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2942
static void rbj_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3053
2943
{
3054
2944
        if (con && list) {
3055
 
                bRigidBodyJointConstraint *data= con->data;
3056
 
                bConstraintTarget *ct= list->first;
 
2945
                bRigidBodyJointConstraint *data = con->data;
 
2946
                bConstraintTarget *ct = list->first;
3057
2947
                
3058
2948
                /* the following macro is used for all standard single-target constraints */
3059
 
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy)
 
2949
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy);
3060
2950
        }
3061
2951
}
3062
2952
 
3066
2956
        "Rigid Body Joint", /* name */
3067
2957
        "bRigidBodyJointConstraint", /* struct name */
3068
2958
        NULL, /* free data */
3069
 
        NULL, /* relink data */
3070
2959
        rbj_id_looper, /* id looper */
3071
2960
        NULL, /* copy data */
3072
2961
        rbj_new_data, /* new data */
3078
2967
 
3079
2968
/* -------- Clamp To ---------- */
3080
2969
 
3081
 
static void clampto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
2970
static void clampto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
3082
2971
{
3083
 
        bClampToConstraint *data= con->data;
 
2972
        bClampToConstraint *data = con->data;
3084
2973
        
3085
2974
        /* target only */
3086
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
2975
        func(con, (ID **)&data->tar, FALSE, userdata);
3087
2976
}
3088
2977
 
3089
 
static int clampto_get_tars (bConstraint *con, ListBase *list)
 
2978
static int clampto_get_tars(bConstraint *con, ListBase *list)
3090
2979
{
3091
2980
        if (con && list) {
3092
 
                bClampToConstraint *data= con->data;
 
2981
                bClampToConstraint *data = con->data;
3093
2982
                bConstraintTarget *ct;
3094
2983
                
3095
2984
                /* standard target-getting macro for single-target constraints without subtargets */
3096
 
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list)
 
2985
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list);
3097
2986
                
3098
2987
                return 1;
3099
2988
        }
3101
2990
        return 0;
3102
2991
}
3103
2992
 
3104
 
static void clampto_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
2993
static void clampto_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3105
2994
{
3106
2995
        if (con && list) {
3107
 
                bClampToConstraint *data= con->data;
3108
 
                bConstraintTarget *ct= list->first;
 
2996
                bClampToConstraint *data = con->data;
 
2997
                bConstraintTarget *ct = list->first;
3109
2998
                
3110
2999
                /* the following macro is used for all standard single-target constraints */
3111
 
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy)
 
3000
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy);
3112
3001
        }
3113
3002
}
3114
3003
 
3115
 
static void clampto_get_tarmat (bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
3004
static void clampto_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
3116
3005
{
3117
3006
        if (VALID_CONS_TARGET(ct)) {
3118
 
                Curve *cu= ct->tar->data;
 
3007
                Curve *cu = ct->tar->data;
3119
3008
                
3120
3009
                /* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
3121
3010
                 *              currently for paths to work it needs to go through the bevlist/displist system (ton) 
3122
3011
                 */
3123
3012
                
3124
3013
                /* only happens on reload file, but violates depsgraph still... fix! */
3125
 
                if (cu->path==NULL || cu->path->data==NULL)
3126
 
                        makeDispListCurveTypes(cob->scene, ct->tar, 0);
 
3014
                if (cu->path == NULL || cu->path->data == NULL)
 
3015
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
3127
3016
        }
3128
3017
        
3129
3018
        /* technically, this isn't really needed for evaluation, but we don't know what else
3133
3022
                unit_m4(ct->matrix);
3134
3023
}
3135
3024
 
3136
 
static void clampto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
3025
static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
3137
3026
{
3138
 
        bClampToConstraint *data= con->data;
3139
 
        bConstraintTarget *ct= targets->first;
 
3027
        bClampToConstraint *data = con->data;
 
3028
        bConstraintTarget *ct = targets->first;
3140
3029
        
3141
3030
        /* only evaluate if there is a target and it is a curve */
3142
3031
        if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_CURVE)) {
3143
 
                Curve *cu= data->tar->data;
 
3032
                Curve *cu = data->tar->data;
3144
3033
                float obmat[4][4], ownLoc[3];
3145
3034
                float curveMin[3], curveMax[3];
3146
 
                float targetMatrix[4][4]= MAT4_UNITY;
 
3035
                float targetMatrix[4][4] = MAT4_UNITY;
3147
3036
                
3148
3037
                copy_m4_m4(obmat, cob->matrix);
3149
3038
                copy_v3_v3(ownLoc, obmat[3]);
3150
3039
                
3151
 
                INIT_MINMAX(curveMin, curveMax)
3152
 
                minmax_object(ct->tar, curveMin, curveMax);
 
3040
                INIT_MINMAX(curveMin, curveMax);
 
3041
                /* XXX - don't think this is good calling this here - campbell */
 
3042
                BKE_object_minmax(ct->tar, curveMin, curveMax, TRUE);
3153
3043
                
3154
3044
                /* get targetmatrix */
3155
3045
                if (cu->path && cu->path->data) {
3167
3057
                                 * extent. Otherwise, default to the x-axis, as that is quite
3168
3058
                                 * frequently used.
3169
3059
                                 */
3170
 
                                if ((size[2]>size[0]) && (size[2]>size[1]))
3171
 
                                        clamp_axis= CLAMPTO_Z - 1;
3172
 
                                else if ((size[1]>size[0]) && (size[1]>size[2]))
3173
 
                                        clamp_axis= CLAMPTO_Y - 1;
 
3060
                                if ((size[2] > size[0]) && (size[2] > size[1]))
 
3061
                                        clamp_axis = CLAMPTO_Z - 1;
 
3062
                                else if ((size[1] > size[0]) && (size[1] > size[2]))
 
3063
                                        clamp_axis = CLAMPTO_Y - 1;
3174
3064
                                else
3175
3065
                                        clamp_axis = CLAMPTO_X - 1;
3176
3066
                        }
3177
3067
                        else 
3178
 
                                clamp_axis= data->flag - 1;
 
3068
                                clamp_axis = data->flag - 1;
3179
3069
                                
3180
3070
                        /* 2. determine position relative to curve on a 0-1 scale based on bounding box */
3181
3071
                        if (data->flag2 & CLAMPTO_CYCLIC) {
3182
3072
                                /* cyclic, so offset within relative bounding box is used */
3183
 
                                float len= (curveMax[clamp_axis] - curveMin[clamp_axis]);
 
3073
                                float len = (curveMax[clamp_axis] - curveMin[clamp_axis]);
3184
3074
                                float offset;
3185
3075
                                
3186
3076
                                /* check to make sure len is not so close to zero that it'll cause errors */
3188
3078
                                        /* find bounding-box range where target is located */
3189
3079
                                        if (ownLoc[clamp_axis] < curveMin[clamp_axis]) {
3190
3080
                                                /* bounding-box range is before */
3191
 
                                                offset = curveMin[clamp_axis] - ceil((curveMin[clamp_axis] - ownLoc[clamp_axis]) / len) * len;
 
3081
                                                offset = curveMin[clamp_axis] - ceilf((curveMin[clamp_axis] - ownLoc[clamp_axis]) / len) * len;
3192
3082
 
3193
3083
                                                /* now, we calculate as per normal, except using offset instead of curveMin[clamp_axis] */
3194
3084
                                                curvetime = (ownLoc[clamp_axis] - offset) / (len);
3195
3085
                                        }
3196
3086
                                        else if (ownLoc[clamp_axis] > curveMax[clamp_axis]) {
3197
3087
                                                /* bounding-box range is after */
3198
 
                                                offset= curveMax[clamp_axis] + (int)((ownLoc[clamp_axis] - curveMax[clamp_axis]) / len) * len;
 
3088
                                                offset = curveMax[clamp_axis] + (int)((ownLoc[clamp_axis] - curveMax[clamp_axis]) / len) * len;
3199
3089
 
3200
3090
                                                /* now, we calculate as per normal, except using offset instead of curveMax[clamp_axis] */
3201
3091
                                                curvetime = (ownLoc[clamp_axis] - offset) / (len);
3207
3097
                                }
3208
3098
                                else {
3209
3099
                                        /* as length is close to zero, curvetime by default should be 0 (i.e. the start) */
3210
 
                                        curvetime= 0.0f;
 
3100
                                        curvetime = 0.0f;
3211
3101
                                }
3212
3102
                        }
3213
3103
                        else {
3216
3106
                                        curvetime = 0.0f;
3217
3107
                                else if (ownLoc[clamp_axis] >= curveMax[clamp_axis])
3218
3108
                                        curvetime = 1.0f;
3219
 
                                else if ( IS_EQ((curveMax[clamp_axis] - curveMin[clamp_axis]), 0) == 0 )
 
3109
                                else if (IS_EQ((curveMax[clamp_axis] - curveMin[clamp_axis]), 0) == 0)
3220
3110
                                        curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]);
3221
3111
                                else 
3222
3112
                                        curvetime = 0.0f;
3242
3132
        "Clamp To", /* name */
3243
3133
        "bClampToConstraint", /* struct name */
3244
3134
        NULL, /* free data */
3245
 
        NULL, /* relink data */
3246
3135
        clampto_id_looper, /* id looper */
3247
3136
        NULL, /* copy data */
3248
3137
        NULL, /* new data */
3254
3143
 
3255
3144
/* ---------- Transform Constraint ----------- */
3256
3145
 
3257
 
static void transform_new_data (void *cdata)
 
3146
static void transform_new_data(void *cdata)
3258
3147
{
3259
 
        bTransformConstraint *data= (bTransformConstraint *)cdata;
 
3148
        bTransformConstraint *data = (bTransformConstraint *)cdata;
3260
3149
        
3261
 
        data->map[0]= 0;
3262
 
        data->map[1]= 1;
3263
 
        data->map[2]= 2;
 
3150
        data->map[0] = 0;
 
3151
        data->map[1] = 1;
 
3152
        data->map[2] = 2;
3264
3153
}
3265
3154
 
3266
 
static void transform_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
3155
static void transform_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
3267
3156
{
3268
 
        bTransformConstraint *data= con->data;
 
3157
        bTransformConstraint *data = con->data;
3269
3158
        
3270
3159
        /* target only */
3271
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
3160
        func(con, (ID **)&data->tar, FALSE, userdata);
3272
3161
}
3273
3162
 
3274
 
static int transform_get_tars (bConstraint *con, ListBase *list)
 
3163
static int transform_get_tars(bConstraint *con, ListBase *list)
3275
3164
{
3276
3165
        if (con && list) {
3277
 
                bTransformConstraint *data= con->data;
 
3166
                bTransformConstraint *data = con->data;
3278
3167
                bConstraintTarget *ct;
3279
3168
                
3280
3169
                /* standard target-getting macro for single-target constraints */
3281
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
3170
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
3282
3171
                
3283
3172
                return 1;
3284
3173
        }
3286
3175
        return 0;
3287
3176
}
3288
3177
 
3289
 
static void transform_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
3178
static void transform_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3290
3179
{
3291
3180
        if (con && list) {
3292
 
                bTransformConstraint *data= con->data;
3293
 
                bConstraintTarget *ct= list->first;
 
3181
                bTransformConstraint *data = con->data;
 
3182
                bConstraintTarget *ct = list->first;
3294
3183
                
3295
3184
                /* the following macro is used for all standard single-target constraints */
3296
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
3185
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
3297
3186
        }
3298
3187
}
3299
3188
 
3300
 
static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
3189
static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
3301
3190
{
3302
 
        bTransformConstraint *data= con->data;
3303
 
        bConstraintTarget *ct= targets->first;
 
3191
        bTransformConstraint *data = con->data;
 
3192
        bConstraintTarget *ct = targets->first;
3304
3193
        
3305
3194
        /* only evaluate if there is a target */
3306
3195
        if (VALID_CONS_TARGET(ct)) {
3311
3200
                /* obtain target effect */
3312
3201
                switch (data->from) {
3313
3202
                        case 2: /* scale */
3314
 
                                mat4_to_size( dvec,ct->matrix);
 
3203
                                mat4_to_size(dvec, ct->matrix);
 
3204
                                
 
3205
                                if (is_negative_m4(ct->matrix)) {
 
3206
                                        /* Bugfix [#27886] 
 
3207
                                         * We can't be sure which axis/axes are negative, though we know that something is negative.
 
3208
                                         * Assume we don't care about negativity of separate axes. <--- This is a limitation that
 
3209
                                         * riggers will have to live with for now.
 
3210
                                         */
 
3211
                                        negate_v3(dvec);
 
3212
                                }
3315
3213
                                break;
3316
3214
                        case 1: /* rotation (convert to degrees first) */
3317
3215
                                mat4_to_eulO(dvec, cob->rotOrder, ct->matrix);
3325
3223
                /* extract components of owner's matrix */
3326
3224
                copy_v3_v3(loc, cob->matrix[3]);
3327
3225
                mat4_to_eulO(eul, cob->rotOrder, cob->matrix);
3328
 
                mat4_to_size(size, cob->matrix);        
 
3226
                mat4_to_size(size, cob->matrix);
3329
3227
                
3330
3228
                /* determine where in range current transforms lie */
3331
3229
                if (data->expo) {
3332
 
                        for (i=0; i<3; i++) {
 
3230
                        for (i = 0; i < 3; i++) {
3333
3231
                                if (data->from_max[i] - data->from_min[i])
3334
 
                                        sval[i]= (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]);
 
3232
                                        sval[i] = (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]);
3335
3233
                                else
3336
 
                                        sval[i]= 0.0f;
 
3234
                                        sval[i] = 0.0f;
3337
3235
                        }
3338
3236
                }
3339
3237
                else {
3340
3238
                        /* clamp transforms out of range */
3341
 
                        for (i=0; i<3; i++) {
 
3239
                        for (i = 0; i < 3; i++) {
3342
3240
                                CLAMP(dvec[i], data->from_min[i], data->from_max[i]);
3343
3241
                                if (data->from_max[i] - data->from_min[i])
3344
 
                                        sval[i]= (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]);
 
3242
                                        sval[i] = (dvec[i] - data->from_min[i]) / (data->from_max[i] - data->from_min[i]);
3345
3243
                                else
3346
 
                                        sval[i]= 0.0f;
 
3244
                                        sval[i] = 0.0f;
3347
3245
                        }
3348
3246
                }
3349
3247
                
3351
3249
                /* apply transforms */
3352
3250
                switch (data->to) {
3353
3251
                        case 2: /* scaling */
3354
 
                                for (i=0; i<3; i++)
3355
 
                                        size[i]= data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])); 
 
3252
                                for (i = 0; i < 3; i++)
 
3253
                                        size[i] = data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]));
3356
3254
                                break;
3357
3255
                        case 1: /* rotation */
3358
 
                                for (i=0; i<3; i++) {
 
3256
                                for (i = 0; i < 3; i++) {
3359
3257
                                        float tmin, tmax;
3360
3258
                                        
3361
 
                                        tmin= data->to_min[i];
3362
 
                                        tmax= data->to_max[i];
 
3259
                                        tmin = data->to_min[i];
 
3260
                                        tmax = data->to_max[i];
3363
3261
                                        
3364
3262
                                        /* all values here should be in degrees */
3365
 
                                        eul[i]= tmin + (sval[(int)data->map[i]] * (tmax - tmin)); 
 
3263
                                        eul[i] = tmin + (sval[(int)data->map[i]] * (tmax - tmin));
3366
3264
                                        
3367
3265
                                        /* now convert final value back to radians */
3368
3266
                                        eul[i] = DEG2RADF(eul[i]);
3370
3268
                                break;
3371
3269
                        default: /* location */
3372
3270
                                /* get new location */
3373
 
                                for (i=0; i<3; i++)
3374
 
                                        loc[i]= (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])));
 
3271
                                for (i = 0; i < 3; i++)
 
3272
                                        loc[i] = (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])));
3375
3273
                                
3376
3274
                                /* add original location back on (so that it can still be moved) */
3377
3275
                                add_v3_v3v3(loc, cob->matrix[3], loc);
3386
3284
static bConstraintTypeInfo CTI_TRANSFORM = {
3387
3285
        CONSTRAINT_TYPE_TRANSFORM, /* type */
3388
3286
        sizeof(bTransformConstraint), /* size */
3389
 
        "Transform", /* name */
 
3287
        "Transformation", /* name */
3390
3288
        "bTransformConstraint", /* struct name */
3391
3289
        NULL, /* free data */
3392
 
        NULL, /* relink data */
3393
3290
        transform_id_looper, /* id looper */
3394
3291
        NULL, /* copy data */
3395
3292
        transform_new_data, /* new data */
3401
3298
 
3402
3299
/* ---------- Shrinkwrap Constraint ----------- */
3403
3300
 
3404
 
static void shrinkwrap_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
3301
static void shrinkwrap_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
3405
3302
{
3406
3303
        bShrinkwrapConstraint *data = con->data;
3407
3304
        
3408
3305
        /* target only */
3409
 
        func(con, (ID**)&data->target, FALSE, userdata);
 
3306
        func(con, (ID **)&data->target, FALSE, userdata);
3410
3307
}
3411
3308
 
3412
 
static int shrinkwrap_get_tars (bConstraint *con, ListBase *list)
 
3309
static int shrinkwrap_get_tars(bConstraint *con, ListBase *list)
3413
3310
{
3414
3311
        if (con && list) {
3415
3312
                bShrinkwrapConstraint *data = con->data;
3416
3313
                bConstraintTarget *ct;
3417
3314
                
3418
 
                SINGLETARGETNS_GET_TARS(con, data->target, ct, list)
 
3315
                SINGLETARGETNS_GET_TARS(con, data->target, ct, list);
3419
3316
                
3420
3317
                return 1;
3421
3318
        }
3424
3321
}
3425
3322
 
3426
3323
 
3427
 
static void shrinkwrap_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
3324
static void shrinkwrap_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3428
3325
{
3429
3326
        if (con && list) {
3430
3327
                bShrinkwrapConstraint *data = con->data;
3431
 
                bConstraintTarget *ct= list->first;
 
3328
                bConstraintTarget *ct = list->first;
3432
3329
                
3433
 
                SINGLETARGETNS_FLUSH_TARS(con, data->target, ct, list, nocopy)
 
3330
                SINGLETARGETNS_FLUSH_TARS(con, data->target, ct, list, nocopy);
3434
3331
        }
3435
3332
}
3436
3333
 
3437
3334
 
3438
 
static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
3335
static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
3439
3336
{
3440
3337
        bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data;
3441
3338
        
3442
 
        if ( VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) )
3443
 
        {
 
3339
        if (VALID_CONS_TARGET(ct) && (ct->tar->type == OB_MESH) ) {
3444
3340
                int fail = FALSE;
3445
3341
                float co[3] = {0.0f, 0.0f, 0.0f};
3446
3342
                float no[3] = {0.0f, 0.0f, 0.0f};
3451
3347
                BVHTreeRayHit hit;
3452
3348
                BVHTreeNearest nearest;
3453
3349
                
3454
 
                BVHTreeFromMesh treeData= {NULL};
 
3350
                BVHTreeFromMesh treeData = {NULL};
3455
3351
                
3456
3352
                nearest.index = -1;
3457
3353
                nearest.dist = FLT_MAX;
3461
3357
                
3462
3358
                unit_m4(ct->matrix);
3463
3359
                
3464
 
                if (target != NULL)
3465
 
                {
 
3360
                if (target != NULL) {
3466
3361
                        space_transform_from_matrixs(&transform, cob->matrix, ct->tar->obmat);
3467
3362
                        
3468
 
                        switch(scon->shrinkType)
3469
 
                        {
 
3363
                        switch (scon->shrinkType) {
3470
3364
                                case MOD_SHRINKWRAP_NEAREST_SURFACE:
3471
3365
                                case MOD_SHRINKWRAP_NEAREST_VERTEX:
3472
3366
                                        
3475
3369
                                        else
3476
3370
                                                bvhtree_from_mesh_faces(&treeData, target, 0.0, 2, 6);
3477
3371
                                        
3478
 
                                        if (treeData.tree == NULL)
3479
 
                                        {
 
3372
                                        if (treeData.tree == NULL) {
3480
3373
                                                fail = TRUE;
3481
3374
                                                break;
3482
3375
                                        }
3487
3380
                                        
3488
3381
                                        dist = len_v3v3(co, nearest.co);
3489
3382
                                        if (dist != 0.0f) {
3490
 
                                                interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist)/dist);   /* linear interpolation */
 
3383
                                                interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist) / dist);   /* linear interpolation */
3491
3384
                                        }
3492
3385
                                        space_transform_invert(&transform, co);
3493
 
                                break;
 
3386
                                        break;
3494
3387
                                
3495
3388
                                case MOD_SHRINKWRAP_PROJECT:
3496
3389
                                        if (scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) no[0] = 1.0f;
3506
3399
                                        
3507
3400
                                        
3508
3401
                                        bvhtree_from_mesh_faces(&treeData, target, scon->dist, 4, 6);
3509
 
                                        if (treeData.tree == NULL)
3510
 
                                        {
 
3402
                                        if (treeData.tree == NULL) {
3511
3403
                                                fail = TRUE;
3512
3404
                                                break;
3513
3405
                                        }
3514
3406
                                        
3515
 
                                        if (normal_projection_project_vertex(0, co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) == FALSE)
3516
 
                                        {
 
3407
                                        if (normal_projection_project_vertex(0, co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) == FALSE) {
3517
3408
                                                fail = TRUE;
3518
3409
                                                break;
3519
3410
                                        }
3520
3411
                                        copy_v3_v3(co, hit.co);
3521
 
                                break;
 
3412
                                        break;
3522
3413
                        }
3523
3414
                        
3524
3415
                        free_bvhtree_from_mesh(&treeData);
3537
3428
        }
3538
3429
}
3539
3430
 
3540
 
static void shrinkwrap_evaluate (bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
 
3431
static void shrinkwrap_evaluate(bConstraint *UNUSED(con), bConstraintOb *cob, ListBase *targets)
3541
3432
{
3542
 
        bConstraintTarget *ct= targets->first;
 
3433
        bConstraintTarget *ct = targets->first;
3543
3434
        
3544
3435
        /* only evaluate if there is a target */
3545
 
        if (VALID_CONS_TARGET(ct))
3546
 
        {
 
3436
        if (VALID_CONS_TARGET(ct)) {
3547
3437
                copy_v3_v3(cob->matrix[3], ct->matrix[3]);
3548
3438
        }
3549
3439
}
3554
3444
        "Shrinkwrap", /* name */
3555
3445
        "bShrinkwrapConstraint", /* struct name */
3556
3446
        NULL, /* free data */
3557
 
        NULL, /* relink data */
3558
3447
        shrinkwrap_id_looper, /* id looper */
3559
3448
        NULL, /* copy data */
3560
3449
        NULL, /* new data */
3566
3455
 
3567
3456
/* --------- Damped Track ---------- */
3568
3457
 
3569
 
static void damptrack_new_data (void *cdata)
 
3458
static void damptrack_new_data(void *cdata)
3570
3459
{
3571
 
        bDampTrackConstraint *data= (bDampTrackConstraint *)cdata;
 
3460
        bDampTrackConstraint *data = (bDampTrackConstraint *)cdata;
3572
3461
        
3573
3462
        data->trackflag = TRACK_Y;
3574
3463
}       
3575
3464
 
3576
 
static void damptrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
3465
static void damptrack_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
3577
3466
{
3578
 
        bDampTrackConstraint *data= con->data;
 
3467
        bDampTrackConstraint *data = con->data;
3579
3468
        
3580
3469
        /* target only */
3581
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
3470
        func(con, (ID **)&data->tar, FALSE, userdata);
3582
3471
}
3583
3472
 
3584
 
static int damptrack_get_tars (bConstraint *con, ListBase *list)
 
3473
static int damptrack_get_tars(bConstraint *con, ListBase *list)
3585
3474
{
3586
3475
        if (con && list) {
3587
 
                bDampTrackConstraint *data= con->data;
 
3476
                bDampTrackConstraint *data = con->data;
3588
3477
                bConstraintTarget *ct;
3589
3478
                
3590
3479
                /* the following macro is used for all standard single-target constraints */
3591
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
3480
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
3592
3481
                
3593
3482
                return 1;
3594
3483
        }
3596
3485
        return 0;
3597
3486
}
3598
3487
 
3599
 
static void damptrack_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
3488
static void damptrack_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3600
3489
{
3601
3490
        if (con && list) {
3602
 
                bDampTrackConstraint *data= con->data;
3603
 
                bConstraintTarget *ct= list->first;
 
3491
                bDampTrackConstraint *data = con->data;
 
3492
                bConstraintTarget *ct = list->first;
3604
3493
                
3605
3494
                /* the following macro is used for all standard single-target constraints */
3606
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
3495
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
3607
3496
        }
3608
3497
}
3609
3498
 
3610
3499
/* array of direction vectors for the tracking flags */
3611
3500
static const float track_dir_vecs[6][3] = {
3612
 
        {+1,0,0}, {0,+1,0}, {0,0,+1},           /* TRACK_X,  TRACK_Y,  TRACK_Z */
3613
 
        {-1,0,0}, {0,-1,0}, {0,0,-1}            /* TRACK_NX, TRACK_NY, TRACK_NZ */
 
3501
        {+1, 0, 0}, {0, +1, 0}, {0, 0, +1},     /* TRACK_X,  TRACK_Y,  TRACK_Z */
 
3502
        {-1, 0, 0}, {0, -1, 0}, {0, 0, -1}      /* TRACK_NX, TRACK_NY, TRACK_NZ */
3614
3503
};
3615
3504
 
3616
 
static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
3505
static void damptrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
3617
3506
{
3618
 
        bDampTrackConstraint *data= con->data;
3619
 
        bConstraintTarget *ct= targets->first;
 
3507
        bDampTrackConstraint *data = con->data;
 
3508
        bConstraintTarget *ct = targets->first;
3620
3509
        
3621
3510
        if (VALID_CONS_TARGET(ct)) {
3622
3511
                float obvec[3], tarvec[3], obloc[3];
3642
3531
                
3643
3532
                if (normalize_v3(tarvec) == 0.0f) {
3644
3533
                        /* the target is sitting on the owner, so just make them use the same direction vectors */
3645
 
                        // FIXME: or would it be better to use the pure direction vector?
 
3534
                        /* FIXME: or would it be better to use the pure direction vector? */
3646
3535
                        copy_v3_v3(tarvec, obvec);
3647
3536
                        //copy_v3_v3(tarvec, track_dir_vecs[data->trackflag]);
3648
3537
                }
3657
3546
                 */
3658
3547
                cross_v3_v3v3(raxis, obvec, tarvec);
3659
3548
                
3660
 
                rangle= dot_v3v3(obvec, tarvec);
3661
 
                rangle= acos( MAX2(-1.0f, MIN2(1.0f, rangle)) );
 
3549
                rangle = dot_v3v3(obvec, tarvec);
 
3550
                rangle = acos(max_ff(-1.0f, min_ff(1.0f, rangle)));
3662
3551
                
3663
3552
                /* construct rotation matrix from the axis-angle rotation found above 
3664
3553
                 *      - this call takes care to make sure that the axis provided is a unit vector first
3682
3571
        "Damped Track", /* name */
3683
3572
        "bDampTrackConstraint", /* struct name */
3684
3573
        NULL, /* free data */
3685
 
        NULL, /* relink data */
3686
3574
        damptrack_id_looper, /* id looper */
3687
3575
        NULL, /* copy data */
3688
3576
        damptrack_new_data, /* new data */
3694
3582
 
3695
3583
/* ----------- Spline IK ------------ */
3696
3584
 
3697
 
static void splineik_free (bConstraint *con)
 
3585
static void splineik_free(bConstraint *con)
3698
3586
{
3699
 
        bSplineIKConstraint *data= con->data;
 
3587
        bSplineIKConstraint *data = con->data;
3700
3588
        
3701
3589
        /* binding array */
3702
3590
        if (data->points)
3703
3591
                MEM_freeN(data->points);
3704
3592
}       
3705
3593
 
3706
 
static void splineik_copy (bConstraint *con, bConstraint *srccon)
 
3594
static void splineik_copy(bConstraint *con, bConstraint *srccon)
3707
3595
{
3708
 
        bSplineIKConstraint *src= srccon->data;
3709
 
        bSplineIKConstraint *dst= con->data;
 
3596
        bSplineIKConstraint *src = srccon->data;
 
3597
        bSplineIKConstraint *dst = con->data;
3710
3598
        
3711
3599
        /* copy the binding array */
3712
 
        dst->points= MEM_dupallocN(src->points);
3713
 
}
3714
 
 
3715
 
static void splineik_new_data (void *cdata)
3716
 
{
3717
 
        bSplineIKConstraint *data= (bSplineIKConstraint *)cdata;
3718
 
 
3719
 
        data->chainlen= 1;
3720
 
}
3721
 
 
3722
 
static void splineik_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
3723
 
{
3724
 
        bSplineIKConstraint *data= con->data;
 
3600
        dst->points = MEM_dupallocN(src->points);
 
3601
}
 
3602
 
 
3603
static void splineik_new_data(void *cdata)
 
3604
{
 
3605
        bSplineIKConstraint *data = (bSplineIKConstraint *)cdata;
 
3606
 
 
3607
        data->chainlen = 1;
 
3608
}
 
3609
 
 
3610
static void splineik_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
 
3611
{
 
3612
        bSplineIKConstraint *data = con->data;
3725
3613
        
3726
3614
        /* target only */
3727
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
3615
        func(con, (ID **)&data->tar, FALSE, userdata);
3728
3616
}
3729
3617
 
3730
 
static int splineik_get_tars (bConstraint *con, ListBase *list)
 
3618
static int splineik_get_tars(bConstraint *con, ListBase *list)
3731
3619
{
3732
3620
        if (con && list) {
3733
 
                bSplineIKConstraint *data= con->data;
 
3621
                bSplineIKConstraint *data = con->data;
3734
3622
                bConstraintTarget *ct;
3735
3623
                
3736
3624
                /* standard target-getting macro for single-target constraints without subtargets */
3737
 
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list)
 
3625
                SINGLETARGETNS_GET_TARS(con, data->tar, ct, list);
3738
3626
                
3739
3627
                return 1;
3740
3628
        }
3742
3630
        return 0;
3743
3631
}
3744
3632
 
3745
 
static void splineik_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
3633
static void splineik_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3746
3634
{
3747
3635
        if (con && list) {
3748
 
                bSplineIKConstraint *data= con->data;
3749
 
                bConstraintTarget *ct= list->first;
 
3636
                bSplineIKConstraint *data = con->data;
 
3637
                bConstraintTarget *ct = list->first;
3750
3638
                
3751
3639
                /* the following macro is used for all standard single-target constraints */
3752
 
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy)
 
3640
                SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, nocopy);
3753
3641
        }
3754
3642
}
3755
3643
 
3756
 
static void splineik_get_tarmat (bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
 
3644
static void splineik_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
3757
3645
{
3758
3646
        if (VALID_CONS_TARGET(ct)) {
3759
 
                Curve *cu= ct->tar->data;
 
3647
                Curve *cu = ct->tar->data;
3760
3648
                
3761
3649
                /* note: when creating constraints that follow path, the curve gets the CU_PATH set now,
3762
3650
                 *              currently for paths to work it needs to go through the bevlist/displist system (ton) 
3763
3651
                 */
3764
3652
                
3765
3653
                /* only happens on reload file, but violates depsgraph still... fix! */
3766
 
                if (cu->path==NULL || cu->path->data==NULL)
3767
 
                        makeDispListCurveTypes(cob->scene, ct->tar, 0);
 
3654
                if (cu->path == NULL || cu->path->data == NULL)
 
3655
                        BKE_displist_make_curveTypes(cob->scene, ct->tar, 0);
3768
3656
        }
3769
3657
        
3770
3658
        /* technically, this isn't really needed for evaluation, but we don't know what else
3780
3668
        "Spline IK", /* name */
3781
3669
        "bSplineIKConstraint", /* struct name */
3782
3670
        splineik_free, /* free data */
3783
 
        NULL, /* relink data */
3784
3671
        splineik_id_looper, /* id looper */
3785
3672
        splineik_copy, /* copy data */
3786
3673
        splineik_new_data, /* new data */
3792
3679
 
3793
3680
/* ----------- Pivot ------------- */
3794
3681
 
3795
 
static void pivotcon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
 
3682
static void pivotcon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
3796
3683
{
3797
 
        bPivotConstraint *data= con->data;
 
3684
        bPivotConstraint *data = con->data;
3798
3685
        
3799
3686
        /* target only */
3800
 
        func(con, (ID**)&data->tar, FALSE, userdata);
 
3687
        func(con, (ID **)&data->tar, FALSE, userdata);
3801
3688
}
3802
3689
 
3803
 
static int pivotcon_get_tars (bConstraint *con, ListBase *list)
 
3690
static int pivotcon_get_tars(bConstraint *con, ListBase *list)
3804
3691
{
3805
3692
        if (con && list) {
3806
 
                bPivotConstraint *data= con->data;
 
3693
                bPivotConstraint *data = con->data;
3807
3694
                bConstraintTarget *ct;
3808
3695
                
3809
3696
                /* standard target-getting macro for single-target constraints */
3810
 
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list)
 
3697
                SINGLETARGET_GET_TARS(con, data->tar, data->subtarget, ct, list);
3811
3698
                
3812
3699
                return 1;
3813
3700
        }
3815
3702
        return 0;
3816
3703
}
3817
3704
 
3818
 
static void pivotcon_flush_tars (bConstraint *con, ListBase *list, short nocopy)
 
3705
static void pivotcon_flush_tars(bConstraint *con, ListBase *list, short nocopy)
3819
3706
{
3820
3707
        if (con && list) {
3821
 
                bPivotConstraint *data= con->data;
3822
 
                bConstraintTarget *ct= list->first;
 
3708
                bPivotConstraint *data = con->data;
 
3709
                bConstraintTarget *ct = list->first;
3823
3710
                
3824
3711
                /* the following macro is used for all standard single-target constraints */
3825
 
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy)
 
3712
                SINGLETARGET_FLUSH_TARS(con, data->tar, data->subtarget, ct, list, nocopy);
3826
3713
        }
3827
3714
}
3828
3715
 
3829
 
static void pivotcon_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
 
3716
static void pivotcon_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
3830
3717
{
3831
 
        bPivotConstraint *data= con->data;
3832
 
        bConstraintTarget *ct= targets->first;
 
3718
        bPivotConstraint *data = con->data;
 
3719
        bConstraintTarget *ct = targets->first;
3833
3720
        
3834
3721
        float pivot[3], vec[3];
3835
3722
        float rotMat[3][3];
3875
3762
        }
3876
3763
        
3877
3764
        /* get rotation matrix representing the rotation of the owner */
3878
 
        // TODO: perhaps we might want to include scaling based on the pivot too?
 
3765
        /* TODO: perhaps we might want to include scaling based on the pivot too? */
3879
3766
        copy_m3_m4(rotMat, cob->matrix);
3880
3767
        normalize_m3(rotMat);
3881
3768
 
3890
3777
        }
3891
3778
 
3892
3779
        /* perform the pivoting... */
3893
 
                /* 1. take the vector from owner to the pivot */
 
3780
        /* 1. take the vector from owner to the pivot */
3894
3781
        sub_v3_v3v3(vec, cob->matrix[3], pivot);
3895
 
                /* 2. rotate this vector by the rotation of the object... */
 
3782
        /* 2. rotate this vector by the rotation of the object... */
3896
3783
        mul_m3_v3(rotMat, vec);
3897
 
                /* 3. make the rotation in terms of the pivot now */
 
3784
        /* 3. make the rotation in terms of the pivot now */
3898
3785
        add_v3_v3v3(cob->matrix[3], pivot, vec);
3899
3786
}
3900
3787
 
3905
3792
        "Pivot", /* name */
3906
3793
        "bPivotConstraint", /* struct name */
3907
3794
        NULL, /* free data */
3908
 
        NULL, /* relink data */
3909
3795
        pivotcon_id_looper, /* id looper */
3910
3796
        NULL, /* copy data */
3911
3797
        NULL, /* new data */ // XXX: might be needed to get 'normal' pivot behavior...
3929
3815
{
3930
3816
        bFollowTrackConstraint *data = con->data;
3931
3817
 
3932
 
        func(con, (ID**)&data->clip, TRUE, userdata);
3933
 
        func(con, (ID**)&data->camera, FALSE, userdata);
3934
 
        func(con, (ID**)&data->depth_ob, FALSE, userdata);
 
3818
        func(con, (ID **)&data->clip, TRUE, userdata);
 
3819
        func(con, (ID **)&data->camera, FALSE, userdata);
 
3820
        func(con, (ID **)&data->depth_ob, FALSE, userdata);
3935
3821
}
3936
3822
 
3937
3823
static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
3942
3828
        MovieTracking *tracking;
3943
3829
        MovieTrackingTrack *track;
3944
3830
        MovieTrackingObject *tracking_object;
3945
 
        Object *camob= data->camera ? data->camera : scene->camera;
 
3831
        Object *camob = data->camera ? data->camera : scene->camera;
 
3832
        int framenr;
3946
3833
 
3947
3834
        if (data->flag & FOLLOWTRACK_ACTIVECLIP)
3948
 
                clip= scene->clip;
 
3835
                clip = scene->clip;
3949
3836
 
3950
3837
        if (!clip || !data->track[0] || !camob)
3951
3838
                return;
3953
3840
        tracking = &clip->tracking;
3954
3841
 
3955
3842
        if (data->object[0])
3956
 
                tracking_object = BKE_tracking_named_object(tracking, data->object);
 
3843
                tracking_object = BKE_tracking_object_get_named(tracking, data->object);
3957
3844
        else
3958
 
                tracking_object = BKE_tracking_get_camera_object(tracking);
 
3845
                tracking_object = BKE_tracking_object_get_camera(tracking);
3959
3846
 
3960
3847
        if (!tracking_object)
3961
3848
                return;
3962
3849
 
3963
 
        track = BKE_tracking_named_track(tracking, tracking_object, data->track);
 
3850
        track = BKE_tracking_track_get_named(tracking, tracking_object, data->track);
3964
3851
 
3965
3852
        if (!track)
3966
3853
                return;
3967
3854
 
 
3855
        framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, scene->r.cfra);
 
3856
 
3968
3857
        if (data->flag & FOLLOWTRACK_USE_3D_POSITION) {
3969
3858
                if (track->flag & TRACK_HAS_BUNDLE) {
3970
3859
                        float obmat[4][4], mat[4][4];
3971
3860
 
3972
3861
                        copy_m4_m4(obmat, cob->matrix);
3973
3862
 
3974
 
                        if ((tracking_object->flag & TRACKING_OBJECT_CAMERA)==0) {
 
3863
                        if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0) {
3975
3864
                                float imat[4][4];
3976
3865
 
3977
3866
                                copy_m4_m4(mat, camob->obmat);
3978
3867
 
3979
 
                                BKE_tracking_get_interpolated_camera(tracking, tracking_object, scene->r.cfra, imat);
 
3868
                                BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object, framenr, imat);
3980
3869
                                invert_m4(imat);
3981
3870
 
3982
3871
                                mul_serie_m4(cob->matrix, obmat, mat, imat, NULL, NULL, NULL, NULL, NULL);
3983
3872
                                translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
3984
3873
                        }
3985
3874
                        else {
3986
 
                                BKE_get_tracking_mat(cob->scene, camob, mat);
 
3875
                                BKE_tracking_get_camera_object_matrix(cob->scene, camob, mat);
3987
3876
 
3988
3877
                                mult_m4_m4m4(cob->matrix, obmat, mat);
3989
3878
                                translate_m4(cob->matrix, track->bundle_pos[0], track->bundle_pos[1], track->bundle_pos[2]);
3993
3882
        else {
3994
3883
                MovieTrackingMarker *marker;
3995
3884
                float vec[3], disp[3], axis[3], mat[4][4];
3996
 
                float aspect= (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp);
 
3885
                float aspect = (scene->r.xsch * scene->r.xasp) / (scene->r.ysch * scene->r.yasp);
3997
3886
                float len, d;
3998
3887
 
3999
 
                where_is_object_mat(scene, camob, mat);
 
3888
                BKE_object_where_is_calc_mat4(scene, camob, mat);
4000
3889
 
4001
3890
                /* camera axis */
4002
3891
                vec[0] = 0.0f;
4015
3904
                        CameraParams params;
4016
3905
                        float pos[2], rmat[4][4];
4017
3906
 
4018
 
                        marker = BKE_tracking_get_marker(track, scene->r.cfra);
 
3907
                        marker = BKE_tracking_marker_get(track, framenr);
4019
3908
 
4020
3909
                        add_v2_v2v2(pos, marker->pos, track->offset);
4021
3910
 
4022
 
                        camera_params_init(&params);
4023
 
                        camera_params_from_object(&params, camob);
 
3911
                        /* aspect correction */
 
3912
                        if (data->frame_method != FOLLOWTRACK_FRAME_STRETCH) {
 
3913
                                int width, height;
 
3914
                                float w_src, h_src, w_dst, h_dst, asp_src, asp_dst;
 
3915
 
 
3916
                                BKE_movieclip_get_size(clip, NULL, &width, &height);
 
3917
 
 
3918
                                /* apply clip display aspect */
 
3919
                                w_src = width * clip->aspx;
 
3920
                                h_src = height * clip->aspy;
 
3921
 
 
3922
                                w_dst = scene->r.xsch * scene->r.xasp;
 
3923
                                h_dst = scene->r.ysch * scene->r.yasp;
 
3924
 
 
3925
                                asp_src = w_src / h_src;
 
3926
                                asp_dst = w_dst / h_dst;
 
3927
 
 
3928
                                if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
 
3929
                                        if ((asp_src > asp_dst) == (data->frame_method == FOLLOWTRACK_FRAME_CROP)) {
 
3930
                                                /* fit X */
 
3931
                                                float div = asp_src / asp_dst;
 
3932
                                                float cent = (float) width / 2.0f;
 
3933
 
 
3934
                                                pos[0] = (((pos[0] * width - cent) * div) + cent) / width;
 
3935
                                        }
 
3936
                                        else {
 
3937
                                                /* fit Y */
 
3938
                                                float div = asp_dst / asp_src;
 
3939
                                                float cent = (float) height / 2.0f;
 
3940
 
 
3941
                                                pos[1] = (((pos[1] * height - cent) * div) + cent) / height;
 
3942
                                        }
 
3943
                                }
 
3944
                        }
 
3945
 
 
3946
                        BKE_camera_params_init(&params);
 
3947
                        BKE_camera_params_from_object(&params, camob);
4024
3948
 
4025
3949
                        if (params.is_ortho) {
4026
3950
                                vec[0] = params.ortho_scale * (pos[0] - 0.5f + params.shiftx);
4041
3965
                                copy_v3_v3(cob->matrix[3], disp);
4042
3966
                        }
4043
3967
                        else {
4044
 
                                d=  (len * params.sensor_x) / (2.0f * params.lens);
 
3968
                                d =  (len * params.sensor_x) / (2.0f * params.lens);
4045
3969
 
4046
3970
                                vec[0] = d * (2.0f * (pos[0] + params.shiftx) - 1.0f);
4047
3971
                                vec[1] = d * (2.0f * (pos[1] + params.shifty) - 1.0f);
4062
3986
                                copy_v3_v3(cob->matrix[3], disp);
4063
3987
                        }
4064
3988
 
4065
 
                        if (data->depth_ob && data->depth_ob->derivedFinal) {
 
3989
                        if (data->depth_ob) {
4066
3990
                                Object *depth_ob = data->depth_ob;
4067
 
                                BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;
4068
 
                                BVHTreeRayHit hit;
4069
 
                                float ray_start[3], ray_end[3], ray_nor[3], imat[4][4];
4070
 
                                int result;
4071
 
 
4072
 
                                invert_m4_m4(imat, depth_ob->obmat);
4073
 
 
4074
 
                                mul_v3_m4v3(ray_start, imat, camob->obmat[3]);
4075
 
                                mul_v3_m4v3(ray_end, imat, cob->matrix[3]);
4076
 
 
4077
 
                                sub_v3_v3v3(ray_nor, ray_end, ray_start);
4078
 
 
4079
 
                                bvhtree_from_mesh_faces(&treeData, depth_ob->derivedFinal, 0.0f, 4, 6);
4080
 
 
4081
 
                                hit.dist = FLT_MAX;
4082
 
                                hit.index = -1;
4083
 
 
4084
 
                                result = BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData);
4085
 
 
4086
 
                                if (result != -1) {
4087
 
                                        mul_v3_m4v3(cob->matrix[3], depth_ob->obmat, hit.co);
 
3991
                                DerivedMesh *target = object_get_derived_final(depth_ob);
 
3992
                                if (target) {
 
3993
                                        BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;
 
3994
                                        BVHTreeRayHit hit;
 
3995
                                        float ray_start[3], ray_end[3], ray_nor[3], imat[4][4];
 
3996
                                        int result;
 
3997
 
 
3998
                                        invert_m4_m4(imat, depth_ob->obmat);
 
3999
 
 
4000
                                        mul_v3_m4v3(ray_start, imat, camob->obmat[3]);
 
4001
                                        mul_v3_m4v3(ray_end, imat, cob->matrix[3]);
 
4002
 
 
4003
                                        sub_v3_v3v3(ray_nor, ray_end, ray_start);
 
4004
 
 
4005
                                        bvhtree_from_mesh_faces(&treeData, target, 0.0f, 4, 6);
 
4006
 
 
4007
                                        hit.dist = FLT_MAX;
 
4008
                                        hit.index = -1;
 
4009
 
 
4010
                                        result = BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData);
 
4011
 
 
4012
                                        if (result != -1) {
 
4013
                                                mul_v3_m4v3(cob->matrix[3], depth_ob->obmat, hit.co);
 
4014
                                        }
 
4015
 
 
4016
                                        free_bvhtree_from_mesh(&treeData);
 
4017
                                        target->release(target);
4088
4018
                                }
4089
 
 
4090
 
                                free_bvhtree_from_mesh(&treeData);
4091
4019
                        }
4092
4020
                }
4093
4021
        }
4099
4027
        "Follow Track", /* name */
4100
4028
        "bFollowTrackConstraint", /* struct name */
4101
4029
        NULL, /* free data */
4102
 
        NULL, /* relink data */
4103
4030
        followtrack_id_looper, /* id looper */
4104
4031
        NULL, /* copy data */
4105
4032
        followtrack_new_data, /* new data */
4123
4050
{
4124
4051
        bCameraSolverConstraint *data = con->data;
4125
4052
 
4126
 
        func(con, (ID**)&data->clip, TRUE, userdata);
 
4053
        func(con, (ID **)&data->clip, TRUE, userdata);
4127
4054
}
4128
4055
 
4129
4056
static void camerasolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
4138
4065
        if (clip) {
4139
4066
                float mat[4][4], obmat[4][4];
4140
4067
                MovieTracking *tracking = &clip->tracking;
4141
 
                MovieTrackingObject *object = BKE_tracking_get_camera_object(tracking);
 
4068
                MovieTrackingObject *object = BKE_tracking_object_get_camera(tracking);
 
4069
                int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, scene->r.cfra);
4142
4070
 
4143
 
                BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat);
 
4071
                BKE_tracking_camera_get_reconstructed_interpolate(tracking, object, framenr, mat);
4144
4072
 
4145
4073
                copy_m4_m4(obmat, cob->matrix);
4146
4074
 
4154
4082
        "Camera Solver", /* name */
4155
4083
        "bCameraSolverConstraint", /* struct name */
4156
4084
        NULL, /* free data */
4157
 
        NULL, /* relink data */
4158
4085
        camerasolver_id_looper, /* id looper */
4159
4086
        NULL, /* copy data */
4160
4087
        camerasolver_new_data, /* new data */
4177
4104
 
4178
4105
static void objectsolver_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
4179
4106
{
4180
 
        bObjectSolverConstraint *data= con->data;
 
4107
        bObjectSolverConstraint *data = con->data;
4181
4108
 
4182
 
        func(con, (ID**)&data->clip, FALSE, userdata);
4183
 
        func(con, (ID**)&data->camera, FALSE, userdata);
 
4109
        func(con, (ID **)&data->clip, FALSE, userdata);
 
4110
        func(con, (ID **)&data->camera, FALSE, userdata);
4184
4111
}
4185
4112
 
4186
4113
static void objectsolver_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *UNUSED(targets))
4191
4118
        Object *camob = data->camera ? data->camera : scene->camera;
4192
4119
 
4193
4120
        if (data->flag & OBJECTSOLVER_ACTIVECLIP)
4194
 
                clip= scene->clip;
 
4121
                clip = scene->clip;
4195
4122
 
4196
4123
        if (!camob || !clip)
4197
4124
                return;
4200
4127
                MovieTracking *tracking = &clip->tracking;
4201
4128
                MovieTrackingObject *object;
4202
4129
 
4203
 
                object = BKE_tracking_named_object(tracking, data->object);
 
4130
                object = BKE_tracking_object_get_named(tracking, data->object);
4204
4131
 
4205
4132
                if (object) {
4206
4133
                        float mat[4][4], obmat[4][4], imat[4][4], cammat[4][4], camimat[4][4], parmat[4][4];
4207
 
 
4208
 
                        where_is_object_mat(scene, camob, cammat);
4209
 
 
4210
 
                        BKE_tracking_get_interpolated_camera(tracking, object, scene->r.cfra, mat);
 
4134
                        int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, scene->r.cfra);
 
4135
 
 
4136
                        BKE_object_where_is_calc_mat4(scene, camob, cammat);
 
4137
 
 
4138
                        BKE_tracking_camera_get_reconstructed_interpolate(tracking, object, framenr, mat);
4211
4139
 
4212
4140
                        invert_m4_m4(camimat, cammat);
4213
4141
                        mult_m4_m4m4(parmat, cammat, data->invmat);
4228
4156
        "Object Solver", /* name */
4229
4157
        "bObjectSolverConstraint", /* struct name */
4230
4158
        NULL, /* free data */
4231
 
        NULL, /* relink data */
4232
4159
        objectsolver_id_looper, /* id looper */
4233
4160
        NULL, /* copy data */
4234
4161
        objectsolver_new_data, /* new data */
4245
4172
 
4246
4173
/* These globals only ever get directly accessed in this file */
4247
4174
static bConstraintTypeInfo *constraintsTypeInfo[NUM_CONSTRAINT_TYPES];
4248
 
static short CTI_INIT= 1; /* when non-zero, the list needs to be updated */
 
4175
static short CTI_INIT = 1; /* when non-zero, the list needs to be updated */
4249
4176
 
4250
4177
/* This function only gets called when CTI_INIT is non-zero */
4251
 
static void constraints_init_typeinfo (void)
 
4178
static void constraints_init_typeinfo(void)
4252
4179
{
4253
 
        constraintsTypeInfo[0]=  NULL;                                  /* 'Null' Constraint */
4254
 
        constraintsTypeInfo[1]=  &CTI_CHILDOF;                  /* ChildOf Constraint */
4255
 
        constraintsTypeInfo[2]=  &CTI_TRACKTO;                  /* TrackTo Constraint */
4256
 
        constraintsTypeInfo[3]=  &CTI_KINEMATIC;                /* IK Constraint */
4257
 
        constraintsTypeInfo[4]=  &CTI_FOLLOWPATH;               /* Follow-Path Constraint */
4258
 
        constraintsTypeInfo[5]=  &CTI_ROTLIMIT;                 /* Limit Rotation Constraint */
4259
 
        constraintsTypeInfo[6]=  &CTI_LOCLIMIT;                 /* Limit Location Constraint */
4260
 
        constraintsTypeInfo[7]=  &CTI_SIZELIMIT;                /* Limit Scaling Constraint */
4261
 
        constraintsTypeInfo[8]=  &CTI_ROTLIKE;                  /* Copy Rotation Constraint */
4262
 
        constraintsTypeInfo[9]=  &CTI_LOCLIKE;                  /* Copy Location Constraint */
4263
 
        constraintsTypeInfo[10]= &CTI_SIZELIKE;                 /* Copy Scaling Constraint */
4264
 
        constraintsTypeInfo[11]= &CTI_PYTHON;                   /* Python/Script Constraint */
4265
 
        constraintsTypeInfo[12]= &CTI_ACTION;                   /* Action Constraint */
4266
 
        constraintsTypeInfo[13]= &CTI_LOCKTRACK;                /* Locked-Track Constraint */
4267
 
        constraintsTypeInfo[14]= &CTI_DISTLIMIT;                /* Limit Distance Constraint */
4268
 
        constraintsTypeInfo[15]= &CTI_STRETCHTO;                /* StretchTo Constaint */ 
4269
 
        constraintsTypeInfo[16]= &CTI_MINMAX;                   /* Floor Constraint */
4270
 
        constraintsTypeInfo[17]= &CTI_RIGIDBODYJOINT;   /* RigidBody Constraint */
4271
 
        constraintsTypeInfo[18]= &CTI_CLAMPTO;                  /* ClampTo Constraint */        
4272
 
        constraintsTypeInfo[19]= &CTI_TRANSFORM;                /* Transformation Constraint */
4273
 
        constraintsTypeInfo[20]= &CTI_SHRINKWRAP;               /* Shrinkwrap Constraint */
4274
 
        constraintsTypeInfo[21]= &CTI_DAMPTRACK;                /* Damped TrackTo Constraint */
4275
 
        constraintsTypeInfo[22]= &CTI_SPLINEIK;                 /* Spline IK Constraint */
4276
 
        constraintsTypeInfo[23]= &CTI_TRANSLIKE;                /* Copy Transforms Constraint */
4277
 
        constraintsTypeInfo[24]= &CTI_SAMEVOL;                  /* Maintain Volume Constraint */
4278
 
        constraintsTypeInfo[25]= &CTI_PIVOT;                    /* Pivot Constraint */
4279
 
        constraintsTypeInfo[26]= &CTI_FOLLOWTRACK;              /* Follow Track Constraint */
4280
 
        constraintsTypeInfo[27]= &CTI_CAMERASOLVER;             /* Camera Solver Constraint */
4281
 
        constraintsTypeInfo[28]= &CTI_OBJECTSOLVER;             /* Object Solver Constraint */
 
4180
        constraintsTypeInfo[0] =  NULL;                  /* 'Null' Constraint */
 
4181
        constraintsTypeInfo[1] =  &CTI_CHILDOF;          /* ChildOf Constraint */
 
4182
        constraintsTypeInfo[2] =  &CTI_TRACKTO;          /* TrackTo Constraint */
 
4183
        constraintsTypeInfo[3] =  &CTI_KINEMATIC;        /* IK Constraint */
 
4184
        constraintsTypeInfo[4] =  &CTI_FOLLOWPATH;       /* Follow-Path Constraint */
 
4185
        constraintsTypeInfo[5] =  &CTI_ROTLIMIT;         /* Limit Rotation Constraint */
 
4186
        constraintsTypeInfo[6] =  &CTI_LOCLIMIT;         /* Limit Location Constraint */
 
4187
        constraintsTypeInfo[7] =  &CTI_SIZELIMIT;        /* Limit Scale Constraint */
 
4188
        constraintsTypeInfo[8] =  &CTI_ROTLIKE;          /* Copy Rotation Constraint */
 
4189
        constraintsTypeInfo[9] =  &CTI_LOCLIKE;          /* Copy Location Constraint */
 
4190
        constraintsTypeInfo[10] = &CTI_SIZELIKE;         /* Copy Scale Constraint */
 
4191
        constraintsTypeInfo[11] = &CTI_PYTHON;           /* Python/Script Constraint */
 
4192
        constraintsTypeInfo[12] = &CTI_ACTION;           /* Action Constraint */
 
4193
        constraintsTypeInfo[13] = &CTI_LOCKTRACK;        /* Locked-Track Constraint */
 
4194
        constraintsTypeInfo[14] = &CTI_DISTLIMIT;        /* Limit Distance Constraint */
 
4195
        constraintsTypeInfo[15] = &CTI_STRETCHTO;        /* StretchTo Constaint */
 
4196
        constraintsTypeInfo[16] = &CTI_MINMAX;           /* Floor Constraint */
 
4197
        constraintsTypeInfo[17] = &CTI_RIGIDBODYJOINT;   /* RigidBody Constraint */
 
4198
        constraintsTypeInfo[18] = &CTI_CLAMPTO;          /* ClampTo Constraint */
 
4199
        constraintsTypeInfo[19] = &CTI_TRANSFORM;        /* Transformation Constraint */
 
4200
        constraintsTypeInfo[20] = &CTI_SHRINKWRAP;       /* Shrinkwrap Constraint */
 
4201
        constraintsTypeInfo[21] = &CTI_DAMPTRACK;        /* Damped TrackTo Constraint */
 
4202
        constraintsTypeInfo[22] = &CTI_SPLINEIK;         /* Spline IK Constraint */
 
4203
        constraintsTypeInfo[23] = &CTI_TRANSLIKE;        /* Copy Transforms Constraint */
 
4204
        constraintsTypeInfo[24] = &CTI_SAMEVOL;          /* Maintain Volume Constraint */
 
4205
        constraintsTypeInfo[25] = &CTI_PIVOT;            /* Pivot Constraint */
 
4206
        constraintsTypeInfo[26] = &CTI_FOLLOWTRACK;      /* Follow Track Constraint */
 
4207
        constraintsTypeInfo[27] = &CTI_CAMERASOLVER;     /* Camera Solver Constraint */
 
4208
        constraintsTypeInfo[28] = &CTI_OBJECTSOLVER;     /* Object Solver Constraint */
4282
4209
}
4283
4210
 
4284
4211
/* This function should be used for getting the appropriate type-info when only
4285
4212
 * a constraint type is known
4286
4213
 */
4287
 
bConstraintTypeInfo *get_constraint_typeinfo (int type)
 
4214
bConstraintTypeInfo *BKE_get_constraint_typeinfo(int type)
4288
4215
{
4289
4216
        /* initialize the type-info list? */
4290
4217
        if (CTI_INIT) {
4293
4220
        }
4294
4221
        
4295
4222
        /* only return for valid types */
4296
 
        if ( (type >= CONSTRAINT_TYPE_NULL) && 
4297
 
                 (type < NUM_CONSTRAINT_TYPES ) ) 
 
4223
        if ((type >= CONSTRAINT_TYPE_NULL) &&
 
4224
            (type < NUM_CONSTRAINT_TYPES))
4298
4225
        {
4299
4226
                /* there shouldn't be any segfaults here... */
4300
4227
                return constraintsTypeInfo[type];
4309
4236
/* This function should always be used to get the appropriate type-info, as it
4310
4237
 * has checks which prevent segfaults in some weird cases.
4311
4238
 */
4312
 
bConstraintTypeInfo *constraint_get_typeinfo (bConstraint *con)
 
4239
bConstraintTypeInfo *BKE_constraint_get_typeinfo(bConstraint *con)
4313
4240
{
4314
4241
        /* only return typeinfo for valid constraints */
4315
4242
        if (con)
4316
 
                return get_constraint_typeinfo(con->type);
 
4243
                return BKE_get_constraint_typeinfo(con->type);
4317
4244
        else
4318
4245
                return NULL;
4319
4246
}
4325
4252
 
4326
4253
/* ---------- Data Management ------- */
4327
4254
 
 
4255
/* helper function for BKE_free_constraint_data() - unlinks references */
 
4256
static void con_unlink_refs_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *UNUSED(userData))
 
4257
{
 
4258
        if (*idpoin && isReference)
 
4259
                id_us_min(*idpoin);
 
4260
}
 
4261
 
4328
4262
/* Free data of a specific constraint if it has any info.
4329
4263
 * be sure to run BIK_clear_data() when freeing an IK constraint,
4330
 
 * unless DAG_scene_sort is called. */
4331
 
void free_constraint_data (bConstraint *con)
 
4264
 * unless DAG_scene_sort is called. 
 
4265
 */
 
4266
void BKE_free_constraint_data(bConstraint *con)
4332
4267
{
4333
4268
        if (con->data) {
4334
 
                bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
4269
                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
4335
4270
                
4336
 
                /* perform any special freeing constraint may have */
4337
 
                if (cti && cti->free_data)
4338
 
                        cti->free_data(con);
 
4271
                if (cti) {
 
4272
                        /* perform any special freeing constraint may have */
 
4273
                        if (cti->free_data)
 
4274
                                cti->free_data(con);
 
4275
                                
 
4276
                        /* unlink the referenced resources it uses */
 
4277
                        if (cti->id_looper)
 
4278
                                cti->id_looper(con, con_unlink_refs_cb, NULL);
 
4279
                }
4339
4280
                
4340
4281
                /* free constraint data now */
4341
4282
                MEM_freeN(con->data);
4343
4284
}
4344
4285
 
4345
4286
/* Free all constraints from a constraint-stack */
4346
 
void free_constraints (ListBase *list)
 
4287
void BKE_free_constraints(ListBase *list)
4347
4288
{
4348
4289
        bConstraint *con;
4349
4290
        
4350
4291
        /* Free constraint data and also any extra data */
4351
 
        for (con= list->first; con; con= con->next)
4352
 
                free_constraint_data(con);
 
4292
        for (con = list->first; con; con = con->next)
 
4293
                BKE_free_constraint_data(con);
4353
4294
        
4354
4295
        /* Free the whole list */
4355
4296
        BLI_freelistN(list);
4357
4298
 
4358
4299
 
4359
4300
/* Remove the specified constraint from the given constraint stack */
4360
 
int remove_constraint (ListBase *list, bConstraint *con)
 
4301
int BKE_remove_constraint(ListBase *list, bConstraint *con)
4361
4302
{
4362
4303
        if (con) {
4363
 
                free_constraint_data(con);
 
4304
                BKE_free_constraint_data(con);
4364
4305
                BLI_freelinkN(list, con);
4365
4306
                return 1;
4366
4307
        }
4369
4310
}
4370
4311
 
4371
4312
/* Remove all the constraints of the specified type from the given constraint stack */
4372
 
void remove_constraints_type (ListBase *list, short type, short last_only)
 
4313
void BKE_remove_constraints_type(ListBase *list, short type, short last_only)
4373
4314
{
4374
4315
        bConstraint *con, *conp;
4375
4316
        
4377
4318
                return;
4378
4319
        
4379
4320
        /* remove from the end of the list to make it faster to find the last instance */
4380
 
        for (con= list->last; con; con= conp) {
4381
 
                conp= con->prev;
 
4321
        for (con = list->last; con; con = conp) {
 
4322
                conp = con->prev;
4382
4323
                
4383
4324
                if (con->type == type) {
4384
 
                        remove_constraint(list, con);
 
4325
                        BKE_remove_constraint(list, con);
4385
4326
                        if (last_only) 
4386
4327
                                return;
4387
4328
                }
4391
4332
/* ......... */
4392
4333
 
4393
4334
/* Creates a new constraint, initializes its data, and returns it */
4394
 
static bConstraint *add_new_constraint_internal (const char *name, short type)
 
4335
static bConstraint *add_new_constraint_internal(const char *name, short type)
4395
4336
{
4396
 
        bConstraint *con= MEM_callocN(sizeof(bConstraint), "Constraint");
4397
 
        bConstraintTypeInfo *cti= get_constraint_typeinfo(type);
 
4337
        bConstraint *con = MEM_callocN(sizeof(bConstraint), "Constraint");
 
4338
        bConstraintTypeInfo *cti = BKE_get_constraint_typeinfo(type);
4398
4339
        const char *newName;
4399
4340
 
4400
4341
        /* Set up a generic constraint datablock */
4412
4353
                        cti->new_data(con->data);
4413
4354
                
4414
4355
                /* if no name is provided, use the type of the constraint as the name */
4415
 
                newName= (name && name[0]) ? name : cti->name;
 
4356
                newName = (name && name[0]) ? name : cti->name;
4416
4357
        }
4417
4358
        else {
4418
4359
                /* if no name is provided, use the generic "Const" name */
4419
 
                // NOTE: any constraint type that gets here really shouldn't get added...
4420
 
                newName= (name && name[0]) ? name : "Const";
 
4360
                /* NOTE: any constraint type that gets here really shouldn't get added... */
 
4361
                newName = (name && name[0]) ? name : "Const";
4421
4362
        }
4422
4363
        
4423
4364
        /* copy the name */
4428
4369
}
4429
4370
 
4430
4371
/* if pchan is not NULL then assume we're adding a pose constraint */
4431
 
static bConstraint *add_new_constraint (Object *ob, bPoseChannel *pchan, const char *name, short type)
 
4372
static bConstraint *add_new_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type)
4432
4373
{
4433
4374
        bConstraint *con;
4434
4375
        ListBase *list;
4435
4376
        
4436
4377
        /* add the constraint */
4437
 
        con= add_new_constraint_internal(name, type);
 
4378
        con = add_new_constraint_internal(name, type);
4438
4379
        
4439
4380
        /* find the constraint stack - bone or object? */
4440
4381
        list = (pchan) ? (&pchan->constraints) : (&ob->constraints);
4444
4385
                 * (otherwise unique-naming code will fail, since it assumes element exists in list)
4445
4386
                 */
4446
4387
                BLI_addtail(list, con);
4447
 
                unique_constraint_name(con, list);
 
4388
                BKE_unique_constraint_name(con, list);
4448
4389
                
4449
4390
                /* if the target list is a list on some PoseChannel belonging to a proxy-protected
4450
4391
                 * Armature layer, we must tag newly added constraints with a flag which allows them
4451
4392
                 * to persist after proxy syncing has been done
4452
4393
                 */
4453
 
                if (proxylocked_constraints_owner(ob, pchan))
 
4394
                if (BKE_proxylocked_constraints_owner(ob, pchan))
4454
4395
                        con->flag |= CONSTRAINT_PROXY_LOCAL;
4455
4396
                
4456
4397
                /* make this constraint the active one */
4457
 
                constraints_set_active(list, con);
 
4398
                BKE_constraints_set_active(list, con);
4458
4399
        }
4459
 
        
 
4400
 
4460
4401
        /* set type+owner specific immutable settings */
4461
 
        // TODO: does action constraint need anything here - i.e. spaceonce?
 
4402
        /* TODO: does action constraint need anything here - i.e. spaceonce? */
4462
4403
        switch (type) {
4463
4404
                case CONSTRAINT_TYPE_CHILDOF:
4464
4405
                {
4469
4410
                                con->flag |= CONSTRAINT_SPACEONCE;
4470
4411
                        }
4471
4412
                }
4472
 
                        break;
 
4413
                break;
4473
4414
        }
4474
4415
        
4475
4416
        return con;
4478
4419
/* ......... */
4479
4420
 
4480
4421
/* Add new constraint for the given bone */
4481
 
bConstraint *add_pose_constraint (Object *ob, bPoseChannel *pchan, const char *name, short type)
 
4422
bConstraint *BKE_add_pose_constraint(Object *ob, bPoseChannel *pchan, const char *name, short type)
4482
4423
{
4483
4424
        if (pchan == NULL)
4484
4425
                return NULL;
4487
4428
}
4488
4429
 
4489
4430
/* Add new constraint for the given object */
4490
 
bConstraint *add_ob_constraint(Object *ob, const char *name, short type)
 
4431
bConstraint *BKE_add_ob_constraint(Object *ob, const char *name, short type)
4491
4432
{
4492
4433
        return add_new_constraint(ob, NULL, name, type);
4493
4434
}
4494
4435
 
4495
4436
/* ......... */
4496
4437
 
 
4438
/* helper for BKE_relink_constraints() - call ID_NEW() on every ID reference the constraint has */
 
4439
static void con_relink_id_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *UNUSED(userdata))
 
4440
{
 
4441
        /* ID_NEW() expects a struct with inline "id" member as first
 
4442
         * since we've got the actual ID block, let's just inline this
 
4443
         * code. 
 
4444
         *
 
4445
         * See ID_NEW(a) in DNA_ID.h
 
4446
         */
 
4447
        if ((*idpoin) && (*idpoin)->newid)
 
4448
                (*idpoin) = (void *)(*idpoin)->newid;
 
4449
}
 
4450
 
4497
4451
/* Reassign links that constraints have to other data (called during file loading?) */
4498
 
void relink_constraints (ListBase *conlist)
 
4452
void BKE_relink_constraints(ListBase *conlist)
4499
4453
{
4500
 
        bConstraint *con;
4501
 
        bConstraintTarget *ct;
4502
 
        
4503
 
        for (con= conlist->first; con; con= con->next) {
4504
 
                bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
4505
 
                
4506
 
                if (cti) {
4507
 
                        /* relink any targets */
4508
 
                        if (cti->get_constraint_targets) {
4509
 
                                ListBase targets = {NULL, NULL};
4510
 
                                
4511
 
                                cti->get_constraint_targets(con, &targets);
4512
 
                                for (ct= targets.first; ct; ct= ct->next) {
4513
 
                                        ID_NEW(ct->tar);
4514
 
                                }
4515
 
                                
4516
 
                                if (cti->flush_constraint_targets)
4517
 
                                        cti->flush_constraint_targets(con, &targets, 0);
4518
 
                        }
4519
 
                        
4520
 
                        /* relink any other special data */
4521
 
                        if (cti->relink_data)
4522
 
                                cti->relink_data(con);
4523
 
                }
4524
 
        }
 
4454
        /* just a wrapper around ID-loop for just calling ID_NEW() on all ID refs */
 
4455
        BKE_id_loop_constraints(conlist, con_relink_id_cb, NULL);
4525
4456
}
4526
4457
 
 
4458
 
4527
4459
/* Run the given callback on all ID-blocks in list of constraints */
4528
 
void id_loop_constraints (ListBase *conlist, ConstraintIDFunc func, void *userdata)
 
4460
void BKE_id_loop_constraints(ListBase *conlist, ConstraintIDFunc func, void *userdata)
4529
4461
{
4530
4462
        bConstraint *con;
4531
4463
        
4532
 
        for (con= conlist->first; con; con= con->next) {
4533
 
                bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
4464
        for (con = conlist->first; con; con = con->next) {
 
4465
                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
4534
4466
                
4535
4467
                if (cti) {
4536
4468
                        if (cti->id_looper)
4541
4473
 
4542
4474
/* ......... */
4543
4475
 
4544
 
/* helper for copy_constraints(), to be used for making sure that ID's are valid */
 
4476
/* helper for BKE_copy_constraints(), to be used for making sure that ID's are valid */
4545
4477
static void con_extern_cb(bConstraint *UNUSED(con), ID **idpoin, short UNUSED(isReference), void *UNUSED(userData))
4546
4478
{
4547
4479
        if (*idpoin && (*idpoin)->lib)
4548
4480
                id_lib_extern(*idpoin);
4549
4481
}
4550
4482
 
4551
 
/* helper for copy_constraints(), to be used for making sure that usercounts of copied ID's are fixed up */
4552
 
static void con_fix_copied_refs_cb(bConstraint *con, ID **idpoin, short isReference, void *UNUSED(userData))
 
4483
/* helper for BKE_copy_constraints(), to be used for making sure that usercounts of copied ID's are fixed up */
 
4484
static void con_fix_copied_refs_cb(bConstraint *UNUSED(con), ID **idpoin, short isReference, void *UNUSED(userData))
4553
4485
{
4554
4486
        /* increment usercount if this is a reference type */
4555
4487
        if ((*idpoin) && (isReference))
4557
4489
}
4558
4490
 
4559
4491
/* duplicate all of the constraints in a constraint stack */
4560
 
void copy_constraints (ListBase *dst, const ListBase *src, int do_extern)
 
4492
void BKE_copy_constraints(ListBase *dst, const ListBase *src, int do_extern)
4561
4493
{
4562
4494
        bConstraint *con, *srccon;
4563
4495
        
4564
 
        dst->first= dst->last= NULL;
 
4496
        dst->first = dst->last = NULL;
4565
4497
        BLI_duplicatelist(dst, src);
4566
4498
        
4567
 
        for (con=dst->first, srccon=src->first; con && srccon; srccon=srccon->next, con=con->next) {
4568
 
                bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
4499
        for (con = dst->first, srccon = src->first; con && srccon; srccon = srccon->next, con = con->next) {
 
4500
                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
4569
4501
                
4570
4502
                /* make a new copy of the constraint's data */
4571
4503
                con->data = MEM_dupallocN(con->data);
4592
4524
 
4593
4525
/* ......... */
4594
4526
 
4595
 
bConstraint *constraints_findByName(ListBase *list, const char *name)
 
4527
bConstraint *BKE_constraints_findByName(ListBase *list, const char *name)
4596
4528
{
4597
4529
        return BLI_findstring(list, name, offsetof(bConstraint, name));
4598
4530
}
4599
4531
 
4600
4532
/* finds the 'active' constraint in a constraint stack */
4601
 
bConstraint *constraints_get_active (ListBase *list)
 
4533
bConstraint *BKE_constraints_get_active(ListBase *list)
4602
4534
{
4603
4535
        bConstraint *con;
4604
4536
        
4605
4537
        /* search for the first constraint with the 'active' flag set */
4606
4538
        if (list) {
4607
 
                for (con= list->first; con; con= con->next) {
 
4539
                for (con = list->first; con; con = con->next) {
4608
4540
                        if (con->flag & CONSTRAINT_ACTIVE)
4609
4541
                                return con;
4610
4542
                }
4615
4547
}
4616
4548
 
4617
4549
/* Set the given constraint as the active one (clearing all the others) */
4618
 
void constraints_set_active (ListBase *list, bConstraint *con)
 
4550
void BKE_constraints_set_active(ListBase *list, bConstraint *con)
4619
4551
{
4620
4552
        bConstraint *c;
4621
4553
        
4622
4554
        if (list) {
4623
 
                for (c= list->first; c; c= c->next) {
 
4555
                for (c = list->first; c; c = c->next) {
4624
4556
                        if (c == con) 
4625
4557
                                c->flag |= CONSTRAINT_ACTIVE;
4626
4558
                        else 
4632
4564
/* -------- Constraints and Proxies ------- */
4633
4565
 
4634
4566
/* Rescue all constraints tagged as being CONSTRAINT_PROXY_LOCAL (i.e. added to bone that's proxy-synced in this file) */
4635
 
void extract_proxylocal_constraints (ListBase *dst, ListBase *src)
 
4567
void BKE_extract_proxylocal_constraints(ListBase *dst, ListBase *src)
4636
4568
{
4637
4569
        bConstraint *con, *next;
4638
4570
        
4639
4571
        /* for each tagged constraint, remove from src and move to dst */
4640
 
        for (con= src->first; con; con= next) {
4641
 
                next= con->next;
 
4572
        for (con = src->first; con; con = next) {
 
4573
                next = con->next;
4642
4574
                
4643
4575
                /* check if tagged */
4644
4576
                if (con->flag & CONSTRAINT_PROXY_LOCAL) {
4649
4581
}
4650
4582
 
4651
4583
/* Returns if the owner of the constraint is proxy-protected */
4652
 
short proxylocked_constraints_owner (Object *ob, bPoseChannel *pchan)
 
4584
short BKE_proxylocked_constraints_owner(Object *ob, bPoseChannel *pchan)
4653
4585
{
4654
4586
        /* Currently, constraints can only be on object or bone level */
4655
4587
        if (ob && ob->proxy) {
4656
4588
                if (ob->pose && pchan) {
4657
 
                        bArmature *arm= ob->data;
 
4589
                        bArmature *arm = ob->data;
4658
4590
                        
4659
4591
                        /* On bone-level, check if bone is on proxy-protected layer */
4660
4592
                        if ((pchan->bone) && (pchan->bone->layer & arm->layer_protected))
4663
4595
                else {
4664
4596
                        /* FIXME: constraints on object-level are not handled well yet */
4665
4597
                        return 1;
4666
 
                }       
 
4598
                }
4667
4599
        }
4668
4600
        
4669
4601
        return 0;
4678
4610
 * None of the actual calculations of the matrices should be done here! Also, this function is
4679
4611
 * not to be used by any new constraints, particularly any that have multiple targets.
4680
4612
 */
4681
 
void get_constraint_target_matrix (struct Scene *scene, bConstraint *con, int n, short ownertype, void *ownerdata, float mat[][4], float ctime)
 
4613
void BKE_get_constraint_target_matrix(Scene *scene, bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime)
4682
4614
{
4683
 
        bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
4615
        bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
4684
4616
        ListBase targets = {NULL, NULL};
4685
4617
        bConstraintOb *cob;
4686
4618
        bConstraintTarget *ct;
4687
4619
        
4688
4620
        if (cti && cti->get_constraint_targets) {
4689
4621
                /* make 'constraint-ob' */
4690
 
                cob= MEM_callocN(sizeof(bConstraintOb), "tempConstraintOb");
4691
 
                cob->type= ownertype;
 
4622
                cob = MEM_callocN(sizeof(bConstraintOb), "tempConstraintOb");
 
4623
                cob->type = ownertype;
4692
4624
                cob->scene = scene;
4693
4625
                switch (ownertype) {
4694
4626
                        case CONSTRAINT_OBTYPE_OBJECT: /* it is usually this case */
4695
4627
                        {
4696
 
                                cob->ob= (Object *)ownerdata;
4697
 
                                cob->pchan= NULL;
 
4628
                                cob->ob = (Object *)ownerdata;
 
4629
                                cob->pchan = NULL;
4698
4630
                                if (cob->ob) {
4699
4631
                                        copy_m4_m4(cob->matrix, cob->ob->obmat);
4700
4632
                                        copy_m4_m4(cob->startmat, cob->matrix);
4703
4635
                                        unit_m4(cob->matrix);
4704
4636
                                        unit_m4(cob->startmat);
4705
4637
                                }
4706
 
                        }       
4707
 
                                break;
 
4638
                        }
 
4639
                        break;
4708
4640
                        case CONSTRAINT_OBTYPE_BONE: /* this may occur in some cases */
4709
4641
                        {
4710
 
                                cob->ob= NULL; /* this might not work at all :/ */
4711
 
                                cob->pchan= (bPoseChannel *)ownerdata;
 
4642
                                cob->ob = NULL; /* this might not work at all :/ */
 
4643
                                cob->pchan = (bPoseChannel *)ownerdata;
4712
4644
                                if (cob->pchan) {
4713
4645
                                        copy_m4_m4(cob->matrix, cob->pchan->pose_mat);
4714
4646
                                        copy_m4_m4(cob->startmat, cob->matrix);
4718
4650
                                        unit_m4(cob->startmat);
4719
4651
                                }
4720
4652
                        }
4721
 
                                break;
 
4653
                        break;
4722
4654
                }
4723
4655
                
4724
4656
                /* get targets - we only need the first one though (and there should only be one) */
4725
4657
                cti->get_constraint_targets(con, &targets);
4726
4658
                
4727
4659
                /* only calculate the target matrix on the first target */
4728
 
                ct= (bConstraintTarget *)targets.first;
4729
 
                while (ct && n-- > 0)
4730
 
                        ct= ct->next;
4731
 
 
 
4660
                ct = (bConstraintTarget *)BLI_findlink(&targets, index);
 
4661
                
4732
4662
                if (ct) {
4733
4663
                        if (cti->get_target_matrix)
4734
4664
                                cti->get_target_matrix(con, cob, ct, ctime);
4747
4677
}
4748
4678
 
4749
4679
/* Get the list of targets required for solving a constraint */
4750
 
void get_constraint_targets_for_solving (bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime)
 
4680
void BKE_get_constraint_targets_for_solving(bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime)
4751
4681
{
4752
 
        bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
4682
        bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
4753
4683
        
4754
4684
        if (cti && cti->get_constraint_targets) {
4755
4685
                bConstraintTarget *ct;
4756
4686
                
4757
4687
                /* get targets 
4758
 
                 *      - constraints should use ct->matrix, not directly accessing values
 
4688
                 *  - constraints should use ct->matrix, not directly accessing values
4759
4689
                 *      - ct->matrix members have not yet been calculated here! 
4760
4690
                 */
4761
4691
                cti->get_constraint_targets(con, targets);
4762
4692
                
4763
4693
                /* set matrices 
4764
 
                 *      - calculate if possible, otherwise just initialize as identity matrix 
 
4694
                 *  - calculate if possible, otherwise just initialize as identity matrix
4765
4695
                 */
4766
4696
                if (cti->get_target_matrix) {
4767
 
                        for (ct= targets->first; ct; ct= ct->next) 
 
4697
                        for (ct = targets->first; ct; ct = ct->next)
4768
4698
                                cti->get_target_matrix(con, cob, ct, ctime);
4769
4699
                }
4770
4700
                else {
4771
 
                        for (ct= targets->first; ct; ct= ct->next)
 
4701
                        for (ct = targets->first; ct; ct = ct->next)
4772
4702
                                unit_m4(ct->matrix);
4773
4703
                }
4774
4704
        }
4779
4709
/* This function is called whenever constraints need to be evaluated. Currently, all
4780
4710
 * constraints that can be evaluated are everytime this gets run.
4781
4711
 *
4782
 
 * constraints_make_evalob and constraints_clear_evalob should be called before and 
 
4712
 * BKE_constraints_make_evalob and BKE_constraints_clear_evalob should be called before and 
4783
4713
 * after running this function, to sort out cob
4784
4714
 */
4785
 
void solve_constraints (ListBase *conlist, bConstraintOb *cob, float ctime)
 
4715
void BKE_solve_constraints(ListBase *conlist, bConstraintOb *cob, float ctime)
4786
4716
{
4787
4717
        bConstraint *con;
4788
4718
        float oldmat[4][4];
4793
4723
                return;
4794
4724
        
4795
4725
        /* loop over available constraints, solving and blending them */
4796
 
        for (con= conlist->first; con; con= con->next) {
4797
 
                bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
 
4726
        for (con = conlist->first; con; con = con->next) {
 
4727
                bConstraintTypeInfo *cti = BKE_constraint_get_typeinfo(con);
4798
4728
                ListBase targets = {NULL, NULL};
4799
4729
                
4800
4730
                /* these we can skip completely (invalid constraints...) */
4801
4731
                if (cti == NULL) continue;
4802
 
                if (con->flag & (CONSTRAINT_DISABLE|CONSTRAINT_OFF)) continue;
 
4732
                if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) continue;
4803
4733
                /* these constraints can't be evaluated anyway */
4804
4734
                if (cti->evaluate_constraint == NULL) continue;
4805
4735
                /* influence == 0 should be ignored */
4806
4736
                if (con->enforce == 0.0f) continue;
4807
4737
                
4808
4738
                /* influence of constraint
4809
 
                 *      - value should have been set from animation data already
 
4739
                 *  - value should have been set from animation data already
4810
4740
                 */
4811
4741
                enf = con->enforce;
4812
4742
                
4814
4744
                copy_m4_m4(oldmat, cob->matrix);
4815
4745
                
4816
4746
                /* move owner matrix into right space */
4817
 
                constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace);
 
4747
                BKE_constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace);
4818
4748
                
4819
4749
                /* prepare targets for constraint solving */
4820
 
                get_constraint_targets_for_solving(con, cob, &targets, ctime);
 
4750
                BKE_get_constraint_targets_for_solving(con, cob, &targets, ctime);
4821
4751
                
4822
4752
                /* Solve the constraint and put result in cob->matrix */
4823
4753
                cti->evaluate_constraint(con, cob, &targets);
4832
4762
                
4833
4763
                /* move owner back into worldspace for next constraint/other business */
4834
4764
                if ((con->flag & CONSTRAINT_SPACEONCE) == 0) 
4835
 
                        constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD);
 
4765
                        BKE_constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, con->ownspace, CONSTRAINT_SPACE_WORLD);
4836
4766
                        
4837
4767
                /* Interpolate the enforcement, to blend result of constraint into final owner transform 
4838
 
                 *      - all this happens in worldspace to prevent any weirdness creeping in ([#26014] and [#25725]),
4839
 
                 *        since some constraints may not convert the solution back to the input space before blending
4840
 
                 *        but all are guaranteed to end up in good "worldspace" result
 
4768
                 *  - all this happens in worldspace to prevent any weirdness creeping in ([#26014] and [#25725]),
 
4769
                 *    since some constraints may not convert the solution back to the input space before blending
 
4770
                 *    but all are guaranteed to end up in good "worldspace" result
4841
4771
                 */
4842
 
                /* Note: all kind of stuff here before (caused trouble), much easier to just interpolate, or did I miss something? -jahka */
 
4772
                /* Note: all kind of stuff here before (caused trouble), much easier to just interpolate, or did I miss something? -jahka (r.32105) */
4843
4773
                if (enf < 1.0f) {
4844
4774
                        float solution[4][4];
4845
4775
                        copy_m4_m4(solution, cob->matrix);