Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Leung <aligorith@gmail.com>2010-05-27 15:56:31 +0400
committerJoshua Leung <aligorith@gmail.com>2010-05-27 15:56:31 +0400
commit5d6bdd7c2ea0413b707dd08d3b3b67154ccd9a55 (patch)
tree60247689e80fd7a491bbbdfb63b2c02bccd118b4 /source/blender/blenkernel/intern/constraint.c
parente689ca078d255963d11de2448847eb7a65bccc2b (diff)
Various constraint code cleanups:
1) Fixed some weird formatting introduced during math-lib cleanups, and some other inconsistencies 2) Optimised the Maintain Volume constraint by taking the value calculations out Copy All Constraints Operators: * Added one for bones too * These are now included in the menus * Removed some weird/extra code copying/changing/bleh the actcol/totcol stuff...
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r--source/blender/blenkernel/intern/constraint.c106
1 files changed, 53 insertions, 53 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 1a8d665a91d..171276d118e 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -820,12 +820,12 @@ static void childof_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
/* extract components of both matrices */
VECCOPY(loc, ct->matrix[3]);
- mat4_to_eulO( eul, ct->rotOrder,ct->matrix);
- mat4_to_size( size,ct->matrix);
+ mat4_to_eulO(eul, ct->rotOrder, ct->matrix);
+ mat4_to_size(size, ct->matrix);
VECCOPY(loco, invmat[3]);
- mat4_to_eulO( eulo, cob->rotOrder,invmat);
- mat4_to_size( sizo,invmat);
+ mat4_to_eulO(eulo, cob->rotOrder, invmat);
+ mat4_to_size(sizo, invmat);
/* disable channels not enabled */
if (!(data->flag & CHILDOF_LOCX)) loc[0]= loco[0]= 0.0f;
@@ -1017,7 +1017,7 @@ static void trackto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
float tmat[4][4];
/* Get size property, since ob->size is only the object's own relative size, not its global one */
- mat4_to_size( size,cob->matrix);
+ mat4_to_size(size, cob->matrix);
/* Clear the object's rotation */
cob->matrix[0][0]=size[0];
@@ -1385,9 +1385,9 @@ static void rotlimit_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *t
float size[3];
VECCOPY(loc, cob->matrix[3]);
- mat4_to_size( size,cob->matrix);
+ mat4_to_size(size, cob->matrix);
- mat4_to_eulO( eul, cob->rotOrder,cob->matrix);
+ mat4_to_eulO(eul, cob->rotOrder, cob->matrix);
/* constraint data uses radians internally */
@@ -1638,11 +1638,11 @@ static void rotlike_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *ta
float size[3];
VECCOPY(loc, cob->matrix[3]);
- mat4_to_size( size,cob->matrix);
+ mat4_to_size(size, cob->matrix);
/* to allow compatible rotations, must get both rotations in the order of the owner... */
- mat4_to_eulO( eul, cob->rotOrder,ct->matrix);
- mat4_to_eulO( obeul, cob->rotOrder,cob->matrix);
+ mat4_to_eulO(eul, cob->rotOrder, ct->matrix);
+ mat4_to_eulO(obeul, cob->rotOrder, cob->matrix);
if ((data->flag & ROTLIKE_X)==0)
eul[0] = obeul[0];
@@ -1868,29 +1868,29 @@ static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob, ListBase
{
bSameVolumeConstraint *data= con->data;
+ float volume = data->volume;
+ float fac = 1.0f;
float obsize[3];
- float volume=data->volume;
mat4_to_size(obsize, cob->matrix);
-
+
+ /* calculate normalising scale factor for non-essential values */
+ if (obsize[data->flag] != 0)
+ fac = sqrt(volume / obsize[data->flag]) / obsize[data->flag];
+
+ /* apply scaling factor to the channels not being kept */
switch (data->flag) {
case SAMEVOL_X:
- if (obsize[0]!=0) {
- mul_v3_fl(cob->matrix[1], sqrt(volume/obsize[0])/obsize[0]);
- mul_v3_fl(cob->matrix[2], sqrt(volume/obsize[0])/obsize[0]);
- }
+ mul_v3_fl(cob->matrix[1], fac);
+ mul_v3_fl(cob->matrix[2], fac);
break;
case SAMEVOL_Y:
- if (obsize[1]!=0) {
- mul_v3_fl(cob->matrix[0], sqrt(volume/obsize[1])/obsize[1]);
- mul_v3_fl(cob->matrix[2], sqrt(volume/obsize[1])/obsize[1]);
- }
+ mul_v3_fl(cob->matrix[0], fac);
+ mul_v3_fl(cob->matrix[2], fac);
break;
case SAMEVOL_Z:
- if (obsize[2]!=0) {
- mul_v3_fl(cob->matrix[0], sqrt(volume/obsize[2])/obsize[2]);
- mul_v3_fl(cob->matrix[1], sqrt(volume/obsize[2])/obsize[2]);
- }
+ mul_v3_fl(cob->matrix[0], fac);
+ mul_v3_fl(cob->matrix[1], fac);
break;
}
}
@@ -2770,7 +2770,7 @@ static void stretchto_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
float dist;
/* store scaling before destroying obmat */
- mat4_to_size( size,cob->matrix);
+ mat4_to_size(size, cob->matrix);
/* store X orientation before destroying obmat */
xx[0] = cob->matrix[0][0];
@@ -3353,7 +3353,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
mat4_to_size( dvec,ct->matrix);
break;
case 1: /* rotation (convert to degrees first) */
- mat4_to_eulO( dvec, cob->rotOrder,ct->matrix);
+ mat4_to_eulO(dvec, cob->rotOrder, ct->matrix);
for (i=0; i<3; i++)
dvec[i] = (float)(dvec[i] / M_PI * 180);
break;
@@ -3364,8 +3364,8 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
/* extract components of owner's matrix */
VECCOPY(loc, cob->matrix[3]);
- mat4_to_eulO( eul, cob->rotOrder,cob->matrix);
- mat4_to_size( size,cob->matrix);
+ mat4_to_eulO(eul, cob->rotOrder, cob->matrix);
+ mat4_to_size(size, cob->matrix);
/* determine where in range current transforms lie */
if (data->expo) {
@@ -3485,73 +3485,73 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
float co[3] = {0.0f, 0.0f, 0.0f};
float no[3] = {0.0f, 0.0f, 0.0f};
float dist;
-
+
SpaceTransform transform;
DerivedMesh *target = object_get_derived_final(cob->scene, ct->tar, CD_MASK_BAREMESH);
BVHTreeRayHit hit;
BVHTreeNearest nearest;
-
+
BVHTreeFromMesh treeData;
- memset( &treeData, 0, sizeof(treeData) );
-
+ memset(&treeData, 0, sizeof(treeData));
+
nearest.index = -1;
nearest.dist = FLT_MAX;
-
+
hit.index = -1;
hit.dist = 100000.0f; //TODO should use FLT_MAX.. but normal projection doenst yet supports it
-
+
unit_m4(ct->matrix);
-
+
if(target != NULL)
{
space_transform_from_matrixs(&transform, cob->matrix, ct->tar->obmat);
-
+
switch(scon->shrinkType)
{
case MOD_SHRINKWRAP_NEAREST_SURFACE:
case MOD_SHRINKWRAP_NEAREST_VERTEX:
-
+
if(scon->shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX)
bvhtree_from_mesh_verts(&treeData, target, 0.0, 2, 6);
else
bvhtree_from_mesh_faces(&treeData, target, 0.0, 2, 6);
-
+
if(treeData.tree == NULL)
{
fail = TRUE;
break;
}
-
+
space_transform_apply(&transform, co);
-
+
BLI_bvhtree_find_nearest(treeData.tree, co, &nearest, treeData.nearest_callback, &treeData);
dist = len_v3v3(co, nearest.co);
interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist)/dist); /* linear interpolation */
space_transform_invert(&transform, co);
break;
-
+
case MOD_SHRINKWRAP_PROJECT:
if(scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_X_AXIS) no[0] = 1.0f;
if(scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Y_AXIS) no[1] = 1.0f;
if(scon->projAxis & MOD_SHRINKWRAP_PROJECT_OVER_Z_AXIS) no[2] = 1.0f;
-
+
if(INPR(no,no) < FLT_EPSILON)
{
fail = TRUE;
break;
}
-
+
normalize_v3(no);
-
-
+
+
bvhtree_from_mesh_faces(&treeData, target, scon->dist, 4, 6);
if(treeData.tree == NULL)
{
fail = TRUE;
break;
}
-
+
if(normal_projection_project_vertex(0, co, no, &transform, treeData.tree, &hit, treeData.raycast_callback, &treeData) == FALSE)
{
fail = TRUE;
@@ -3560,17 +3560,17 @@ static void shrinkwrap_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstr
VECCOPY(co, hit.co);
break;
}
-
+
free_bvhtree_from_mesh(&treeData);
-
+
target->release(target);
-
+
if(fail == TRUE)
{
/* Don't move the point */
co[0] = co[1] = co[2] = 0.0f;
}
-
+
/* co is in local object coordinates, change it to global and update target position */
mul_m4_v3(cob->matrix, co);
VECCOPY(ct->matrix[3], co);
@@ -3704,7 +3704,7 @@ static void damptrack_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
/* construct rotation matrix from the axis-angle rotation found above
* - this call takes care to make sure that the axis provided is a unit vector first
*/
- axis_angle_to_mat3( rmat,raxis, rangle);
+ axis_angle_to_mat3(rmat, raxis, rangle);
/* rotate the owner in the way defined by this rotation matrix, then reapply the location since
* we may have destroyed that in the process of multiplying the matrix
@@ -4262,9 +4262,9 @@ void copy_constraints (ListBase *dst, const ListBase *src, int do_extern)
/* perform custom copying operations if needed */
if (cti->copy_data)
cti->copy_data(con, srccon);
-
+
/* for proxies we dont want to make extern */
- if(do_extern) {
+ if (do_extern) {
/* go over used ID-links for this constraint to ensure that they are valid for proxies */
if (cti->id_looper)
cti->id_looper(con, con_extern_cb, NULL);