~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/constraint.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: constraint.c,v 1.61 2007/01/14 23:42:06 theeth Exp $
 
2
 * $Id: constraint.c,v 1.68 2007/04/11 12:44:03 ton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
129
129
                                ID_NEW(data->tar);
130
130
                        }
131
131
                                break;
132
 
                        case CONSTRAINT_TYPE_NULL:
133
 
                        {
134
 
                        }
135
 
                                break;
136
132
                        case CONSTRAINT_TYPE_TRACKTO:
137
133
                        {
138
134
                                bTrackToConstraint *data;
213
209
                                ID_NEW(data->tar);
214
210
                        }
215
211
                                break;
216
 
                        case CONSTRAINT_TYPE_LOCLIMIT:
217
 
                        {
218
 
                                bLocLimitConstraint *data;
219
 
                                data = con->data;
220
 
                        }
221
 
                                break;
222
 
                        case CONSTRAINT_TYPE_ROTLIMIT:
223
 
                        {
224
 
                                bRotLimitConstraint *data;
225
 
                                data = con->data;
226
 
                        }
227
 
                                break;
228
 
                        case CONSTRAINT_TYPE_SIZELIMIT:
229
 
                        {
230
 
                                bSizeLimitConstraint *data;
231
 
                                data = con->data;
 
212
                        case CONSTRAINT_TYPE_CLAMPTO:
 
213
                        {       
 
214
                                bClampToConstraint *data;
 
215
                                data = con->data;
 
216
                                
 
217
                                ID_NEW(data->tar);
232
218
                        }
233
219
                                break;
234
220
                }
355
341
                                return 1;
356
342
                }
357
343
                break;
 
344
        case CONSTRAINT_TYPE_CLAMPTO:
 
345
                {
 
346
                        bClampToConstraint *data = con->data;
 
347
                        if (data->tar)
 
348
                                return 1;
 
349
                }
 
350
                        break;
358
351
        }
359
352
        // Unknown types or CONSTRAINT_TYPE_NULL or no target
360
353
        return 0;
444
437
                        return data->tar;
445
438
                }
446
439
                break;
 
440
        case CONSTRAINT_TYPE_CLAMPTO:
 
441
                {
 
442
                        bClampToConstraint *data = con->data;
 
443
                        *subtarget= NULL;
 
444
                        return data->tar;
 
445
                }
 
446
                break;
447
447
        default:
448
448
                *subtarget= NULL;
449
449
                break;
533
533
                        if(subtarget) BLI_strncpy(data->subtarget, subtarget, 32);
534
534
                }
535
535
                        break;
 
536
                case CONSTRAINT_TYPE_CLAMPTO: 
 
537
                {
 
538
                        bClampToConstraint *data = con->data;
 
539
                        data->tar= ob;
 
540
                }
 
541
                        break;
536
542
        }
537
543
}
538
544
 
544
550
        int exists = 0;
545
551
        bConstraint *curcon;
546
552
        
 
553
        /* See if we are given an empty string */
 
554
        if (con->name[0] == '\0') {
 
555
                /* give it default name first */
 
556
                strcpy (con->name, "Const");
 
557
        }
 
558
        
547
559
        /* See if we even need to do this */
