Blender  V2.93
transform_constraints.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "GPU_immediate.h"
#include "GPU_matrix.h"
#include "GPU_state.h"
#include "BLI_math.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "ED_view3d.h"
#include "BLT_translation.h"
#include "UI_resources.h"
#include "transform.h"
#include "transform_orientations.h"
#include "transform_snap.h"
#include "transform_constraints.h"

Go to the source code of this file.

Functions

Drawing Constraints
static void drawObjectConstraint (TransInfo *t)
 
void drawConstraint (TransInfo *t)
 
void drawPropCircle (const struct bContext *C, TransInfo *t)
 
Internal Setup Calls
void setConstraint (TransInfo *t, int mode, const char text[])
 
void setAxisMatrixConstraint (TransInfo *t, int mode, const char text[])
 
void setLocalConstraint (TransInfo *t, int mode, const char text[])
 
void setUserConstraint (TransInfo *t, int mode, const char ftext[])
 
Start / Stop Constraints
void startConstraint (TransInfo *t)
 
void stopConstraint (TransInfo *t)
 
Middle Mouse Button Select
void initSelectConstraint (TransInfo *t)
 
void selectConstraint (TransInfo *t)
 
void postSelectConstraint (TransInfo *t)
 
static void setNearestAxis2d (TransInfo *t)
 
static void setNearestAxis3d (TransInfo *t)
 
void setNearestAxis (TransInfo *t)
 
Helper Functions
int constraintModeToIndex (const TransInfo *t)
 
bool isLockConstraint (TransInfo *t)
 
int getConstraintSpaceDimension (TransInfo *t)
 

Internal Utilities

#define CONSTRAIN_EPSILON   0.0001f
 
static void projection_matrix_calc (const TransInfo *t, float r_pmtx[3][3])
 
static void view_vector_calc (const TransInfo *t, const float focus[3], float r_vec[3])
 
static void constraint_plane_calc (TransInfo *t, float r_plane[4])
 
void constraintNumInput (TransInfo *t, float vec[3])
 
static void viewAxisCorrectCenter (const TransInfo *t, float t_con_center[3])
 
static void axisProjection (const TransInfo *t, const float axis[3], const float in[3], float out[3])
 
static void constraint_snap_plane_to_edge (const TransInfo *t, const float plane[4], float r_out[3])
 
static void UNUSED_FUNCTION (constraint_snap_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3]))
 
void transform_constraint_snap_axis_to_edge (const TransInfo *t, const float axis[3], float r_out[3])
 
void transform_constraint_snap_axis_to_face (const TransInfo *t, const float axis[3], float r_out[3])
 
static bool isPlaneProjectionViewAligned (const TransInfo *t, const float plane[4])
 
static void planeProjection (const TransInfo *t, const float in[3], float out[3])
 
static void applyAxisConstraintVec (TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, const float in[3], float out[3])
 
static void applyObjectConstraintVec (TransInfo *t, TransDataContainer *tc, TransData *td, const float in[3], float out[3])
 
static void applyAxisConstraintSize (TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float smat[3][3])
 
static void applyObjectConstraintSize (TransInfo *t, TransDataContainer *tc, TransData *td, float smat[3][3])
 
static void constraints_rotation_impl (TransInfo *t, const float axismtx[3][3], float r_vec[3], float *r_angle)
 
static void applyAxisConstraintRot (TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float vec[3], float *angle)
 
static void applyObjectConstraintRot (TransInfo *t, TransDataContainer *tc, TransData *td, float vec[3], float *angle)
 

Macro Definition Documentation

◆ CONSTRAIN_EPSILON

#define CONSTRAIN_EPSILON   0.0001f

Definition at line 98 of file transform_constraints.c.

Function Documentation

◆ applyAxisConstraintRot()

static void applyAxisConstraintRot ( TransInfo t,
TransDataContainer UNUSEDtc,
TransData td,
float  vec[3],
float angle 
)
static

Generic callback for constant spatial constraints applied to rotations

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 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).

Definition at line 598 of file transform_constraints.c.

References angle(), CON_APPLY, constraints_rotation_impl(), and t.

Referenced by setConstraint().

◆ applyAxisConstraintSize()

static void applyAxisConstraintSize ( TransInfo t,
TransDataContainer UNUSEDtc,
TransData td,
float  smat[3][3] 
)
static

Generic callback for constant spatial constraints applied to resize motion.

Definition at line 497 of file transform_constraints.c.

References CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, mul_m3_m3m3(), and t.

