213
209
ID_NEW(data->tar);
216
case CONSTRAINT_TYPE_LOCLIMIT:
218
bLocLimitConstraint *data;
222
case CONSTRAINT_TYPE_ROTLIMIT:
224
bRotLimitConstraint *data;
228
case CONSTRAINT_TYPE_SIZELIMIT:
230
bSizeLimitConstraint *data;
212
case CONSTRAINT_TYPE_CLAMPTO:
214
bClampToConstraint *data;
545
551
bConstraint *curcon;
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");
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){
963
954
VecSubf(proj, u, proj); /* then onto the plane */
964
955
/* proj specifies the transformation of the up axis */
966
if(Normalise(proj) == 0.0) { /* degenerate projection */
957
if(Normalize(proj) == 0.0) { /* degenerate projection */
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);
976
967
if(axis != upflag) {
977
968
right_index = 3 - axis - upflag;
1107
1098
case CONSTRAINT_TYPE_LOCLIKE:
1109
1100
bLocateLikeConstraint *data = (bLocateLikeConstraint*)con->data;
1112
constraint_target_to_mat4(data->tar, data->subtarget, mat, size);
1101
Object *ob= data->tar;
1104
if (strlen(data->subtarget)) {
1105
bPoseChannel *pchan;
1107
float bsize[3]={1, 1, 1};
1109
pchan = get_pose_channel(ob->pose, data->subtarget);
1111
Mat4CpyMat4(tmat, pchan->pose_mat);
1113
if (data->flag & LOCLIKE_TIP)
1114
VECCOPY(tmat[3], pchan->pose_tail);
1116
Mat4MulMat4 (mat, tmat, ob->obmat);
1119
Mat4CpyMat4 (mat, ob->obmat);
1121
VECCOPY(size, bsize); // what's this hack for?
1124
Mat4CpyMat4 (mat, ob->obmat);
1125
VECCOPY(size, data->tar->size); // what's this hack for?
1293
case CONSTRAINT_TYPE_CLAMPTO:
1295
bClampToConstraint *data;
1296
data = (bClampToConstraint*)con->data;
1299
Curve *cu= data->tar->data;
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) */
1304
if(cu->path==NULL || cu->path->data==NULL) /* only happens on reload file, but violates depsgraph still... fix! */
1305
makeDispListCurveTypes(data->tar, 0);
1314
1349
case CONSTRAINT_TYPE_LOCLIKE:
1316
1351
bLocateLikeConstraint *data;
1352
float offset[3] = {0.0f, 0.0f, 0.0f};
1318
1354
data = constraint->data;
1320
if (data->flag & LOCLIKE_X)
1356
if (data->flag & LOCLIKE_OFFSET)
1357
VECCOPY(offset, ob->obmat[3]);
1359
if (data->flag & LOCLIKE_X) {
1321
1360
ob->obmat[3][0] = targetmat[3][0];
1322
if (data->flag & LOCLIKE_Y)
1362
if(data->flag & LOCLIKE_X_INVERT) ob->obmat[3][0] *= -1;
1363
ob->obmat[3][0] += offset[0];
1365
if (data->flag & LOCLIKE_Y) {
1323
1366
ob->obmat[3][1] = targetmat[3][1];
1324
if (data->flag & LOCLIKE_Z)
1368
if(data->flag & LOCLIKE_Y_INVERT) ob->obmat[3][1] *= -1;
1369
ob->obmat[3][1] += offset[1];
1371
if (data->flag & LOCLIKE_Z) {
1325
1372
ob->obmat[3][2] = targetmat[3][2];
1374
if(data->flag & LOCLIKE_Z_INVERT) ob->obmat[3][2] *= -1;
1375
ob->obmat[3][2] += offset[2];
1328
1379
case CONSTRAINT_TYPE_ROTLIKE:
1340
1391
Mat4ToEul(targetmat, eul);
1341
1392
Mat4ToEul(ob->obmat, obeul);
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)) {
1398
if(!(data->flag & ROTLIKE_Y)) {
1401
if(!(data->flag & ROTLIKE_Z)) {
1347
1404
compatible_eul(eul, obeul);
1407
if((data->flag & ROTLIKE_X) && (data->flag & ROTLIKE_X_INVERT))
1409
if((data->flag & ROTLIKE_Y) && (data->flag & ROTLIKE_Y_INVERT))
1411
if((data->flag & ROTLIKE_Z) && (data->flag & ROTLIKE_Z_INVERT))
1350
1414
LocEulSizeToMat4(ob->obmat, loc, eul, size);
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]);
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]);
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]);
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]);
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);
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]);
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);
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]);
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]);
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]);
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]);
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]);
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);
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]);
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);
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]);
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]);
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]);
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]);
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]);
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);
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]);
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);
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]);
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];
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];
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];
1877
dist = Normalise(vec);
1932
dist = Normalize(vec);
1878
1933
//dist = VecLenf( ob->obmat[3], targetmat[3]);
1880
1935
if (data->orglength == 0) data->orglength = dist;
1975
2030
data = constraint->data;
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 */
2236
case CONSTRAINT_TYPE_CLAMPTO:
2238
bClampToConstraint *data;
2240
float obmat[4][4], targetMatrix[4][4], ownLoc[3];
2241
float curveMin[3], curveMax[3];
2243
data = constraint->data;
2245
/* prevent crash if user deletes curve */
2246
if ((data->tar == NULL) || (data->tar->type != OB_CURVE) )
2249
cu= data->tar->data;
2251
Mat4CpyMat4(obmat, ob->obmat);
2252
Mat4One(targetMatrix);
2253
VECCOPY(ownLoc, obmat[3]);
2255
INIT_MINMAX(curveMin, curveMax)
2256
minmax_object(data->tar, curveMin, curveMax);
2258
/* get targetmatrix */
2259
if(cu->path && cu->path->data) {
2260
float vec[4], dir[3], totmat[4][4];
2264
/* find best position on curve */
2265
/* 1. determine which axis to sample on? */
2266
if (data->flag==CLAMPTO_AUTO) {
2268
VecSubf(size, curveMax, curveMin);
2270
/* find axis along which the bounding box has the greatest
2271
* extent. Otherwise, default to the x-axis, as that is quite
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;
2279
clamp_axis = CLAMPTO_X;
2282
clamp_axis= data->flag;
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])
2288
else if (ownLoc[clamp_axis] >= curveMax[clamp_axis])
2291
curvetime = (ownLoc[clamp_axis] - curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]); // umm
2293
/* 3. position on curve */
2294
if(where_on_path(data->tar, curvetime, vec, dir) ) {
2296
VECCOPY(totmat[3], vec);
2298
Mat4MulSerie(targetMatrix, data->tar->obmat, totmat, NULL, NULL, NULL, NULL, NULL, NULL);
2302
/* obtain final object position */
2303
VECCOPY(ob->obmat[3], targetMatrix[3]);
2182
2307
printf ("Error: Unknown constraint type\n");