2294
static void locktrack_flush_tars (bConstraint *con, ListBase *list, short nocopy)
2193
static void locktrack_flush_tars(bConstraint *con, ListBase *list, short nocopy)
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;
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);
2305
static void locktrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *targets)
2204
static void locktrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *targets)
2307
bLockTrackConstraint *data= con->data;
2308
bConstraintTarget *ct= targets->first;
2206
bLockTrackConstraint *data = con->data;
2207
bConstraintTarget *ct = targets->first;
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];
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 */
2323
switch (data->trackflag) {
2324
case TRACK_Y: /* LOCK X TRACK Y */
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]);
2331
/* the x axis is fixed */
2332
normalize_v3_v3(totmat[0], cob->matrix[0]);
2334
/* the z axis gets mapped onto a third orthogonal vector */
2335
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2338
case TRACK_Z: /* LOCK X TRACK Z */
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]);
2345
/* the x axis is fixed */
2346
normalize_v3_v3(totmat[0], cob->matrix[0]);
2348
/* the z axis gets mapped onto a third orthogonal vector */
2349
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2352
case TRACK_nY: /* LOCK X TRACK -Y */
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]);
2360
/* the x axis is fixed */
2361
normalize_v3_v3(totmat[0], cob->matrix[0]);
2363
/* the z axis gets mapped onto a third orthogonal vector */
2364
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2367
case TRACK_nZ: /* LOCK X TRACK -Z */
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]);
2375
/* the x axis is fixed */
2376
normalize_v3_v3(totmat[0], cob->matrix[0]);
2378
/* the z axis gets mapped onto a third orthogonal vector */
2379
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2219
case LOCK_X: /* LOCK X */
2221
switch (data->trackflag) {
2222
case TRACK_Y: /* LOCK X TRACK Y */
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]);
2229
/* the x axis is fixed */
2230
normalize_v3_v3(totmat[0], cob->matrix[0]);
2232
/* the z axis gets mapped onto a third orthogonal vector */
2233
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2236
case TRACK_Z: /* LOCK X TRACK Z */
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]);
2243
/* the x axis is fixed */
2244
normalize_v3_v3(totmat[0], cob->matrix[0]);
2246
/* the z axis gets mapped onto a third orthogonal vector */
2247
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2250
case TRACK_nY: /* LOCK X TRACK -Y */
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]);
2258
/* the x axis is fixed */
2259
normalize_v3_v3(totmat[0], cob->matrix[0]);
2261
/* the z axis gets mapped onto a third orthogonal vector */
2262
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2265
case TRACK_nZ: /* LOCK X TRACK -Z */
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]);
2273
/* the x axis is fixed */
2274
normalize_v3_v3(totmat[0], cob->matrix[0]);
2276
/* the z axis gets mapped onto a third orthogonal vector */
2277
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2390
case LOCK_Y: /* LOCK Y */
2392
switch (data->trackflag) {
2393
case TRACK_X: /* LOCK Y TRACK X */
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 */
2290
switch (data->trackflag) {
2291
case TRACK_X: /* LOCK Y TRACK X */
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]);
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]);
2403
/* the z axis gets mapped onto a third orthogonal vector */
2404
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2407
case TRACK_Z: /* LOCK Y TRACK Z */
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]);
2414
/* the y axis is fixed */
2415
normalize_v3_v3(totmat[1], cob->matrix[1]);
2417
/* the z axis gets mapped onto a third orthogonal vector */
2418
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2421
case TRACK_nX: /* LOCK Y TRACK -X */
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]);
2429
/* the y axis is fixed */
2430
normalize_v3_v3(totmat[1], cob->matrix[1]);
2432
/* the z axis gets mapped onto a third orthogonal vector */
2433
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2436
case TRACK_nZ: /* LOCK Y TRACK -Z */
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]);
2444
/* the y axis is fixed */
2445
normalize_v3_v3(totmat[1], cob->matrix[1]);
2447
/* the z axis gets mapped onto a third orthogonal vector */
2448
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2459
case LOCK_Z: /* LOCK Z */
2461
switch (data->trackflag) {
2462
case TRACK_X: /* LOCK Z TRACK X */
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]);
2469
/* the z axis is fixed */
2470
normalize_v3_v3(totmat[2], cob->matrix[2]);
2472
/* the x axis gets mapped onto a third orthogonal vector */
2473
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2476
case TRACK_Y: /* LOCK Z TRACK Y */
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]);
2483
/* the z axis is fixed */
2484
normalize_v3_v3(totmat[2], cob->matrix[2]);
2486
/* the x axis gets mapped onto a third orthogonal vector */
2487
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2490
case TRACK_nX: /* LOCK Z TRACK -X */
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]);
2498
/* the z axis is fixed */
2499
normalize_v3_v3(totmat[2], cob->matrix[2]);
2501
/* the x axis gets mapped onto a third orthogonal vector */
2502
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2505
case TRACK_nY: /* LOCK Z TRACK -Y */
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]);
2513
/* the z axis is fixed */
2514
normalize_v3_v3(totmat[2], cob->matrix[2]);
2516
/* the x axis gets mapped onto a third orthogonal vector */
2517
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2301
/* the z axis gets mapped onto a third orthogonal vector */
2302
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2305
case TRACK_Z: /* LOCK Y TRACK Z */
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]);
2312
/* the y axis is fixed */
2313
normalize_v3_v3(totmat[1], cob->matrix[1]);
2315
/* the z axis gets mapped onto a third orthogonal vector */
2316
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2319
case TRACK_nX: /* LOCK Y TRACK -X */
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]);
2327
/* the y axis is fixed */
2328
normalize_v3_v3(totmat[1], cob->matrix[1]);
2330
/* the z axis gets mapped onto a third orthogonal vector */
2331
cross_v3_v3v3(totmat[2], totmat[0], totmat[1]);
2334
case TRACK_nZ: /* LOCK Y TRACK -Z */
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]);
2342
/* the y axis is fixed */
2343
normalize_v3_v3(totmat[1], cob->matrix[1]);
2345
/* the z axis gets mapped onto a third orthogonal vector */
2346
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2357
case LOCK_Z: /* LOCK Z */
2359
switch (data->trackflag) {
2360
case TRACK_X: /* LOCK Z TRACK X */
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]);
2367
/* the z axis is fixed */
2368
normalize_v3_v3(totmat[2], cob->matrix[2]);
2370
/* the x axis gets mapped onto a third orthogonal vector */
2371
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2374
case TRACK_Y: /* LOCK Z TRACK Y */
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]);
2381
/* the z axis is fixed */
2382
normalize_v3_v3(totmat[2], cob->matrix[2]);
2384
/* the x axis gets mapped onto a third orthogonal vector */
2385
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2388
case TRACK_nX: /* LOCK Z TRACK -X */
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]);
2396
/* the z axis is fixed */
2397
normalize_v3_v3(totmat[2], cob->matrix[2]);
2399
/* the x axis gets mapped onto a third orthogonal vector */
2400
cross_v3_v3v3(totmat[1], totmat[2], totmat[0]);
2403
case TRACK_nY: /* LOCK Z TRACK -Y */
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]);
2411
/* the z axis is fixed */
2412
normalize_v3_v3(totmat[2], cob->matrix[2]);
2414
/* the x axis gets mapped onto a third orthogonal vector */
2415
cross_v3_v3v3(totmat[0], totmat[1], totmat[2]);
2534
2432
/* Block to keep matrix heading */
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 */
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)
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 */
4284
4211
/* This function should be used for getting the appropriate type-info when only
4285
4212
* a constraint type is known
4287
bConstraintTypeInfo *get_constraint_typeinfo (int type)
4214
bConstraintTypeInfo *BKE_get_constraint_typeinfo(int type)
4289
4216
/* initialize the type-info list? */
4290
4217
if (CTI_INIT) {