Referenced by setConstraint().

◆ applyAxisConstraintVec()

static void applyAxisConstraintVec ( TransInfo t,
TransDataContainer UNUSEDtc,
TransData td,
const float  in[3],
float  out[3] 
)
static

Generic callback for constant spatial constraints applied to linear motion

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)

Definition at line 394 of file transform_constraints.c.

References activeSnap(), axisProjection(), BLI_assert, Freestyle::c, CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, constraint_plane_calc(), constraint_snap_plane_to_edge(), copy_v3_v3(), getConstraintSpaceDimension(), is_zero_v3(), isPlaneProjectionViewAligned(), mul_m3_v3(), planeProjection(), SCE_SNAP_MODE_EDGE, SCE_SNAP_MODE_FACE, SCE_SNAP_MODE_GRID, t, transform_constraint_snap_axis_to_edge(), transform_constraint_snap_axis_to_face(), and validSnap().

Referenced by applyObjectConstraintVec(), and setConstraint().

◆ applyObjectConstraintRot()

static void applyObjectConstraintRot ( TransInfo t,
TransDataContainer tc,
TransData td,
float  vec[3],
float angle 
)
static

Callback for object based spatial constraints applied to rotations

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 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).

Definition at line 619 of file transform_constraints.c.

References angle(), TransData::axismtx, BLI_assert, CON_APPLY, constraints_rotation_impl(), TransDataContainer::data, float(), TransDataContainer::mat3_unit, mul_m3_m3m3(), NULL, t, T_EDIT, and TRANS_DATA_CONTAINER_FIRST_OK.

Referenced by setAxisMatrixConstraint().

◆ applyObjectConstraintSize()

static void applyObjectConstraintSize ( TransInfo t,
TransDataContainer tc,
TransData td,
float  smat[3][3] 
)
static

Callback for object based spatial constraints applied to resize motion.

Definition at line 523 of file transform_constraints.c.

References TransData::axismtx, CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, invert_m3_m3(), TransDataContainer::mat3_unit, mul_m3_m3m3(), t, and T_EDIT.

Referenced by setAxisMatrixConstraint().

◆ applyObjectConstraintVec()

static void applyObjectConstraintVec ( TransInfo t,
TransDataContainer tc,
TransData td,
const float  in[3],
float  out[3] 
)
static

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).

Further down, that vector is mapped to each data's space.

Definition at line 475 of file transform_constraints.c.

References applyAxisConstraintVec(), TransData::axismtx, CON_APPLY, copy_v3_v3(), TransDataContainer::mat3_unit, mul_m3_v3(), t, and T_EDIT.

Referenced by setAxisMatrixConstraint().

◆ axisProjection()

static void axisProjection ( const TransInfo t,
const float  axis[3],
const float  in[3],
float  out[3] 
)
static

◆ constraint_plane_calc()

static void constraint_plane_calc ( TransInfo t,
float  r_plane[4] 
)
static

Definition at line 100 of file transform_constraints.c.

References BLI_assert, CON_AXIS0, cross_v3_v3v3(), dot_v3v3(), normalize_v3(), and t.

Referenced by applyAxisConstraintVec().

◆ constraint_snap_plane_to_edge()

static void constraint_snap_plane_to_edge ( const TransInfo t,
const float  plane[4],
float  r_out[3] 
)
static

Snap to the intersection between the edge direction and the constraint plane.

Definition at line 286 of file transform_constraints.c.

References CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_ray_plane_v3(), madd_v3_v3v3fl(), sub_v3_v3(), and t.

Referenced by applyAxisConstraintVec().

◆ constraintModeToIndex()

int constraintModeToIndex ( const TransInfo t)

Definition at line 1121 of file transform_constraints.c.

References CON_APPLY, CON_AXIS0, CON_AXIS1, CON_AXIS2, and t.

Referenced by saveTransform().

◆ constraintNumInput()

void constraintNumInput ( TransInfo t,
float  vec[3] 
)

◆ constraints_rotation_impl()

static void constraints_rotation_impl ( TransInfo t,
const float  axismtx[3][3],
float  r_vec[3],
float r_angle 
)
static

◆ drawConstraint()

void drawConstraint ( TransInfo t)

◆ drawObjectConstraint()

static void drawObjectConstraint ( TransInfo t)
static

◆ drawPropCircle()

void drawPropCircle ( const struct bContext C,
TransInfo t 
)

◆ getConstraintSpaceDimension()

int getConstraintSpaceDimension ( TransInfo t)

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.)

