diff options
Diffstat (limited to 'source/blender/editors/transform/transform_constraints.c')
-rw-r--r-- | source/blender/editors/transform/transform_constraints.c | 130 |
1 files changed, 70 insertions, 60 deletions
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 78d3f213102..09d3a991cc1 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -58,6 +58,10 @@ static void drawObjectConstraint(TransInfo *t); +/* -------------------------------------------------------------------- */ +/** \name Internal Utilities + * \{ */ + static void projection_matrix_calc(const TransInfo *t, float r_pmtx[3][3]) { unit_m3(r_pmtx); @@ -79,7 +83,6 @@ static void projection_matrix_calc(const TransInfo *t, float r_pmtx[3][3]) mul_m3_m3m3(r_pmtx, t->spacemtx, mat); } -/* ************************** CONSTRAINTS ************************* */ #define CONSTRAIN_EPSILON 0.0001f static void constraint_plane_calc(TransInfo *t, float r_plane[4]) @@ -369,14 +372,13 @@ static void planeProjection(const TransInfo *t, const float in[3], float out[3]) add_v3_v3v3(out, in, vec); } -/* +/** * Generic callback for constant spatial constraints applied to linear motion * - * The IN vector in projected into the constrained space and then further + * The `in` vector in projected into the constrained space and then further * projected along the view vector. * (in perspective mode, the view vector is relative to the position on screen) */ - static void applyAxisConstraintVec( TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, const float in[3], float out[3]) { @@ -448,17 +450,16 @@ static void applyAxisConstraintVec( } } -/* +/** * Generic callback for object based spatial constraints applied to linear motion * * At first, the following is applied without orientation * The IN vector in projected into the constrained space and then further * projected along the view vector. - * (in perspective mode, the view vector is relative to the position on screen) + * (in perspective mode, the view vector is relative to the position on screen). * * Further down, that vector is mapped to each data's space. */ - static void applyObjectConstraintVec( TransInfo *t, TransDataContainer *tc, TransData *td, const float in[3], float out[3]) { @@ -478,10 +479,9 @@ static void applyObjectConstraintVec( } } -/* - * Generic callback for constant spatial constraints applied to resize motion +/** + * Generic callback for constant spatial constraints applied to resize motion. */ - static void applyAxisConstraintSize(TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, @@ -505,10 +505,9 @@ static void applyAxisConstraintSize(TransInfo *t, } } -/* - * Callback for object based spatial constraints applied to resize motion +/** + * Callback for object based spatial constraints applied to resize motion. */ - static void applyObjectConstraintSize(TransInfo *t, TransDataContainer *tc, TransData *td, @@ -568,15 +567,15 @@ static void constraints_rotation_imp(TransInfo *t, } } -/* +/** * Generic callback for constant spatial constraints applied to rotations * - * The rotation axis is copied into VEC. + * The rotation axis is copied into `vec`. * * In the case of single axis constraints, the rotation axis is directly the one constrained to. * For planar constraints (2 axis), the rotation axis is the normal of the plane. * - * The following only applies when CON_NOFLIP is not set. + * The following only applies when #CON_NOFLIP is not set. * The vector is then modified to always point away from the screen (in global space) * This insures that the rotation is always logically following the mouse. * (ie: not doing counterclockwise rotations when the mouse moves clockwise). @@ -589,15 +588,15 @@ static void applyAxisConstraintRot( } } -/* +/** * Callback for object based spatial constraints applied to rotations * - * The rotation axis is copied into VEC. + * The rotation axis is copied into `vec`. * * In the case of single axis constraints, the rotation axis is directly the one constrained to. * For planar constraints (2 axis), the rotation axis is the normal of the plane. * - * The following only applies when CON_NOFLIP is not set. + * The following only applies when #CON_NOFLIP is not set. * The vector is then modified to always point away from the screen (in global space) * This insures that the rotation is always logically following the mouse. * (ie: not doing counterclockwise rotations when the mouse moves clockwise). @@ -628,7 +627,11 @@ static void applyObjectConstraintRot( } } -/*--------------------- INTERNAL SETUP CALLS ------------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Internal Setup Calls + * \{ */ void setConstraint(TransInfo *t, int mode, const char text[]) { @@ -663,7 +666,7 @@ void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[]) void setLocalConstraint(TransInfo *t, int mode, const char text[]) { - if (t->flag & T_EDIT) { + if ((t->flag & T_EDIT) || t->data_len_all == 1) { /* Although in edit-mode each object has its local space, use the * orientation of the active object. */ setConstraint(t, mode, text); @@ -673,10 +676,10 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[]) } } -/* +/** * Set the constraint according to the user defined orientation * - * ftext is a format string passed to BLI_snprintf. It will add the name of + * `ftext` is a format string passed to #BLI_snprintf. It will add the name of * the orientation where %s is (logically). */ void setUserConstraint(TransInfo *t, int mode, const char ftext[]) @@ -691,40 +694,35 @@ void setUserConstraint(TransInfo *t, int mode, const char ftext[]) const char *spacename = transform_orientations_spacename_get(t, orientation); BLI_snprintf(text, sizeof(text), ftext, spacename); - if (t->modifiers & (MOD_CONSTRAINT_SELECT | MOD_CONSTRAINT_PLANE)) { - /* Force the orientation of the active object. - * Although possible, it is not convenient to use the local or axis constraint - * with the modifier to select constraint. - * This also follows the convention of older versions. */ - setConstraint(t, mode, text); - } - else { - switch (orientation) { - case V3D_ORIENT_LOCAL: - setLocalConstraint(t, mode, text); - break; - case V3D_ORIENT_NORMAL: - if (checkUseAxisMatrix(t)) { - setAxisMatrixConstraint(t, mode, text); - break; - } - ATTR_FALLTHROUGH; - case V3D_ORIENT_GLOBAL: - case V3D_ORIENT_VIEW: - case V3D_ORIENT_CURSOR: - case V3D_ORIENT_GIMBAL: - case V3D_ORIENT_CUSTOM_MATRIX: - case V3D_ORIENT_CUSTOM: - default: { - setConstraint(t, mode, text); + switch (orientation) { + case V3D_ORIENT_LOCAL: + setLocalConstraint(t, mode, text); + break; + case V3D_ORIENT_NORMAL: + if (checkUseAxisMatrix(t)) { + setAxisMatrixConstraint(t, mode, text); break; } + ATTR_FALLTHROUGH; + case V3D_ORIENT_GLOBAL: + case V3D_ORIENT_VIEW: + case V3D_ORIENT_CURSOR: + case V3D_ORIENT_GIMBAL: + case V3D_ORIENT_CUSTOM_MATRIX: + case V3D_ORIENT_CUSTOM: + default: { + setConstraint(t, mode, text); + break; } } t->con.mode |= CON_USER; } -/*----------------- DRAWING CONSTRAINTS -------------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Drawing Constraints + * \{ */ void drawConstraint(TransInfo *t) { @@ -925,7 +923,11 @@ static void drawObjectConstraint(TransInfo *t) } } -/*--------------------- START / STOP CONSTRAINTS ---------------------- */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Start / Stop Constraints + * \{ */ void startConstraint(TransInfo *t) { @@ -946,7 +948,11 @@ void stopConstraint(TransInfo *t) t->num.idx_max = t->idx_max; } -/*------------------------- MMB Select -------------------------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Middle Mouse Button Select + * \{ */ void initSelectConstraint(TransInfo *t) { @@ -1093,7 +1099,11 @@ void setNearestAxis(TransInfo *t) projection_matrix_calc(t, t->con.pmtx); } -/*-------------- HELPER FUNCTIONS ----------------*/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Helper Functions + * \{ */ int constraintModeToIndex(const TransInfo *t) { @@ -1134,14 +1144,13 @@ bool isLockConstraint(TransInfo *t) return false; } -/* +/** * Returns the dimension of the constraint space. * * For that reason, the flags always needs to be set to properly evaluate here, - * even if they aren't actually used in the callback function. (Which could happen - * for weird constraints not yet designed. Along a path for example.) + * even if they aren't actually used in the callback function. + * (Which could happen for weird constraints not yet designed. Along a path for example.) */ - int getConstraintSpaceDimension(TransInfo *t) { int n = 0; @@ -1159,11 +1168,12 @@ int getConstraintSpaceDimension(TransInfo *t) } return n; - /* - * Someone willing to do it cryptically could do the following instead: + /* Someone willing to do it cryptically could do the following instead: * - * return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2); + * `return t->con & (CON_AXIS0|CON_AXIS1|CON_AXIS2);` * * Based on the assumptions that the axis flags are one after the other and start at 1 */ } + +/** \} */ |