Transform: map mouse input to shear direction
This commit is contained in:
@@ -3341,13 +3341,42 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2]))
|
||||
/** \name Transform Shear
|
||||
* \{ */
|
||||
|
||||
static void initShear_mouseInputMode(TransInfo *t)
|
||||
{
|
||||
float dir[3];
|
||||
|
||||
if (t->custom.mode.data == NULL) {
|
||||
copy_v3_v3(dir, t->axis_ortho);
|
||||
}
|
||||
else {
|
||||
cross_v3_v3v3(dir, t->axis_ortho, t->axis);
|
||||
}
|
||||
|
||||
mul_mat3_m4_v3(t->viewmat, dir);
|
||||
if (normalize_v2(dir) == 0.0f) {
|
||||
dir[0] = 1.0f;
|
||||
}
|
||||
setCustomPointsFromDirection(t, &t->mouse, dir);
|
||||
|
||||
initMouseInputMode(t, &t->mouse, INPUT_CUSTOM_RATIO);
|
||||
}
|
||||
|
||||
static void initShear(TransInfo *t)
|
||||
{
|
||||
t->mode = TFM_SHEAR;
|
||||
t->transform = applyShear;
|
||||
t->handleEvent = handleEventShear;
|
||||
|
||||
initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
|
||||
if (is_zero_v3(t->axis)) {
|
||||
negate_v3_v3(t->axis, t->viewinv[2]);
|
||||
normalize_v3(t->axis);
|
||||
}
|
||||
if (is_zero_v3(t->axis_ortho)) {
|
||||
copy_v3_v3(t->axis_ortho, t->viewinv[0]);
|
||||
normalize_v3(t->axis_ortho);
|
||||
}
|
||||
|
||||
initShear_mouseInputMode(t);
|
||||
|
||||
t->idx_max = 0;
|
||||
t->num.idx_max = 0;
|
||||
@@ -3360,15 +3389,6 @@ static void initShear(TransInfo *t)
|
||||
t->num.unit_type[0] = B_UNIT_NONE; /* Don't think we have any unit here? */
|
||||
|
||||
t->flag |= T_NO_CONSTRAINT;
|
||||
|
||||
if (is_zero_v3(t->axis)) {
|
||||
negate_v3_v3(t->axis, t->viewinv[2]);
|
||||
normalize_v3(t->axis);
|
||||
}
|
||||
if (is_zero_v3(t->axis_ortho)) {
|
||||
copy_v3_v3(t->axis_ortho, t->viewinv[0]);
|
||||
normalize_v3(t->axis_ortho);
|
||||
}
|
||||
}
|
||||
|
||||
static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
|
||||
@@ -3378,25 +3398,24 @@ static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
|
||||
if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
|
||||
/* Use custom.mode.data pointer to signal Shear direction */
|
||||
if (t->custom.mode.data == NULL) {
|
||||
initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_RATIO);
|
||||
t->custom.mode.data = (void *)1;
|
||||
}
|
||||
else {
|
||||
initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
|
||||
t->custom.mode.data = NULL;
|
||||
}
|
||||
initShear_mouseInputMode(t);
|
||||
|
||||
status = TREDRAW_HARD;
|
||||
}
|
||||
else if (event->type == XKEY && event->val == KM_PRESS) {
|
||||
initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
|
||||
t->custom.mode.data = NULL;
|
||||
initShear_mouseInputMode(t);
|
||||
|
||||
status = TREDRAW_HARD;
|
||||
}
|
||||
else if (event->type == YKEY && event->val == KM_PRESS) {
|
||||
initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_RATIO);
|
||||
t->custom.mode.data = (void *)1;
|
||||
initShear_mouseInputMode(t);
|
||||
|
||||
status = TREDRAW_HARD;
|
||||
}
|
||||
|
||||
@@ -825,6 +825,7 @@ eRedrawFlag handleMouseInput(struct TransInfo *t, struct MouseInput *mi, const s
|
||||
void applyMouseInput(struct TransInfo *t, struct MouseInput *mi, const int mval[2], float output[3]);
|
||||
|
||||
void setCustomPoints(TransInfo *t, MouseInput *mi, const int start[2], const int end[2]);
|
||||
void setCustomPointsFromDirection(TransInfo *t, MouseInput *mi, const float dir[2]);
|
||||
void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float values[3]));
|
||||
|
||||
/*********************** Generics ********************************/
|
||||
|
||||
@@ -137,6 +137,18 @@ void setCustomPoints(TransInfo *UNUSED(t), MouseInput *mi, const int mval_start[
|
||||
data[3] = mval_end[1];
|
||||
}
|
||||
|
||||
void setCustomPointsFromDirection(TransInfo *t, MouseInput *mi, const float dir[2])
|
||||
{
|
||||
BLI_ASSERT_UNIT_V2(dir);
|
||||
const int win_axis = t->ar ? ((abs(t->ar->winx * dir[0]) + abs(t->ar->winy * dir[1])) / 2) : 1;
|
||||
const int mval_start[2] = {
|
||||
mi->imval[0] + dir[0] * win_axis,
|
||||
mi->imval[1] + dir[1] * win_axis,
|
||||
};
|
||||
const int mval_end[2] = {mi->imval[0], mi->imval[1]};
|
||||
setCustomPoints(t, mi, mval_start, mval_end);
|
||||
}
|
||||
|
||||
static void InputCustomRatioFlip(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3])
|
||||
{
|
||||
double length;
|
||||
|
||||
Reference in New Issue
Block a user