548
560
        for (curcon = list->first; curcon; curcon=curcon->next){
549
561
                if (curcon!=con){
706
718
                {
707
719
                        bLocLimitConstraint *data;
708
720
                        data = MEM_callocN(sizeof(bLocLimitConstraint), "LocLimitConstraint");
709
 
                        
710
 
                        data->flag = 0;
711
 
                        data->flag2 = 0;
712
 
                        data->xmin = 0.0f;
713
 
                        data->xmax = 0.0f;
714
 
                        data->ymin = 0.0f;
715
 
                        data->ymax = 0.0f;
716
 
                        data->zmin = 0.0f;
717
 
                        data->zmax = 0.0f;
718
 
                        
719
721
                        result = data;
720
722
                }
721
723
                break;
723
725
                {
724
726
                        bRotLimitConstraint *data;
725
727
                        data = MEM_callocN(sizeof(bRotLimitConstraint), "RotLimitConstraint");
726
 
                        
727
 
                        data->flag = 0;
728
 
                        data->xmin = 0.0f;
729
 
                        data->xmax = 0.0f;
730
 
                        data->ymin = 0.0f;
731
 
                        data->ymax = 0.0f;
732
 
                        data->zmin = 0.0f;
733
 
                        data->zmax = 0.0f;
734
 
                        
735
728
                        result = data;
736
729
                }
737
730
                break;
739
732
                {
740
733
                        bSizeLimitConstraint *data;
741
734
                        data = MEM_callocN(sizeof(bSizeLimitConstraint), "SizeLimitConstraint");
742
 
                        
743
 
                        data->flag = 0;
744
 
                        data->xmin = 0.0f;
745
 
                        data->xmax = 0.0f;
746
 
                        data->ymin = 0.0f;
747
 
                        data->ymax = 0.0f;
748
 
                        data->zmin = 0.0f;
749
 
                        data->zmax = 0.0f;
750
 
                        
751
735
                        result = data;
752
736
                }
753
737
                break;
783
767
                        result = data;
784
768
                }
785
769
                break;
 
770
        case CONSTRAINT_TYPE_CLAMPTO:
 
771
                {
 
772
                        bClampToConstraint *data;
 
773
                        data = MEM_callocN(sizeof(bClampToConstraint), "ClampToConstraint");
 
774
                        result = data;
 
775
                }
 
776
                break;
786
777
  
787
778
        default:
788
779
                result = NULL;
935
926
        int right_index;
936
927
 
937
928
        VecCopyf(n, vec);
938
 
        if(Normalise(n) == 0.0) { 
 
929
        if(Normalize(n) == 0.0) { 
939
930
                n[0] = 0.0;
940
931
                n[1] = 0.0;
941
932
                n[2] = 1.0;
963
954
        VecSubf(proj, u, proj); /* then onto the plane */
964
955
        /* proj specifies the transformation of the up axis */
965
956
 
966
 
        if(Normalise(proj) == 0.0) { /* degenerate projection */
 
957
        if(Normalize(proj) == 0.0) { /* degenerate projection */
967
958
                proj[0] = 0.0;
968
959
                proj[1] = 1.0;
969
960
                proj[2] = 0.0;
970
961
        }
971
962
 
972
 
        /* normalised cross product of n and proj specifies transformation of the right axis */
 
963
        /* Normalized cross product of n and proj specifies transformation of the right axis */
973
964
        Crossf(right, proj, n);
974
 
        Normalise(right);
 
965
        Normalize(right);
975
966
 
976
967
        if(axis != upflag) {
977
968
                right_index = 3 - axis - upflag;
1107
1098
        case CONSTRAINT_TYPE_LOCLIKE:
1108
1099
                {
1109
1100
                        bLocateLikeConstraint *data = (bLocateLikeConstraint*)con->data;
1110
 
 
1111
 
                        if (data->tar){
1112
 
                                constraint_target_to_mat4(data->tar, data->subtarget, mat, size);
 
1101
                        Object *ob= data->tar;
 
1102
                        
 
1103
                        if (data->tar) {
 
1104
                                if (strlen(data->subtarget)) {
 
1105
                                        bPoseChannel *pchan;
 
1106
                                        float tmat[4][4];
 
1107
                                        float bsize[3]={1, 1, 1};
 
1108
                                        
 
1109
                                        pchan = get_pose_channel(ob->pose, data->subtarget);
 
1110
                                        if (pchan) {
 
1111
                                                Mat4CpyMat4(tmat, pchan->pose_mat);
 
1112
                                                
 
1113
                                                if (data->flag & LOCLIKE_TIP) 
 
1114
                                                        VECCOPY(tmat[3], pchan->pose_tail);
 
1115
                                                        
 
1116
                                                Mat4MulMat4 (mat, tmat, ob->obmat);
 
1117
                                        }
 
1118
                                        else 
 
1119
                                                Mat4CpyMat4 (mat, ob->obmat);
 
1120
                                        
 
1121
                                        VECCOPY(size, bsize); // what's this hack for? 
 
1122
                                }
 
1123
                                else {
 
1124
                                        Mat4CpyMat4 (mat, ob->obmat);
 
1125
                                        VECCOPY(size, data->tar->size); // what's this hack for? 
 
1126
                                }
1113
1127
                                valid=1;
1114
1128
                        }
1115
1129
                        else
1241
1255
                                                if(data->followflag){
1242
1256
                                                        quat= vectoquat(dir, (short) data->trackflag, (short) data->upflag);
1243
1257
 
1244
 
                                                        Normalise(dir);
 
1258
                                                        Normalize(dir);
1245
1259
                                                        q[0]= (float)cos(0.5*vec[3]);
1246
1260
                                                        x1= (float)sin(0.5*vec[3]);
1247
1261
                                                        q[1]= -x1*dir[0];
1276
1290
                                Mat4One (mat);
1277
1291
                }
1278
1292
                break;
 
1293
        case CONSTRAINT_TYPE_CLAMPTO:
 
1294
                {
 
1295
                        bClampToConstraint *data;
 
1296
                        data = (bClampToConstraint*)con->data;
 
1297
 
 
1298
                        if (data->tar) {
 
1299
                                Curve *cu= data->tar->data;
 
1300
                                
 
1301
                                /* note; when creating constraints that follow path, the curve gets the CU_PATH set now,
 
1302
                                        currently for paths to work it needs to go through the bevlist/displist system (ton) */
 
1303
                                
 
1304
                                if(cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */
 
1305
                                        makeDispListCurveTypes(data->tar, 0);
 
1306
                        }
 
1307
                        
 
1308
                        Mat4One (mat);
 
1309
                }
 
1310
                break;
1279
1311
 
1280
1312
        default:
1281
1313
                Mat4One(mat);
1285
1317
        return valid;
1286
1318
}
1287
1319
 
1288
 
 
1289
1320
/* only called during solve_constraints */
1290
1321
/* bone constraints create a fake object to work on, then ob is a workob */
1291
1322
/* if ownerdata is set, it's the posechannel */
1299
1330
 
1300
1331
        Mat4One (M_identity);
1301
1332
        
1302
 
        switch (constraint->type){
 
1333
        switch (constraint->type) {
 
1334
        case CONSTRAINT_TYPE_NULL:
 
1335
        case CONSTRAINT_TYPE_KINEMATIC: /* removed */
 
1336
                break;
 
1337
        
1303
1338
        case CONSTRAINT_TYPE_ACTION:
1304
1339
                {
1305
1340
                        float temp[4][4];
1314
1349
        case CONSTRAINT_TYPE_LOCLIKE:
1315
1350
                {
1316
1351
                        bLocateLikeConstraint *data;
 
1352
                        float offset[3] = {0.0f, 0.0f, 0.0f};
1317
1353
 
1318
1354
                        data = constraint->data;
1319
1355
                        
1320
 
                        if (data->flag & LOCLIKE_X)
 
1356
                        if (data->flag & LOCLIKE_OFFSET)
 
1357
                                VECCOPY(offset, ob->obmat[3]);
 
1358
                        
 
1359
                        if (data->flag & LOCLIKE_X) {
1321
1360
                                ob->obmat[3][0] = targetmat[3][0];
1322
 
                        if (data->flag & LOCLIKE_Y)
 
1361
                                
 
1362
                                if(data->flag & LOCLIKE_X_INVERT) ob->obmat[3][0] *= -1;
 
1363
                                ob->obmat[3][0] += offset[0];
 
1364
                        }
 
1365
                        if (data->flag & LOCLIKE_Y) {
1323
1366
                                ob->obmat[3][1] = targetmat[3][1];
1324
 
                        if (data->flag & LOCLIKE_Z)
 
1367
                                
 
1368
                                if(data->flag & LOCLIKE_Y_INVERT) ob->obmat[3][1] *= -1;
 
1369
                                ob->obmat[3][1] += offset[1];
 
1370
                        }
 
1371
                        if (data->flag & LOCLIKE_Z) {
1325
1372
                                ob->obmat[3][2] = targetmat[3][2];
 
1373
                                
 
1374
                                if(data->flag & LOCLIKE_Z_INVERT) ob->obmat[3][2] *= -1;
 
1375
                                ob->obmat[3][2] += offset[2];
 
1376
                        }
1326
1377
                }
1327
1378
                break;
1328
1379
        case CONSTRAINT_TYPE_ROTLIKE:
1339
1390
                        
1340
1391
                        Mat4ToEul(targetmat, eul);
1341
1392
                        Mat4ToEul(ob->obmat, obeul);
1342
 
                        
 
1393
                                
1343
1394
                        if(data->flag != (ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z)) {
1344
 
                                if(!(data->flag & ROTLIKE_X)) eul[0]= obeul[0];
1345
 
                                if(!(data->flag & ROTLIKE_Y)) eul[1]= obeul[1];
1346
 
                                if(!(data->flag & ROTLIKE_Z)) eul[2]= obeul[2];
 
1395
                                if(!(data->flag & ROTLIKE_X)) {
 
1396
                                        eul[0]= obeul[0];
 
1397
                                }
 
1398
                                if(!(data->flag & ROTLIKE_Y)) {
 
1399
                                        eul[1]= obeul[1];
 
1400
                                }
 
1401
                                if(!(data->flag & ROTLIKE_Z)) {
 
1402
                                        eul[2]= obeul[2];
 
1403
                                }
1347
1404
                                compatible_eul(eul, obeul);
1348
1405
                        }
1349
 
 
 
1406
                        
 
1407
                        if((data->flag & ROTLIKE_X) && (data->flag & ROTLIKE_X_INVERT))
 
1408
                                eul[0]*=-1;
 
1409
                        if((data->flag & ROTLIKE_Y) && (data->flag & ROTLIKE_Y_INVERT))
 
1410
                                eul[1]*=-1;
 
1411
                        if((data->flag & ROTLIKE_Z) && (data->flag & ROTLIKE_Z_INVERT))
 
1412
                                eul[2]*=-1;
 
1413
                        
1350
1414
                        LocEulSizeToMat4(ob->obmat, loc, eul, size);
1351
1415
                }
1352
1416
                break;
1368
1432
                                VecMulf(ob->obmat[2], size[2] / obsize[2]);
1369
1433
                }
1370
1434
                break;
1371
 
        case CONSTRAINT_TYPE_NULL:
1372
 
                {
1373
 
                }
1374
 
                break;
1375
1435
        case CONSTRAINT_TYPE_MINMAX:
1376
1436
                {
1377
1437
                        float val1, val2;
1491
1551
                        }
1492
1552
                }
1493
1553
                break;
1494
 
        case CONSTRAINT_TYPE_KINEMATIC:
1495
 
                {
1496
 
                        /* removed */
1497
 
                }
1498
 
                break;
1499
1554
        case CONSTRAINT_TYPE_LOCKTRACK:
1500
1555
                {
1501
1556
                        bLockTrackConstraint *data;
1524
1579
                                                /* Projection of Vector on the plane */
1525
1580
                                                Projf(vec2, vec, ob->obmat[0]);
1526
1581
                                                VecSubf(totmat[1], vec, vec2);
1527
 
                                                Normalise(totmat[1]);
 
1582
                                                Normalize(totmat[1]);
1528
1583
 
1529
1584
                                                /* the x axis is fixed*/
1530
1585
                                                totmat[0][0] = ob->obmat[0][0];
1531
1586
                                                totmat[0][1] = ob->obmat[0][1];
1532
1587
                                                totmat[0][2] = ob->obmat[0][2];
1533
 
                                                Normalise(totmat[0]);
 
1588
                                                Normalize(totmat[0]);
1534
1589
                                
1535
1590
                                                /* the z axis gets mapped onto
1536
1591
                                                a third orthogonal vector */
1542
1597
                                                /* Projection of Vector on the plane */
1543
1598
                                                Projf(vec2, vec, ob->obmat[0]);
1544
1599
                                                VecSubf(totmat[2], vec, vec2);
1545
 
                                                Normalise(totmat[2]);
 
1600
                                                Normalize(totmat[2]);
1546
1601
 
1547
1602
                                                /* the x axis is fixed*/
1548
1603
                                                totmat[0][0] = ob->obmat[0][0];
1549
1604
                                                totmat[0][1] = ob->obmat[0][1];
1550
1605
                                                totmat[0][2] = ob->obmat[0][2];
1551
 
                                                Normalise(totmat[0]);
 
1606
                                                Normalize(totmat[0]);
1552
1607
                                
1553
1608
                                                /* the z axis gets mapped onto
1554
1609
                                                a third orthogonal vector */
1560
1615
                                                /* Projection of Vector on the plane */
1561
1616
                                                Projf(vec2, vec, ob->obmat[0]);
1562
1617
                                                VecSubf(totmat[1], vec, vec2);
1563
 
                                                Normalise(totmat[1]);
 
1618
                                                Normalize(totmat[1]);
1564
1619
                                                VecMulf(totmat[1],-1);
1565
1620
 
1566
1621
                                                /* the x axis is fixed*/
1567
1622
                                                totmat[0][0] = ob->obmat[0][0];
1568
1623
                                                totmat[0][1] = ob->obmat[0][1];
1569
1624
                                                totmat[0][2] = ob->obmat[0][2];
1570
 
                                                Normalise(totmat[0]);
 
1625
                                                Normalize(totmat[0]);
1571
1626
                                
1572
1627
                                                /* the z axis gets mapped onto
1573
1628
                                                a third orthogonal vector */
1579
1634
                                                /* Projection of Vector on the plane */
1580
1635
                                                Projf(vec2, vec, ob->obmat[0]);
1581
1636
                                                VecSubf(totmat[2], vec, vec2);
1582
 
                                                Normalise(totmat[2]);
 
1637
                                                Normalize(totmat[2]);
1583
1638
                                                VecMulf(totmat[2],-1);
1584
1639
 
1585
1640
                                                /* the x axis is fixed*/
1586
1641
                                                totmat[0][0] = ob->obmat[0][0];
1587
1642
                                                totmat[0][1] = ob->obmat[0][1];
1588
1643
                                                totmat[0][2] = ob->obmat[0][2];
1589
 
                                                Normalise(totmat[0]);
 
1644
                                                Normalize(totmat[0]);
1590
1645
                                
1591
1646
                                                /* the z axis gets mapped onto
1592
1647
                                                a third orthogonal vector */
1611
1666
                                                /* Projection of Vector on the plane */
1612
1667
                                                Projf(vec2, vec, ob->obmat[1]);
1613
1668
                                                VecSubf(totmat[0], vec, vec2);
1614
 
                                                Normalise(totmat[0]);
 
1669
                                                Normalize(totmat[0]);
1615
1670
 
1616
1671
                                                /* the y axis is fixed*/
1617
1672
                                                totmat[1][0] = ob->obmat[1][0];
1618
1673
                                                totmat[1][1] = ob->obmat[1][1];
1619
1674
                                                totmat[1][2] = ob->obmat[1][2];
1620
 
                                                Normalise(totmat[1]);
 
1675
                                                Normalize(totmat[1]);
1621
1676
                                                
1622
1677
                                                /* the z axis gets mapped onto
1623
1678
                                                a third orthogonal vector */
1629
1684
                                                /* Projection of Vector on the plane */
1630
1685
                                                Projf(vec2, vec, ob->obmat[1]);
1631
1686
                                                VecSubf(totmat[2], vec, vec2);
1632
 
                                                Normalise(totmat[2]);
 
1687
                                                Normalize(totmat[2]);
1633
1688
 
1634
1689
                                                /* the y axis is fixed*/
1635
1690
                                                totmat[1][0] = ob->obmat[1][0];
1636
1691
                                                totmat[1][1] = ob->obmat[1][1];
1637
1692
                                                totmat[1][2] = ob->obmat[1][2];
1638
 
                                                Normalise(totmat[1]);
 
1693
                                                Normalize(totmat[1]);
1639
1694
                                                
1640
1695
                                                /* the z axis gets mapped onto
1641
1696
                                                a third orthogonal vector */
1647
1702
                                                /* Projection of Vector on the plane */
1648
1703
                                                Projf(vec2, vec, ob->obmat[1]);
1649
1704
                                                VecSubf(totmat[0], vec, vec2);
1650
 
                                                Normalise(totmat[0]);
 
1705
                                                Normalize(totmat[0]);
1651
1706
                                                VecMulf(totmat[0],-1);
1652
1707
 
1653
1708
                                                /* the y axis is fixed*/
1654
1709
                                                totmat[1][0] = ob->obmat[1][0];
1655
1710
                                                totmat[1][1] = ob->obmat[1][1];
1656
1711
                                                totmat[1][2] = ob->obmat[1][2];
1657
 
                                                Normalise(totmat[1]);
 
1712
                                                Normalize(totmat[1]);
1658
1713
                                                
1659
1714
                                                /* the z axis gets mapped onto
1660
1715
                                                a third orthogonal vector */
1666
1721
                                                /* Projection of Vector on the plane */
1667
1722
                                                Projf(vec2, vec, ob->obmat[1]);
1668
1723
                                                VecSubf(totmat[2], vec, vec2);
1669
 
                                                Normalise(totmat[2]);
 
1724
                                                Normalize(totmat[2]);
1670
1725
                                                VecMulf(totmat[2],-1);
1671
1726
 
1672
1727
                                                /* the y axis is fixed*/
1673
1728
                                                totmat[1][0] = ob->obmat[1][0];
1674
1729
                                                totmat[1][1] = ob->obmat[1][1];
1675
1730
                                                totmat[1][2] = ob->obmat[1][2];
1676
 
                                                Normalise(totmat[1]);
 
1731
                                                Normalize(totmat[1]);
1677
1732
                                                
1678
1733
                                                /* the z axis gets mapped onto
1679
1734
                                                a third orthogonal vector */
1698
1753
                                                /* Projection of Vector on the plane */
1699
1754
                                                Projf(vec2, vec, ob->obmat[2]);
1700
1755
                                                VecSubf(totmat[0], vec, vec2);
1701
 
                                                Normalise(totmat[0]);
 
1756
                                                Normalize(totmat[0]);
1702
1757
 
1703
1758
                                                /* the z axis is fixed*/
1704
1759
                                                totmat[2][0] = ob->obmat[2][0];
1705
1760
                                                totmat[2][1] = ob->obmat[2][1];
1706
1761
                                                totmat[2][2] = ob->obmat[2][2];
1707
 
                                                Normalise(totmat[2]);
 
1762
                                                Normalize(totmat[2]);
1708
1763
                                                
1709
1764
                                                /* the x axis gets mapped onto
1710
1765
                                                a third orthogonal vector */
1716
1771
                                                /* Projection of Vector on the plane */
1717
1772
                                                Projf(vec2, vec, ob->obmat[2]);
1718
1773
                                                VecSubf(totmat[1], vec, vec2);
1719
 
                                                Normalise(totmat[1]);
 
1774
                                                Normalize(totmat[1]);
1720
1775
 
1721
1776
                                                /* the z axis is fixed*/
1722
1777
                                                totmat[2][0] = ob->obmat[2][0];
1723
1778
                                                totmat[2][1] = ob->obmat[2][1];
1724
1779
                                                totmat[2][2] = ob->obmat[2][2];
1725
 
                                                Normalise(totmat[2]);
 
1780
                                                Normalize(totmat[2]);
1726
1781
                                                
1727
1782
                                                /* the x axis gets mapped onto
1728
1783
                                                a third orthogonal vector */
1734
1789
                                                /* Projection of Vector on the plane */
1735
1790
                                                Projf(vec2, vec, ob->obmat[2]);
1736
1791
                                                VecSubf(totmat[0], vec, vec2);
1737
 
                                                Normalise(totmat[0]);
 
1792
                                                Normalize(totmat[0]);
1738
1793
                                                VecMulf(totmat[0],-1);
1739
1794
 
1740
1795
                                                /* the z axis is fixed*/
1741
1796
                                                totmat[2][0] = ob->obmat[2][0];
1742
1797
                                                totmat[2][1] = ob->obmat[2][1];
1743
1798
                                                totmat[2][2] = ob->obmat[2][2];
1744
 
                                                Normalise(totmat[2]);
 
1799
                                                Normalize(totmat[2]);
1745
1800
                                                
1746
1801
                                                /* the x axis gets mapped onto
1747
1802
                                                a third orthogonal vector */
1753
1808
                                                /* Projection of Vector on the plane */
1754
1809
                                                Projf(vec2, vec, ob->obmat[2]);
1755
1810
                                                VecSubf(totmat[1], vec, vec2);
1756
 
                                                Normalise(totmat[1]);
 
1811
                                                Normalize(totmat[1]);
1757
1812
                                                VecMulf(totmat[1],-1);
1758
1813
 
1759
1814
                                                /* the z axis is fixed*/
1760
1815
                                                totmat[2][0] = ob->obmat[2][0];
1761
1816
                                                totmat[2][1] = ob->obmat[2][1];
1762
1817
                                                totmat[2][2] = ob->obmat[2][2];
1763
 
                                                Normalise(totmat[2]);
 
1818
                                                Normalize(totmat[2]);
1764
1819
                                                
1765
1820
                                                /* the x axis gets mapped onto
1766
1821
                                                a third orthogonal vector */
1789
1844
                                tmpmat[0][0] = ob->obmat[0][0];tmpmat[0][1] = ob->obmat[0][1];tmpmat[0][2] = ob->obmat[0][2];
1790
1845
                                tmpmat[1][0] = ob->obmat[1][0];tmpmat[1][1] = ob->obmat[1][1];tmpmat[1][2] = ob->obmat[1][2];
1791
1846
                                tmpmat[2][0] = ob->obmat[2][0];tmpmat[2][1] = ob->obmat[2][1];tmpmat[2][2] = ob->obmat[2][2];
1792
 
                                Normalise(tmpmat[0]);
1793
 
                                Normalise(tmpmat[1]);
1794
 
                                Normalise(tmpmat[2]);
 
1847
                                Normalize(tmpmat[0]);
 
1848
                                Normalize(tmpmat[1]);
 
1849
                                Normalize(tmpmat[2]);
1795
1850
                                Mat3Inv(invmat,tmpmat);
1796
1851
                                Mat3MulMat3(tmpmat,totmat,invmat);
1797
1852
                                totmat[0][0] = tmpmat[0][0];totmat[0][1] = tmpmat[0][1];totmat[0][2] = tmpmat[0][2];
1861
1916
                xx[0] = ob->obmat[0][0];
1862
1917
                xx[1] = ob->obmat[0][1];
1863
1918
                xx[2] = ob->obmat[0][2];
1864
 
                Normalise(xx);
 
1919
                Normalize(xx);
1865
1920
 
1866
1921
                /* store Z orientation before destroying obmat */
1867
1922
                zz[0] = ob->obmat[2][0];
1868
1923
                zz[1] = ob->obmat[2][1];
1869
1924
                zz[2] = ob->obmat[2][2];
1870
 
                Normalise(zz);
 
1925
                Normalize(zz);
1871
1926
 
1872
1927
                                VecSubf(vec, ob->obmat[3], targetmat[3]);
1873
1928
                                vec[0] /= size[0];
1874
1929
                                vec[1] /= size[1];
1875
1930
                                vec[2] /= size[2];
1876
1931
 
1877
 
                                dist = Normalise(vec);
 
1932
                                dist = Normalize(vec);
1878
1933
                //dist = VecLenf( ob->obmat[3], targetmat[3]);
1879
1934
 
1880
1935
                if (data->orglength == 0)  data->orglength = dist;
1916
1971
                ob->obmat[2][2]=size[2]*scale[2];
1917
1972
                
1918
1973
                VecSubf(vec, ob->obmat[3], targetmat[3]);
1919
 
                Normalise(vec);
 
1974
                Normalize(vec);
1920
1975
                /* new Y aligns  object target connection*/
1921
1976
                totmat[1][0] = -vec[0];
1922
1977
                totmat[1][1] = -vec[1];
1926
1981
                    /* build new Z vector */
1927
1982
                    /* othogonal to "new Y" "old X! plane */
1928
1983
                    Crossf(orth, vec, xx);
1929
 
                    Normalise(orth);
 
1984
                    Normalize(orth);
1930
1985
                    
1931
1986
                    /* new Z*/
1932
1987
                    totmat[2][0] = orth[0];
1935
1990
                    
1936
1991
                    /* we decided to keep X plane*/
1937
1992
                    Crossf(xx,orth, vec);
1938
 
                    Normalise(xx);
 
1993
                    Normalize(xx);
1939
1994
                    totmat[0][0] = xx[0];
1940
1995
                    totmat[0][1] = xx[1];
1941
1996
                    totmat[0][2] = xx[2];
1944
1999
                    /* build new X vector */
1945
2000
                    /* othogonal to "new Y" "old Z! plane */
1946
2001
                    Crossf(orth, vec, zz);
1947
 
                    Normalise(orth);
 
2002
                    Normalize(orth);
1948
2003
                    
1949
2004
                    /* new X*/
1950
2005
                    totmat[0][0] = -orth[0];
1953
2008
                    
1954
2009
                    /* we decided to keep Z */
1955
2010
                    Crossf(zz,orth, vec);
1956
 
                    Normalise(zz);
 
2011
                    Normalize(zz);
1957
2012
                    totmat[2][0] = zz[0];
1958
2013
                    totmat[2][1] = zz[1];
1959
2014
                    totmat[2][2] = zz[2];
1975
2030
                        data = constraint->data;
1976
2031
                        
1977
2032
                        /* limit location relative to origin or parent   */
1978
 
                        if (data->flag2 & LIMIT_NOPARENT) {
 
2033
                        if ((data->flag2 & LIMIT_NOPARENT) && ob->parent) {
1979
2034
                                /* limiting relative to parent */
1980
2035
                                float parmat[4][4]; /* matrix of parent */
1981
2036
                                float objLoc[3], parLoc[3]; /* location of object, and location of parent */
2177
2232
 
2178
2233
 
2179
2234
        }
2180
 
        break;          
 
2235
        break;  
 
2236
        case CONSTRAINT_TYPE_CLAMPTO:
 
2237
                {
 
2238
                        bClampToConstraint *data;
 
2239
                        Curve *cu;
 
2240
                        float obmat[4][4], targetMatrix[4][4], ownLoc[3];
 
2241
                        float curveMin[3], curveMax[3];
 
2242
                        
 
2243
                        data = constraint->data;
 
2244
                        
 
2245
                        /* prevent crash if user deletes curve */
 
2246
                        if ((data->tar == NULL) || (data->tar->type != OB_CURVE) ) 
 
2247
                                return;
 
2248
                        else
 
2249
                                cu= data->tar->data;
 
2250
                        
 
2251
                        Mat4CpyMat4(obmat, ob->obmat);
 
2252
                        Mat4One(targetMatrix);
 
2253
                        VECCOPY(ownLoc, obmat[3]);
 
2254
                        
 
2255
                        INIT_MINMAX(curveMin, curveMax)
 
2256
                        minmax_object(data->tar, curveMin, curveMax);
 
2257
                        
 
2258
                        /* get targetmatrix */
 
2259
                        if(cu->path && cu->path->data) {
 
2260
                                float vec[4], dir[3], totmat[4][4];
 
2261
                                float curvetime;
 
2262
                                short clamp_axis;
 
2263
                                
 
2264
                                /* find best position on curve */
 
2265
                                /* 1. determine which axis to sample on? */
 
2266
                                if (data->flag==CLAMPTO_AUTO) {
 
2267
                                        float size[3];
 
2268
                                        VecSubf(size, curveMax, curveMin);
 
2269
                                        
 
2270
                                        /* find axis along which the bounding box has the greatest
 
2271
                                         * extent. Otherwise, default to the x-axis, as that is quite
 
2272
                                         * frequently used.
 
2273
                                         */
 
2274
                                        if ((size[2]>size[0]) && (size[2]>size[1]))
 
2275
                                                clamp_axis= CLAMPTO_Z;
 
2276
                                        else if ((size[1]>size[0]) && (size[1]>size[2]))
 
2277
                                                clamp_axis= CLAMPTO_Y;
 
2278
                                        else
 
2279
                                                clamp_axis = CLAMPTO_X;
 
2280
                                }
 
2281
                                else 
 
2282
                                        clamp_axis= data->flag;
 
2283
                                        
 
2284
                                /* 2. determine position relative to curve on a 0-1 scale */
 
2285
                                if (clamp_axis > 0) clamp_axis--;
 
2286
                                if (ownLoc[clamp_axis] <= curveMin[clamp_axis])
 
2287
                                        curvetime = 0.0;
 
2288
                                else if (ownLoc[clamp_axis] >= curveMax[clamp_axis])
 
2289
                                        curvetime = 1.0;
 
2290
                                else
 
2291
                                        curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]); // umm
 
2292
                                
 
2293
                                /* 3. position on curve */
 
2294
                                if(where_on_path(data->tar, curvetime, vec, dir) ) {
 
2295
                                        Mat4One(totmat);
 
2296
                                        VECCOPY(totmat[3], vec);
 
2297
                                        
 
2298
                                        Mat4MulSerie(targetMatrix, data->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL);
 
2299
                                }
 
2300
                        }
 
2301
                        
 
2302
                        /* obtain final object position */
 
2303
                        VECCOPY(ob->obmat[3], targetMatrix[3]);
 
2304
                }
 
2305
                break;
2181
2306
        default:
2182
2307
                printf ("Error: Unknown constraint type\n");
2183
2308
                break;