Definition at line 1167 of file transform_constraints.c.

References CON_AXIS0, CON_AXIS1, CON_AXIS2, and t.

Referenced by applyAxisConstraintVec(), constraintNumInput(), and startConstraint().

◆ initSelectConstraint()

void initSelectConstraint ( TransInfo t)

◆ isLockConstraint()

bool isLockConstraint ( TransInfo t)

Definition at line 1141 of file transform_constraints.c.

References CON_AXIS0, CON_AXIS1, CON_AXIS2, and t.

Referenced by applyPushPull().

◆ isPlaneProjectionViewAligned()

static bool isPlaneProjectionViewAligned ( const TransInfo t,
const float  plane[4] 
)
static

Return true if the 2x axis are both aligned when projected into the view. In this case, we can't usefully project the cursor onto the plane.

Definition at line 356 of file transform_constraints.c.

References dot_v3v3(), eps, fabsf, t, and view_vector_calc().

Referenced by applyAxisConstraintVec().

◆ planeProjection()

static void planeProjection ( const TransInfo t,
const float  in[3],
float  out[3] 
)
static

◆ postSelectConstraint()

void postSelectConstraint ( TransInfo t)

◆ projection_matrix_calc()

static void projection_matrix_calc ( const TransInfo t,
float  r_pmtx[3][3] 
)
static

◆ selectConstraint()

void selectConstraint ( TransInfo t)

Definition at line 980 of file transform_constraints.c.

References CON_SELECT, setNearestAxis(), startConstraint(), and t.

Referenced by transformApply().

◆ setAxisMatrixConstraint()

void setAxisMatrixConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

◆ setConstraint()

void setConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

◆ setLocalConstraint()

void setLocalConstraint ( TransInfo t,
int  mode,
const char  text[] 
)

Definition at line 682 of file transform_constraints.c.

References setAxisMatrixConstraint(), setConstraint(), t, and T_EDIT.

Referenced by setUserConstraint(), and transformEvent().

◆ setNearestAxis()

void setNearestAxis ( TransInfo t)

◆ setNearestAxis2d()

static void setNearestAxis2d ( TransInfo t)
static

Definition at line 1005 of file transform_constraints.c.

References abs(), BLI_strncpy(), CON_AXIS0, CON_AXIS1, t, and TIP_.

Referenced by setNearestAxis().

◆ setNearestAxis3d()

static void setNearestAxis3d ( TransInfo t)
static

◆ setUserConstraint()

void setUserConstraint ( TransInfo t,
int  mode,
const char  ftext[] 
)

◆ startConstraint()

void startConstraint ( TransInfo t)

◆ stopConstraint()

void stopConstraint ( TransInfo t)

◆ transform_constraint_snap_axis_to_edge()

void transform_constraint_snap_axis_to_edge ( const TransInfo t,
const float  axis[3],
float  r_out[3] 
)

Snap to the nearest point on the axis to the edge/line element.

Definition at line 320 of file transform_constraints.c.

References CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_ray_ray_v3(), mul_v3_v3fl(), NULL, and t.

Referenced by applyAxisConstraintVec(), edge_slide_snap_apply(), and vert_slide_snap_apply().

◆ transform_constraint_snap_axis_to_face()

void transform_constraint_snap_axis_to_face ( const TransInfo t,
const float  axis[3],
float  r_out[3] 
)

Snap to the intersection of the axis and the plane defined by the face.

Definition at line 337 of file transform_constraints.c.

References CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_ray_plane_v3(), mul_v3_v3fl(), plane_from_point_normal_v3(), and t.

Referenced by applyAxisConstraintVec(), edge_slide_snap_apply(), and vert_slide_snap_apply().

◆ UNUSED_FUNCTION()

static void UNUSED_FUNCTION ( constraint_snap_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3])  )
static

Snap to the nearest point between the snap point and the line that intersects the face plane with the constraint plane.

Definition at line 302 of file transform_constraints.c.

References closest_to_ray_v3(), CONSTRAIN_EPSILON, dot_v3v3(), fabsf, blender::tests::is_aligned(), isect_plane_plane_v3(), plane_from_point_normal_v3(), sub_v3_v3(), and t.

◆ view_vector_calc()

static void view_vector_calc ( const TransInfo t,
const float  focus[3],
float  r_vec[3] 
)
static

◆ viewAxisCorrectCenter()

static void viewAxisCorrectCenter ( const TransInfo t,
float  t_con_center[3] 
)
static