Blender  V2.93
transform_mode_shear.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stdlib.h>
25 
26 #include "DNA_gpencil_types.h"
27 
28 #include "BLI_math.h"
29 #include "BLI_string.h"
30 
31 #include "BKE_context.h"
32 #include "BKE_unit.h"
33 
34 #include "ED_screen.h"
35 
36 #include "WM_types.h"
37 
38 #include "UI_interface.h"
39 
40 #include "BLT_translation.h"
41 
42 #include "transform.h"
43 #include "transform_mode.h"
44 #include "transform_snap.h"
45 
46 /* -------------------------------------------------------------------- */
51 {
52  float dir[3];
53  bool dir_flip = false;
54  copy_v3_v3(dir, t->spacemtx[t->orient_axis_ortho]);
55 
56  /* Needed for axis aligned view gizmo. */
57  if (t->orient[t->orient_curr].type == V3D_ORIENT_VIEW) {
58  if (t->orient_axis_ortho == 0) {
59  if (t->center2d[1] > t->mouse.imval[1]) {
60  dir_flip = !dir_flip;
61  }
62  }
63  else if (t->orient_axis_ortho == 1) {
64  if (t->center2d[0] > t->mouse.imval[0]) {
65  dir_flip = !dir_flip;
66  }
67  }
68  }
69 
70  /* Without this, half the gizmo handles move in the opposite direction. */
71  if ((t->orient_axis_ortho + 1) % 3 != t->orient_axis) {
72  dir_flip = !dir_flip;
73  }
74 
75  if (dir_flip) {
76  negate_v3(dir);
77  }
78 
79  mul_mat3_m4_v3(t->viewmat, dir);
80  if (normalize_v2(dir) == 0.0f) {
81  dir[0] = 1.0f;
82  }
83  setCustomPointsFromDirection(t, &t->mouse, dir);
84 
86 }
87 
89 {
91 
92  if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
93  /* Use custom.mode.data pointer to signal Shear direction */
94  do {
95  t->orient_axis_ortho = (t->orient_axis_ortho + 1) % 3;
96  } while (t->orient_axis_ortho == t->orient_axis);
97 
99 
100  status = TREDRAW_HARD;
101  }
102  else if (event->type == EVT_XKEY && event->val == KM_PRESS) {
103  t->orient_axis_ortho = (t->orient_axis + 1) % 3;
105 
106  status = TREDRAW_HARD;
107  }
108  else if (event->type == EVT_YKEY && event->val == KM_PRESS) {
109  t->orient_axis_ortho = (t->orient_axis + 2) % 3;
111 
112  status = TREDRAW_HARD;
113  }
114 
115  return status;
116 }
117 
118 static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
119 {
120  float vec[3];
121  float smat[3][3], tmat[3][3], totmat[3][3], axismat[3][3], axismat_inv[3][3];
122  float value;
123  int i;
124  char str[UI_MAX_DRAW_STR];
125  const bool is_local_center = transdata_check_local_center(t, t->around);
126 
127  value = t->values[0];
128 
129  transform_snap_increment(t, &value);
130 
131  applyNumInput(&t->num, &value);
132 
133  t->values_final[0] = value;
134 
135  /* header print for NumInput */
136  if (hasNumInput(&t->num)) {
137  char c[NUM_STR_REP_LEN];
138 
139  outputNumInput(&(t->num), c, &t->scene->unit);
140 
141  BLI_snprintf(str, sizeof(str), TIP_("Shear: %s %s"), c, t->proptext);
142  }
143  else {
144  /* default header print */
146  sizeof(str),
147  TIP_("Shear: %.3f %s (Press X or Y to set shear axis)"),
148  value,
149  t->proptext);
150  }
151 
152  unit_m3(smat);
153  smat[1][0] = value;
154 
155  copy_v3_v3(axismat_inv[0], t->spacemtx[t->orient_axis_ortho]);
156  copy_v3_v3(axismat_inv[2], t->spacemtx[t->orient_axis]);
157  cross_v3_v3v3(axismat_inv[1], axismat_inv[0], axismat_inv[2]);
158  invert_m3_m3(axismat, axismat_inv);
159 
160  mul_m3_series(totmat, axismat_inv, smat, axismat);
161 
163  TransData *td = tc->data;
164  for (i = 0; i < tc->data_len; i++, td++) {
165  const float *center;
166  if (td->flag & TD_SKIP) {
167  continue;
168  }
169 
170  if (t->flag & T_EDIT) {
171  mul_m3_series(tmat, td->smtx, totmat, td->mtx);
172  }
173  else {
174  copy_m3_m3(tmat, totmat);
175  }
176 
177  if (is_local_center) {
178  center = td->center;
179  }
180  else {
181  center = tc->center_local;
182  }
183 
184  sub_v3_v3v3(vec, td->iloc, center);
185  mul_m3_v3(tmat, vec);
186  add_v3_v3(vec, center);
187  sub_v3_v3(vec, td->iloc);
188 
189  if (t->options & CTX_GPENCIL_STROKES) {
190  /* grease pencil multiframe falloff */
191  bGPDstroke *gps = (bGPDstroke *)td->extra;
192  if (gps != NULL) {
193  mul_v3_fl(vec, td->factor * gps->runtime.multi_frame_falloff);
194  }
195  else {
196  mul_v3_fl(vec, td->factor);
197  }
198  }
199  else {
200  mul_v3_fl(vec, td->factor);
201  }
202 
203  add_v3_v3v3(td->loc, td->iloc, vec);
204  }
205  }
206 
207  recalcData(t);
208 
209  ED_area_status_text(t->area, str);
210 }
211 
213 {
214  t->mode = TFM_SHEAR;
215  t->transform = applyShear;
216  t->handleEvent = handleEventShear;
217 
218  if (t->orient_axis == t->orient_axis_ortho) {
219  t->orient_axis = 2;
220  t->orient_axis_ortho = 1;
221  }
222 
224 
225  t->idx_max = 0;
226  t->num.idx_max = 0;
227  t->snap[0] = 0.1f;
228  t->snap[1] = t->snap[0] * 0.1f;
229 
230  copy_v3_fl(t->num.val_inc, t->snap[0]);
231  t->num.unit_sys = t->scene->unit.system;
232  t->num.unit_type[0] = B_UNIT_NONE; /* Don't think we have any unit here? */
233 
234  t->flag |= T_NO_CONSTRAINT;
235 
237 }
@ B_UNIT_NONE
Definition: BKE_unit.h:78
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:89
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:794
bool invert_m3_m3(float R[3][3], const float A[3][3])
Definition: math_matrix.c:1161
#define mul_m3_series(...)
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void negate_v3(float r[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE float normalize_v2(float r[2])
MINLINE void add_v3_v3(float r[3], const float a[3])
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define UNUSED(x)
#define TIP_(msgid)
@ V3D_ORIENT_VIEW
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:102
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:27
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:207
bool hasNumInput(const NumInput *n)
Definition: numinput.c:185
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:815
@ TFM_SHEAR
Definition: ED_transform.h:51
NSNotificationCenter * center
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:90
#define KM_PRESS
Definition: WM_types.h:242
#define str(s)
static unsigned c
Definition: RandGen.cpp:97
float smtx[3][3]
float mtx[3][3]
bGPDstroke_Runtime runtime
short val
Definition: WM_types.h:579
short type
Definition: WM_types.h:577
@ INPUT_CUSTOM_RATIO
Definition: transform.h:739
void recalcData(TransInfo *t)
@ CTX_GPENCIL_STROKES
Definition: transform.h:82
eRedrawFlag
Definition: transform.h:197
@ TREDRAW_NOTHING
Definition: transform.h:198
@ TREDRAW_HARD
Definition: transform.h:199
@ T_NO_CONSTRAINT
Definition: transform.h:106
@ T_EDIT
Definition: transform.h:102
void setCustomPointsFromDirection(TransInfo *t, MouseInput *mi, const float dir[2])
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition: transform.h:813
@ TD_SKIP
bool transdata_check_local_center(TransInfo *t, short around)
void transform_mode_default_modal_orientation_set(TransInfo *t, int type)
transform modes used by different operators.
void initShear(TransInfo *t)
static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
static void initShear_mouseInputMode(TransInfo *t)
static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
bool transform_snap_increment(TransInfo *t, float *r_val)
@ EVT_YKEY
@ EVT_XKEY
@ MIDDLEMOUSE